compiler-core.esm-bundler.js 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699
  1. import { isString, hyphenate, NOOP, extend, isObject, NO, isArray, makeMap, isSymbol, capitalize, camelize, EMPTY_OBJ, PatchFlagNames, slotFlagsText, isOn, isBuiltInDirective, isReservedProp, toHandlerKey } from '@vue/shared';
  2. export { generateCodeFrame } from '@vue/shared';
  3. function defaultOnError(error) {
  4. throw error;
  5. }
  6. function defaultOnWarn(msg) {
  7. !!(process.env.NODE_ENV !== "production") && console.warn(`[Vue warn] ${msg.message}`);
  8. }
  9. function createCompilerError(code, loc, messages, additionalMessage) {
  10. const msg = !!(process.env.NODE_ENV !== "production") || false ? (messages || errorMessages)[code] + (additionalMessage || ``) : code;
  11. const error = new SyntaxError(String(msg));
  12. error.code = code;
  13. error.loc = loc;
  14. return error;
  15. }
  16. const errorMessages = {
  17. // parse errors
  18. [0]: "Illegal comment.",
  19. [1]: "CDATA section is allowed only in XML context.",
  20. [2]: "Duplicate attribute.",
  21. [3]: "End tag cannot have attributes.",
  22. [4]: "Illegal '/' in tags.",
  23. [5]: "Unexpected EOF in tag.",
  24. [6]: "Unexpected EOF in CDATA section.",
  25. [7]: "Unexpected EOF in comment.",
  26. [8]: "Unexpected EOF in script.",
  27. [9]: "Unexpected EOF in tag.",
  28. [10]: "Incorrectly closed comment.",
  29. [11]: "Incorrectly opened comment.",
  30. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  31. [13]: "Attribute value was expected.",
  32. [14]: "End tag name was expected.",
  33. [15]: "Whitespace was expected.",
  34. [16]: "Unexpected '<!--' in comment.",
  35. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  36. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  37. [19]: "Attribute name cannot start with '='.",
  38. [21]: "'<?' is allowed only in XML context.",
  39. [20]: `Unexpected null character.`,
  40. [22]: "Illegal '/' in tags.",
  41. // Vue-specific parse errors
  42. [23]: "Invalid end tag.",
  43. [24]: "Element is missing end tag.",
  44. [25]: "Interpolation end sign was not found.",
  45. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  46. [26]: "Legal directive name was expected.",
  47. // transform errors
  48. [28]: `v-if/v-else-if is missing expression.`,
  49. [29]: `v-if/else branches must use unique keys.`,
  50. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  51. [31]: `v-for is missing expression.`,
  52. [32]: `v-for has invalid expression.`,
  53. [33]: `<template v-for> key should be placed on the <template> tag.`,
  54. [34]: `v-bind is missing expression.`,
  55. [35]: `v-on is missing expression.`,
  56. [36]: `Unexpected custom directive on <slot> outlet.`,
  57. [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
  58. [38]: `Duplicate slot names found. `,
  59. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  60. [40]: `v-slot can only be used on components or <template> tags.`,
  61. [41]: `v-model is missing expression.`,
  62. [42]: `v-model value must be a valid JavaScript member expression.`,
  63. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  64. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  65. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  66. [45]: `Error parsing JavaScript expression: `,
  67. [46]: `<KeepAlive> expects exactly one child component.`,
  68. // generic errors
  69. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  70. [48]: `ES module mode is not supported in this build of compiler.`,
  71. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  72. [50]: `"scopeId" option is only supported in module mode.`,
  73. // deprecations
  74. [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
  75. [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
  76. // just to fulfill types
  77. [53]: ``
  78. };
  79. const FRAGMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Fragment` : ``);
  80. const TELEPORT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Teleport` : ``);
  81. const SUSPENSE = Symbol(!!(process.env.NODE_ENV !== "production") ? `Suspense` : ``);
  82. const KEEP_ALIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `KeepAlive` : ``);
  83. const BASE_TRANSITION = Symbol(!!(process.env.NODE_ENV !== "production") ? `BaseTransition` : ``);
  84. const OPEN_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `openBlock` : ``);
  85. const CREATE_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createBlock` : ``);
  86. const CREATE_ELEMENT_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createElementBlock` : ``);
  87. const CREATE_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createVNode` : ``);
  88. const CREATE_ELEMENT_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createElementVNode` : ``);
  89. const CREATE_COMMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `createCommentVNode` : ``);
  90. const CREATE_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? `createTextVNode` : ``);
  91. const CREATE_STATIC = Symbol(!!(process.env.NODE_ENV !== "production") ? `createStaticVNode` : ``);
  92. const RESOLVE_COMPONENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveComponent` : ``);
  93. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  94. !!(process.env.NODE_ENV !== "production") ? `resolveDynamicComponent` : ``
  95. );
  96. const RESOLVE_DIRECTIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveDirective` : ``);
  97. const RESOLVE_FILTER = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveFilter` : ``);
  98. const WITH_DIRECTIVES = Symbol(!!(process.env.NODE_ENV !== "production") ? `withDirectives` : ``);
  99. const RENDER_LIST = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderList` : ``);
  100. const RENDER_SLOT = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderSlot` : ``);
  101. const CREATE_SLOTS = Symbol(!!(process.env.NODE_ENV !== "production") ? `createSlots` : ``);
  102. const TO_DISPLAY_STRING = Symbol(!!(process.env.NODE_ENV !== "production") ? `toDisplayString` : ``);
  103. const MERGE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `mergeProps` : ``);
  104. const NORMALIZE_CLASS = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeClass` : ``);
  105. const NORMALIZE_STYLE = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeStyle` : ``);
  106. const NORMALIZE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeProps` : ``);
  107. const GUARD_REACTIVE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `guardReactiveProps` : ``);
  108. const TO_HANDLERS = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlers` : ``);
  109. const CAMELIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `camelize` : ``);
  110. const CAPITALIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `capitalize` : ``);
  111. const TO_HANDLER_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlerKey` : ``);
  112. const SET_BLOCK_TRACKING = Symbol(!!(process.env.NODE_ENV !== "production") ? `setBlockTracking` : ``);
  113. const PUSH_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `pushScopeId` : ``);
  114. const POP_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `popScopeId` : ``);
  115. const WITH_CTX = Symbol(!!(process.env.NODE_ENV !== "production") ? `withCtx` : ``);
  116. const UNREF = Symbol(!!(process.env.NODE_ENV !== "production") ? `unref` : ``);
  117. const IS_REF = Symbol(!!(process.env.NODE_ENV !== "production") ? `isRef` : ``);
  118. const WITH_MEMO = Symbol(!!(process.env.NODE_ENV !== "production") ? `withMemo` : ``);
  119. const IS_MEMO_SAME = Symbol(!!(process.env.NODE_ENV !== "production") ? `isMemoSame` : ``);
  120. const helperNameMap = {
  121. [FRAGMENT]: `Fragment`,
  122. [TELEPORT]: `Teleport`,
  123. [SUSPENSE]: `Suspense`,
  124. [KEEP_ALIVE]: `KeepAlive`,
  125. [BASE_TRANSITION]: `BaseTransition`,
  126. [OPEN_BLOCK]: `openBlock`,
  127. [CREATE_BLOCK]: `createBlock`,
  128. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  129. [CREATE_VNODE]: `createVNode`,
  130. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  131. [CREATE_COMMENT]: `createCommentVNode`,
  132. [CREATE_TEXT]: `createTextVNode`,
  133. [CREATE_STATIC]: `createStaticVNode`,
  134. [RESOLVE_COMPONENT]: `resolveComponent`,
  135. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  136. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  137. [RESOLVE_FILTER]: `resolveFilter`,
  138. [WITH_DIRECTIVES]: `withDirectives`,
  139. [RENDER_LIST]: `renderList`,
  140. [RENDER_SLOT]: `renderSlot`,
  141. [CREATE_SLOTS]: `createSlots`,
  142. [TO_DISPLAY_STRING]: `toDisplayString`,
  143. [MERGE_PROPS]: `mergeProps`,
  144. [NORMALIZE_CLASS]: `normalizeClass`,
  145. [NORMALIZE_STYLE]: `normalizeStyle`,
  146. [NORMALIZE_PROPS]: `normalizeProps`,
  147. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  148. [TO_HANDLERS]: `toHandlers`,
  149. [CAMELIZE]: `camelize`,
  150. [CAPITALIZE]: `capitalize`,
  151. [TO_HANDLER_KEY]: `toHandlerKey`,
  152. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  153. [PUSH_SCOPE_ID]: `pushScopeId`,
  154. [POP_SCOPE_ID]: `popScopeId`,
  155. [WITH_CTX]: `withCtx`,
  156. [UNREF]: `unref`,
  157. [IS_REF]: `isRef`,
  158. [WITH_MEMO]: `withMemo`,
  159. [IS_MEMO_SAME]: `isMemoSame`
  160. };
  161. function registerRuntimeHelpers(helpers) {
  162. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  163. helperNameMap[s] = helpers[s];
  164. });
  165. }
  166. const locStub = {
  167. source: "",
  168. start: { line: 1, column: 1, offset: 0 },
  169. end: { line: 1, column: 1, offset: 0 }
  170. };
  171. function createRoot(children, loc = locStub) {
  172. return {
  173. type: 0,
  174. children,
  175. helpers: /* @__PURE__ */ new Set(),
  176. components: [],
  177. directives: [],
  178. hoists: [],
  179. imports: [],
  180. cached: 0,
  181. temps: 0,
  182. codegenNode: void 0,
  183. loc
  184. };
  185. }
  186. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  187. if (context) {
  188. if (isBlock) {
  189. context.helper(OPEN_BLOCK);
  190. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  191. } else {
  192. context.helper(getVNodeHelper(context.inSSR, isComponent));
  193. }
  194. if (directives) {
  195. context.helper(WITH_DIRECTIVES);
  196. }
  197. }
  198. return {
  199. type: 13,
  200. tag,
  201. props,
  202. children,
  203. patchFlag,
  204. dynamicProps,
  205. directives,
  206. isBlock,
  207. disableTracking,
  208. isComponent,
  209. loc
  210. };
  211. }
  212. function createArrayExpression(elements, loc = locStub) {
  213. return {
  214. type: 17,
  215. loc,
  216. elements
  217. };
  218. }
  219. function createObjectExpression(properties, loc = locStub) {
  220. return {
  221. type: 15,
  222. loc,
  223. properties
  224. };
  225. }
  226. function createObjectProperty(key, value) {
  227. return {
  228. type: 16,
  229. loc: locStub,
  230. key: isString(key) ? createSimpleExpression(key, true) : key,
  231. value
  232. };
  233. }
  234. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  235. return {
  236. type: 4,
  237. loc,
  238. content,
  239. isStatic,
  240. constType: isStatic ? 3 : constType
  241. };
  242. }
  243. function createInterpolation(content, loc) {
  244. return {
  245. type: 5,
  246. loc,
  247. content: isString(content) ? createSimpleExpression(content, false, loc) : content
  248. };
  249. }
  250. function createCompoundExpression(children, loc = locStub) {
  251. return {
  252. type: 8,
  253. loc,
  254. children
  255. };
  256. }
  257. function createCallExpression(callee, args = [], loc = locStub) {
  258. return {
  259. type: 14,
  260. loc,
  261. callee,
  262. arguments: args
  263. };
  264. }
  265. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  266. return {
  267. type: 18,
  268. params,
  269. returns,
  270. newline,
  271. isSlot,
  272. loc
  273. };
  274. }
  275. function createConditionalExpression(test, consequent, alternate, newline = true) {
  276. return {
  277. type: 19,
  278. test,
  279. consequent,
  280. alternate,
  281. newline,
  282. loc: locStub
  283. };
  284. }
  285. function createCacheExpression(index, value, isVNode = false) {
  286. return {
  287. type: 20,
  288. index,
  289. value,
  290. isVNode,
  291. loc: locStub
  292. };
  293. }
  294. function createBlockStatement(body) {
  295. return {
  296. type: 21,
  297. body,
  298. loc: locStub
  299. };
  300. }
  301. function createTemplateLiteral(elements) {
  302. return {
  303. type: 22,
  304. elements,
  305. loc: locStub
  306. };
  307. }
  308. function createIfStatement(test, consequent, alternate) {
  309. return {
  310. type: 23,
  311. test,
  312. consequent,
  313. alternate,
  314. loc: locStub
  315. };
  316. }
  317. function createAssignmentExpression(left, right) {
  318. return {
  319. type: 24,
  320. left,
  321. right,
  322. loc: locStub
  323. };
  324. }
  325. function createSequenceExpression(expressions) {
  326. return {
  327. type: 25,
  328. expressions,
  329. loc: locStub
  330. };
  331. }
  332. function createReturnStatement(returns) {
  333. return {
  334. type: 26,
  335. returns,
  336. loc: locStub
  337. };
  338. }
  339. function getVNodeHelper(ssr, isComponent) {
  340. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  341. }
  342. function getVNodeBlockHelper(ssr, isComponent) {
  343. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  344. }
  345. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  346. if (!node.isBlock) {
  347. node.isBlock = true;
  348. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  349. helper(OPEN_BLOCK);
  350. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  351. }
  352. }
  353. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  354. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  355. function isCoreComponent(tag) {
  356. if (isBuiltInType(tag, "Teleport")) {
  357. return TELEPORT;
  358. } else if (isBuiltInType(tag, "Suspense")) {
  359. return SUSPENSE;
  360. } else if (isBuiltInType(tag, "KeepAlive")) {
  361. return KEEP_ALIVE;
  362. } else if (isBuiltInType(tag, "BaseTransition")) {
  363. return BASE_TRANSITION;
  364. }
  365. }
  366. const nonIdentifierRE = /^\d|[^\$\w]/;
  367. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  368. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  369. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  370. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  371. const isMemberExpressionBrowser = (path) => {
  372. path = path.trim().replace(whitespaceRE, (s) => s.trim());
  373. let state = 0 /* inMemberExp */;
  374. let stateStack = [];
  375. let currentOpenBracketCount = 0;
  376. let currentOpenParensCount = 0;
  377. let currentStringType = null;
  378. for (let i = 0; i < path.length; i++) {
  379. const char = path.charAt(i);
  380. switch (state) {
  381. case 0 /* inMemberExp */:
  382. if (char === "[") {
  383. stateStack.push(state);
  384. state = 1 /* inBrackets */;
  385. currentOpenBracketCount++;
  386. } else if (char === "(") {
  387. stateStack.push(state);
  388. state = 2 /* inParens */;
  389. currentOpenParensCount++;
  390. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  391. return false;
  392. }
  393. break;
  394. case 1 /* inBrackets */:
  395. if (char === `'` || char === `"` || char === "`") {
  396. stateStack.push(state);
  397. state = 3 /* inString */;
  398. currentStringType = char;
  399. } else if (char === `[`) {
  400. currentOpenBracketCount++;
  401. } else if (char === `]`) {
  402. if (!--currentOpenBracketCount) {
  403. state = stateStack.pop();
  404. }
  405. }
  406. break;
  407. case 2 /* inParens */:
  408. if (char === `'` || char === `"` || char === "`") {
  409. stateStack.push(state);
  410. state = 3 /* inString */;
  411. currentStringType = char;
  412. } else if (char === `(`) {
  413. currentOpenParensCount++;
  414. } else if (char === `)`) {
  415. if (i === path.length - 1) {
  416. return false;
  417. }
  418. if (!--currentOpenParensCount) {
  419. state = stateStack.pop();
  420. }
  421. }
  422. break;
  423. case 3 /* inString */:
  424. if (char === currentStringType) {
  425. state = stateStack.pop();
  426. currentStringType = null;
  427. }
  428. break;
  429. }
  430. }
  431. return !currentOpenBracketCount && !currentOpenParensCount;
  432. };
  433. const isMemberExpressionNode = NOOP ;
  434. const isMemberExpression = isMemberExpressionBrowser ;
  435. function getInnerRange(loc, offset, length) {
  436. const source = loc.source.slice(offset, offset + length);
  437. const newLoc = {
  438. source,
  439. start: advancePositionWithClone(loc.start, loc.source, offset),
  440. end: loc.end
  441. };
  442. if (length != null) {
  443. newLoc.end = advancePositionWithClone(
  444. loc.start,
  445. loc.source,
  446. offset + length
  447. );
  448. }
  449. return newLoc;
  450. }
  451. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  452. return advancePositionWithMutation(
  453. extend({}, pos),
  454. source,
  455. numberOfCharacters
  456. );
  457. }
  458. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  459. let linesCount = 0;
  460. let lastNewLinePos = -1;
  461. for (let i = 0; i < numberOfCharacters; i++) {
  462. if (source.charCodeAt(i) === 10) {
  463. linesCount++;
  464. lastNewLinePos = i;
  465. }
  466. }
  467. pos.offset += numberOfCharacters;
  468. pos.line += linesCount;
  469. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  470. return pos;
  471. }
  472. function assert(condition, msg) {
  473. if (!condition) {
  474. throw new Error(msg || `unexpected compiler condition`);
  475. }
  476. }
  477. function findDir(node, name, allowEmpty = false) {
  478. for (let i = 0; i < node.props.length; i++) {
  479. const p = node.props[i];
  480. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  481. return p;
  482. }
  483. }
  484. }
  485. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  486. for (let i = 0; i < node.props.length; i++) {
  487. const p = node.props[i];
  488. if (p.type === 6) {
  489. if (dynamicOnly)
  490. continue;
  491. if (p.name === name && (p.value || allowEmpty)) {
  492. return p;
  493. }
  494. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  495. return p;
  496. }
  497. }
  498. }
  499. function isStaticArgOf(arg, name) {
  500. return !!(arg && isStaticExp(arg) && arg.content === name);
  501. }
  502. function hasDynamicKeyVBind(node) {
  503. return node.props.some(
  504. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  505. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  506. !p.arg.isStatic)
  507. // v-bind:[foo]
  508. );
  509. }
  510. function isText$1(node) {
  511. return node.type === 5 || node.type === 2;
  512. }
  513. function isVSlot(p) {
  514. return p.type === 7 && p.name === "slot";
  515. }
  516. function isTemplateNode(node) {
  517. return node.type === 1 && node.tagType === 3;
  518. }
  519. function isSlotOutlet(node) {
  520. return node.type === 1 && node.tagType === 2;
  521. }
  522. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  523. function getUnnormalizedProps(props, callPath = []) {
  524. if (props && !isString(props) && props.type === 14) {
  525. const callee = props.callee;
  526. if (!isString(callee) && propsHelperSet.has(callee)) {
  527. return getUnnormalizedProps(
  528. props.arguments[0],
  529. callPath.concat(props)
  530. );
  531. }
  532. }
  533. return [props, callPath];
  534. }
  535. function injectProp(node, prop, context) {
  536. let propsWithInjection;
  537. let props = node.type === 13 ? node.props : node.arguments[2];
  538. let callPath = [];
  539. let parentCall;
  540. if (props && !isString(props) && props.type === 14) {
  541. const ret = getUnnormalizedProps(props);
  542. props = ret[0];
  543. callPath = ret[1];
  544. parentCall = callPath[callPath.length - 1];
  545. }
  546. if (props == null || isString(props)) {
  547. propsWithInjection = createObjectExpression([prop]);
  548. } else if (props.type === 14) {
  549. const first = props.arguments[0];
  550. if (!isString(first) && first.type === 15) {
  551. if (!hasProp(prop, first)) {
  552. first.properties.unshift(prop);
  553. }
  554. } else {
  555. if (props.callee === TO_HANDLERS) {
  556. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  557. createObjectExpression([prop]),
  558. props
  559. ]);
  560. } else {
  561. props.arguments.unshift(createObjectExpression([prop]));
  562. }
  563. }
  564. !propsWithInjection && (propsWithInjection = props);
  565. } else if (props.type === 15) {
  566. if (!hasProp(prop, props)) {
  567. props.properties.unshift(prop);
  568. }
  569. propsWithInjection = props;
  570. } else {
  571. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  572. createObjectExpression([prop]),
  573. props
  574. ]);
  575. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  576. parentCall = callPath[callPath.length - 2];
  577. }
  578. }
  579. if (node.type === 13) {
  580. if (parentCall) {
  581. parentCall.arguments[0] = propsWithInjection;
  582. } else {
  583. node.props = propsWithInjection;
  584. }
  585. } else {
  586. if (parentCall) {
  587. parentCall.arguments[0] = propsWithInjection;
  588. } else {
  589. node.arguments[2] = propsWithInjection;
  590. }
  591. }
  592. }
  593. function hasProp(prop, props) {
  594. let result = false;
  595. if (prop.key.type === 4) {
  596. const propKeyName = prop.key.content;
  597. result = props.properties.some(
  598. (p) => p.key.type === 4 && p.key.content === propKeyName
  599. );
  600. }
  601. return result;
  602. }
  603. function toValidAssetId(name, type) {
  604. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  605. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  606. })}`;
  607. }
  608. function hasScopeRef(node, ids) {
  609. if (!node || Object.keys(ids).length === 0) {
  610. return false;
  611. }
  612. switch (node.type) {
  613. case 1:
  614. for (let i = 0; i < node.props.length; i++) {
  615. const p = node.props[i];
  616. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  617. return true;
  618. }
  619. }
  620. return node.children.some((c) => hasScopeRef(c, ids));
  621. case 11:
  622. if (hasScopeRef(node.source, ids)) {
  623. return true;
  624. }
  625. return node.children.some((c) => hasScopeRef(c, ids));
  626. case 9:
  627. return node.branches.some((b) => hasScopeRef(b, ids));
  628. case 10:
  629. if (hasScopeRef(node.condition, ids)) {
  630. return true;
  631. }
  632. return node.children.some((c) => hasScopeRef(c, ids));
  633. case 4:
  634. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  635. case 8:
  636. return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
  637. case 5:
  638. case 12:
  639. return hasScopeRef(node.content, ids);
  640. case 2:
  641. case 3:
  642. return false;
  643. default:
  644. if (!!(process.env.NODE_ENV !== "production")) ;
  645. return false;
  646. }
  647. }
  648. function getMemoedVNodeCall(node) {
  649. if (node.type === 14 && node.callee === WITH_MEMO) {
  650. return node.arguments[1].returns;
  651. } else {
  652. return node;
  653. }
  654. }
  655. const deprecationData = {
  656. ["COMPILER_IS_ON_ELEMENT"]: {
  657. message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
  658. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  659. },
  660. ["COMPILER_V_BIND_SYNC"]: {
  661. message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
  662. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  663. },
  664. ["COMPILER_V_BIND_PROP"]: {
  665. message: `.prop modifier for v-bind has been removed and no longer necessary. Vue 3 will automatically set a binding as DOM property when appropriate.`
  666. },
  667. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  668. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
  669. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  670. },
  671. ["COMPILER_V_ON_NATIVE"]: {
  672. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  673. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  674. },
  675. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  676. message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
  677. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  678. },
  679. ["COMPILER_NATIVE_TEMPLATE"]: {
  680. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  681. },
  682. ["COMPILER_INLINE_TEMPLATE"]: {
  683. message: `"inline-template" has been removed in Vue 3.`,
  684. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  685. },
  686. ["COMPILER_FILTER"]: {
  687. message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
  688. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  689. }
  690. };
  691. function getCompatValue(key, context) {
  692. const config = context.options ? context.options.compatConfig : context.compatConfig;
  693. const value = config && config[key];
  694. if (key === "MODE") {
  695. return value || 3;
  696. } else {
  697. return value;
  698. }
  699. }
  700. function isCompatEnabled(key, context) {
  701. const mode = getCompatValue("MODE", context);
  702. const value = getCompatValue(key, context);
  703. return mode === 3 ? value === true : value !== false;
  704. }
  705. function checkCompatEnabled(key, context, loc, ...args) {
  706. const enabled = isCompatEnabled(key, context);
  707. if (!!(process.env.NODE_ENV !== "production") && enabled) {
  708. warnDeprecation(key, context, loc, ...args);
  709. }
  710. return enabled;
  711. }
  712. function warnDeprecation(key, context, loc, ...args) {
  713. const val = getCompatValue(key, context);
  714. if (val === "suppress-warning") {
  715. return;
  716. }
  717. const { message, link } = deprecationData[key];
  718. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  719. Details: ${link}` : ``}`;
  720. const err = new SyntaxError(msg);
  721. err.code = key;
  722. if (loc)
  723. err.loc = loc;
  724. context.onWarn(err);
  725. }
  726. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  727. const decodeMap = {
  728. gt: ">",
  729. lt: "<",
  730. amp: "&",
  731. apos: "'",
  732. quot: '"'
  733. };
  734. const defaultParserOptions = {
  735. delimiters: [`{{`, `}}`],
  736. getNamespace: () => 0,
  737. getTextMode: () => 0,
  738. isVoidTag: NO,
  739. isPreTag: NO,
  740. isCustomElement: NO,
  741. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  742. onError: defaultOnError,
  743. onWarn: defaultOnWarn,
  744. comments: !!(process.env.NODE_ENV !== "production")
  745. };
  746. function baseParse(content, options = {}) {
  747. const context = createParserContext(content, options);
  748. const start = getCursor(context);
  749. return createRoot(
  750. parseChildren(context, 0, []),
  751. getSelection(context, start)
  752. );
  753. }
  754. function createParserContext(content, rawOptions) {
  755. const options = extend({}, defaultParserOptions);
  756. let key;
  757. for (key in rawOptions) {
  758. options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
  759. }
  760. return {
  761. options,
  762. column: 1,
  763. line: 1,
  764. offset: 0,
  765. originalSource: content,
  766. source: content,
  767. inPre: false,
  768. inVPre: false,
  769. onWarn: options.onWarn
  770. };
  771. }
  772. function parseChildren(context, mode, ancestors) {
  773. const parent = last(ancestors);
  774. const ns = parent ? parent.ns : 0;
  775. const nodes = [];
  776. while (!isEnd(context, mode, ancestors)) {
  777. const s = context.source;
  778. let node = void 0;
  779. if (mode === 0 || mode === 1) {
  780. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  781. node = parseInterpolation(context, mode);
  782. } else if (mode === 0 && s[0] === "<") {
  783. if (s.length === 1) {
  784. emitError(context, 5, 1);
  785. } else if (s[1] === "!") {
  786. if (startsWith(s, "<!--")) {
  787. node = parseComment(context);
  788. } else if (startsWith(s, "<!DOCTYPE")) {
  789. node = parseBogusComment(context);
  790. } else if (startsWith(s, "<![CDATA[")) {
  791. if (ns !== 0) {
  792. node = parseCDATA(context, ancestors);
  793. } else {
  794. emitError(context, 1);
  795. node = parseBogusComment(context);
  796. }
  797. } else {
  798. emitError(context, 11);
  799. node = parseBogusComment(context);
  800. }
  801. } else if (s[1] === "/") {
  802. if (s.length === 2) {
  803. emitError(context, 5, 2);
  804. } else if (s[2] === ">") {
  805. emitError(context, 14, 2);
  806. advanceBy(context, 3);
  807. continue;
  808. } else if (/[a-z]/i.test(s[2])) {
  809. emitError(context, 23);
  810. parseTag(context, TagType.End, parent);
  811. continue;
  812. } else {
  813. emitError(
  814. context,
  815. 12,
  816. 2
  817. );
  818. node = parseBogusComment(context);
  819. }
  820. } else if (/[a-z]/i.test(s[1])) {
  821. node = parseElement(context, ancestors);
  822. if (isCompatEnabled(
  823. "COMPILER_NATIVE_TEMPLATE",
  824. context
  825. ) && node && node.tag === "template" && !node.props.some(
  826. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  827. )) {
  828. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  829. "COMPILER_NATIVE_TEMPLATE",
  830. context,
  831. node.loc
  832. );
  833. node = node.children;
  834. }
  835. } else if (s[1] === "?") {
  836. emitError(
  837. context,
  838. 21,
  839. 1
  840. );
  841. node = parseBogusComment(context);
  842. } else {
  843. emitError(context, 12, 1);
  844. }
  845. }
  846. }
  847. if (!node) {
  848. node = parseText(context, mode);
  849. }
  850. if (isArray(node)) {
  851. for (let i = 0; i < node.length; i++) {
  852. pushNode(nodes, node[i]);
  853. }
  854. } else {
  855. pushNode(nodes, node);
  856. }
  857. }
  858. let removedWhitespace = false;
  859. if (mode !== 2 && mode !== 1) {
  860. const shouldCondense = context.options.whitespace !== "preserve";
  861. for (let i = 0; i < nodes.length; i++) {
  862. const node = nodes[i];
  863. if (node.type === 2) {
  864. if (!context.inPre) {
  865. if (!/[^\t\r\n\f ]/.test(node.content)) {
  866. const prev = nodes[i - 1];
  867. const next = nodes[i + 1];
  868. if (!prev || !next || shouldCondense && (prev.type === 3 && next.type === 3 || prev.type === 3 && next.type === 1 || prev.type === 1 && next.type === 3 || prev.type === 1 && next.type === 1 && /[\r\n]/.test(node.content))) {
  869. removedWhitespace = true;
  870. nodes[i] = null;
  871. } else {
  872. node.content = " ";
  873. }
  874. } else if (shouldCondense) {
  875. node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
  876. }
  877. } else {
  878. node.content = node.content.replace(/\r\n/g, "\n");
  879. }
  880. } else if (node.type === 3 && !context.options.comments) {
  881. removedWhitespace = true;
  882. nodes[i] = null;
  883. }
  884. }
  885. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  886. const first = nodes[0];
  887. if (first && first.type === 2) {
  888. first.content = first.content.replace(/^\r?\n/, "");
  889. }
  890. }
  891. }
  892. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  893. }
  894. function pushNode(nodes, node) {
  895. if (node.type === 2) {
  896. const prev = last(nodes);
  897. if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
  898. prev.content += node.content;
  899. prev.loc.end = node.loc.end;
  900. prev.loc.source += node.loc.source;
  901. return;
  902. }
  903. }
  904. nodes.push(node);
  905. }
  906. function parseCDATA(context, ancestors) {
  907. advanceBy(context, 9);
  908. const nodes = parseChildren(context, 3, ancestors);
  909. if (context.source.length === 0) {
  910. emitError(context, 6);
  911. } else {
  912. advanceBy(context, 3);
  913. }
  914. return nodes;
  915. }
  916. function parseComment(context) {
  917. const start = getCursor(context);
  918. let content;
  919. const match = /--(\!)?>/.exec(context.source);
  920. if (!match) {
  921. content = context.source.slice(4);
  922. advanceBy(context, context.source.length);
  923. emitError(context, 7);
  924. } else {
  925. if (match.index <= 3) {
  926. emitError(context, 0);
  927. }
  928. if (match[1]) {
  929. emitError(context, 10);
  930. }
  931. content = context.source.slice(4, match.index);
  932. const s = context.source.slice(0, match.index);
  933. let prevIndex = 1, nestedIndex = 0;
  934. while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
  935. advanceBy(context, nestedIndex - prevIndex + 1);
  936. if (nestedIndex + 4 < s.length) {
  937. emitError(context, 16);
  938. }
  939. prevIndex = nestedIndex + 1;
  940. }
  941. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  942. }
  943. return {
  944. type: 3,
  945. content,
  946. loc: getSelection(context, start)
  947. };
  948. }
  949. function parseBogusComment(context) {
  950. const start = getCursor(context);
  951. const contentStart = context.source[1] === "?" ? 1 : 2;
  952. let content;
  953. const closeIndex = context.source.indexOf(">");
  954. if (closeIndex === -1) {
  955. content = context.source.slice(contentStart);
  956. advanceBy(context, context.source.length);
  957. } else {
  958. content = context.source.slice(contentStart, closeIndex);
  959. advanceBy(context, closeIndex + 1);
  960. }
  961. return {
  962. type: 3,
  963. content,
  964. loc: getSelection(context, start)
  965. };
  966. }
  967. function parseElement(context, ancestors) {
  968. const wasInPre = context.inPre;
  969. const wasInVPre = context.inVPre;
  970. const parent = last(ancestors);
  971. const element = parseTag(context, TagType.Start, parent);
  972. const isPreBoundary = context.inPre && !wasInPre;
  973. const isVPreBoundary = context.inVPre && !wasInVPre;
  974. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  975. if (isPreBoundary) {
  976. context.inPre = false;
  977. }
  978. if (isVPreBoundary) {
  979. context.inVPre = false;
  980. }
  981. return element;
  982. }
  983. ancestors.push(element);
  984. const mode = context.options.getTextMode(element, parent);
  985. const children = parseChildren(context, mode, ancestors);
  986. ancestors.pop();
  987. {
  988. const inlineTemplateProp = element.props.find(
  989. (p) => p.type === 6 && p.name === "inline-template"
  990. );
  991. if (inlineTemplateProp && checkCompatEnabled(
  992. "COMPILER_INLINE_TEMPLATE",
  993. context,
  994. inlineTemplateProp.loc
  995. )) {
  996. const loc = getSelection(context, element.loc.end);
  997. inlineTemplateProp.value = {
  998. type: 2,
  999. content: loc.source,
  1000. loc
  1001. };
  1002. }
  1003. }
  1004. element.children = children;
  1005. if (startsWithEndTagOpen(context.source, element.tag)) {
  1006. parseTag(context, TagType.End, parent);
  1007. } else {
  1008. emitError(context, 24, 0, element.loc.start);
  1009. if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
  1010. const first = children[0];
  1011. if (first && startsWith(first.loc.source, "<!--")) {
  1012. emitError(context, 8);
  1013. }
  1014. }
  1015. }
  1016. element.loc = getSelection(context, element.loc.start);
  1017. if (isPreBoundary) {
  1018. context.inPre = false;
  1019. }
  1020. if (isVPreBoundary) {
  1021. context.inVPre = false;
  1022. }
  1023. return element;
  1024. }
  1025. var TagType = /* @__PURE__ */ ((TagType2) => {
  1026. TagType2[TagType2["Start"] = 0] = "Start";
  1027. TagType2[TagType2["End"] = 1] = "End";
  1028. return TagType2;
  1029. })(TagType || {});
  1030. const isSpecialTemplateDirective = /* @__PURE__ */ makeMap(
  1031. `if,else,else-if,for,slot`
  1032. );
  1033. function parseTag(context, type, parent) {
  1034. const start = getCursor(context);
  1035. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  1036. const tag = match[1];
  1037. const ns = context.options.getNamespace(tag, parent);
  1038. advanceBy(context, match[0].length);
  1039. advanceSpaces(context);
  1040. const cursor = getCursor(context);
  1041. const currentSource = context.source;
  1042. if (context.options.isPreTag(tag)) {
  1043. context.inPre = true;
  1044. }
  1045. let props = parseAttributes(context, type);
  1046. if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
  1047. context.inVPre = true;
  1048. extend(context, cursor);
  1049. context.source = currentSource;
  1050. props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
  1051. }
  1052. let isSelfClosing = false;
  1053. if (context.source.length === 0) {
  1054. emitError(context, 9);
  1055. } else {
  1056. isSelfClosing = startsWith(context.source, "/>");
  1057. if (type === 1 /* End */ && isSelfClosing) {
  1058. emitError(context, 4);
  1059. }
  1060. advanceBy(context, isSelfClosing ? 2 : 1);
  1061. }
  1062. if (type === 1 /* End */) {
  1063. return;
  1064. }
  1065. if (!!(process.env.NODE_ENV !== "production") && isCompatEnabled(
  1066. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1067. context
  1068. )) {
  1069. let hasIf = false;
  1070. let hasFor = false;
  1071. for (let i = 0; i < props.length; i++) {
  1072. const p = props[i];
  1073. if (p.type === 7) {
  1074. if (p.name === "if") {
  1075. hasIf = true;
  1076. } else if (p.name === "for") {
  1077. hasFor = true;
  1078. }
  1079. }
  1080. if (hasIf && hasFor) {
  1081. warnDeprecation(
  1082. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1083. context,
  1084. getSelection(context, start)
  1085. );
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. let tagType = 0;
  1091. if (!context.inVPre) {
  1092. if (tag === "slot") {
  1093. tagType = 2;
  1094. } else if (tag === "template") {
  1095. if (props.some(
  1096. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  1097. )) {
  1098. tagType = 3;
  1099. }
  1100. } else if (isComponent(tag, props, context)) {
  1101. tagType = 1;
  1102. }
  1103. }
  1104. return {
  1105. type: 1,
  1106. ns,
  1107. tag,
  1108. tagType,
  1109. props,
  1110. isSelfClosing,
  1111. children: [],
  1112. loc: getSelection(context, start),
  1113. codegenNode: void 0
  1114. // to be created during transform phase
  1115. };
  1116. }
  1117. function isComponent(tag, props, context) {
  1118. const options = context.options;
  1119. if (options.isCustomElement(tag)) {
  1120. return false;
  1121. }
  1122. if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
  1123. return true;
  1124. }
  1125. for (let i = 0; i < props.length; i++) {
  1126. const p = props[i];
  1127. if (p.type === 6) {
  1128. if (p.name === "is" && p.value) {
  1129. if (p.value.content.startsWith("vue:")) {
  1130. return true;
  1131. } else if (checkCompatEnabled(
  1132. "COMPILER_IS_ON_ELEMENT",
  1133. context,
  1134. p.loc
  1135. )) {
  1136. return true;
  1137. }
  1138. }
  1139. } else {
  1140. if (p.name === "is") {
  1141. return true;
  1142. } else if (
  1143. // :is on plain element - only treat as component in compat mode
  1144. p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
  1145. "COMPILER_IS_ON_ELEMENT",
  1146. context,
  1147. p.loc
  1148. )
  1149. ) {
  1150. return true;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. function parseAttributes(context, type) {
  1156. const props = [];
  1157. const attributeNames = /* @__PURE__ */ new Set();
  1158. while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
  1159. if (startsWith(context.source, "/")) {
  1160. emitError(context, 22);
  1161. advanceBy(context, 1);
  1162. advanceSpaces(context);
  1163. continue;
  1164. }
  1165. if (type === 1 /* End */) {
  1166. emitError(context, 3);
  1167. }
  1168. const attr = parseAttribute(context, attributeNames);
  1169. if (attr.type === 6 && attr.value && attr.name === "class") {
  1170. attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
  1171. }
  1172. if (type === 0 /* Start */) {
  1173. props.push(attr);
  1174. }
  1175. if (/^[^\t\r\n\f />]/.test(context.source)) {
  1176. emitError(context, 15);
  1177. }
  1178. advanceSpaces(context);
  1179. }
  1180. return props;
  1181. }
  1182. function parseAttribute(context, nameSet) {
  1183. var _a;
  1184. const start = getCursor(context);
  1185. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  1186. const name = match[0];
  1187. if (nameSet.has(name)) {
  1188. emitError(context, 2);
  1189. }
  1190. nameSet.add(name);
  1191. if (name[0] === "=") {
  1192. emitError(context, 19);
  1193. }
  1194. {
  1195. const pattern = /["'<]/g;
  1196. let m;
  1197. while (m = pattern.exec(name)) {
  1198. emitError(
  1199. context,
  1200. 17,
  1201. m.index
  1202. );
  1203. }
  1204. }
  1205. advanceBy(context, name.length);
  1206. let value = void 0;
  1207. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  1208. advanceSpaces(context);
  1209. advanceBy(context, 1);
  1210. advanceSpaces(context);
  1211. value = parseAttributeValue(context);
  1212. if (!value) {
  1213. emitError(context, 13);
  1214. }
  1215. }
  1216. const loc = getSelection(context, start);
  1217. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  1218. const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
  1219. name
  1220. );
  1221. let isPropShorthand = startsWith(name, ".");
  1222. let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
  1223. let arg;
  1224. if (match2[2]) {
  1225. const isSlot = dirName === "slot";
  1226. const startOffset = name.lastIndexOf(
  1227. match2[2],
  1228. name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
  1229. );
  1230. const loc2 = getSelection(
  1231. context,
  1232. getNewPosition(context, start, startOffset),
  1233. getNewPosition(
  1234. context,
  1235. start,
  1236. startOffset + match2[2].length + (isSlot && match2[3] || "").length
  1237. )
  1238. );
  1239. let content = match2[2];
  1240. let isStatic = true;
  1241. if (content.startsWith("[")) {
  1242. isStatic = false;
  1243. if (!content.endsWith("]")) {
  1244. emitError(
  1245. context,
  1246. 27
  1247. );
  1248. content = content.slice(1);
  1249. } else {
  1250. content = content.slice(1, content.length - 1);
  1251. }
  1252. } else if (isSlot) {
  1253. content += match2[3] || "";
  1254. }
  1255. arg = {
  1256. type: 4,
  1257. content,
  1258. isStatic,
  1259. constType: isStatic ? 3 : 0,
  1260. loc: loc2
  1261. };
  1262. }
  1263. if (value && value.isQuoted) {
  1264. const valueLoc = value.loc;
  1265. valueLoc.start.offset++;
  1266. valueLoc.start.column++;
  1267. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  1268. valueLoc.source = valueLoc.source.slice(1, -1);
  1269. }
  1270. const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
  1271. if (isPropShorthand)
  1272. modifiers.push("prop");
  1273. if (dirName === "bind" && arg) {
  1274. if (modifiers.includes("sync") && checkCompatEnabled(
  1275. "COMPILER_V_BIND_SYNC",
  1276. context,
  1277. loc,
  1278. arg.loc.source
  1279. )) {
  1280. dirName = "model";
  1281. modifiers.splice(modifiers.indexOf("sync"), 1);
  1282. }
  1283. if (!!(process.env.NODE_ENV !== "production") && modifiers.includes("prop")) {
  1284. checkCompatEnabled(
  1285. "COMPILER_V_BIND_PROP",
  1286. context,
  1287. loc
  1288. );
  1289. }
  1290. }
  1291. return {
  1292. type: 7,
  1293. name: dirName,
  1294. exp: value && {
  1295. type: 4,
  1296. content: value.content,
  1297. isStatic: false,
  1298. // Treat as non-constant by default. This can be potentially set to
  1299. // other values by `transformExpression` to make it eligible for hoisting.
  1300. constType: 0,
  1301. loc: value.loc
  1302. },
  1303. arg,
  1304. modifiers,
  1305. loc
  1306. };
  1307. }
  1308. if (!context.inVPre && startsWith(name, "v-")) {
  1309. emitError(context, 26);
  1310. }
  1311. return {
  1312. type: 6,
  1313. name,
  1314. value: value && {
  1315. type: 2,
  1316. content: value.content,
  1317. loc: value.loc
  1318. },
  1319. loc
  1320. };
  1321. }
  1322. function parseAttributeValue(context) {
  1323. const start = getCursor(context);
  1324. let content;
  1325. const quote = context.source[0];
  1326. const isQuoted = quote === `"` || quote === `'`;
  1327. if (isQuoted) {
  1328. advanceBy(context, 1);
  1329. const endIndex = context.source.indexOf(quote);
  1330. if (endIndex === -1) {
  1331. content = parseTextData(
  1332. context,
  1333. context.source.length,
  1334. 4
  1335. );
  1336. } else {
  1337. content = parseTextData(context, endIndex, 4);
  1338. advanceBy(context, 1);
  1339. }
  1340. } else {
  1341. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  1342. if (!match) {
  1343. return void 0;
  1344. }
  1345. const unexpectedChars = /["'<=`]/g;
  1346. let m;
  1347. while (m = unexpectedChars.exec(match[0])) {
  1348. emitError(
  1349. context,
  1350. 18,
  1351. m.index
  1352. );
  1353. }
  1354. content = parseTextData(context, match[0].length, 4);
  1355. }
  1356. return { content, isQuoted, loc: getSelection(context, start) };
  1357. }
  1358. function parseInterpolation(context, mode) {
  1359. const [open, close] = context.options.delimiters;
  1360. const closeIndex = context.source.indexOf(close, open.length);
  1361. if (closeIndex === -1) {
  1362. emitError(context, 25);
  1363. return void 0;
  1364. }
  1365. const start = getCursor(context);
  1366. advanceBy(context, open.length);
  1367. const innerStart = getCursor(context);
  1368. const innerEnd = getCursor(context);
  1369. const rawContentLength = closeIndex - open.length;
  1370. const rawContent = context.source.slice(0, rawContentLength);
  1371. const preTrimContent = parseTextData(context, rawContentLength, mode);
  1372. const content = preTrimContent.trim();
  1373. const startOffset = preTrimContent.indexOf(content);
  1374. if (startOffset > 0) {
  1375. advancePositionWithMutation(innerStart, rawContent, startOffset);
  1376. }
  1377. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  1378. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  1379. advanceBy(context, close.length);
  1380. return {
  1381. type: 5,
  1382. content: {
  1383. type: 4,
  1384. isStatic: false,
  1385. // Set `isConstant` to false by default and will decide in transformExpression
  1386. constType: 0,
  1387. content,
  1388. loc: getSelection(context, innerStart, innerEnd)
  1389. },
  1390. loc: getSelection(context, start)
  1391. };
  1392. }
  1393. function parseText(context, mode) {
  1394. const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
  1395. let endIndex = context.source.length;
  1396. for (let i = 0; i < endTokens.length; i++) {
  1397. const index = context.source.indexOf(endTokens[i], 1);
  1398. if (index !== -1 && endIndex > index) {
  1399. endIndex = index;
  1400. }
  1401. }
  1402. const start = getCursor(context);
  1403. const content = parseTextData(context, endIndex, mode);
  1404. return {
  1405. type: 2,
  1406. content,
  1407. loc: getSelection(context, start)
  1408. };
  1409. }
  1410. function parseTextData(context, length, mode) {
  1411. const rawText = context.source.slice(0, length);
  1412. advanceBy(context, length);
  1413. if (mode === 2 || mode === 3 || !rawText.includes("&")) {
  1414. return rawText;
  1415. } else {
  1416. return context.options.decodeEntities(
  1417. rawText,
  1418. mode === 4
  1419. );
  1420. }
  1421. }
  1422. function getCursor(context) {
  1423. const { column, line, offset } = context;
  1424. return { column, line, offset };
  1425. }
  1426. function getSelection(context, start, end) {
  1427. end = end || getCursor(context);
  1428. return {
  1429. start,
  1430. end,
  1431. source: context.originalSource.slice(start.offset, end.offset)
  1432. };
  1433. }
  1434. function last(xs) {
  1435. return xs[xs.length - 1];
  1436. }
  1437. function startsWith(source, searchString) {
  1438. return source.startsWith(searchString);
  1439. }
  1440. function advanceBy(context, numberOfCharacters) {
  1441. const { source } = context;
  1442. advancePositionWithMutation(context, source, numberOfCharacters);
  1443. context.source = source.slice(numberOfCharacters);
  1444. }
  1445. function advanceSpaces(context) {
  1446. const match = /^[\t\r\n\f ]+/.exec(context.source);
  1447. if (match) {
  1448. advanceBy(context, match[0].length);
  1449. }
  1450. }
  1451. function getNewPosition(context, start, numberOfCharacters) {
  1452. return advancePositionWithClone(
  1453. start,
  1454. context.originalSource.slice(start.offset, numberOfCharacters),
  1455. numberOfCharacters
  1456. );
  1457. }
  1458. function emitError(context, code, offset, loc = getCursor(context)) {
  1459. if (offset) {
  1460. loc.offset += offset;
  1461. loc.column += offset;
  1462. }
  1463. context.options.onError(
  1464. createCompilerError(code, {
  1465. start: loc,
  1466. end: loc,
  1467. source: ""
  1468. })
  1469. );
  1470. }
  1471. function isEnd(context, mode, ancestors) {
  1472. const s = context.source;
  1473. switch (mode) {
  1474. case 0:
  1475. if (startsWith(s, "</")) {
  1476. for (let i = ancestors.length - 1; i >= 0; --i) {
  1477. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  1478. return true;
  1479. }
  1480. }
  1481. }
  1482. break;
  1483. case 1:
  1484. case 2: {
  1485. const parent = last(ancestors);
  1486. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  1487. return true;
  1488. }
  1489. break;
  1490. }
  1491. case 3:
  1492. if (startsWith(s, "]]>")) {
  1493. return true;
  1494. }
  1495. break;
  1496. }
  1497. return !s;
  1498. }
  1499. function startsWithEndTagOpen(source, tag) {
  1500. return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
  1501. }
  1502. function hoistStatic(root, context) {
  1503. walk(
  1504. root,
  1505. context,
  1506. // Root node is unfortunately non-hoistable due to potential parent
  1507. // fallthrough attributes.
  1508. isSingleElementRoot(root, root.children[0])
  1509. );
  1510. }
  1511. function isSingleElementRoot(root, child) {
  1512. const { children } = root;
  1513. return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
  1514. }
  1515. function walk(node, context, doNotHoistNode = false) {
  1516. const { children } = node;
  1517. const originalCount = children.length;
  1518. let hoistedCount = 0;
  1519. for (let i = 0; i < children.length; i++) {
  1520. const child = children[i];
  1521. if (child.type === 1 && child.tagType === 0) {
  1522. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  1523. if (constantType > 0) {
  1524. if (constantType >= 2) {
  1525. child.codegenNode.patchFlag = -1 + (!!(process.env.NODE_ENV !== "production") ? ` /* HOISTED */` : ``);
  1526. child.codegenNode = context.hoist(child.codegenNode);
  1527. hoistedCount++;
  1528. continue;
  1529. }
  1530. } else {
  1531. const codegenNode = child.codegenNode;
  1532. if (codegenNode.type === 13) {
  1533. const flag = getPatchFlag(codegenNode);
  1534. if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  1535. const props = getNodeProps(child);
  1536. if (props) {
  1537. codegenNode.props = context.hoist(props);
  1538. }
  1539. }
  1540. if (codegenNode.dynamicProps) {
  1541. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  1542. }
  1543. }
  1544. }
  1545. }
  1546. if (child.type === 1) {
  1547. const isComponent = child.tagType === 1;
  1548. if (isComponent) {
  1549. context.scopes.vSlot++;
  1550. }
  1551. walk(child, context);
  1552. if (isComponent) {
  1553. context.scopes.vSlot--;
  1554. }
  1555. } else if (child.type === 11) {
  1556. walk(child, context, child.children.length === 1);
  1557. } else if (child.type === 9) {
  1558. for (let i2 = 0; i2 < child.branches.length; i2++) {
  1559. walk(
  1560. child.branches[i2],
  1561. context,
  1562. child.branches[i2].children.length === 1
  1563. );
  1564. }
  1565. }
  1566. }
  1567. if (hoistedCount && context.transformHoist) {
  1568. context.transformHoist(children, context, node);
  1569. }
  1570. if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  1571. node.codegenNode.children = context.hoist(
  1572. createArrayExpression(node.codegenNode.children)
  1573. );
  1574. }
  1575. }
  1576. function getConstantType(node, context) {
  1577. const { constantCache } = context;
  1578. switch (node.type) {
  1579. case 1:
  1580. if (node.tagType !== 0) {
  1581. return 0;
  1582. }
  1583. const cached = constantCache.get(node);
  1584. if (cached !== void 0) {
  1585. return cached;
  1586. }
  1587. const codegenNode = node.codegenNode;
  1588. if (codegenNode.type !== 13) {
  1589. return 0;
  1590. }
  1591. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
  1592. return 0;
  1593. }
  1594. const flag = getPatchFlag(codegenNode);
  1595. if (!flag) {
  1596. let returnType2 = 3;
  1597. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  1598. if (generatedPropsType === 0) {
  1599. constantCache.set(node, 0);
  1600. return 0;
  1601. }
  1602. if (generatedPropsType < returnType2) {
  1603. returnType2 = generatedPropsType;
  1604. }
  1605. for (let i = 0; i < node.children.length; i++) {
  1606. const childType = getConstantType(node.children[i], context);
  1607. if (childType === 0) {
  1608. constantCache.set(node, 0);
  1609. return 0;
  1610. }
  1611. if (childType < returnType2) {
  1612. returnType2 = childType;
  1613. }
  1614. }
  1615. if (returnType2 > 1) {
  1616. for (let i = 0; i < node.props.length; i++) {
  1617. const p = node.props[i];
  1618. if (p.type === 7 && p.name === "bind" && p.exp) {
  1619. const expType = getConstantType(p.exp, context);
  1620. if (expType === 0) {
  1621. constantCache.set(node, 0);
  1622. return 0;
  1623. }
  1624. if (expType < returnType2) {
  1625. returnType2 = expType;
  1626. }
  1627. }
  1628. }
  1629. }
  1630. if (codegenNode.isBlock) {
  1631. for (let i = 0; i < node.props.length; i++) {
  1632. const p = node.props[i];
  1633. if (p.type === 7) {
  1634. constantCache.set(node, 0);
  1635. return 0;
  1636. }
  1637. }
  1638. context.removeHelper(OPEN_BLOCK);
  1639. context.removeHelper(
  1640. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  1641. );
  1642. codegenNode.isBlock = false;
  1643. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  1644. }
  1645. constantCache.set(node, returnType2);
  1646. return returnType2;
  1647. } else {
  1648. constantCache.set(node, 0);
  1649. return 0;
  1650. }
  1651. case 2:
  1652. case 3:
  1653. return 3;
  1654. case 9:
  1655. case 11:
  1656. case 10:
  1657. return 0;
  1658. case 5:
  1659. case 12:
  1660. return getConstantType(node.content, context);
  1661. case 4:
  1662. return node.constType;
  1663. case 8:
  1664. let returnType = 3;
  1665. for (let i = 0; i < node.children.length; i++) {
  1666. const child = node.children[i];
  1667. if (isString(child) || isSymbol(child)) {
  1668. continue;
  1669. }
  1670. const childType = getConstantType(child, context);
  1671. if (childType === 0) {
  1672. return 0;
  1673. } else if (childType < returnType) {
  1674. returnType = childType;
  1675. }
  1676. }
  1677. return returnType;
  1678. default:
  1679. if (!!(process.env.NODE_ENV !== "production")) ;
  1680. return 0;
  1681. }
  1682. }
  1683. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  1684. NORMALIZE_CLASS,
  1685. NORMALIZE_STYLE,
  1686. NORMALIZE_PROPS,
  1687. GUARD_REACTIVE_PROPS
  1688. ]);
  1689. function getConstantTypeOfHelperCall(value, context) {
  1690. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  1691. const arg = value.arguments[0];
  1692. if (arg.type === 4) {
  1693. return getConstantType(arg, context);
  1694. } else if (arg.type === 14) {
  1695. return getConstantTypeOfHelperCall(arg, context);
  1696. }
  1697. }
  1698. return 0;
  1699. }
  1700. function getGeneratedPropsConstantType(node, context) {
  1701. let returnType = 3;
  1702. const props = getNodeProps(node);
  1703. if (props && props.type === 15) {
  1704. const { properties } = props;
  1705. for (let i = 0; i < properties.length; i++) {
  1706. const { key, value } = properties[i];
  1707. const keyType = getConstantType(key, context);
  1708. if (keyType === 0) {
  1709. return keyType;
  1710. }
  1711. if (keyType < returnType) {
  1712. returnType = keyType;
  1713. }
  1714. let valueType;
  1715. if (value.type === 4) {
  1716. valueType = getConstantType(value, context);
  1717. } else if (value.type === 14) {
  1718. valueType = getConstantTypeOfHelperCall(value, context);
  1719. } else {
  1720. valueType = 0;
  1721. }
  1722. if (valueType === 0) {
  1723. return valueType;
  1724. }
  1725. if (valueType < returnType) {
  1726. returnType = valueType;
  1727. }
  1728. }
  1729. }
  1730. return returnType;
  1731. }
  1732. function getNodeProps(node) {
  1733. const codegenNode = node.codegenNode;
  1734. if (codegenNode.type === 13) {
  1735. return codegenNode.props;
  1736. }
  1737. }
  1738. function getPatchFlag(node) {
  1739. const flag = node.patchFlag;
  1740. return flag ? parseInt(flag, 10) : void 0;
  1741. }
  1742. function createTransformContext(root, {
  1743. filename = "",
  1744. prefixIdentifiers = false,
  1745. hoistStatic: hoistStatic2 = false,
  1746. cacheHandlers = false,
  1747. nodeTransforms = [],
  1748. directiveTransforms = {},
  1749. transformHoist = null,
  1750. isBuiltInComponent = NOOP,
  1751. isCustomElement = NOOP,
  1752. expressionPlugins = [],
  1753. scopeId = null,
  1754. slotted = true,
  1755. ssr = false,
  1756. inSSR = false,
  1757. ssrCssVars = ``,
  1758. bindingMetadata = EMPTY_OBJ,
  1759. inline = false,
  1760. isTS = false,
  1761. onError = defaultOnError,
  1762. onWarn = defaultOnWarn,
  1763. compatConfig
  1764. }) {
  1765. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  1766. const context = {
  1767. // options
  1768. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  1769. prefixIdentifiers,
  1770. hoistStatic: hoistStatic2,
  1771. cacheHandlers,
  1772. nodeTransforms,
  1773. directiveTransforms,
  1774. transformHoist,
  1775. isBuiltInComponent,
  1776. isCustomElement,
  1777. expressionPlugins,
  1778. scopeId,
  1779. slotted,
  1780. ssr,
  1781. inSSR,
  1782. ssrCssVars,
  1783. bindingMetadata,
  1784. inline,
  1785. isTS,
  1786. onError,
  1787. onWarn,
  1788. compatConfig,
  1789. // state
  1790. root,
  1791. helpers: /* @__PURE__ */ new Map(),
  1792. components: /* @__PURE__ */ new Set(),
  1793. directives: /* @__PURE__ */ new Set(),
  1794. hoists: [],
  1795. imports: [],
  1796. constantCache: /* @__PURE__ */ new Map(),
  1797. temps: 0,
  1798. cached: 0,
  1799. identifiers: /* @__PURE__ */ Object.create(null),
  1800. scopes: {
  1801. vFor: 0,
  1802. vSlot: 0,
  1803. vPre: 0,
  1804. vOnce: 0
  1805. },
  1806. parent: null,
  1807. currentNode: root,
  1808. childIndex: 0,
  1809. inVOnce: false,
  1810. // methods
  1811. helper(name) {
  1812. const count = context.helpers.get(name) || 0;
  1813. context.helpers.set(name, count + 1);
  1814. return name;
  1815. },
  1816. removeHelper(name) {
  1817. const count = context.helpers.get(name);
  1818. if (count) {
  1819. const currentCount = count - 1;
  1820. if (!currentCount) {
  1821. context.helpers.delete(name);
  1822. } else {
  1823. context.helpers.set(name, currentCount);
  1824. }
  1825. }
  1826. },
  1827. helperString(name) {
  1828. return `_${helperNameMap[context.helper(name)]}`;
  1829. },
  1830. replaceNode(node) {
  1831. if (!!(process.env.NODE_ENV !== "production")) {
  1832. if (!context.currentNode) {
  1833. throw new Error(`Node being replaced is already removed.`);
  1834. }
  1835. if (!context.parent) {
  1836. throw new Error(`Cannot replace root node.`);
  1837. }
  1838. }
  1839. context.parent.children[context.childIndex] = context.currentNode = node;
  1840. },
  1841. removeNode(node) {
  1842. if (!!(process.env.NODE_ENV !== "production") && !context.parent) {
  1843. throw new Error(`Cannot remove root node.`);
  1844. }
  1845. const list = context.parent.children;
  1846. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  1847. if (!!(process.env.NODE_ENV !== "production") && removalIndex < 0) {
  1848. throw new Error(`node being removed is not a child of current parent`);
  1849. }
  1850. if (!node || node === context.currentNode) {
  1851. context.currentNode = null;
  1852. context.onNodeRemoved();
  1853. } else {
  1854. if (context.childIndex > removalIndex) {
  1855. context.childIndex--;
  1856. context.onNodeRemoved();
  1857. }
  1858. }
  1859. context.parent.children.splice(removalIndex, 1);
  1860. },
  1861. onNodeRemoved: () => {
  1862. },
  1863. addIdentifiers(exp) {
  1864. },
  1865. removeIdentifiers(exp) {
  1866. },
  1867. hoist(exp) {
  1868. if (isString(exp))
  1869. exp = createSimpleExpression(exp);
  1870. context.hoists.push(exp);
  1871. const identifier = createSimpleExpression(
  1872. `_hoisted_${context.hoists.length}`,
  1873. false,
  1874. exp.loc,
  1875. 2
  1876. );
  1877. identifier.hoisted = exp;
  1878. return identifier;
  1879. },
  1880. cache(exp, isVNode = false) {
  1881. return createCacheExpression(context.cached++, exp, isVNode);
  1882. }
  1883. };
  1884. {
  1885. context.filters = /* @__PURE__ */ new Set();
  1886. }
  1887. return context;
  1888. }
  1889. function transform(root, options) {
  1890. const context = createTransformContext(root, options);
  1891. traverseNode(root, context);
  1892. if (options.hoistStatic) {
  1893. hoistStatic(root, context);
  1894. }
  1895. if (!options.ssr) {
  1896. createRootCodegen(root, context);
  1897. }
  1898. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  1899. root.components = [...context.components];
  1900. root.directives = [...context.directives];
  1901. root.imports = context.imports;
  1902. root.hoists = context.hoists;
  1903. root.temps = context.temps;
  1904. root.cached = context.cached;
  1905. {
  1906. root.filters = [...context.filters];
  1907. }
  1908. }
  1909. function createRootCodegen(root, context) {
  1910. const { helper } = context;
  1911. const { children } = root;
  1912. if (children.length === 1) {
  1913. const child = children[0];
  1914. if (isSingleElementRoot(root, child) && child.codegenNode) {
  1915. const codegenNode = child.codegenNode;
  1916. if (codegenNode.type === 13) {
  1917. convertToBlock(codegenNode, context);
  1918. }
  1919. root.codegenNode = codegenNode;
  1920. } else {
  1921. root.codegenNode = child;
  1922. }
  1923. } else if (children.length > 1) {
  1924. let patchFlag = 64;
  1925. let patchFlagText = PatchFlagNames[64];
  1926. if (!!(process.env.NODE_ENV !== "production") && children.filter((c) => c.type !== 3).length === 1) {
  1927. patchFlag |= 2048;
  1928. patchFlagText += `, ${PatchFlagNames[2048]}`;
  1929. }
  1930. root.codegenNode = createVNodeCall(
  1931. context,
  1932. helper(FRAGMENT),
  1933. void 0,
  1934. root.children,
  1935. patchFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${patchFlagText} */` : ``),
  1936. void 0,
  1937. void 0,
  1938. true,
  1939. void 0,
  1940. false
  1941. /* isComponent */
  1942. );
  1943. } else ;
  1944. }
  1945. function traverseChildren(parent, context) {
  1946. let i = 0;
  1947. const nodeRemoved = () => {
  1948. i--;
  1949. };
  1950. for (; i < parent.children.length; i++) {
  1951. const child = parent.children[i];
  1952. if (isString(child))
  1953. continue;
  1954. context.parent = parent;
  1955. context.childIndex = i;
  1956. context.onNodeRemoved = nodeRemoved;
  1957. traverseNode(child, context);
  1958. }
  1959. }
  1960. function traverseNode(node, context) {
  1961. context.currentNode = node;
  1962. const { nodeTransforms } = context;
  1963. const exitFns = [];
  1964. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  1965. const onExit = nodeTransforms[i2](node, context);
  1966. if (onExit) {
  1967. if (isArray(onExit)) {
  1968. exitFns.push(...onExit);
  1969. } else {
  1970. exitFns.push(onExit);
  1971. }
  1972. }
  1973. if (!context.currentNode) {
  1974. return;
  1975. } else {
  1976. node = context.currentNode;
  1977. }
  1978. }
  1979. switch (node.type) {
  1980. case 3:
  1981. if (!context.ssr) {
  1982. context.helper(CREATE_COMMENT);
  1983. }
  1984. break;
  1985. case 5:
  1986. if (!context.ssr) {
  1987. context.helper(TO_DISPLAY_STRING);
  1988. }
  1989. break;
  1990. case 9:
  1991. for (let i2 = 0; i2 < node.branches.length; i2++) {
  1992. traverseNode(node.branches[i2], context);
  1993. }
  1994. break;
  1995. case 10:
  1996. case 11:
  1997. case 1:
  1998. case 0:
  1999. traverseChildren(node, context);
  2000. break;
  2001. }
  2002. context.currentNode = node;
  2003. let i = exitFns.length;
  2004. while (i--) {
  2005. exitFns[i]();
  2006. }
  2007. }
  2008. function createStructuralDirectiveTransform(name, fn) {
  2009. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  2010. return (node, context) => {
  2011. if (node.type === 1) {
  2012. const { props } = node;
  2013. if (node.tagType === 3 && props.some(isVSlot)) {
  2014. return;
  2015. }
  2016. const exitFns = [];
  2017. for (let i = 0; i < props.length; i++) {
  2018. const prop = props[i];
  2019. if (prop.type === 7 && matches(prop.name)) {
  2020. props.splice(i, 1);
  2021. i--;
  2022. const onExit = fn(node, prop, context);
  2023. if (onExit)
  2024. exitFns.push(onExit);
  2025. }
  2026. }
  2027. return exitFns;
  2028. }
  2029. };
  2030. }
  2031. const PURE_ANNOTATION = `/*#__PURE__*/`;
  2032. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  2033. function createCodegenContext(ast, {
  2034. mode = "function",
  2035. prefixIdentifiers = mode === "module",
  2036. sourceMap = false,
  2037. filename = `template.vue.html`,
  2038. scopeId = null,
  2039. optimizeImports = false,
  2040. runtimeGlobalName = `Vue`,
  2041. runtimeModuleName = `vue`,
  2042. ssrRuntimeModuleName = "vue/server-renderer",
  2043. ssr = false,
  2044. isTS = false,
  2045. inSSR = false
  2046. }) {
  2047. const context = {
  2048. mode,
  2049. prefixIdentifiers,
  2050. sourceMap,
  2051. filename,
  2052. scopeId,
  2053. optimizeImports,
  2054. runtimeGlobalName,
  2055. runtimeModuleName,
  2056. ssrRuntimeModuleName,
  2057. ssr,
  2058. isTS,
  2059. inSSR,
  2060. source: ast.loc.source,
  2061. code: ``,
  2062. column: 1,
  2063. line: 1,
  2064. offset: 0,
  2065. indentLevel: 0,
  2066. pure: false,
  2067. map: void 0,
  2068. helper(key) {
  2069. return `_${helperNameMap[key]}`;
  2070. },
  2071. push(code, node) {
  2072. context.code += code;
  2073. },
  2074. indent() {
  2075. newline(++context.indentLevel);
  2076. },
  2077. deindent(withoutNewLine = false) {
  2078. if (withoutNewLine) {
  2079. --context.indentLevel;
  2080. } else {
  2081. newline(--context.indentLevel);
  2082. }
  2083. },
  2084. newline() {
  2085. newline(context.indentLevel);
  2086. }
  2087. };
  2088. function newline(n) {
  2089. context.push("\n" + ` `.repeat(n));
  2090. }
  2091. return context;
  2092. }
  2093. function generate(ast, options = {}) {
  2094. const context = createCodegenContext(ast, options);
  2095. if (options.onContextCreated)
  2096. options.onContextCreated(context);
  2097. const {
  2098. mode,
  2099. push,
  2100. prefixIdentifiers,
  2101. indent,
  2102. deindent,
  2103. newline,
  2104. scopeId,
  2105. ssr
  2106. } = context;
  2107. const helpers = Array.from(ast.helpers);
  2108. const hasHelpers = helpers.length > 0;
  2109. const useWithBlock = !prefixIdentifiers && mode !== "module";
  2110. const isSetupInlined = false;
  2111. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  2112. {
  2113. genFunctionPreamble(ast, preambleContext);
  2114. }
  2115. const functionName = ssr ? `ssrRender` : `render`;
  2116. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  2117. const signature = args.join(", ");
  2118. {
  2119. push(`function ${functionName}(${signature}) {`);
  2120. }
  2121. indent();
  2122. if (useWithBlock) {
  2123. push(`with (_ctx) {`);
  2124. indent();
  2125. if (hasHelpers) {
  2126. push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
  2127. push(`
  2128. `);
  2129. newline();
  2130. }
  2131. }
  2132. if (ast.components.length) {
  2133. genAssets(ast.components, "component", context);
  2134. if (ast.directives.length || ast.temps > 0) {
  2135. newline();
  2136. }
  2137. }
  2138. if (ast.directives.length) {
  2139. genAssets(ast.directives, "directive", context);
  2140. if (ast.temps > 0) {
  2141. newline();
  2142. }
  2143. }
  2144. if (ast.filters && ast.filters.length) {
  2145. newline();
  2146. genAssets(ast.filters, "filter", context);
  2147. newline();
  2148. }
  2149. if (ast.temps > 0) {
  2150. push(`let `);
  2151. for (let i = 0; i < ast.temps; i++) {
  2152. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  2153. }
  2154. }
  2155. if (ast.components.length || ast.directives.length || ast.temps) {
  2156. push(`
  2157. `);
  2158. newline();
  2159. }
  2160. if (!ssr) {
  2161. push(`return `);
  2162. }
  2163. if (ast.codegenNode) {
  2164. genNode(ast.codegenNode, context);
  2165. } else {
  2166. push(`null`);
  2167. }
  2168. if (useWithBlock) {
  2169. deindent();
  2170. push(`}`);
  2171. }
  2172. deindent();
  2173. push(`}`);
  2174. return {
  2175. ast,
  2176. code: context.code,
  2177. preamble: isSetupInlined ? preambleContext.code : ``,
  2178. // SourceMapGenerator does have toJSON() method but it's not in the types
  2179. map: context.map ? context.map.toJSON() : void 0
  2180. };
  2181. }
  2182. function genFunctionPreamble(ast, context) {
  2183. const {
  2184. ssr,
  2185. prefixIdentifiers,
  2186. push,
  2187. newline,
  2188. runtimeModuleName,
  2189. runtimeGlobalName,
  2190. ssrRuntimeModuleName
  2191. } = context;
  2192. const VueBinding = runtimeGlobalName;
  2193. const helpers = Array.from(ast.helpers);
  2194. if (helpers.length > 0) {
  2195. {
  2196. push(`const _Vue = ${VueBinding}
  2197. `);
  2198. if (ast.hoists.length) {
  2199. const staticHelpers = [
  2200. CREATE_VNODE,
  2201. CREATE_ELEMENT_VNODE,
  2202. CREATE_COMMENT,
  2203. CREATE_TEXT,
  2204. CREATE_STATIC
  2205. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  2206. push(`const { ${staticHelpers} } = _Vue
  2207. `);
  2208. }
  2209. }
  2210. }
  2211. genHoists(ast.hoists, context);
  2212. newline();
  2213. push(`return `);
  2214. }
  2215. function genAssets(assets, type, { helper, push, newline, isTS }) {
  2216. const resolver = helper(
  2217. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  2218. );
  2219. for (let i = 0; i < assets.length; i++) {
  2220. let id = assets[i];
  2221. const maybeSelfReference = id.endsWith("__self");
  2222. if (maybeSelfReference) {
  2223. id = id.slice(0, -6);
  2224. }
  2225. push(
  2226. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  2227. );
  2228. if (i < assets.length - 1) {
  2229. newline();
  2230. }
  2231. }
  2232. }
  2233. function genHoists(hoists, context) {
  2234. if (!hoists.length) {
  2235. return;
  2236. }
  2237. context.pure = true;
  2238. const { push, newline, helper, scopeId, mode } = context;
  2239. newline();
  2240. for (let i = 0; i < hoists.length; i++) {
  2241. const exp = hoists[i];
  2242. if (exp) {
  2243. push(
  2244. `const _hoisted_${i + 1} = ${``}`
  2245. );
  2246. genNode(exp, context);
  2247. newline();
  2248. }
  2249. }
  2250. context.pure = false;
  2251. }
  2252. function isText(n) {
  2253. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  2254. }
  2255. function genNodeListAsArray(nodes, context) {
  2256. const multilines = nodes.length > 3 || !!(process.env.NODE_ENV !== "production") && nodes.some((n) => isArray(n) || !isText(n));
  2257. context.push(`[`);
  2258. multilines && context.indent();
  2259. genNodeList(nodes, context, multilines);
  2260. multilines && context.deindent();
  2261. context.push(`]`);
  2262. }
  2263. function genNodeList(nodes, context, multilines = false, comma = true) {
  2264. const { push, newline } = context;
  2265. for (let i = 0; i < nodes.length; i++) {
  2266. const node = nodes[i];
  2267. if (isString(node)) {
  2268. push(node);
  2269. } else if (isArray(node)) {
  2270. genNodeListAsArray(node, context);
  2271. } else {
  2272. genNode(node, context);
  2273. }
  2274. if (i < nodes.length - 1) {
  2275. if (multilines) {
  2276. comma && push(",");
  2277. newline();
  2278. } else {
  2279. comma && push(", ");
  2280. }
  2281. }
  2282. }
  2283. }
  2284. function genNode(node, context) {
  2285. if (isString(node)) {
  2286. context.push(node);
  2287. return;
  2288. }
  2289. if (isSymbol(node)) {
  2290. context.push(context.helper(node));
  2291. return;
  2292. }
  2293. switch (node.type) {
  2294. case 1:
  2295. case 9:
  2296. case 11:
  2297. !!(process.env.NODE_ENV !== "production") && assert(
  2298. node.codegenNode != null,
  2299. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  2300. );
  2301. genNode(node.codegenNode, context);
  2302. break;
  2303. case 2:
  2304. genText(node, context);
  2305. break;
  2306. case 4:
  2307. genExpression(node, context);
  2308. break;
  2309. case 5:
  2310. genInterpolation(node, context);
  2311. break;
  2312. case 12:
  2313. genNode(node.codegenNode, context);
  2314. break;
  2315. case 8:
  2316. genCompoundExpression(node, context);
  2317. break;
  2318. case 3:
  2319. genComment(node, context);
  2320. break;
  2321. case 13:
  2322. genVNodeCall(node, context);
  2323. break;
  2324. case 14:
  2325. genCallExpression(node, context);
  2326. break;
  2327. case 15:
  2328. genObjectExpression(node, context);
  2329. break;
  2330. case 17:
  2331. genArrayExpression(node, context);
  2332. break;
  2333. case 18:
  2334. genFunctionExpression(node, context);
  2335. break;
  2336. case 19:
  2337. genConditionalExpression(node, context);
  2338. break;
  2339. case 20:
  2340. genCacheExpression(node, context);
  2341. break;
  2342. case 21:
  2343. genNodeList(node.body, context, true, false);
  2344. break;
  2345. case 22:
  2346. break;
  2347. case 23:
  2348. break;
  2349. case 24:
  2350. break;
  2351. case 25:
  2352. break;
  2353. case 26:
  2354. break;
  2355. case 10:
  2356. break;
  2357. default:
  2358. if (!!(process.env.NODE_ENV !== "production")) {
  2359. assert(false, `unhandled codegen node type: ${node.type}`);
  2360. const exhaustiveCheck = node;
  2361. return exhaustiveCheck;
  2362. }
  2363. }
  2364. }
  2365. function genText(node, context) {
  2366. context.push(JSON.stringify(node.content), node);
  2367. }
  2368. function genExpression(node, context) {
  2369. const { content, isStatic } = node;
  2370. context.push(isStatic ? JSON.stringify(content) : content, node);
  2371. }
  2372. function genInterpolation(node, context) {
  2373. const { push, helper, pure } = context;
  2374. if (pure)
  2375. push(PURE_ANNOTATION);
  2376. push(`${helper(TO_DISPLAY_STRING)}(`);
  2377. genNode(node.content, context);
  2378. push(`)`);
  2379. }
  2380. function genCompoundExpression(node, context) {
  2381. for (let i = 0; i < node.children.length; i++) {
  2382. const child = node.children[i];
  2383. if (isString(child)) {
  2384. context.push(child);
  2385. } else {
  2386. genNode(child, context);
  2387. }
  2388. }
  2389. }
  2390. function genExpressionAsPropertyKey(node, context) {
  2391. const { push } = context;
  2392. if (node.type === 8) {
  2393. push(`[`);
  2394. genCompoundExpression(node, context);
  2395. push(`]`);
  2396. } else if (node.isStatic) {
  2397. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  2398. push(text, node);
  2399. } else {
  2400. push(`[${node.content}]`, node);
  2401. }
  2402. }
  2403. function genComment(node, context) {
  2404. const { push, helper, pure } = context;
  2405. if (pure) {
  2406. push(PURE_ANNOTATION);
  2407. }
  2408. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  2409. }
  2410. function genVNodeCall(node, context) {
  2411. const { push, helper, pure } = context;
  2412. const {
  2413. tag,
  2414. props,
  2415. children,
  2416. patchFlag,
  2417. dynamicProps,
  2418. directives,
  2419. isBlock,
  2420. disableTracking,
  2421. isComponent
  2422. } = node;
  2423. if (directives) {
  2424. push(helper(WITH_DIRECTIVES) + `(`);
  2425. }
  2426. if (isBlock) {
  2427. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  2428. }
  2429. if (pure) {
  2430. push(PURE_ANNOTATION);
  2431. }
  2432. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  2433. push(helper(callHelper) + `(`, node);
  2434. genNodeList(
  2435. genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
  2436. context
  2437. );
  2438. push(`)`);
  2439. if (isBlock) {
  2440. push(`)`);
  2441. }
  2442. if (directives) {
  2443. push(`, `);
  2444. genNode(directives, context);
  2445. push(`)`);
  2446. }
  2447. }
  2448. function genNullableArgs(args) {
  2449. let i = args.length;
  2450. while (i--) {
  2451. if (args[i] != null)
  2452. break;
  2453. }
  2454. return args.slice(0, i + 1).map((arg) => arg || `null`);
  2455. }
  2456. function genCallExpression(node, context) {
  2457. const { push, helper, pure } = context;
  2458. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  2459. if (pure) {
  2460. push(PURE_ANNOTATION);
  2461. }
  2462. push(callee + `(`, node);
  2463. genNodeList(node.arguments, context);
  2464. push(`)`);
  2465. }
  2466. function genObjectExpression(node, context) {
  2467. const { push, indent, deindent, newline } = context;
  2468. const { properties } = node;
  2469. if (!properties.length) {
  2470. push(`{}`, node);
  2471. return;
  2472. }
  2473. const multilines = properties.length > 1 || !!(process.env.NODE_ENV !== "production") && properties.some((p) => p.value.type !== 4);
  2474. push(multilines ? `{` : `{ `);
  2475. multilines && indent();
  2476. for (let i = 0; i < properties.length; i++) {
  2477. const { key, value } = properties[i];
  2478. genExpressionAsPropertyKey(key, context);
  2479. push(`: `);
  2480. genNode(value, context);
  2481. if (i < properties.length - 1) {
  2482. push(`,`);
  2483. newline();
  2484. }
  2485. }
  2486. multilines && deindent();
  2487. push(multilines ? `}` : ` }`);
  2488. }
  2489. function genArrayExpression(node, context) {
  2490. genNodeListAsArray(node.elements, context);
  2491. }
  2492. function genFunctionExpression(node, context) {
  2493. const { push, indent, deindent } = context;
  2494. const { params, returns, body, newline, isSlot } = node;
  2495. if (isSlot) {
  2496. push(`_${helperNameMap[WITH_CTX]}(`);
  2497. }
  2498. push(`(`, node);
  2499. if (isArray(params)) {
  2500. genNodeList(params, context);
  2501. } else if (params) {
  2502. genNode(params, context);
  2503. }
  2504. push(`) => `);
  2505. if (newline || body) {
  2506. push(`{`);
  2507. indent();
  2508. }
  2509. if (returns) {
  2510. if (newline) {
  2511. push(`return `);
  2512. }
  2513. if (isArray(returns)) {
  2514. genNodeListAsArray(returns, context);
  2515. } else {
  2516. genNode(returns, context);
  2517. }
  2518. } else if (body) {
  2519. genNode(body, context);
  2520. }
  2521. if (newline || body) {
  2522. deindent();
  2523. push(`}`);
  2524. }
  2525. if (isSlot) {
  2526. if (node.isNonScopedSlot) {
  2527. push(`, undefined, true`);
  2528. }
  2529. push(`)`);
  2530. }
  2531. }
  2532. function genConditionalExpression(node, context) {
  2533. const { test, consequent, alternate, newline: needNewline } = node;
  2534. const { push, indent, deindent, newline } = context;
  2535. if (test.type === 4) {
  2536. const needsParens = !isSimpleIdentifier(test.content);
  2537. needsParens && push(`(`);
  2538. genExpression(test, context);
  2539. needsParens && push(`)`);
  2540. } else {
  2541. push(`(`);
  2542. genNode(test, context);
  2543. push(`)`);
  2544. }
  2545. needNewline && indent();
  2546. context.indentLevel++;
  2547. needNewline || push(` `);
  2548. push(`? `);
  2549. genNode(consequent, context);
  2550. context.indentLevel--;
  2551. needNewline && newline();
  2552. needNewline || push(` `);
  2553. push(`: `);
  2554. const isNested = alternate.type === 19;
  2555. if (!isNested) {
  2556. context.indentLevel++;
  2557. }
  2558. genNode(alternate, context);
  2559. if (!isNested) {
  2560. context.indentLevel--;
  2561. }
  2562. needNewline && deindent(
  2563. true
  2564. /* without newline */
  2565. );
  2566. }
  2567. function genCacheExpression(node, context) {
  2568. const { push, helper, indent, deindent, newline } = context;
  2569. push(`_cache[${node.index}] || (`);
  2570. if (node.isVNode) {
  2571. indent();
  2572. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  2573. newline();
  2574. }
  2575. push(`_cache[${node.index}] = `);
  2576. genNode(node.value, context);
  2577. if (node.isVNode) {
  2578. push(`,`);
  2579. newline();
  2580. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  2581. newline();
  2582. push(`_cache[${node.index}]`);
  2583. deindent();
  2584. }
  2585. push(`)`);
  2586. }
  2587. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  2588. {
  2589. return;
  2590. }
  2591. }
  2592. function isReferencedIdentifier(id, parent, parentStack) {
  2593. {
  2594. return false;
  2595. }
  2596. }
  2597. function isInDestructureAssignment(parent, parentStack) {
  2598. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  2599. let i = parentStack.length;
  2600. while (i--) {
  2601. const p = parentStack[i];
  2602. if (p.type === "AssignmentExpression") {
  2603. return true;
  2604. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  2605. break;
  2606. }
  2607. }
  2608. }
  2609. return false;
  2610. }
  2611. function walkFunctionParams(node, onIdent) {
  2612. for (const p of node.params) {
  2613. for (const id of extractIdentifiers(p)) {
  2614. onIdent(id);
  2615. }
  2616. }
  2617. }
  2618. function walkBlockDeclarations(block, onIdent) {
  2619. for (const stmt of block.body) {
  2620. if (stmt.type === "VariableDeclaration") {
  2621. if (stmt.declare)
  2622. continue;
  2623. for (const decl of stmt.declarations) {
  2624. for (const id of extractIdentifiers(decl.id)) {
  2625. onIdent(id);
  2626. }
  2627. }
  2628. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  2629. if (stmt.declare || !stmt.id)
  2630. continue;
  2631. onIdent(stmt.id);
  2632. }
  2633. }
  2634. }
  2635. function extractIdentifiers(param, nodes = []) {
  2636. switch (param.type) {
  2637. case "Identifier":
  2638. nodes.push(param);
  2639. break;
  2640. case "MemberExpression":
  2641. let object = param;
  2642. while (object.type === "MemberExpression") {
  2643. object = object.object;
  2644. }
  2645. nodes.push(object);
  2646. break;
  2647. case "ObjectPattern":
  2648. for (const prop of param.properties) {
  2649. if (prop.type === "RestElement") {
  2650. extractIdentifiers(prop.argument, nodes);
  2651. } else {
  2652. extractIdentifiers(prop.value, nodes);
  2653. }
  2654. }
  2655. break;
  2656. case "ArrayPattern":
  2657. param.elements.forEach((element) => {
  2658. if (element)
  2659. extractIdentifiers(element, nodes);
  2660. });
  2661. break;
  2662. case "RestElement":
  2663. extractIdentifiers(param.argument, nodes);
  2664. break;
  2665. case "AssignmentPattern":
  2666. extractIdentifiers(param.left, nodes);
  2667. break;
  2668. }
  2669. return nodes;
  2670. }
  2671. const isFunctionType = (node) => {
  2672. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  2673. };
  2674. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  2675. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  2676. const TS_NODE_TYPES = [
  2677. "TSAsExpression",
  2678. // foo as number
  2679. "TSTypeAssertion",
  2680. // (<number>foo)
  2681. "TSNonNullExpression",
  2682. // foo!
  2683. "TSInstantiationExpression",
  2684. // foo<string>
  2685. "TSSatisfiesExpression"
  2686. // foo satisfies T
  2687. ];
  2688. const prohibitedKeywordRE = new RegExp(
  2689. "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
  2690. );
  2691. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  2692. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  2693. const exp = node.content;
  2694. if (!exp.trim()) {
  2695. return;
  2696. }
  2697. try {
  2698. new Function(
  2699. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  2700. );
  2701. } catch (e) {
  2702. let message = e.message;
  2703. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  2704. if (keywordMatch) {
  2705. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  2706. }
  2707. context.onError(
  2708. createCompilerError(
  2709. 45,
  2710. node.loc,
  2711. void 0,
  2712. message
  2713. )
  2714. );
  2715. }
  2716. }
  2717. const transformExpression = (node, context) => {
  2718. if (node.type === 5) {
  2719. node.content = processExpression(
  2720. node.content,
  2721. context
  2722. );
  2723. } else if (node.type === 1) {
  2724. for (let i = 0; i < node.props.length; i++) {
  2725. const dir = node.props[i];
  2726. if (dir.type === 7 && dir.name !== "for") {
  2727. const exp = dir.exp;
  2728. const arg = dir.arg;
  2729. if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
  2730. dir.exp = processExpression(
  2731. exp,
  2732. context,
  2733. // slot args must be processed as function params
  2734. dir.name === "slot"
  2735. );
  2736. }
  2737. if (arg && arg.type === 4 && !arg.isStatic) {
  2738. dir.arg = processExpression(arg, context);
  2739. }
  2740. }
  2741. }
  2742. }
  2743. };
  2744. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  2745. {
  2746. if (!!(process.env.NODE_ENV !== "production")) {
  2747. validateBrowserExpression(node, context, asParams, asRawStatements);
  2748. }
  2749. return node;
  2750. }
  2751. }
  2752. function stringifyExpression(exp) {
  2753. if (isString(exp)) {
  2754. return exp;
  2755. } else if (exp.type === 4) {
  2756. return exp.content;
  2757. } else {
  2758. return exp.children.map(stringifyExpression).join("");
  2759. }
  2760. }
  2761. const transformIf = createStructuralDirectiveTransform(
  2762. /^(if|else|else-if)$/,
  2763. (node, dir, context) => {
  2764. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  2765. const siblings = context.parent.children;
  2766. let i = siblings.indexOf(ifNode);
  2767. let key = 0;
  2768. while (i-- >= 0) {
  2769. const sibling = siblings[i];
  2770. if (sibling && sibling.type === 9) {
  2771. key += sibling.branches.length;
  2772. }
  2773. }
  2774. return () => {
  2775. if (isRoot) {
  2776. ifNode.codegenNode = createCodegenNodeForBranch(
  2777. branch,
  2778. key,
  2779. context
  2780. );
  2781. } else {
  2782. const parentCondition = getParentCondition(ifNode.codegenNode);
  2783. parentCondition.alternate = createCodegenNodeForBranch(
  2784. branch,
  2785. key + ifNode.branches.length - 1,
  2786. context
  2787. );
  2788. }
  2789. };
  2790. });
  2791. }
  2792. );
  2793. function processIf(node, dir, context, processCodegen) {
  2794. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  2795. const loc = dir.exp ? dir.exp.loc : node.loc;
  2796. context.onError(
  2797. createCompilerError(28, dir.loc)
  2798. );
  2799. dir.exp = createSimpleExpression(`true`, false, loc);
  2800. }
  2801. if (!!(process.env.NODE_ENV !== "production") && true && dir.exp) {
  2802. validateBrowserExpression(dir.exp, context);
  2803. }
  2804. if (dir.name === "if") {
  2805. const branch = createIfBranch(node, dir);
  2806. const ifNode = {
  2807. type: 9,
  2808. loc: node.loc,
  2809. branches: [branch]
  2810. };
  2811. context.replaceNode(ifNode);
  2812. if (processCodegen) {
  2813. return processCodegen(ifNode, branch, true);
  2814. }
  2815. } else {
  2816. const siblings = context.parent.children;
  2817. const comments = [];
  2818. let i = siblings.indexOf(node);
  2819. while (i-- >= -1) {
  2820. const sibling = siblings[i];
  2821. if (sibling && sibling.type === 3) {
  2822. context.removeNode(sibling);
  2823. !!(process.env.NODE_ENV !== "production") && comments.unshift(sibling);
  2824. continue;
  2825. }
  2826. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  2827. context.removeNode(sibling);
  2828. continue;
  2829. }
  2830. if (sibling && sibling.type === 9) {
  2831. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  2832. context.onError(
  2833. createCompilerError(30, node.loc)
  2834. );
  2835. }
  2836. context.removeNode();
  2837. const branch = createIfBranch(node, dir);
  2838. if (!!(process.env.NODE_ENV !== "production") && comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  2839. !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
  2840. branch.children = [...comments, ...branch.children];
  2841. }
  2842. if (!!(process.env.NODE_ENV !== "production") || false) {
  2843. const key = branch.userKey;
  2844. if (key) {
  2845. sibling.branches.forEach(({ userKey }) => {
  2846. if (isSameKey(userKey, key)) {
  2847. context.onError(
  2848. createCompilerError(
  2849. 29,
  2850. branch.userKey.loc
  2851. )
  2852. );
  2853. }
  2854. });
  2855. }
  2856. }
  2857. sibling.branches.push(branch);
  2858. const onExit = processCodegen && processCodegen(sibling, branch, false);
  2859. traverseNode(branch, context);
  2860. if (onExit)
  2861. onExit();
  2862. context.currentNode = null;
  2863. } else {
  2864. context.onError(
  2865. createCompilerError(30, node.loc)
  2866. );
  2867. }
  2868. break;
  2869. }
  2870. }
  2871. }
  2872. function createIfBranch(node, dir) {
  2873. const isTemplateIf = node.tagType === 3;
  2874. return {
  2875. type: 10,
  2876. loc: node.loc,
  2877. condition: dir.name === "else" ? void 0 : dir.exp,
  2878. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  2879. userKey: findProp(node, `key`),
  2880. isTemplateIf
  2881. };
  2882. }
  2883. function createCodegenNodeForBranch(branch, keyIndex, context) {
  2884. if (branch.condition) {
  2885. return createConditionalExpression(
  2886. branch.condition,
  2887. createChildrenCodegenNode(branch, keyIndex, context),
  2888. // make sure to pass in asBlock: true so that the comment node call
  2889. // closes the current block.
  2890. createCallExpression(context.helper(CREATE_COMMENT), [
  2891. !!(process.env.NODE_ENV !== "production") ? '"v-if"' : '""',
  2892. "true"
  2893. ])
  2894. );
  2895. } else {
  2896. return createChildrenCodegenNode(branch, keyIndex, context);
  2897. }
  2898. }
  2899. function createChildrenCodegenNode(branch, keyIndex, context) {
  2900. const { helper } = context;
  2901. const keyProperty = createObjectProperty(
  2902. `key`,
  2903. createSimpleExpression(
  2904. `${keyIndex}`,
  2905. false,
  2906. locStub,
  2907. 2
  2908. )
  2909. );
  2910. const { children } = branch;
  2911. const firstChild = children[0];
  2912. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  2913. if (needFragmentWrapper) {
  2914. if (children.length === 1 && firstChild.type === 11) {
  2915. const vnodeCall = firstChild.codegenNode;
  2916. injectProp(vnodeCall, keyProperty, context);
  2917. return vnodeCall;
  2918. } else {
  2919. let patchFlag = 64;
  2920. let patchFlagText = PatchFlagNames[64];
  2921. if (!!(process.env.NODE_ENV !== "production") && !branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  2922. patchFlag |= 2048;
  2923. patchFlagText += `, ${PatchFlagNames[2048]}`;
  2924. }
  2925. return createVNodeCall(
  2926. context,
  2927. helper(FRAGMENT),
  2928. createObjectExpression([keyProperty]),
  2929. children,
  2930. patchFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${patchFlagText} */` : ``),
  2931. void 0,
  2932. void 0,
  2933. true,
  2934. false,
  2935. false,
  2936. branch.loc
  2937. );
  2938. }
  2939. } else {
  2940. const ret = firstChild.codegenNode;
  2941. const vnodeCall = getMemoedVNodeCall(ret);
  2942. if (vnodeCall.type === 13) {
  2943. convertToBlock(vnodeCall, context);
  2944. }
  2945. injectProp(vnodeCall, keyProperty, context);
  2946. return ret;
  2947. }
  2948. }
  2949. function isSameKey(a, b) {
  2950. if (!a || a.type !== b.type) {
  2951. return false;
  2952. }
  2953. if (a.type === 6) {
  2954. if (a.value.content !== b.value.content) {
  2955. return false;
  2956. }
  2957. } else {
  2958. const exp = a.exp;
  2959. const branchExp = b.exp;
  2960. if (exp.type !== branchExp.type) {
  2961. return false;
  2962. }
  2963. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  2964. return false;
  2965. }
  2966. }
  2967. return true;
  2968. }
  2969. function getParentCondition(node) {
  2970. while (true) {
  2971. if (node.type === 19) {
  2972. if (node.alternate.type === 19) {
  2973. node = node.alternate;
  2974. } else {
  2975. return node;
  2976. }
  2977. } else if (node.type === 20) {
  2978. node = node.value;
  2979. }
  2980. }
  2981. }
  2982. const transformFor = createStructuralDirectiveTransform(
  2983. "for",
  2984. (node, dir, context) => {
  2985. const { helper, removeHelper } = context;
  2986. return processFor(node, dir, context, (forNode) => {
  2987. const renderExp = createCallExpression(helper(RENDER_LIST), [
  2988. forNode.source
  2989. ]);
  2990. const isTemplate = isTemplateNode(node);
  2991. const memo = findDir(node, "memo");
  2992. const keyProp = findProp(node, `key`);
  2993. const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
  2994. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  2995. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  2996. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  2997. forNode.codegenNode = createVNodeCall(
  2998. context,
  2999. helper(FRAGMENT),
  3000. void 0,
  3001. renderExp,
  3002. fragmentFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``),
  3003. void 0,
  3004. void 0,
  3005. true,
  3006. !isStableFragment,
  3007. false,
  3008. node.loc
  3009. );
  3010. return () => {
  3011. let childBlock;
  3012. const { children } = forNode;
  3013. if ((!!(process.env.NODE_ENV !== "production") || false) && isTemplate) {
  3014. node.children.some((c) => {
  3015. if (c.type === 1) {
  3016. const key = findProp(c, "key");
  3017. if (key) {
  3018. context.onError(
  3019. createCompilerError(
  3020. 33,
  3021. key.loc
  3022. )
  3023. );
  3024. return true;
  3025. }
  3026. }
  3027. });
  3028. }
  3029. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  3030. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  3031. if (slotOutlet) {
  3032. childBlock = slotOutlet.codegenNode;
  3033. if (isTemplate && keyProperty) {
  3034. injectProp(childBlock, keyProperty, context);
  3035. }
  3036. } else if (needFragmentWrapper) {
  3037. childBlock = createVNodeCall(
  3038. context,
  3039. helper(FRAGMENT),
  3040. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  3041. node.children,
  3042. 64 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[64]} */` : ``),
  3043. void 0,
  3044. void 0,
  3045. true,
  3046. void 0,
  3047. false
  3048. /* isComponent */
  3049. );
  3050. } else {
  3051. childBlock = children[0].codegenNode;
  3052. if (isTemplate && keyProperty) {
  3053. injectProp(childBlock, keyProperty, context);
  3054. }
  3055. if (childBlock.isBlock !== !isStableFragment) {
  3056. if (childBlock.isBlock) {
  3057. removeHelper(OPEN_BLOCK);
  3058. removeHelper(
  3059. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  3060. );
  3061. } else {
  3062. removeHelper(
  3063. getVNodeHelper(context.inSSR, childBlock.isComponent)
  3064. );
  3065. }
  3066. }
  3067. childBlock.isBlock = !isStableFragment;
  3068. if (childBlock.isBlock) {
  3069. helper(OPEN_BLOCK);
  3070. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  3071. } else {
  3072. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  3073. }
  3074. }
  3075. if (memo) {
  3076. const loop = createFunctionExpression(
  3077. createForLoopParams(forNode.parseResult, [
  3078. createSimpleExpression(`_cached`)
  3079. ])
  3080. );
  3081. loop.body = createBlockStatement([
  3082. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  3083. createCompoundExpression([
  3084. `if (_cached`,
  3085. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  3086. ` && ${context.helperString(
  3087. IS_MEMO_SAME
  3088. )}(_cached, _memo)) return _cached`
  3089. ]),
  3090. createCompoundExpression([`const _item = `, childBlock]),
  3091. createSimpleExpression(`_item.memo = _memo`),
  3092. createSimpleExpression(`return _item`)
  3093. ]);
  3094. renderExp.arguments.push(
  3095. loop,
  3096. createSimpleExpression(`_cache`),
  3097. createSimpleExpression(String(context.cached++))
  3098. );
  3099. } else {
  3100. renderExp.arguments.push(
  3101. createFunctionExpression(
  3102. createForLoopParams(forNode.parseResult),
  3103. childBlock,
  3104. true
  3105. /* force newline */
  3106. )
  3107. );
  3108. }
  3109. };
  3110. });
  3111. }
  3112. );
  3113. function processFor(node, dir, context, processCodegen) {
  3114. if (!dir.exp) {
  3115. context.onError(
  3116. createCompilerError(31, dir.loc)
  3117. );
  3118. return;
  3119. }
  3120. const parseResult = parseForExpression(
  3121. // can only be simple expression because vFor transform is applied
  3122. // before expression transform.
  3123. dir.exp,
  3124. context
  3125. );
  3126. if (!parseResult) {
  3127. context.onError(
  3128. createCompilerError(32, dir.loc)
  3129. );
  3130. return;
  3131. }
  3132. const { addIdentifiers, removeIdentifiers, scopes } = context;
  3133. const { source, value, key, index } = parseResult;
  3134. const forNode = {
  3135. type: 11,
  3136. loc: dir.loc,
  3137. source,
  3138. valueAlias: value,
  3139. keyAlias: key,
  3140. objectIndexAlias: index,
  3141. parseResult,
  3142. children: isTemplateNode(node) ? node.children : [node]
  3143. };
  3144. context.replaceNode(forNode);
  3145. scopes.vFor++;
  3146. const onExit = processCodegen && processCodegen(forNode);
  3147. return () => {
  3148. scopes.vFor--;
  3149. if (onExit)
  3150. onExit();
  3151. };
  3152. }
  3153. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  3154. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  3155. const stripParensRE = /^\(|\)$/g;
  3156. function parseForExpression(input, context) {
  3157. const loc = input.loc;
  3158. const exp = input.content;
  3159. const inMatch = exp.match(forAliasRE);
  3160. if (!inMatch)
  3161. return;
  3162. const [, LHS, RHS] = inMatch;
  3163. const result = {
  3164. source: createAliasExpression(
  3165. loc,
  3166. RHS.trim(),
  3167. exp.indexOf(RHS, LHS.length)
  3168. ),
  3169. value: void 0,
  3170. key: void 0,
  3171. index: void 0
  3172. };
  3173. if (!!(process.env.NODE_ENV !== "production") && true) {
  3174. validateBrowserExpression(result.source, context);
  3175. }
  3176. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  3177. const trimmedOffset = LHS.indexOf(valueContent);
  3178. const iteratorMatch = valueContent.match(forIteratorRE);
  3179. if (iteratorMatch) {
  3180. valueContent = valueContent.replace(forIteratorRE, "").trim();
  3181. const keyContent = iteratorMatch[1].trim();
  3182. let keyOffset;
  3183. if (keyContent) {
  3184. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  3185. result.key = createAliasExpression(loc, keyContent, keyOffset);
  3186. if (!!(process.env.NODE_ENV !== "production") && true) {
  3187. validateBrowserExpression(
  3188. result.key,
  3189. context,
  3190. true
  3191. );
  3192. }
  3193. }
  3194. if (iteratorMatch[2]) {
  3195. const indexContent = iteratorMatch[2].trim();
  3196. if (indexContent) {
  3197. result.index = createAliasExpression(
  3198. loc,
  3199. indexContent,
  3200. exp.indexOf(
  3201. indexContent,
  3202. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  3203. )
  3204. );
  3205. if (!!(process.env.NODE_ENV !== "production") && true) {
  3206. validateBrowserExpression(
  3207. result.index,
  3208. context,
  3209. true
  3210. );
  3211. }
  3212. }
  3213. }
  3214. }
  3215. if (valueContent) {
  3216. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  3217. if (!!(process.env.NODE_ENV !== "production") && true) {
  3218. validateBrowserExpression(
  3219. result.value,
  3220. context,
  3221. true
  3222. );
  3223. }
  3224. }
  3225. return result;
  3226. }
  3227. function createAliasExpression(range, content, offset) {
  3228. return createSimpleExpression(
  3229. content,
  3230. false,
  3231. getInnerRange(range, offset, content.length)
  3232. );
  3233. }
  3234. function createForLoopParams({ value, key, index }, memoArgs = []) {
  3235. return createParamsList([value, key, index, ...memoArgs]);
  3236. }
  3237. function createParamsList(args) {
  3238. let i = args.length;
  3239. while (i--) {
  3240. if (args[i])
  3241. break;
  3242. }
  3243. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  3244. }
  3245. const defaultFallback = createSimpleExpression(`undefined`, false);
  3246. const trackSlotScopes = (node, context) => {
  3247. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  3248. const vSlot = findDir(node, "slot");
  3249. if (vSlot) {
  3250. vSlot.exp;
  3251. context.scopes.vSlot++;
  3252. return () => {
  3253. context.scopes.vSlot--;
  3254. };
  3255. }
  3256. }
  3257. };
  3258. const trackVForSlotScopes = (node, context) => {
  3259. let vFor;
  3260. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  3261. const result = vFor.parseResult = parseForExpression(
  3262. vFor.exp,
  3263. context
  3264. );
  3265. if (result) {
  3266. const { value, key, index } = result;
  3267. const { addIdentifiers, removeIdentifiers } = context;
  3268. value && addIdentifiers(value);
  3269. key && addIdentifiers(key);
  3270. index && addIdentifiers(index);
  3271. return () => {
  3272. value && removeIdentifiers(value);
  3273. key && removeIdentifiers(key);
  3274. index && removeIdentifiers(index);
  3275. };
  3276. }
  3277. }
  3278. };
  3279. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(
  3280. props,
  3281. children,
  3282. false,
  3283. true,
  3284. children.length ? children[0].loc : loc
  3285. );
  3286. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  3287. context.helper(WITH_CTX);
  3288. const { children, loc } = node;
  3289. const slotsProperties = [];
  3290. const dynamicSlots = [];
  3291. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  3292. const onComponentSlot = findDir(node, "slot", true);
  3293. if (onComponentSlot) {
  3294. const { arg, exp } = onComponentSlot;
  3295. if (arg && !isStaticExp(arg)) {
  3296. hasDynamicSlots = true;
  3297. }
  3298. slotsProperties.push(
  3299. createObjectProperty(
  3300. arg || createSimpleExpression("default", true),
  3301. buildSlotFn(exp, children, loc)
  3302. )
  3303. );
  3304. }
  3305. let hasTemplateSlots = false;
  3306. let hasNamedDefaultSlot = false;
  3307. const implicitDefaultChildren = [];
  3308. const seenSlotNames = /* @__PURE__ */ new Set();
  3309. let conditionalBranchIndex = 0;
  3310. for (let i = 0; i < children.length; i++) {
  3311. const slotElement = children[i];
  3312. let slotDir;
  3313. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  3314. if (slotElement.type !== 3) {
  3315. implicitDefaultChildren.push(slotElement);
  3316. }
  3317. continue;
  3318. }
  3319. if (onComponentSlot) {
  3320. context.onError(
  3321. createCompilerError(37, slotDir.loc)
  3322. );
  3323. break;
  3324. }
  3325. hasTemplateSlots = true;
  3326. const { children: slotChildren, loc: slotLoc } = slotElement;
  3327. const {
  3328. arg: slotName = createSimpleExpression(`default`, true),
  3329. exp: slotProps,
  3330. loc: dirLoc
  3331. } = slotDir;
  3332. let staticSlotName;
  3333. if (isStaticExp(slotName)) {
  3334. staticSlotName = slotName ? slotName.content : `default`;
  3335. } else {
  3336. hasDynamicSlots = true;
  3337. }
  3338. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  3339. let vIf;
  3340. let vElse;
  3341. let vFor;
  3342. if (vIf = findDir(slotElement, "if")) {
  3343. hasDynamicSlots = true;
  3344. dynamicSlots.push(
  3345. createConditionalExpression(
  3346. vIf.exp,
  3347. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  3348. defaultFallback
  3349. )
  3350. );
  3351. } else if (vElse = findDir(
  3352. slotElement,
  3353. /^else(-if)?$/,
  3354. true
  3355. /* allowEmpty */
  3356. )) {
  3357. let j = i;
  3358. let prev;
  3359. while (j--) {
  3360. prev = children[j];
  3361. if (prev.type !== 3) {
  3362. break;
  3363. }
  3364. }
  3365. if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
  3366. children.splice(i, 1);
  3367. i--;
  3368. let conditional = dynamicSlots[dynamicSlots.length - 1];
  3369. while (conditional.alternate.type === 19) {
  3370. conditional = conditional.alternate;
  3371. }
  3372. conditional.alternate = vElse.exp ? createConditionalExpression(
  3373. vElse.exp,
  3374. buildDynamicSlot(
  3375. slotName,
  3376. slotFunction,
  3377. conditionalBranchIndex++
  3378. ),
  3379. defaultFallback
  3380. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  3381. } else {
  3382. context.onError(
  3383. createCompilerError(30, vElse.loc)
  3384. );
  3385. }
  3386. } else if (vFor = findDir(slotElement, "for")) {
  3387. hasDynamicSlots = true;
  3388. const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
  3389. if (parseResult) {
  3390. dynamicSlots.push(
  3391. createCallExpression(context.helper(RENDER_LIST), [
  3392. parseResult.source,
  3393. createFunctionExpression(
  3394. createForLoopParams(parseResult),
  3395. buildDynamicSlot(slotName, slotFunction),
  3396. true
  3397. /* force newline */
  3398. )
  3399. ])
  3400. );
  3401. } else {
  3402. context.onError(
  3403. createCompilerError(32, vFor.loc)
  3404. );
  3405. }
  3406. } else {
  3407. if (staticSlotName) {
  3408. if (seenSlotNames.has(staticSlotName)) {
  3409. context.onError(
  3410. createCompilerError(
  3411. 38,
  3412. dirLoc
  3413. )
  3414. );
  3415. continue;
  3416. }
  3417. seenSlotNames.add(staticSlotName);
  3418. if (staticSlotName === "default") {
  3419. hasNamedDefaultSlot = true;
  3420. }
  3421. }
  3422. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  3423. }
  3424. }
  3425. if (!onComponentSlot) {
  3426. const buildDefaultSlotProperty = (props, children2) => {
  3427. const fn = buildSlotFn(props, children2, loc);
  3428. if (context.compatConfig) {
  3429. fn.isNonScopedSlot = true;
  3430. }
  3431. return createObjectProperty(`default`, fn);
  3432. };
  3433. if (!hasTemplateSlots) {
  3434. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  3435. } else if (implicitDefaultChildren.length && // #3766
  3436. // with whitespace: 'preserve', whitespaces between slots will end up in
  3437. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  3438. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  3439. if (hasNamedDefaultSlot) {
  3440. context.onError(
  3441. createCompilerError(
  3442. 39,
  3443. implicitDefaultChildren[0].loc
  3444. )
  3445. );
  3446. } else {
  3447. slotsProperties.push(
  3448. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  3449. );
  3450. }
  3451. }
  3452. }
  3453. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  3454. let slots = createObjectExpression(
  3455. slotsProperties.concat(
  3456. createObjectProperty(
  3457. `_`,
  3458. // 2 = compiled but dynamic = can skip normalization, but must run diff
  3459. // 1 = compiled and static = can skip normalization AND diff as optimized
  3460. createSimpleExpression(
  3461. slotFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${slotFlagsText[slotFlag]} */` : ``),
  3462. false
  3463. )
  3464. )
  3465. ),
  3466. loc
  3467. );
  3468. if (dynamicSlots.length) {
  3469. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  3470. slots,
  3471. createArrayExpression(dynamicSlots)
  3472. ]);
  3473. }
  3474. return {
  3475. slots,
  3476. hasDynamicSlots
  3477. };
  3478. }
  3479. function buildDynamicSlot(name, fn, index) {
  3480. const props = [
  3481. createObjectProperty(`name`, name),
  3482. createObjectProperty(`fn`, fn)
  3483. ];
  3484. if (index != null) {
  3485. props.push(
  3486. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  3487. );
  3488. }
  3489. return createObjectExpression(props);
  3490. }
  3491. function hasForwardedSlots(children) {
  3492. for (let i = 0; i < children.length; i++) {
  3493. const child = children[i];
  3494. switch (child.type) {
  3495. case 1:
  3496. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  3497. return true;
  3498. }
  3499. break;
  3500. case 9:
  3501. if (hasForwardedSlots(child.branches))
  3502. return true;
  3503. break;
  3504. case 10:
  3505. case 11:
  3506. if (hasForwardedSlots(child.children))
  3507. return true;
  3508. break;
  3509. }
  3510. }
  3511. return false;
  3512. }
  3513. function isNonWhitespaceContent(node) {
  3514. if (node.type !== 2 && node.type !== 12)
  3515. return true;
  3516. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  3517. }
  3518. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  3519. const transformElement = (node, context) => {
  3520. return function postTransformElement() {
  3521. node = context.currentNode;
  3522. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  3523. return;
  3524. }
  3525. const { tag, props } = node;
  3526. const isComponent = node.tagType === 1;
  3527. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  3528. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  3529. let vnodeProps;
  3530. let vnodeChildren;
  3531. let vnodePatchFlag;
  3532. let patchFlag = 0;
  3533. let vnodeDynamicProps;
  3534. let dynamicPropNames;
  3535. let vnodeDirectives;
  3536. let shouldUseBlock = (
  3537. // dynamic component may resolve to plain elements
  3538. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  3539. // updates inside get proper isSVG flag at runtime. (#639, #643)
  3540. // This is technically web-specific, but splitting the logic out of core
  3541. // leads to too much unnecessary complexity.
  3542. (tag === "svg" || tag === "foreignObject")
  3543. );
  3544. if (props.length > 0) {
  3545. const propsBuildResult = buildProps(
  3546. node,
  3547. context,
  3548. void 0,
  3549. isComponent,
  3550. isDynamicComponent
  3551. );
  3552. vnodeProps = propsBuildResult.props;
  3553. patchFlag = propsBuildResult.patchFlag;
  3554. dynamicPropNames = propsBuildResult.dynamicPropNames;
  3555. const directives = propsBuildResult.directives;
  3556. vnodeDirectives = directives && directives.length ? createArrayExpression(
  3557. directives.map((dir) => buildDirectiveArgs(dir, context))
  3558. ) : void 0;
  3559. if (propsBuildResult.shouldUseBlock) {
  3560. shouldUseBlock = true;
  3561. }
  3562. }
  3563. if (node.children.length > 0) {
  3564. if (vnodeTag === KEEP_ALIVE) {
  3565. shouldUseBlock = true;
  3566. patchFlag |= 1024;
  3567. if (!!(process.env.NODE_ENV !== "production") && node.children.length > 1) {
  3568. context.onError(
  3569. createCompilerError(46, {
  3570. start: node.children[0].loc.start,
  3571. end: node.children[node.children.length - 1].loc.end,
  3572. source: ""
  3573. })
  3574. );
  3575. }
  3576. }
  3577. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  3578. vnodeTag !== TELEPORT && // explained above.
  3579. vnodeTag !== KEEP_ALIVE;
  3580. if (shouldBuildAsSlots) {
  3581. const { slots, hasDynamicSlots } = buildSlots(node, context);
  3582. vnodeChildren = slots;
  3583. if (hasDynamicSlots) {
  3584. patchFlag |= 1024;
  3585. }
  3586. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  3587. const child = node.children[0];
  3588. const type = child.type;
  3589. const hasDynamicTextChild = type === 5 || type === 8;
  3590. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  3591. patchFlag |= 1;
  3592. }
  3593. if (hasDynamicTextChild || type === 2) {
  3594. vnodeChildren = child;
  3595. } else {
  3596. vnodeChildren = node.children;
  3597. }
  3598. } else {
  3599. vnodeChildren = node.children;
  3600. }
  3601. }
  3602. if (patchFlag !== 0) {
  3603. if (!!(process.env.NODE_ENV !== "production")) {
  3604. if (patchFlag < 0) {
  3605. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3606. } else {
  3607. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3608. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  3609. }
  3610. } else {
  3611. vnodePatchFlag = String(patchFlag);
  3612. }
  3613. if (dynamicPropNames && dynamicPropNames.length) {
  3614. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  3615. }
  3616. }
  3617. node.codegenNode = createVNodeCall(
  3618. context,
  3619. vnodeTag,
  3620. vnodeProps,
  3621. vnodeChildren,
  3622. vnodePatchFlag,
  3623. vnodeDynamicProps,
  3624. vnodeDirectives,
  3625. !!shouldUseBlock,
  3626. false,
  3627. isComponent,
  3628. node.loc
  3629. );
  3630. };
  3631. };
  3632. function resolveComponentType(node, context, ssr = false) {
  3633. let { tag } = node;
  3634. const isExplicitDynamic = isComponentTag(tag);
  3635. const isProp = findProp(node, "is");
  3636. if (isProp) {
  3637. if (isExplicitDynamic || isCompatEnabled(
  3638. "COMPILER_IS_ON_ELEMENT",
  3639. context
  3640. )) {
  3641. const exp = isProp.type === 6 ? isProp.value && createSimpleExpression(isProp.value.content, true) : isProp.exp;
  3642. if (exp) {
  3643. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3644. exp
  3645. ]);
  3646. }
  3647. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  3648. tag = isProp.value.content.slice(4);
  3649. }
  3650. }
  3651. const isDir = !isExplicitDynamic && findDir(node, "is");
  3652. if (isDir && isDir.exp) {
  3653. if (!!(process.env.NODE_ENV !== "production")) {
  3654. context.onWarn(
  3655. createCompilerError(52, isDir.loc)
  3656. );
  3657. }
  3658. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3659. isDir.exp
  3660. ]);
  3661. }
  3662. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  3663. if (builtIn) {
  3664. if (!ssr)
  3665. context.helper(builtIn);
  3666. return builtIn;
  3667. }
  3668. context.helper(RESOLVE_COMPONENT);
  3669. context.components.add(tag);
  3670. return toValidAssetId(tag, `component`);
  3671. }
  3672. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  3673. const { tag, loc: elementLoc, children } = node;
  3674. let properties = [];
  3675. const mergeArgs = [];
  3676. const runtimeDirectives = [];
  3677. const hasChildren = children.length > 0;
  3678. let shouldUseBlock = false;
  3679. let patchFlag = 0;
  3680. let hasRef = false;
  3681. let hasClassBinding = false;
  3682. let hasStyleBinding = false;
  3683. let hasHydrationEventBinding = false;
  3684. let hasDynamicKeys = false;
  3685. let hasVnodeHook = false;
  3686. const dynamicPropNames = [];
  3687. const pushMergeArg = (arg) => {
  3688. if (properties.length) {
  3689. mergeArgs.push(
  3690. createObjectExpression(dedupeProperties(properties), elementLoc)
  3691. );
  3692. properties = [];
  3693. }
  3694. if (arg)
  3695. mergeArgs.push(arg);
  3696. };
  3697. const analyzePatchFlag = ({ key, value }) => {
  3698. if (isStaticExp(key)) {
  3699. const name = key.content;
  3700. const isEventHandler = isOn(name);
  3701. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  3702. // dedicated fast path.
  3703. name.toLowerCase() !== "onclick" && // omit v-model handlers
  3704. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  3705. !isReservedProp(name)) {
  3706. hasHydrationEventBinding = true;
  3707. }
  3708. if (isEventHandler && isReservedProp(name)) {
  3709. hasVnodeHook = true;
  3710. }
  3711. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  3712. return;
  3713. }
  3714. if (name === "ref") {
  3715. hasRef = true;
  3716. } else if (name === "class") {
  3717. hasClassBinding = true;
  3718. } else if (name === "style") {
  3719. hasStyleBinding = true;
  3720. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  3721. dynamicPropNames.push(name);
  3722. }
  3723. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  3724. dynamicPropNames.push(name);
  3725. }
  3726. } else {
  3727. hasDynamicKeys = true;
  3728. }
  3729. };
  3730. for (let i = 0; i < props.length; i++) {
  3731. const prop = props[i];
  3732. if (prop.type === 6) {
  3733. const { loc, name, value } = prop;
  3734. let isStatic = true;
  3735. if (name === "ref") {
  3736. hasRef = true;
  3737. if (context.scopes.vFor > 0) {
  3738. properties.push(
  3739. createObjectProperty(
  3740. createSimpleExpression("ref_for", true),
  3741. createSimpleExpression("true")
  3742. )
  3743. );
  3744. }
  3745. }
  3746. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  3747. "COMPILER_IS_ON_ELEMENT",
  3748. context
  3749. ))) {
  3750. continue;
  3751. }
  3752. properties.push(
  3753. createObjectProperty(
  3754. createSimpleExpression(
  3755. name,
  3756. true,
  3757. getInnerRange(loc, 0, name.length)
  3758. ),
  3759. createSimpleExpression(
  3760. value ? value.content : "",
  3761. isStatic,
  3762. value ? value.loc : loc
  3763. )
  3764. )
  3765. );
  3766. } else {
  3767. const { name, arg, exp, loc } = prop;
  3768. const isVBind = name === "bind";
  3769. const isVOn = name === "on";
  3770. if (name === "slot") {
  3771. if (!isComponent) {
  3772. context.onError(
  3773. createCompilerError(40, loc)
  3774. );
  3775. }
  3776. continue;
  3777. }
  3778. if (name === "once" || name === "memo") {
  3779. continue;
  3780. }
  3781. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  3782. "COMPILER_IS_ON_ELEMENT",
  3783. context
  3784. ))) {
  3785. continue;
  3786. }
  3787. if (isVOn && ssr) {
  3788. continue;
  3789. }
  3790. if (
  3791. // #938: elements with dynamic keys should be forced into blocks
  3792. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  3793. // before children
  3794. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  3795. ) {
  3796. shouldUseBlock = true;
  3797. }
  3798. if (isVBind && isStaticArgOf(arg, "ref") && context.scopes.vFor > 0) {
  3799. properties.push(
  3800. createObjectProperty(
  3801. createSimpleExpression("ref_for", true),
  3802. createSimpleExpression("true")
  3803. )
  3804. );
  3805. }
  3806. if (!arg && (isVBind || isVOn)) {
  3807. hasDynamicKeys = true;
  3808. if (exp) {
  3809. if (isVBind) {
  3810. pushMergeArg();
  3811. {
  3812. if (!!(process.env.NODE_ENV !== "production")) {
  3813. const hasOverridableKeys = mergeArgs.some((arg2) => {
  3814. if (arg2.type === 15) {
  3815. return arg2.properties.some(({ key }) => {
  3816. if (key.type !== 4 || !key.isStatic) {
  3817. return true;
  3818. }
  3819. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  3820. });
  3821. } else {
  3822. return true;
  3823. }
  3824. });
  3825. if (hasOverridableKeys) {
  3826. checkCompatEnabled(
  3827. "COMPILER_V_BIND_OBJECT_ORDER",
  3828. context,
  3829. loc
  3830. );
  3831. }
  3832. }
  3833. if (isCompatEnabled(
  3834. "COMPILER_V_BIND_OBJECT_ORDER",
  3835. context
  3836. )) {
  3837. mergeArgs.unshift(exp);
  3838. continue;
  3839. }
  3840. }
  3841. mergeArgs.push(exp);
  3842. } else {
  3843. pushMergeArg({
  3844. type: 14,
  3845. loc,
  3846. callee: context.helper(TO_HANDLERS),
  3847. arguments: isComponent ? [exp] : [exp, `true`]
  3848. });
  3849. }
  3850. } else {
  3851. context.onError(
  3852. createCompilerError(
  3853. isVBind ? 34 : 35,
  3854. loc
  3855. )
  3856. );
  3857. }
  3858. continue;
  3859. }
  3860. const directiveTransform = context.directiveTransforms[name];
  3861. if (directiveTransform) {
  3862. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  3863. !ssr && props2.forEach(analyzePatchFlag);
  3864. if (isVOn && arg && !isStaticExp(arg)) {
  3865. pushMergeArg(createObjectExpression(props2, elementLoc));
  3866. } else {
  3867. properties.push(...props2);
  3868. }
  3869. if (needRuntime) {
  3870. runtimeDirectives.push(prop);
  3871. if (isSymbol(needRuntime)) {
  3872. directiveImportMap.set(prop, needRuntime);
  3873. }
  3874. }
  3875. } else if (!isBuiltInDirective(name)) {
  3876. runtimeDirectives.push(prop);
  3877. if (hasChildren) {
  3878. shouldUseBlock = true;
  3879. }
  3880. }
  3881. }
  3882. }
  3883. let propsExpression = void 0;
  3884. if (mergeArgs.length) {
  3885. pushMergeArg();
  3886. if (mergeArgs.length > 1) {
  3887. propsExpression = createCallExpression(
  3888. context.helper(MERGE_PROPS),
  3889. mergeArgs,
  3890. elementLoc
  3891. );
  3892. } else {
  3893. propsExpression = mergeArgs[0];
  3894. }
  3895. } else if (properties.length) {
  3896. propsExpression = createObjectExpression(
  3897. dedupeProperties(properties),
  3898. elementLoc
  3899. );
  3900. }
  3901. if (hasDynamicKeys) {
  3902. patchFlag |= 16;
  3903. } else {
  3904. if (hasClassBinding && !isComponent) {
  3905. patchFlag |= 2;
  3906. }
  3907. if (hasStyleBinding && !isComponent) {
  3908. patchFlag |= 4;
  3909. }
  3910. if (dynamicPropNames.length) {
  3911. patchFlag |= 8;
  3912. }
  3913. if (hasHydrationEventBinding) {
  3914. patchFlag |= 32;
  3915. }
  3916. }
  3917. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  3918. patchFlag |= 512;
  3919. }
  3920. if (!context.inSSR && propsExpression) {
  3921. switch (propsExpression.type) {
  3922. case 15:
  3923. let classKeyIndex = -1;
  3924. let styleKeyIndex = -1;
  3925. let hasDynamicKey = false;
  3926. for (let i = 0; i < propsExpression.properties.length; i++) {
  3927. const key = propsExpression.properties[i].key;
  3928. if (isStaticExp(key)) {
  3929. if (key.content === "class") {
  3930. classKeyIndex = i;
  3931. } else if (key.content === "style") {
  3932. styleKeyIndex = i;
  3933. }
  3934. } else if (!key.isHandlerKey) {
  3935. hasDynamicKey = true;
  3936. }
  3937. }
  3938. const classProp = propsExpression.properties[classKeyIndex];
  3939. const styleProp = propsExpression.properties[styleKeyIndex];
  3940. if (!hasDynamicKey) {
  3941. if (classProp && !isStaticExp(classProp.value)) {
  3942. classProp.value = createCallExpression(
  3943. context.helper(NORMALIZE_CLASS),
  3944. [classProp.value]
  3945. );
  3946. }
  3947. if (styleProp && // the static style is compiled into an object,
  3948. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  3949. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  3950. // v-bind:style with static literal object
  3951. styleProp.value.type === 17)) {
  3952. styleProp.value = createCallExpression(
  3953. context.helper(NORMALIZE_STYLE),
  3954. [styleProp.value]
  3955. );
  3956. }
  3957. } else {
  3958. propsExpression = createCallExpression(
  3959. context.helper(NORMALIZE_PROPS),
  3960. [propsExpression]
  3961. );
  3962. }
  3963. break;
  3964. case 14:
  3965. break;
  3966. default:
  3967. propsExpression = createCallExpression(
  3968. context.helper(NORMALIZE_PROPS),
  3969. [
  3970. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  3971. propsExpression
  3972. ])
  3973. ]
  3974. );
  3975. break;
  3976. }
  3977. }
  3978. return {
  3979. props: propsExpression,
  3980. directives: runtimeDirectives,
  3981. patchFlag,
  3982. dynamicPropNames,
  3983. shouldUseBlock
  3984. };
  3985. }
  3986. function dedupeProperties(properties) {
  3987. const knownProps = /* @__PURE__ */ new Map();
  3988. const deduped = [];
  3989. for (let i = 0; i < properties.length; i++) {
  3990. const prop = properties[i];
  3991. if (prop.key.type === 8 || !prop.key.isStatic) {
  3992. deduped.push(prop);
  3993. continue;
  3994. }
  3995. const name = prop.key.content;
  3996. const existing = knownProps.get(name);
  3997. if (existing) {
  3998. if (name === "style" || name === "class" || isOn(name)) {
  3999. mergeAsArray(existing, prop);
  4000. }
  4001. } else {
  4002. knownProps.set(name, prop);
  4003. deduped.push(prop);
  4004. }
  4005. }
  4006. return deduped;
  4007. }
  4008. function mergeAsArray(existing, incoming) {
  4009. if (existing.value.type === 17) {
  4010. existing.value.elements.push(incoming.value);
  4011. } else {
  4012. existing.value = createArrayExpression(
  4013. [existing.value, incoming.value],
  4014. existing.loc
  4015. );
  4016. }
  4017. }
  4018. function buildDirectiveArgs(dir, context) {
  4019. const dirArgs = [];
  4020. const runtime = directiveImportMap.get(dir);
  4021. if (runtime) {
  4022. dirArgs.push(context.helperString(runtime));
  4023. } else {
  4024. {
  4025. context.helper(RESOLVE_DIRECTIVE);
  4026. context.directives.add(dir.name);
  4027. dirArgs.push(toValidAssetId(dir.name, `directive`));
  4028. }
  4029. }
  4030. const { loc } = dir;
  4031. if (dir.exp)
  4032. dirArgs.push(dir.exp);
  4033. if (dir.arg) {
  4034. if (!dir.exp) {
  4035. dirArgs.push(`void 0`);
  4036. }
  4037. dirArgs.push(dir.arg);
  4038. }
  4039. if (Object.keys(dir.modifiers).length) {
  4040. if (!dir.arg) {
  4041. if (!dir.exp) {
  4042. dirArgs.push(`void 0`);
  4043. }
  4044. dirArgs.push(`void 0`);
  4045. }
  4046. const trueExpression = createSimpleExpression(`true`, false, loc);
  4047. dirArgs.push(
  4048. createObjectExpression(
  4049. dir.modifiers.map(
  4050. (modifier) => createObjectProperty(modifier, trueExpression)
  4051. ),
  4052. loc
  4053. )
  4054. );
  4055. }
  4056. return createArrayExpression(dirArgs, dir.loc);
  4057. }
  4058. function stringifyDynamicPropNames(props) {
  4059. let propsNamesString = `[`;
  4060. for (let i = 0, l = props.length; i < l; i++) {
  4061. propsNamesString += JSON.stringify(props[i]);
  4062. if (i < l - 1)
  4063. propsNamesString += ", ";
  4064. }
  4065. return propsNamesString + `]`;
  4066. }
  4067. function isComponentTag(tag) {
  4068. return tag === "component" || tag === "Component";
  4069. }
  4070. const transformSlotOutlet = (node, context) => {
  4071. if (isSlotOutlet(node)) {
  4072. const { children, loc } = node;
  4073. const { slotName, slotProps } = processSlotOutlet(node, context);
  4074. const slotArgs = [
  4075. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  4076. slotName,
  4077. "{}",
  4078. "undefined",
  4079. "true"
  4080. ];
  4081. let expectedLen = 2;
  4082. if (slotProps) {
  4083. slotArgs[2] = slotProps;
  4084. expectedLen = 3;
  4085. }
  4086. if (children.length) {
  4087. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  4088. expectedLen = 4;
  4089. }
  4090. if (context.scopeId && !context.slotted) {
  4091. expectedLen = 5;
  4092. }
  4093. slotArgs.splice(expectedLen);
  4094. node.codegenNode = createCallExpression(
  4095. context.helper(RENDER_SLOT),
  4096. slotArgs,
  4097. loc
  4098. );
  4099. }
  4100. };
  4101. function processSlotOutlet(node, context) {
  4102. let slotName = `"default"`;
  4103. let slotProps = void 0;
  4104. const nonNameProps = [];
  4105. for (let i = 0; i < node.props.length; i++) {
  4106. const p = node.props[i];
  4107. if (p.type === 6) {
  4108. if (p.value) {
  4109. if (p.name === "name") {
  4110. slotName = JSON.stringify(p.value.content);
  4111. } else {
  4112. p.name = camelize(p.name);
  4113. nonNameProps.push(p);
  4114. }
  4115. }
  4116. } else {
  4117. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  4118. if (p.exp)
  4119. slotName = p.exp;
  4120. } else {
  4121. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  4122. p.arg.content = camelize(p.arg.content);
  4123. }
  4124. nonNameProps.push(p);
  4125. }
  4126. }
  4127. }
  4128. if (nonNameProps.length > 0) {
  4129. const { props, directives } = buildProps(
  4130. node,
  4131. context,
  4132. nonNameProps,
  4133. false,
  4134. false
  4135. );
  4136. slotProps = props;
  4137. if (directives.length) {
  4138. context.onError(
  4139. createCompilerError(
  4140. 36,
  4141. directives[0].loc
  4142. )
  4143. );
  4144. }
  4145. }
  4146. return {
  4147. slotName,
  4148. slotProps
  4149. };
  4150. }
  4151. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  4152. const transformOn = (dir, node, context, augmentor) => {
  4153. const { loc, modifiers, arg } = dir;
  4154. if (!dir.exp && !modifiers.length) {
  4155. context.onError(createCompilerError(35, loc));
  4156. }
  4157. let eventName;
  4158. if (arg.type === 4) {
  4159. if (arg.isStatic) {
  4160. let rawName = arg.content;
  4161. if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) {
  4162. context.onWarn(
  4163. createCompilerError(51, arg.loc)
  4164. );
  4165. }
  4166. if (rawName.startsWith("vue:")) {
  4167. rawName = `vnode-${rawName.slice(4)}`;
  4168. }
  4169. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  4170. // for non-element and vnode lifecycle event listeners, auto convert
  4171. // it to camelCase. See issue #2249
  4172. toHandlerKey(camelize(rawName))
  4173. ) : (
  4174. // preserve case for plain element listeners that have uppercase
  4175. // letters, as these may be custom elements' custom events
  4176. `on:${rawName}`
  4177. );
  4178. eventName = createSimpleExpression(eventString, true, arg.loc);
  4179. } else {
  4180. eventName = createCompoundExpression([
  4181. `${context.helperString(TO_HANDLER_KEY)}(`,
  4182. arg,
  4183. `)`
  4184. ]);
  4185. }
  4186. } else {
  4187. eventName = arg;
  4188. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  4189. eventName.children.push(`)`);
  4190. }
  4191. let exp = dir.exp;
  4192. if (exp && !exp.content.trim()) {
  4193. exp = void 0;
  4194. }
  4195. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  4196. if (exp) {
  4197. const isMemberExp = isMemberExpression(exp.content);
  4198. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  4199. const hasMultipleStatements = exp.content.includes(`;`);
  4200. if (!!(process.env.NODE_ENV !== "production") && true) {
  4201. validateBrowserExpression(
  4202. exp,
  4203. context,
  4204. false,
  4205. hasMultipleStatements
  4206. );
  4207. }
  4208. if (isInlineStatement || shouldCache && isMemberExp) {
  4209. exp = createCompoundExpression([
  4210. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  4211. exp,
  4212. hasMultipleStatements ? `}` : `)`
  4213. ]);
  4214. }
  4215. }
  4216. let ret = {
  4217. props: [
  4218. createObjectProperty(
  4219. eventName,
  4220. exp || createSimpleExpression(`() => {}`, false, loc)
  4221. )
  4222. ]
  4223. };
  4224. if (augmentor) {
  4225. ret = augmentor(ret);
  4226. }
  4227. if (shouldCache) {
  4228. ret.props[0].value = context.cache(ret.props[0].value);
  4229. }
  4230. ret.props.forEach((p) => p.key.isHandlerKey = true);
  4231. return ret;
  4232. };
  4233. const transformBind = (dir, _node, context) => {
  4234. const { exp, modifiers, loc } = dir;
  4235. const arg = dir.arg;
  4236. if (arg.type !== 4) {
  4237. arg.children.unshift(`(`);
  4238. arg.children.push(`) || ""`);
  4239. } else if (!arg.isStatic) {
  4240. arg.content = `${arg.content} || ""`;
  4241. }
  4242. if (modifiers.includes("camel")) {
  4243. if (arg.type === 4) {
  4244. if (arg.isStatic) {
  4245. arg.content = camelize(arg.content);
  4246. } else {
  4247. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4248. }
  4249. } else {
  4250. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4251. arg.children.push(`)`);
  4252. }
  4253. }
  4254. if (!context.inSSR) {
  4255. if (modifiers.includes("prop")) {
  4256. injectPrefix(arg, ".");
  4257. }
  4258. if (modifiers.includes("attr")) {
  4259. injectPrefix(arg, "^");
  4260. }
  4261. }
  4262. if (!exp || exp.type === 4 && !exp.content.trim()) {
  4263. context.onError(createCompilerError(34, loc));
  4264. return {
  4265. props: [createObjectProperty(arg, createSimpleExpression("", true, loc))]
  4266. };
  4267. }
  4268. return {
  4269. props: [createObjectProperty(arg, exp)]
  4270. };
  4271. };
  4272. const injectPrefix = (arg, prefix) => {
  4273. if (arg.type === 4) {
  4274. if (arg.isStatic) {
  4275. arg.content = prefix + arg.content;
  4276. } else {
  4277. arg.content = `\`${prefix}\${${arg.content}}\``;
  4278. }
  4279. } else {
  4280. arg.children.unshift(`'${prefix}' + (`);
  4281. arg.children.push(`)`);
  4282. }
  4283. };
  4284. const transformText = (node, context) => {
  4285. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  4286. return () => {
  4287. const children = node.children;
  4288. let currentContainer = void 0;
  4289. let hasText = false;
  4290. for (let i = 0; i < children.length; i++) {
  4291. const child = children[i];
  4292. if (isText$1(child)) {
  4293. hasText = true;
  4294. for (let j = i + 1; j < children.length; j++) {
  4295. const next = children[j];
  4296. if (isText$1(next)) {
  4297. if (!currentContainer) {
  4298. currentContainer = children[i] = createCompoundExpression(
  4299. [child],
  4300. child.loc
  4301. );
  4302. }
  4303. currentContainer.children.push(` + `, next);
  4304. children.splice(j, 1);
  4305. j--;
  4306. } else {
  4307. currentContainer = void 0;
  4308. break;
  4309. }
  4310. }
  4311. }
  4312. }
  4313. if (!hasText || // if this is a plain element with a single text child, leave it
  4314. // as-is since the runtime has dedicated fast path for this by directly
  4315. // setting textContent of the element.
  4316. // for component root it's always normalized anyway.
  4317. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  4318. // custom directives can potentially add DOM elements arbitrarily,
  4319. // we need to avoid setting textContent of the element at runtime
  4320. // to avoid accidentally overwriting the DOM elements added
  4321. // by the user through custom directives.
  4322. !node.props.find(
  4323. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  4324. ) && // in compat mode, <template> tags with no special directives
  4325. // will be rendered as a fragment so its children must be
  4326. // converted into vnodes.
  4327. !(node.tag === "template"))) {
  4328. return;
  4329. }
  4330. for (let i = 0; i < children.length; i++) {
  4331. const child = children[i];
  4332. if (isText$1(child) || child.type === 8) {
  4333. const callArgs = [];
  4334. if (child.type !== 2 || child.content !== " ") {
  4335. callArgs.push(child);
  4336. }
  4337. if (!context.ssr && getConstantType(child, context) === 0) {
  4338. callArgs.push(
  4339. 1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[1]} */` : ``)
  4340. );
  4341. }
  4342. children[i] = {
  4343. type: 12,
  4344. content: child,
  4345. loc: child.loc,
  4346. codegenNode: createCallExpression(
  4347. context.helper(CREATE_TEXT),
  4348. callArgs
  4349. )
  4350. };
  4351. }
  4352. }
  4353. };
  4354. }
  4355. };
  4356. const seen$1 = /* @__PURE__ */ new WeakSet();
  4357. const transformOnce = (node, context) => {
  4358. if (node.type === 1 && findDir(node, "once", true)) {
  4359. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  4360. return;
  4361. }
  4362. seen$1.add(node);
  4363. context.inVOnce = true;
  4364. context.helper(SET_BLOCK_TRACKING);
  4365. return () => {
  4366. context.inVOnce = false;
  4367. const cur = context.currentNode;
  4368. if (cur.codegenNode) {
  4369. cur.codegenNode = context.cache(
  4370. cur.codegenNode,
  4371. true
  4372. /* isVNode */
  4373. );
  4374. }
  4375. };
  4376. }
  4377. };
  4378. const transformModel = (dir, node, context) => {
  4379. const { exp, arg } = dir;
  4380. if (!exp) {
  4381. context.onError(
  4382. createCompilerError(41, dir.loc)
  4383. );
  4384. return createTransformProps();
  4385. }
  4386. const rawExp = exp.loc.source;
  4387. const expString = exp.type === 4 ? exp.content : rawExp;
  4388. const bindingType = context.bindingMetadata[rawExp];
  4389. if (bindingType === "props" || bindingType === "props-aliased") {
  4390. context.onError(createCompilerError(44, exp.loc));
  4391. return createTransformProps();
  4392. }
  4393. const maybeRef = false;
  4394. if (!expString.trim() || !isMemberExpression(expString) && !maybeRef) {
  4395. context.onError(
  4396. createCompilerError(42, exp.loc)
  4397. );
  4398. return createTransformProps();
  4399. }
  4400. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  4401. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  4402. let assignmentExp;
  4403. const eventArg = context.isTS ? `($event: any)` : `$event`;
  4404. {
  4405. assignmentExp = createCompoundExpression([
  4406. `${eventArg} => ((`,
  4407. exp,
  4408. `) = $event)`
  4409. ]);
  4410. }
  4411. const props = [
  4412. // modelValue: foo
  4413. createObjectProperty(propName, dir.exp),
  4414. // "onUpdate:modelValue": $event => (foo = $event)
  4415. createObjectProperty(eventName, assignmentExp)
  4416. ];
  4417. if (dir.modifiers.length && node.tagType === 1) {
  4418. const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  4419. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  4420. props.push(
  4421. createObjectProperty(
  4422. modifiersKey,
  4423. createSimpleExpression(
  4424. `{ ${modifiers} }`,
  4425. false,
  4426. dir.loc,
  4427. 2
  4428. )
  4429. )
  4430. );
  4431. }
  4432. return createTransformProps(props);
  4433. };
  4434. function createTransformProps(props = []) {
  4435. return { props };
  4436. }
  4437. const validDivisionCharRE = /[\w).+\-_$\]]/;
  4438. const transformFilter = (node, context) => {
  4439. if (!isCompatEnabled("COMPILER_FILTER", context)) {
  4440. return;
  4441. }
  4442. if (node.type === 5) {
  4443. rewriteFilter(node.content, context);
  4444. }
  4445. if (node.type === 1) {
  4446. node.props.forEach((prop) => {
  4447. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  4448. rewriteFilter(prop.exp, context);
  4449. }
  4450. });
  4451. }
  4452. };
  4453. function rewriteFilter(node, context) {
  4454. if (node.type === 4) {
  4455. parseFilter(node, context);
  4456. } else {
  4457. for (let i = 0; i < node.children.length; i++) {
  4458. const child = node.children[i];
  4459. if (typeof child !== "object")
  4460. continue;
  4461. if (child.type === 4) {
  4462. parseFilter(child, context);
  4463. } else if (child.type === 8) {
  4464. rewriteFilter(node, context);
  4465. } else if (child.type === 5) {
  4466. rewriteFilter(child.content, context);
  4467. }
  4468. }
  4469. }
  4470. }
  4471. function parseFilter(node, context) {
  4472. const exp = node.content;
  4473. let inSingle = false;
  4474. let inDouble = false;
  4475. let inTemplateString = false;
  4476. let inRegex = false;
  4477. let curly = 0;
  4478. let square = 0;
  4479. let paren = 0;
  4480. let lastFilterIndex = 0;
  4481. let c, prev, i, expression, filters = [];
  4482. for (i = 0; i < exp.length; i++) {
  4483. prev = c;
  4484. c = exp.charCodeAt(i);
  4485. if (inSingle) {
  4486. if (c === 39 && prev !== 92)
  4487. inSingle = false;
  4488. } else if (inDouble) {
  4489. if (c === 34 && prev !== 92)
  4490. inDouble = false;
  4491. } else if (inTemplateString) {
  4492. if (c === 96 && prev !== 92)
  4493. inTemplateString = false;
  4494. } else if (inRegex) {
  4495. if (c === 47 && prev !== 92)
  4496. inRegex = false;
  4497. } else if (c === 124 && // pipe
  4498. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  4499. if (expression === void 0) {
  4500. lastFilterIndex = i + 1;
  4501. expression = exp.slice(0, i).trim();
  4502. } else {
  4503. pushFilter();
  4504. }
  4505. } else {
  4506. switch (c) {
  4507. case 34:
  4508. inDouble = true;
  4509. break;
  4510. case 39:
  4511. inSingle = true;
  4512. break;
  4513. case 96:
  4514. inTemplateString = true;
  4515. break;
  4516. case 40:
  4517. paren++;
  4518. break;
  4519. case 41:
  4520. paren--;
  4521. break;
  4522. case 91:
  4523. square++;
  4524. break;
  4525. case 93:
  4526. square--;
  4527. break;
  4528. case 123:
  4529. curly++;
  4530. break;
  4531. case 125:
  4532. curly--;
  4533. break;
  4534. }
  4535. if (c === 47) {
  4536. let j = i - 1;
  4537. let p;
  4538. for (; j >= 0; j--) {
  4539. p = exp.charAt(j);
  4540. if (p !== " ")
  4541. break;
  4542. }
  4543. if (!p || !validDivisionCharRE.test(p)) {
  4544. inRegex = true;
  4545. }
  4546. }
  4547. }
  4548. }
  4549. if (expression === void 0) {
  4550. expression = exp.slice(0, i).trim();
  4551. } else if (lastFilterIndex !== 0) {
  4552. pushFilter();
  4553. }
  4554. function pushFilter() {
  4555. filters.push(exp.slice(lastFilterIndex, i).trim());
  4556. lastFilterIndex = i + 1;
  4557. }
  4558. if (filters.length) {
  4559. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  4560. "COMPILER_FILTER",
  4561. context,
  4562. node.loc
  4563. );
  4564. for (i = 0; i < filters.length; i++) {
  4565. expression = wrapFilter(expression, filters[i], context);
  4566. }
  4567. node.content = expression;
  4568. }
  4569. }
  4570. function wrapFilter(exp, filter, context) {
  4571. context.helper(RESOLVE_FILTER);
  4572. const i = filter.indexOf("(");
  4573. if (i < 0) {
  4574. context.filters.add(filter);
  4575. return `${toValidAssetId(filter, "filter")}(${exp})`;
  4576. } else {
  4577. const name = filter.slice(0, i);
  4578. const args = filter.slice(i + 1);
  4579. context.filters.add(name);
  4580. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  4581. }
  4582. }
  4583. const seen = /* @__PURE__ */ new WeakSet();
  4584. const transformMemo = (node, context) => {
  4585. if (node.type === 1) {
  4586. const dir = findDir(node, "memo");
  4587. if (!dir || seen.has(node)) {
  4588. return;
  4589. }
  4590. seen.add(node);
  4591. return () => {
  4592. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  4593. if (codegenNode && codegenNode.type === 13) {
  4594. if (node.tagType !== 1) {
  4595. convertToBlock(codegenNode, context);
  4596. }
  4597. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  4598. dir.exp,
  4599. createFunctionExpression(void 0, codegenNode),
  4600. `_cache`,
  4601. String(context.cached++)
  4602. ]);
  4603. }
  4604. };
  4605. }
  4606. };
  4607. function getBaseTransformPreset(prefixIdentifiers) {
  4608. return [
  4609. [
  4610. transformOnce,
  4611. transformIf,
  4612. transformMemo,
  4613. transformFor,
  4614. ...[transformFilter] ,
  4615. ...!!(process.env.NODE_ENV !== "production") ? [transformExpression] : [],
  4616. transformSlotOutlet,
  4617. transformElement,
  4618. trackSlotScopes,
  4619. transformText
  4620. ],
  4621. {
  4622. on: transformOn,
  4623. bind: transformBind,
  4624. model: transformModel
  4625. }
  4626. ];
  4627. }
  4628. function baseCompile(template, options = {}) {
  4629. const onError = options.onError || defaultOnError;
  4630. const isModuleMode = options.mode === "module";
  4631. {
  4632. if (options.prefixIdentifiers === true) {
  4633. onError(createCompilerError(47));
  4634. } else if (isModuleMode) {
  4635. onError(createCompilerError(48));
  4636. }
  4637. }
  4638. const prefixIdentifiers = false;
  4639. if (options.cacheHandlers) {
  4640. onError(createCompilerError(49));
  4641. }
  4642. if (options.scopeId && !isModuleMode) {
  4643. onError(createCompilerError(50));
  4644. }
  4645. const ast = isString(template) ? baseParse(template, options) : template;
  4646. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  4647. transform(
  4648. ast,
  4649. extend({}, options, {
  4650. prefixIdentifiers,
  4651. nodeTransforms: [
  4652. ...nodeTransforms,
  4653. ...options.nodeTransforms || []
  4654. // user transforms
  4655. ],
  4656. directiveTransforms: extend(
  4657. {},
  4658. directiveTransforms,
  4659. options.directiveTransforms || {}
  4660. // user transforms
  4661. )
  4662. })
  4663. );
  4664. return generate(
  4665. ast,
  4666. extend({}, options, {
  4667. prefixIdentifiers
  4668. })
  4669. );
  4670. }
  4671. const noopDirectiveTransform = () => ({ props: [] });
  4672. export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, extractIdentifiers, findDir, findProp, generate, getBaseTransformPreset, getConstantType, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };