compiler-core.esm-bundler.js 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840
  1. import { isString, hyphenate, extend, isObject, isArray, NO, makeMap, isSymbol, NOOP, EMPTY_OBJ, capitalize, camelize as camelize$1, PatchFlagNames, slotFlagsText, isOn, isReservedProp, toHandlerKey } from '@vue/shared';
  2. export { generateCodeFrame } from '@vue/shared';
  3. function defaultOnError(error) {
  4. throw error;
  5. }
  6. function createCompilerError(code, loc, messages, additionalMessage) {
  7. const msg = (process.env.NODE_ENV !== 'production') || !true
  8. ? (messages || errorMessages)[code] + (additionalMessage || ``)
  9. : code;
  10. const error = new SyntaxError(String(msg));
  11. error.code = code;
  12. error.loc = loc;
  13. return error;
  14. }
  15. const errorMessages = {
  16. // parse errors
  17. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  18. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  19. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  20. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  21. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  22. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  23. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  24. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  25. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  26. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  27. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  28. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  29. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  30. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  31. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  32. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  33. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  34. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  35. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  36. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  37. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  38. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  39. // Vue-specific parse errors
  40. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  41. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  42. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  43. [26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  44. 'Note that dynamic directive argument cannot contain spaces.',
  45. // transform errors
  46. [27 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  47. [28 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  48. [29 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
  49. [30 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  50. [31 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  51. [32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  52. [33 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  53. [34 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  54. [35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  55. [36 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  56. `When there are multiple named slots, all slots should use <template> ` +
  57. `syntax to avoid scope ambiguity.`,
  58. [37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  59. [38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  60. `default slot. These children will be ignored.`,
  61. [39 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  62. [40 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  63. [41 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  64. [42 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  65. [43 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  66. [44 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  67. // generic errors
  68. [45 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  69. [46 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  70. [47 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  71. [48 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`
  72. };
  73. const FRAGMENT = Symbol((process.env.NODE_ENV !== 'production') ? `Fragment` : ``);
  74. const TELEPORT = Symbol((process.env.NODE_ENV !== 'production') ? `Teleport` : ``);
  75. const SUSPENSE = Symbol((process.env.NODE_ENV !== 'production') ? `Suspense` : ``);
  76. const KEEP_ALIVE = Symbol((process.env.NODE_ENV !== 'production') ? `KeepAlive` : ``);
  77. const BASE_TRANSITION = Symbol((process.env.NODE_ENV !== 'production') ? `BaseTransition` : ``);
  78. const OPEN_BLOCK = Symbol((process.env.NODE_ENV !== 'production') ? `openBlock` : ``);
  79. const CREATE_BLOCK = Symbol((process.env.NODE_ENV !== 'production') ? `createBlock` : ``);
  80. const CREATE_VNODE = Symbol((process.env.NODE_ENV !== 'production') ? `createVNode` : ``);
  81. const CREATE_COMMENT = Symbol((process.env.NODE_ENV !== 'production') ? `createCommentVNode` : ``);
  82. const CREATE_TEXT = Symbol((process.env.NODE_ENV !== 'production') ? `createTextVNode` : ``);
  83. const CREATE_STATIC = Symbol((process.env.NODE_ENV !== 'production') ? `createStaticVNode` : ``);
  84. const RESOLVE_COMPONENT = Symbol((process.env.NODE_ENV !== 'production') ? `resolveComponent` : ``);
  85. const RESOLVE_DYNAMIC_COMPONENT = Symbol((process.env.NODE_ENV !== 'production') ? `resolveDynamicComponent` : ``);
  86. const RESOLVE_DIRECTIVE = Symbol((process.env.NODE_ENV !== 'production') ? `resolveDirective` : ``);
  87. const WITH_DIRECTIVES = Symbol((process.env.NODE_ENV !== 'production') ? `withDirectives` : ``);
  88. const RENDER_LIST = Symbol((process.env.NODE_ENV !== 'production') ? `renderList` : ``);
  89. const RENDER_SLOT = Symbol((process.env.NODE_ENV !== 'production') ? `renderSlot` : ``);
  90. const CREATE_SLOTS = Symbol((process.env.NODE_ENV !== 'production') ? `createSlots` : ``);
  91. const TO_DISPLAY_STRING = Symbol((process.env.NODE_ENV !== 'production') ? `toDisplayString` : ``);
  92. const MERGE_PROPS = Symbol((process.env.NODE_ENV !== 'production') ? `mergeProps` : ``);
  93. const TO_HANDLERS = Symbol((process.env.NODE_ENV !== 'production') ? `toHandlers` : ``);
  94. const CAMELIZE = Symbol((process.env.NODE_ENV !== 'production') ? `camelize` : ``);
  95. const CAPITALIZE = Symbol((process.env.NODE_ENV !== 'production') ? `capitalize` : ``);
  96. const TO_HANDLER_KEY = Symbol((process.env.NODE_ENV !== 'production') ? `toHandlerKey` : ``);
  97. const SET_BLOCK_TRACKING = Symbol((process.env.NODE_ENV !== 'production') ? `setBlockTracking` : ``);
  98. const PUSH_SCOPE_ID = Symbol((process.env.NODE_ENV !== 'production') ? `pushScopeId` : ``);
  99. const POP_SCOPE_ID = Symbol((process.env.NODE_ENV !== 'production') ? `popScopeId` : ``);
  100. const WITH_SCOPE_ID = Symbol((process.env.NODE_ENV !== 'production') ? `withScopeId` : ``);
  101. const WITH_CTX = Symbol((process.env.NODE_ENV !== 'production') ? `withCtx` : ``);
  102. const UNREF = Symbol((process.env.NODE_ENV !== 'production') ? `unref` : ``);
  103. const IS_REF = Symbol((process.env.NODE_ENV !== 'production') ? `isRef` : ``);
  104. // Name mapping for runtime helpers that need to be imported from 'vue' in
  105. // generated code. Make sure these are correctly exported in the runtime!
  106. // Using `any` here because TS doesn't allow symbols as index type.
  107. const helperNameMap = {
  108. [FRAGMENT]: `Fragment`,
  109. [TELEPORT]: `Teleport`,
  110. [SUSPENSE]: `Suspense`,
  111. [KEEP_ALIVE]: `KeepAlive`,
  112. [BASE_TRANSITION]: `BaseTransition`,
  113. [OPEN_BLOCK]: `openBlock`,
  114. [CREATE_BLOCK]: `createBlock`,
  115. [CREATE_VNODE]: `createVNode`,
  116. [CREATE_COMMENT]: `createCommentVNode`,
  117. [CREATE_TEXT]: `createTextVNode`,
  118. [CREATE_STATIC]: `createStaticVNode`,
  119. [RESOLVE_COMPONENT]: `resolveComponent`,
  120. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  121. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  122. [WITH_DIRECTIVES]: `withDirectives`,
  123. [RENDER_LIST]: `renderList`,
  124. [RENDER_SLOT]: `renderSlot`,
  125. [CREATE_SLOTS]: `createSlots`,
  126. [TO_DISPLAY_STRING]: `toDisplayString`,
  127. [MERGE_PROPS]: `mergeProps`,
  128. [TO_HANDLERS]: `toHandlers`,
  129. [CAMELIZE]: `camelize`,
  130. [CAPITALIZE]: `capitalize`,
  131. [TO_HANDLER_KEY]: `toHandlerKey`,
  132. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  133. [PUSH_SCOPE_ID]: `pushScopeId`,
  134. [POP_SCOPE_ID]: `popScopeId`,
  135. [WITH_SCOPE_ID]: `withScopeId`,
  136. [WITH_CTX]: `withCtx`,
  137. [UNREF]: `unref`,
  138. [IS_REF]: `isRef`
  139. };
  140. function registerRuntimeHelpers(helpers) {
  141. Object.getOwnPropertySymbols(helpers).forEach(s => {
  142. helperNameMap[s] = helpers[s];
  143. });
  144. }
  145. // AST Utilities ---------------------------------------------------------------
  146. // Some expressions, e.g. sequence and conditional expressions, are never
  147. // associated with template nodes, so their source locations are just a stub.
  148. // Container types like CompoundExpression also don't need a real location.
  149. const locStub = {
  150. source: '',
  151. start: { line: 1, column: 1, offset: 0 },
  152. end: { line: 1, column: 1, offset: 0 }
  153. };
  154. function createRoot(children, loc = locStub) {
  155. return {
  156. type: 0 /* ROOT */,
  157. children,
  158. helpers: [],
  159. components: [],
  160. directives: [],
  161. hoists: [],
  162. imports: [],
  163. cached: 0,
  164. temps: 0,
  165. codegenNode: undefined,
  166. loc
  167. };
  168. }
  169. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, loc = locStub) {
  170. if (context) {
  171. if (isBlock) {
  172. context.helper(OPEN_BLOCK);
  173. context.helper(CREATE_BLOCK);
  174. }
  175. else {
  176. context.helper(CREATE_VNODE);
  177. }
  178. if (directives) {
  179. context.helper(WITH_DIRECTIVES);
  180. }
  181. }
  182. return {
  183. type: 13 /* VNODE_CALL */,
  184. tag,
  185. props,
  186. children,
  187. patchFlag,
  188. dynamicProps,
  189. directives,
  190. isBlock,
  191. disableTracking,
  192. loc
  193. };
  194. }
  195. function createArrayExpression(elements, loc = locStub) {
  196. return {
  197. type: 17 /* JS_ARRAY_EXPRESSION */,
  198. loc,
  199. elements
  200. };
  201. }
  202. function createObjectExpression(properties, loc = locStub) {
  203. return {
  204. type: 15 /* JS_OBJECT_EXPRESSION */,
  205. loc,
  206. properties
  207. };
  208. }
  209. function createObjectProperty(key, value) {
  210. return {
  211. type: 16 /* JS_PROPERTY */,
  212. loc: locStub,
  213. key: isString(key) ? createSimpleExpression(key, true) : key,
  214. value
  215. };
  216. }
  217. function createSimpleExpression(content, isStatic, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  218. return {
  219. type: 4 /* SIMPLE_EXPRESSION */,
  220. loc,
  221. content,
  222. isStatic,
  223. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  224. };
  225. }
  226. function createInterpolation(content, loc) {
  227. return {
  228. type: 5 /* INTERPOLATION */,
  229. loc,
  230. content: isString(content)
  231. ? createSimpleExpression(content, false, loc)
  232. : content
  233. };
  234. }
  235. function createCompoundExpression(children, loc = locStub) {
  236. return {
  237. type: 8 /* COMPOUND_EXPRESSION */,
  238. loc,
  239. children
  240. };
  241. }
  242. function createCallExpression(callee, args = [], loc = locStub) {
  243. return {
  244. type: 14 /* JS_CALL_EXPRESSION */,
  245. loc,
  246. callee,
  247. arguments: args
  248. };
  249. }
  250. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  251. return {
  252. type: 18 /* JS_FUNCTION_EXPRESSION */,
  253. params,
  254. returns,
  255. newline,
  256. isSlot,
  257. loc
  258. };
  259. }
  260. function createConditionalExpression(test, consequent, alternate, newline = true) {
  261. return {
  262. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  263. test,
  264. consequent,
  265. alternate,
  266. newline,
  267. loc: locStub
  268. };
  269. }
  270. function createCacheExpression(index, value, isVNode = false) {
  271. return {
  272. type: 20 /* JS_CACHE_EXPRESSION */,
  273. index,
  274. value,
  275. isVNode,
  276. loc: locStub
  277. };
  278. }
  279. function createBlockStatement(body) {
  280. return {
  281. type: 21 /* JS_BLOCK_STATEMENT */,
  282. body,
  283. loc: locStub
  284. };
  285. }
  286. function createTemplateLiteral(elements) {
  287. return {
  288. type: 22 /* JS_TEMPLATE_LITERAL */,
  289. elements,
  290. loc: locStub
  291. };
  292. }
  293. function createIfStatement(test, consequent, alternate) {
  294. return {
  295. type: 23 /* JS_IF_STATEMENT */,
  296. test,
  297. consequent,
  298. alternate,
  299. loc: locStub
  300. };
  301. }
  302. function createAssignmentExpression(left, right) {
  303. return {
  304. type: 24 /* JS_ASSIGNMENT_EXPRESSION */,
  305. left,
  306. right,
  307. loc: locStub
  308. };
  309. }
  310. function createSequenceExpression(expressions) {
  311. return {
  312. type: 25 /* JS_SEQUENCE_EXPRESSION */,
  313. expressions,
  314. loc: locStub
  315. };
  316. }
  317. function createReturnStatement(returns) {
  318. return {
  319. type: 26 /* JS_RETURN_STATEMENT */,
  320. returns,
  321. loc: locStub
  322. };
  323. }
  324. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  325. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  326. function isCoreComponent(tag) {
  327. if (isBuiltInType(tag, 'Teleport')) {
  328. return TELEPORT;
  329. }
  330. else if (isBuiltInType(tag, 'Suspense')) {
  331. return SUSPENSE;
  332. }
  333. else if (isBuiltInType(tag, 'KeepAlive')) {
  334. return KEEP_ALIVE;
  335. }
  336. else if (isBuiltInType(tag, 'BaseTransition')) {
  337. return BASE_TRANSITION;
  338. }
  339. }
  340. const nonIdentifierRE = /^\d|[^\$\w]/;
  341. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  342. const memberExpRE = /^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\[[^\]]+\])*$/;
  343. const isMemberExpression = (path) => {
  344. if (!path)
  345. return false;
  346. return memberExpRE.test(path.trim());
  347. };
  348. function getInnerRange(loc, offset, length) {
  349. const source = loc.source.substr(offset, length);
  350. const newLoc = {
  351. source,
  352. start: advancePositionWithClone(loc.start, loc.source, offset),
  353. end: loc.end
  354. };
  355. if (length != null) {
  356. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  357. }
  358. return newLoc;
  359. }
  360. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  361. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  362. }
  363. // advance by mutation without cloning (for performance reasons), since this
  364. // gets called a lot in the parser
  365. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  366. let linesCount = 0;
  367. let lastNewLinePos = -1;
  368. for (let i = 0; i < numberOfCharacters; i++) {
  369. if (source.charCodeAt(i) === 10 /* newline char code */) {
  370. linesCount++;
  371. lastNewLinePos = i;
  372. }
  373. }
  374. pos.offset += numberOfCharacters;
  375. pos.line += linesCount;
  376. pos.column =
  377. lastNewLinePos === -1
  378. ? pos.column + numberOfCharacters
  379. : numberOfCharacters - lastNewLinePos;
  380. return pos;
  381. }
  382. function assert(condition, msg) {
  383. /* istanbul ignore if */
  384. if (!condition) {
  385. throw new Error(msg || `unexpected compiler condition`);
  386. }
  387. }
  388. function findDir(node, name, allowEmpty = false) {
  389. for (let i = 0; i < node.props.length; i++) {
  390. const p = node.props[i];
  391. if (p.type === 7 /* DIRECTIVE */ &&
  392. (allowEmpty || p.exp) &&
  393. (isString(name) ? p.name === name : name.test(p.name))) {
  394. return p;
  395. }
  396. }
  397. }
  398. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  399. for (let i = 0; i < node.props.length; i++) {
  400. const p = node.props[i];
  401. if (p.type === 6 /* ATTRIBUTE */) {
  402. if (dynamicOnly)
  403. continue;
  404. if (p.name === name && (p.value || allowEmpty)) {
  405. return p;
  406. }
  407. }
  408. else if (p.name === 'bind' &&
  409. (p.exp || allowEmpty) &&
  410. isBindKey(p.arg, name)) {
  411. return p;
  412. }
  413. }
  414. }
  415. function isBindKey(arg, name) {
  416. return !!(arg && isStaticExp(arg) && arg.content === name);
  417. }
  418. function hasDynamicKeyVBind(node) {
  419. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  420. p.name === 'bind' &&
  421. (!p.arg || // v-bind="obj"
  422. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  423. !p.arg.isStatic) // v-bind:[foo]
  424. );
  425. }
  426. function isText(node) {
  427. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  428. }
  429. function isVSlot(p) {
  430. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  431. }
  432. function isTemplateNode(node) {
  433. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  434. }
  435. function isSlotOutlet(node) {
  436. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  437. }
  438. function injectProp(node, prop, context) {
  439. let propsWithInjection;
  440. const props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  441. if (props == null || isString(props)) {
  442. propsWithInjection = createObjectExpression([prop]);
  443. }
  444. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  445. // merged props... add ours
  446. // only inject key to object literal if it's the first argument so that
  447. // if doesn't override user provided keys
  448. const first = props.arguments[0];
  449. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  450. first.properties.unshift(prop);
  451. }
  452. else {
  453. if (props.callee === TO_HANDLERS) {
  454. // #2366
  455. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  456. createObjectExpression([prop]),
  457. props
  458. ]);
  459. }
  460. else {
  461. props.arguments.unshift(createObjectExpression([prop]));
  462. }
  463. }
  464. !propsWithInjection && (propsWithInjection = props);
  465. }
  466. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  467. let alreadyExists = false;
  468. // check existing key to avoid overriding user provided keys
  469. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  470. const propKeyName = prop.key.content;
  471. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  472. p.key.content === propKeyName);
  473. }
  474. if (!alreadyExists) {
  475. props.properties.unshift(prop);
  476. }
  477. propsWithInjection = props;
  478. }
  479. else {
  480. // single v-bind with expression, return a merged replacement
  481. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  482. createObjectExpression([prop]),
  483. props
  484. ]);
  485. }
  486. if (node.type === 13 /* VNODE_CALL */) {
  487. node.props = propsWithInjection;
  488. }
  489. else {
  490. node.arguments[2] = propsWithInjection;
  491. }
  492. }
  493. function toValidAssetId(name, type) {
  494. return `_${type}_${name.replace(/[^\w]/g, '_')}`;
  495. }
  496. // Check if a node contains expressions that reference current context scope ids
  497. function hasScopeRef(node, ids) {
  498. if (!node || Object.keys(ids).length === 0) {
  499. return false;
  500. }
  501. switch (node.type) {
  502. case 1 /* ELEMENT */:
  503. for (let i = 0; i < node.props.length; i++) {
  504. const p = node.props[i];
  505. if (p.type === 7 /* DIRECTIVE */ &&
  506. (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  507. return true;
  508. }
  509. }
  510. return node.children.some(c => hasScopeRef(c, ids));
  511. case 11 /* FOR */:
  512. if (hasScopeRef(node.source, ids)) {
  513. return true;
  514. }
  515. return node.children.some(c => hasScopeRef(c, ids));
  516. case 9 /* IF */:
  517. return node.branches.some(b => hasScopeRef(b, ids));
  518. case 10 /* IF_BRANCH */:
  519. if (hasScopeRef(node.condition, ids)) {
  520. return true;
  521. }
  522. return node.children.some(c => hasScopeRef(c, ids));
  523. case 4 /* SIMPLE_EXPRESSION */:
  524. return (!node.isStatic &&
  525. isSimpleIdentifier(node.content) &&
  526. !!ids[node.content]);
  527. case 8 /* COMPOUND_EXPRESSION */:
  528. return node.children.some(c => isObject(c) && hasScopeRef(c, ids));
  529. case 5 /* INTERPOLATION */:
  530. case 12 /* TEXT_CALL */:
  531. return hasScopeRef(node.content, ids);
  532. case 2 /* TEXT */:
  533. case 3 /* COMMENT */:
  534. return false;
  535. default:
  536. if ((process.env.NODE_ENV !== 'production')) ;
  537. return false;
  538. }
  539. }
  540. // The default decoder only provides escapes for characters reserved as part of
  541. // the template syntax, and is only used if the custom renderer did not provide
  542. // a platform-specific decoder.
  543. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  544. const decodeMap = {
  545. gt: '>',
  546. lt: '<',
  547. amp: '&',
  548. apos: "'",
  549. quot: '"'
  550. };
  551. const defaultParserOptions = {
  552. delimiters: [`{{`, `}}`],
  553. getNamespace: () => 0 /* HTML */,
  554. getTextMode: () => 0 /* DATA */,
  555. isVoidTag: NO,
  556. isPreTag: NO,
  557. isCustomElement: NO,
  558. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  559. onError: defaultOnError,
  560. comments: false
  561. };
  562. function baseParse(content, options = {}) {
  563. const context = createParserContext(content, options);
  564. const start = getCursor(context);
  565. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  566. }
  567. function createParserContext(content, rawOptions) {
  568. const options = extend({}, defaultParserOptions);
  569. for (const key in rawOptions) {
  570. // @ts-ignore
  571. options[key] = rawOptions[key] || defaultParserOptions[key];
  572. }
  573. return {
  574. options,
  575. column: 1,
  576. line: 1,
  577. offset: 0,
  578. originalSource: content,
  579. source: content,
  580. inPre: false,
  581. inVPre: false
  582. };
  583. }
  584. function parseChildren(context, mode, ancestors) {
  585. const parent = last(ancestors);
  586. const ns = parent ? parent.ns : 0 /* HTML */;
  587. const nodes = [];
  588. while (!isEnd(context, mode, ancestors)) {
  589. const s = context.source;
  590. let node = undefined;
  591. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  592. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  593. // '{{'
  594. node = parseInterpolation(context, mode);
  595. }
  596. else if (mode === 0 /* DATA */ && s[0] === '<') {
  597. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  598. if (s.length === 1) {
  599. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  600. }
  601. else if (s[1] === '!') {
  602. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  603. if (startsWith(s, '<!--')) {
  604. node = parseComment(context);
  605. }
  606. else if (startsWith(s, '<!DOCTYPE')) {
  607. // Ignore DOCTYPE by a limitation.
  608. node = parseBogusComment(context);
  609. }
  610. else if (startsWith(s, '<![CDATA[')) {
  611. if (ns !== 0 /* HTML */) {
  612. node = parseCDATA(context, ancestors);
  613. }
  614. else {
  615. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  616. node = parseBogusComment(context);
  617. }
  618. }
  619. else {
  620. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  621. node = parseBogusComment(context);
  622. }
  623. }
  624. else if (s[1] === '/') {
  625. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  626. if (s.length === 2) {
  627. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  628. }
  629. else if (s[2] === '>') {
  630. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  631. advanceBy(context, 3);
  632. continue;
  633. }
  634. else if (/[a-z]/i.test(s[2])) {
  635. emitError(context, 23 /* X_INVALID_END_TAG */);
  636. parseTag(context, 1 /* End */, parent);
  637. continue;
  638. }
  639. else {
  640. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  641. node = parseBogusComment(context);
  642. }
  643. }
  644. else if (/[a-z]/i.test(s[1])) {
  645. node = parseElement(context, ancestors);
  646. }
  647. else if (s[1] === '?') {
  648. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  649. node = parseBogusComment(context);
  650. }
  651. else {
  652. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  653. }
  654. }
  655. }
  656. if (!node) {
  657. node = parseText(context, mode);
  658. }
  659. if (isArray(node)) {
  660. for (let i = 0; i < node.length; i++) {
  661. pushNode(nodes, node[i]);
  662. }
  663. }
  664. else {
  665. pushNode(nodes, node);
  666. }
  667. }
  668. // Whitespace management for more efficient output
  669. // (same as v2 whitespace: 'condense')
  670. let removedWhitespace = false;
  671. if (mode !== 2 /* RAWTEXT */) {
  672. for (let i = 0; i < nodes.length; i++) {
  673. const node = nodes[i];
  674. if (!context.inPre && node.type === 2 /* TEXT */) {
  675. if (!/[^\t\r\n\f ]/.test(node.content)) {
  676. const prev = nodes[i - 1];
  677. const next = nodes[i + 1];
  678. // If:
  679. // - the whitespace is the first or last node, or:
  680. // - the whitespace is adjacent to a comment, or:
  681. // - the whitespace is between two elements AND contains newline
  682. // Then the whitespace is ignored.
  683. if (!prev ||
  684. !next ||
  685. prev.type === 3 /* COMMENT */ ||
  686. next.type === 3 /* COMMENT */ ||
  687. (prev.type === 1 /* ELEMENT */ &&
  688. next.type === 1 /* ELEMENT */ &&
  689. /[\r\n]/.test(node.content))) {
  690. removedWhitespace = true;
  691. nodes[i] = null;
  692. }
  693. else {
  694. // Otherwise, condensed consecutive whitespace inside the text
  695. // down to a single space
  696. node.content = ' ';
  697. }
  698. }
  699. else {
  700. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  701. }
  702. }
  703. // also remove comment nodes in prod by default
  704. if (!(process.env.NODE_ENV !== 'production') &&
  705. node.type === 3 /* COMMENT */ &&
  706. !context.options.comments) {
  707. removedWhitespace = true;
  708. nodes[i] = null;
  709. }
  710. }
  711. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  712. // remove leading newline per html spec
  713. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  714. const first = nodes[0];
  715. if (first && first.type === 2 /* TEXT */) {
  716. first.content = first.content.replace(/^\r?\n/, '');
  717. }
  718. }
  719. }
  720. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  721. }
  722. function pushNode(nodes, node) {
  723. if (node.type === 2 /* TEXT */) {
  724. const prev = last(nodes);
  725. // Merge if both this and the previous node are text and those are
  726. // consecutive. This happens for cases like "a < b".
  727. if (prev &&
  728. prev.type === 2 /* TEXT */ &&
  729. prev.loc.end.offset === node.loc.start.offset) {
  730. prev.content += node.content;
  731. prev.loc.end = node.loc.end;
  732. prev.loc.source += node.loc.source;
  733. return;
  734. }
  735. }
  736. nodes.push(node);
  737. }
  738. function parseCDATA(context, ancestors) {
  739. advanceBy(context, 9);
  740. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  741. if (context.source.length === 0) {
  742. emitError(context, 6 /* EOF_IN_CDATA */);
  743. }
  744. else {
  745. advanceBy(context, 3);
  746. }
  747. return nodes;
  748. }
  749. function parseComment(context) {
  750. const start = getCursor(context);
  751. let content;
  752. // Regular comment.
  753. const match = /--(\!)?>/.exec(context.source);
  754. if (!match) {
  755. content = context.source.slice(4);
  756. advanceBy(context, context.source.length);
  757. emitError(context, 7 /* EOF_IN_COMMENT */);
  758. }
  759. else {
  760. if (match.index <= 3) {
  761. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  762. }
  763. if (match[1]) {
  764. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  765. }
  766. content = context.source.slice(4, match.index);
  767. // Advancing with reporting nested comments.
  768. const s = context.source.slice(0, match.index);
  769. let prevIndex = 1, nestedIndex = 0;
  770. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  771. advanceBy(context, nestedIndex - prevIndex + 1);
  772. if (nestedIndex + 4 < s.length) {
  773. emitError(context, 16 /* NESTED_COMMENT */);
  774. }
  775. prevIndex = nestedIndex + 1;
  776. }
  777. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  778. }
  779. return {
  780. type: 3 /* COMMENT */,
  781. content,
  782. loc: getSelection(context, start)
  783. };
  784. }
  785. function parseBogusComment(context) {
  786. const start = getCursor(context);
  787. const contentStart = context.source[1] === '?' ? 1 : 2;
  788. let content;
  789. const closeIndex = context.source.indexOf('>');
  790. if (closeIndex === -1) {
  791. content = context.source.slice(contentStart);
  792. advanceBy(context, context.source.length);
  793. }
  794. else {
  795. content = context.source.slice(contentStart, closeIndex);
  796. advanceBy(context, closeIndex + 1);
  797. }
  798. return {
  799. type: 3 /* COMMENT */,
  800. content,
  801. loc: getSelection(context, start)
  802. };
  803. }
  804. function parseElement(context, ancestors) {
  805. // Start tag.
  806. const wasInPre = context.inPre;
  807. const wasInVPre = context.inVPre;
  808. const parent = last(ancestors);
  809. const element = parseTag(context, 0 /* Start */, parent);
  810. const isPreBoundary = context.inPre && !wasInPre;
  811. const isVPreBoundary = context.inVPre && !wasInVPre;
  812. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  813. return element;
  814. }
  815. // Children.
  816. ancestors.push(element);
  817. const mode = context.options.getTextMode(element, parent);
  818. const children = parseChildren(context, mode, ancestors);
  819. ancestors.pop();
  820. element.children = children;
  821. // End tag.
  822. if (startsWithEndTagOpen(context.source, element.tag)) {
  823. parseTag(context, 1 /* End */, parent);
  824. }
  825. else {
  826. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  827. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  828. const first = children[0];
  829. if (first && startsWith(first.loc.source, '<!--')) {
  830. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  831. }
  832. }
  833. }
  834. element.loc = getSelection(context, element.loc.start);
  835. if (isPreBoundary) {
  836. context.inPre = false;
  837. }
  838. if (isVPreBoundary) {
  839. context.inVPre = false;
  840. }
  841. return element;
  842. }
  843. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  844. /**
  845. * Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
  846. */
  847. function parseTag(context, type, parent) {
  848. // Tag open.
  849. const start = getCursor(context);
  850. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  851. const tag = match[1];
  852. const ns = context.options.getNamespace(tag, parent);
  853. advanceBy(context, match[0].length);
  854. advanceSpaces(context);
  855. // save current state in case we need to re-parse attributes with v-pre
  856. const cursor = getCursor(context);
  857. const currentSource = context.source;
  858. // Attributes.
  859. let props = parseAttributes(context, type);
  860. // check <pre> tag
  861. if (context.options.isPreTag(tag)) {
  862. context.inPre = true;
  863. }
  864. // check v-pre
  865. if (!context.inVPre &&
  866. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  867. context.inVPre = true;
  868. // reset context
  869. extend(context, cursor);
  870. context.source = currentSource;
  871. // re-parse attrs and filter out v-pre itself
  872. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  873. }
  874. // Tag close.
  875. let isSelfClosing = false;
  876. if (context.source.length === 0) {
  877. emitError(context, 9 /* EOF_IN_TAG */);
  878. }
  879. else {
  880. isSelfClosing = startsWith(context.source, '/>');
  881. if (type === 1 /* End */ && isSelfClosing) {
  882. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  883. }
  884. advanceBy(context, isSelfClosing ? 2 : 1);
  885. }
  886. let tagType = 0 /* ELEMENT */;
  887. const options = context.options;
  888. if (!context.inVPre && !options.isCustomElement(tag)) {
  889. const hasVIs = props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'is');
  890. if (options.isNativeTag && !hasVIs) {
  891. if (!options.isNativeTag(tag))
  892. tagType = 1 /* COMPONENT */;
  893. }
  894. else if (hasVIs ||
  895. isCoreComponent(tag) ||
  896. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  897. /^[A-Z]/.test(tag) ||
  898. tag === 'component') {
  899. tagType = 1 /* COMPONENT */;
  900. }
  901. if (tag === 'slot') {
  902. tagType = 2 /* SLOT */;
  903. }
  904. else if (tag === 'template' &&
  905. props.some(p => {
  906. return (p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name));
  907. })) {
  908. tagType = 3 /* TEMPLATE */;
  909. }
  910. }
  911. return {
  912. type: 1 /* ELEMENT */,
  913. ns,
  914. tag,
  915. tagType,
  916. props,
  917. isSelfClosing,
  918. children: [],
  919. loc: getSelection(context, start),
  920. codegenNode: undefined // to be created during transform phase
  921. };
  922. }
  923. function parseAttributes(context, type) {
  924. const props = [];
  925. const attributeNames = new Set();
  926. while (context.source.length > 0 &&
  927. !startsWith(context.source, '>') &&
  928. !startsWith(context.source, '/>')) {
  929. if (startsWith(context.source, '/')) {
  930. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  931. advanceBy(context, 1);
  932. advanceSpaces(context);
  933. continue;
  934. }
  935. if (type === 1 /* End */) {
  936. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  937. }
  938. const attr = parseAttribute(context, attributeNames);
  939. if (type === 0 /* Start */) {
  940. props.push(attr);
  941. }
  942. if (/^[^\t\r\n\f />]/.test(context.source)) {
  943. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  944. }
  945. advanceSpaces(context);
  946. }
  947. return props;
  948. }
  949. function parseAttribute(context, nameSet) {
  950. // Name.
  951. const start = getCursor(context);
  952. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  953. const name = match[0];
  954. if (nameSet.has(name)) {
  955. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  956. }
  957. nameSet.add(name);
  958. if (name[0] === '=') {
  959. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  960. }
  961. {
  962. const pattern = /["'<]/g;
  963. let m;
  964. while ((m = pattern.exec(name))) {
  965. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  966. }
  967. }
  968. advanceBy(context, name.length);
  969. // Value
  970. let value = undefined;
  971. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  972. advanceSpaces(context);
  973. advanceBy(context, 1);
  974. advanceSpaces(context);
  975. value = parseAttributeValue(context);
  976. if (!value) {
  977. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  978. }
  979. }
  980. const loc = getSelection(context, start);
  981. if (!context.inVPre && /^(v-|:|@|#)/.test(name)) {
  982. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  983. const dirName = match[1] ||
  984. (startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot');
  985. let arg;
  986. if (match[2]) {
  987. const isSlot = dirName === 'slot';
  988. const startOffset = name.indexOf(match[2]);
  989. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  990. let content = match[2];
  991. let isStatic = true;
  992. if (content.startsWith('[')) {
  993. isStatic = false;
  994. if (!content.endsWith(']')) {
  995. emitError(context, 26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  996. }
  997. content = content.substr(1, content.length - 2);
  998. }
  999. else if (isSlot) {
  1000. // #1241 special case for v-slot: vuetify relies extensively on slot
  1001. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  1002. // supports such usage so we are keeping it consistent with 2.x.
  1003. content += match[3] || '';
  1004. }
  1005. arg = {
  1006. type: 4 /* SIMPLE_EXPRESSION */,
  1007. content,
  1008. isStatic,
  1009. constType: isStatic
  1010. ? 3 /* CAN_STRINGIFY */
  1011. : 0 /* NOT_CONSTANT */,
  1012. loc
  1013. };
  1014. }
  1015. if (value && value.isQuoted) {
  1016. const valueLoc = value.loc;
  1017. valueLoc.start.offset++;
  1018. valueLoc.start.column++;
  1019. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  1020. valueLoc.source = valueLoc.source.slice(1, -1);
  1021. }
  1022. return {
  1023. type: 7 /* DIRECTIVE */,
  1024. name: dirName,
  1025. exp: value && {
  1026. type: 4 /* SIMPLE_EXPRESSION */,
  1027. content: value.content,
  1028. isStatic: false,
  1029. // Treat as non-constant by default. This can be potentially set to
  1030. // other values by `transformExpression` to make it eligible for hoisting.
  1031. constType: 0 /* NOT_CONSTANT */,
  1032. loc: value.loc
  1033. },
  1034. arg,
  1035. modifiers: match[3] ? match[3].substr(1).split('.') : [],
  1036. loc
  1037. };
  1038. }
  1039. return {
  1040. type: 6 /* ATTRIBUTE */,
  1041. name,
  1042. value: value && {
  1043. type: 2 /* TEXT */,
  1044. content: value.content,
  1045. loc: value.loc
  1046. },
  1047. loc
  1048. };
  1049. }
  1050. function parseAttributeValue(context) {
  1051. const start = getCursor(context);
  1052. let content;
  1053. const quote = context.source[0];
  1054. const isQuoted = quote === `"` || quote === `'`;
  1055. if (isQuoted) {
  1056. // Quoted value.
  1057. advanceBy(context, 1);
  1058. const endIndex = context.source.indexOf(quote);
  1059. if (endIndex === -1) {
  1060. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  1061. }
  1062. else {
  1063. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  1064. advanceBy(context, 1);
  1065. }
  1066. }
  1067. else {
  1068. // Unquoted
  1069. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  1070. if (!match) {
  1071. return undefined;
  1072. }
  1073. const unexpectedChars = /["'<=`]/g;
  1074. let m;
  1075. while ((m = unexpectedChars.exec(match[0]))) {
  1076. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  1077. }
  1078. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  1079. }
  1080. return { content, isQuoted, loc: getSelection(context, start) };
  1081. }
  1082. function parseInterpolation(context, mode) {
  1083. const [open, close] = context.options.delimiters;
  1084. const closeIndex = context.source.indexOf(close, open.length);
  1085. if (closeIndex === -1) {
  1086. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  1087. return undefined;
  1088. }
  1089. const start = getCursor(context);
  1090. advanceBy(context, open.length);
  1091. const innerStart = getCursor(context);
  1092. const innerEnd = getCursor(context);
  1093. const rawContentLength = closeIndex - open.length;
  1094. const rawContent = context.source.slice(0, rawContentLength);
  1095. const preTrimContent = parseTextData(context, rawContentLength, mode);
  1096. const content = preTrimContent.trim();
  1097. const startOffset = preTrimContent.indexOf(content);
  1098. if (startOffset > 0) {
  1099. advancePositionWithMutation(innerStart, rawContent, startOffset);
  1100. }
  1101. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  1102. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  1103. advanceBy(context, close.length);
  1104. return {
  1105. type: 5 /* INTERPOLATION */,
  1106. content: {
  1107. type: 4 /* SIMPLE_EXPRESSION */,
  1108. isStatic: false,
  1109. // Set `isConstant` to false by default and will decide in transformExpression
  1110. constType: 0 /* NOT_CONSTANT */,
  1111. content,
  1112. loc: getSelection(context, innerStart, innerEnd)
  1113. },
  1114. loc: getSelection(context, start)
  1115. };
  1116. }
  1117. function parseText(context, mode) {
  1118. const endTokens = ['<', context.options.delimiters[0]];
  1119. if (mode === 3 /* CDATA */) {
  1120. endTokens.push(']]>');
  1121. }
  1122. let endIndex = context.source.length;
  1123. for (let i = 0; i < endTokens.length; i++) {
  1124. const index = context.source.indexOf(endTokens[i], 1);
  1125. if (index !== -1 && endIndex > index) {
  1126. endIndex = index;
  1127. }
  1128. }
  1129. const start = getCursor(context);
  1130. const content = parseTextData(context, endIndex, mode);
  1131. return {
  1132. type: 2 /* TEXT */,
  1133. content,
  1134. loc: getSelection(context, start)
  1135. };
  1136. }
  1137. /**
  1138. * Get text data with a given length from the current location.
  1139. * This translates HTML entities in the text data.
  1140. */
  1141. function parseTextData(context, length, mode) {
  1142. const rawText = context.source.slice(0, length);
  1143. advanceBy(context, length);
  1144. if (mode === 2 /* RAWTEXT */ ||
  1145. mode === 3 /* CDATA */ ||
  1146. rawText.indexOf('&') === -1) {
  1147. return rawText;
  1148. }
  1149. else {
  1150. // DATA or RCDATA containing "&"". Entity decoding required.
  1151. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  1152. }
  1153. }
  1154. function getCursor(context) {
  1155. const { column, line, offset } = context;
  1156. return { column, line, offset };
  1157. }
  1158. function getSelection(context, start, end) {
  1159. end = end || getCursor(context);
  1160. return {
  1161. start,
  1162. end,
  1163. source: context.originalSource.slice(start.offset, end.offset)
  1164. };
  1165. }
  1166. function last(xs) {
  1167. return xs[xs.length - 1];
  1168. }
  1169. function startsWith(source, searchString) {
  1170. return source.startsWith(searchString);
  1171. }
  1172. function advanceBy(context, numberOfCharacters) {
  1173. const { source } = context;
  1174. advancePositionWithMutation(context, source, numberOfCharacters);
  1175. context.source = source.slice(numberOfCharacters);
  1176. }
  1177. function advanceSpaces(context) {
  1178. const match = /^[\t\r\n\f ]+/.exec(context.source);
  1179. if (match) {
  1180. advanceBy(context, match[0].length);
  1181. }
  1182. }
  1183. function getNewPosition(context, start, numberOfCharacters) {
  1184. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  1185. }
  1186. function emitError(context, code, offset, loc = getCursor(context)) {
  1187. if (offset) {
  1188. loc.offset += offset;
  1189. loc.column += offset;
  1190. }
  1191. context.options.onError(createCompilerError(code, {
  1192. start: loc,
  1193. end: loc,
  1194. source: ''
  1195. }));
  1196. }
  1197. function isEnd(context, mode, ancestors) {
  1198. const s = context.source;
  1199. switch (mode) {
  1200. case 0 /* DATA */:
  1201. if (startsWith(s, '</')) {
  1202. // TODO: probably bad performance
  1203. for (let i = ancestors.length - 1; i >= 0; --i) {
  1204. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  1205. return true;
  1206. }
  1207. }
  1208. }
  1209. break;
  1210. case 1 /* RCDATA */:
  1211. case 2 /* RAWTEXT */: {
  1212. const parent = last(ancestors);
  1213. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  1214. return true;
  1215. }
  1216. break;
  1217. }
  1218. case 3 /* CDATA */:
  1219. if (startsWith(s, ']]>')) {
  1220. return true;
  1221. }
  1222. break;
  1223. }
  1224. return !s;
  1225. }
  1226. function startsWithEndTagOpen(source, tag) {
  1227. return (startsWith(source, '</') &&
  1228. source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
  1229. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  1230. }
  1231. function hoistStatic(root, context) {
  1232. walk(root, context,
  1233. // Root node is unfortunately non-hoistable due to potential parent
  1234. // fallthrough attributes.
  1235. isSingleElementRoot(root, root.children[0]));
  1236. }
  1237. function isSingleElementRoot(root, child) {
  1238. const { children } = root;
  1239. return (children.length === 1 &&
  1240. child.type === 1 /* ELEMENT */ &&
  1241. !isSlotOutlet(child));
  1242. }
  1243. function walk(node, context, doNotHoistNode = false) {
  1244. let hasHoistedNode = false;
  1245. // Some transforms, e.g. transformAssetUrls from @vue/compiler-sfc, replaces
  1246. // static bindings with expressions. These expressions are guaranteed to be
  1247. // constant so they are still eligible for hoisting, but they are only
  1248. // available at runtime and therefore cannot be evaluated ahead of time.
  1249. // This is only a concern for pre-stringification (via transformHoist by
  1250. // @vue/compiler-dom), but doing it here allows us to perform only one full
  1251. // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
  1252. // stringficiation threshold is met.
  1253. let canStringify = true;
  1254. const { children } = node;
  1255. for (let i = 0; i < children.length; i++) {
  1256. const child = children[i];
  1257. // only plain elements & text calls are eligible for hoisting.
  1258. if (child.type === 1 /* ELEMENT */ &&
  1259. child.tagType === 0 /* ELEMENT */) {
  1260. const constantType = doNotHoistNode
  1261. ? 0 /* NOT_CONSTANT */
  1262. : getConstantType(child, context);
  1263. if (constantType > 0 /* NOT_CONSTANT */) {
  1264. if (constantType < 3 /* CAN_STRINGIFY */) {
  1265. canStringify = false;
  1266. }
  1267. if (constantType >= 2 /* CAN_HOIST */) {
  1268. child.codegenNode.patchFlag =
  1269. -1 /* HOISTED */ + ((process.env.NODE_ENV !== 'production') ? ` /* HOISTED */` : ``);
  1270. child.codegenNode = context.hoist(child.codegenNode);
  1271. hasHoistedNode = true;
  1272. continue;
  1273. }
  1274. }
  1275. else {
  1276. // node may contain dynamic children, but its props may be eligible for
  1277. // hoisting.
  1278. const codegenNode = child.codegenNode;
  1279. if (codegenNode.type === 13 /* VNODE_CALL */) {
  1280. const flag = getPatchFlag(codegenNode);
  1281. if ((!flag ||
  1282. flag === 512 /* NEED_PATCH */ ||
  1283. flag === 1 /* TEXT */) &&
  1284. getGeneratedPropsConstantType(child, context) >=
  1285. 2 /* CAN_HOIST */) {
  1286. const props = getNodeProps(child);
  1287. if (props) {
  1288. codegenNode.props = context.hoist(props);
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. else if (child.type === 12 /* TEXT_CALL */) {
  1295. const contentType = getConstantType(child.content, context);
  1296. if (contentType > 0) {
  1297. if (contentType < 3 /* CAN_STRINGIFY */) {
  1298. canStringify = false;
  1299. }
  1300. if (contentType >= 2 /* CAN_HOIST */) {
  1301. child.codegenNode = context.hoist(child.codegenNode);
  1302. hasHoistedNode = true;
  1303. }
  1304. }
  1305. }
  1306. // walk further
  1307. if (child.type === 1 /* ELEMENT */) {
  1308. walk(child, context);
  1309. }
  1310. else if (child.type === 11 /* FOR */) {
  1311. // Do not hoist v-for single child because it has to be a block
  1312. walk(child, context, child.children.length === 1);
  1313. }
  1314. else if (child.type === 9 /* IF */) {
  1315. for (let i = 0; i < child.branches.length; i++) {
  1316. // Do not hoist v-if single child because it has to be a block
  1317. walk(child.branches[i], context, child.branches[i].children.length === 1);
  1318. }
  1319. }
  1320. }
  1321. if (canStringify && hasHoistedNode && context.transformHoist) {
  1322. context.transformHoist(children, context, node);
  1323. }
  1324. }
  1325. function getConstantType(node, context) {
  1326. const { constantCache } = context;
  1327. switch (node.type) {
  1328. case 1 /* ELEMENT */:
  1329. if (node.tagType !== 0 /* ELEMENT */) {
  1330. return 0 /* NOT_CONSTANT */;
  1331. }
  1332. const cached = constantCache.get(node);
  1333. if (cached !== undefined) {
  1334. return cached;
  1335. }
  1336. const codegenNode = node.codegenNode;
  1337. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  1338. return 0 /* NOT_CONSTANT */;
  1339. }
  1340. const flag = getPatchFlag(codegenNode);
  1341. if (!flag) {
  1342. let returnType = 3 /* CAN_STRINGIFY */;
  1343. // Element itself has no patch flag. However we still need to check:
  1344. // 1. Even for a node with no patch flag, it is possible for it to contain
  1345. // non-hoistable expressions that refers to scope variables, e.g. compiler
  1346. // injected keys or cached event handlers. Therefore we need to always
  1347. // check the codegenNode's props to be sure.
  1348. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  1349. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  1350. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1351. return 0 /* NOT_CONSTANT */;
  1352. }
  1353. if (generatedPropsType < returnType) {
  1354. returnType = generatedPropsType;
  1355. }
  1356. // 2. its children.
  1357. for (let i = 0; i < node.children.length; i++) {
  1358. const childType = getConstantType(node.children[i], context);
  1359. if (childType === 0 /* NOT_CONSTANT */) {
  1360. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1361. return 0 /* NOT_CONSTANT */;
  1362. }
  1363. if (childType < returnType) {
  1364. returnType = childType;
  1365. }
  1366. }
  1367. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  1368. // type, check if any of the props can cause the type to be lowered
  1369. // we can skip can_patch because it's guaranteed by the absence of a
  1370. // patchFlag.
  1371. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  1372. for (let i = 0; i < node.props.length; i++) {
  1373. const p = node.props[i];
  1374. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  1375. const expType = getConstantType(p.exp, context);
  1376. if (expType === 0 /* NOT_CONSTANT */) {
  1377. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1378. return 0 /* NOT_CONSTANT */;
  1379. }
  1380. if (expType < returnType) {
  1381. returnType = expType;
  1382. }
  1383. }
  1384. }
  1385. }
  1386. // only svg/foreignObject could be block here, however if they are
  1387. // static then they don't need to be blocks since there will be no
  1388. // nested updates.
  1389. if (codegenNode.isBlock) {
  1390. codegenNode.isBlock = false;
  1391. context.helper(CREATE_VNODE);
  1392. }
  1393. constantCache.set(node, returnType);
  1394. return returnType;
  1395. }
  1396. else {
  1397. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1398. return 0 /* NOT_CONSTANT */;
  1399. }
  1400. case 2 /* TEXT */:
  1401. case 3 /* COMMENT */:
  1402. return 3 /* CAN_STRINGIFY */;
  1403. case 9 /* IF */:
  1404. case 11 /* FOR */:
  1405. case 10 /* IF_BRANCH */:
  1406. return 0 /* NOT_CONSTANT */;
  1407. case 5 /* INTERPOLATION */:
  1408. case 12 /* TEXT_CALL */:
  1409. return getConstantType(node.content, context);
  1410. case 4 /* SIMPLE_EXPRESSION */:
  1411. return node.constType;
  1412. case 8 /* COMPOUND_EXPRESSION */:
  1413. let returnType = 3 /* CAN_STRINGIFY */;
  1414. for (let i = 0; i < node.children.length; i++) {
  1415. const child = node.children[i];
  1416. if (isString(child) || isSymbol(child)) {
  1417. continue;
  1418. }
  1419. const childType = getConstantType(child, context);
  1420. if (childType === 0 /* NOT_CONSTANT */) {
  1421. return 0 /* NOT_CONSTANT */;
  1422. }
  1423. else if (childType < returnType) {
  1424. returnType = childType;
  1425. }
  1426. }
  1427. return returnType;
  1428. default:
  1429. if ((process.env.NODE_ENV !== 'production')) ;
  1430. return 0 /* NOT_CONSTANT */;
  1431. }
  1432. }
  1433. function getGeneratedPropsConstantType(node, context) {
  1434. let returnType = 3 /* CAN_STRINGIFY */;
  1435. const props = getNodeProps(node);
  1436. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  1437. const { properties } = props;
  1438. for (let i = 0; i < properties.length; i++) {
  1439. const { key, value } = properties[i];
  1440. const keyType = getConstantType(key, context);
  1441. if (keyType === 0 /* NOT_CONSTANT */) {
  1442. return keyType;
  1443. }
  1444. if (keyType < returnType) {
  1445. returnType = keyType;
  1446. }
  1447. if (value.type !== 4 /* SIMPLE_EXPRESSION */) {
  1448. return 0 /* NOT_CONSTANT */;
  1449. }
  1450. const valueType = getConstantType(value, context);
  1451. if (valueType === 0 /* NOT_CONSTANT */) {
  1452. return valueType;
  1453. }
  1454. if (valueType < returnType) {
  1455. returnType = valueType;
  1456. }
  1457. }
  1458. }
  1459. return returnType;
  1460. }
  1461. function getNodeProps(node) {
  1462. const codegenNode = node.codegenNode;
  1463. if (codegenNode.type === 13 /* VNODE_CALL */) {
  1464. return codegenNode.props;
  1465. }
  1466. }
  1467. function getPatchFlag(node) {
  1468. const flag = node.patchFlag;
  1469. return flag ? parseInt(flag, 10) : undefined;
  1470. }
  1471. function createTransformContext(root, { filename = '', prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, ssr = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError }) {
  1472. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  1473. const context = {
  1474. // options
  1475. selfName: nameMatch && capitalize(camelize$1(nameMatch[1])),
  1476. prefixIdentifiers,
  1477. hoistStatic,
  1478. cacheHandlers,
  1479. nodeTransforms,
  1480. directiveTransforms,
  1481. transformHoist,
  1482. isBuiltInComponent,
  1483. isCustomElement,
  1484. expressionPlugins,
  1485. scopeId,
  1486. ssr,
  1487. ssrCssVars,
  1488. bindingMetadata,
  1489. inline,
  1490. isTS,
  1491. onError,
  1492. // state
  1493. root,
  1494. helpers: new Set(),
  1495. components: new Set(),
  1496. directives: new Set(),
  1497. hoists: [],
  1498. imports: [],
  1499. constantCache: new Map(),
  1500. temps: 0,
  1501. cached: 0,
  1502. identifiers: Object.create(null),
  1503. scopes: {
  1504. vFor: 0,
  1505. vSlot: 0,
  1506. vPre: 0,
  1507. vOnce: 0
  1508. },
  1509. parent: null,
  1510. currentNode: root,
  1511. childIndex: 0,
  1512. // methods
  1513. helper(name) {
  1514. context.helpers.add(name);
  1515. return name;
  1516. },
  1517. helperString(name) {
  1518. return `_${helperNameMap[context.helper(name)]}`;
  1519. },
  1520. replaceNode(node) {
  1521. /* istanbul ignore if */
  1522. if ((process.env.NODE_ENV !== 'production')) {
  1523. if (!context.currentNode) {
  1524. throw new Error(`Node being replaced is already removed.`);
  1525. }
  1526. if (!context.parent) {
  1527. throw new Error(`Cannot replace root node.`);
  1528. }
  1529. }
  1530. context.parent.children[context.childIndex] = context.currentNode = node;
  1531. },
  1532. removeNode(node) {
  1533. if ((process.env.NODE_ENV !== 'production') && !context.parent) {
  1534. throw new Error(`Cannot remove root node.`);
  1535. }
  1536. const list = context.parent.children;
  1537. const removalIndex = node
  1538. ? list.indexOf(node)
  1539. : context.currentNode
  1540. ? context.childIndex
  1541. : -1;
  1542. /* istanbul ignore if */
  1543. if ((process.env.NODE_ENV !== 'production') && removalIndex < 0) {
  1544. throw new Error(`node being removed is not a child of current parent`);
  1545. }
  1546. if (!node || node === context.currentNode) {
  1547. // current node removed
  1548. context.currentNode = null;
  1549. context.onNodeRemoved();
  1550. }
  1551. else {
  1552. // sibling node removed
  1553. if (context.childIndex > removalIndex) {
  1554. context.childIndex--;
  1555. context.onNodeRemoved();
  1556. }
  1557. }
  1558. context.parent.children.splice(removalIndex, 1);
  1559. },
  1560. onNodeRemoved: () => { },
  1561. addIdentifiers(exp) {
  1562. },
  1563. removeIdentifiers(exp) {
  1564. },
  1565. hoist(exp) {
  1566. context.hoists.push(exp);
  1567. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  1568. identifier.hoisted = exp;
  1569. return identifier;
  1570. },
  1571. cache(exp, isVNode = false) {
  1572. return createCacheExpression(++context.cached, exp, isVNode);
  1573. }
  1574. };
  1575. return context;
  1576. }
  1577. function transform(root, options) {
  1578. const context = createTransformContext(root, options);
  1579. traverseNode(root, context);
  1580. if (options.hoistStatic) {
  1581. hoistStatic(root, context);
  1582. }
  1583. if (!options.ssr) {
  1584. createRootCodegen(root, context);
  1585. }
  1586. // finalize meta information
  1587. root.helpers = [...context.helpers];
  1588. root.components = [...context.components];
  1589. root.directives = [...context.directives];
  1590. root.imports = context.imports;
  1591. root.hoists = context.hoists;
  1592. root.temps = context.temps;
  1593. root.cached = context.cached;
  1594. }
  1595. function createRootCodegen(root, context) {
  1596. const { helper } = context;
  1597. const { children } = root;
  1598. if (children.length === 1) {
  1599. const child = children[0];
  1600. // if the single child is an element, turn it into a block.
  1601. if (isSingleElementRoot(root, child) && child.codegenNode) {
  1602. // single element root is never hoisted so codegenNode will never be
  1603. // SimpleExpressionNode
  1604. const codegenNode = child.codegenNode;
  1605. if (codegenNode.type === 13 /* VNODE_CALL */) {
  1606. codegenNode.isBlock = true;
  1607. helper(OPEN_BLOCK);
  1608. helper(CREATE_BLOCK);
  1609. }
  1610. root.codegenNode = codegenNode;
  1611. }
  1612. else {
  1613. // - single <slot/>, IfNode, ForNode: already blocks.
  1614. // - single text node: always patched.
  1615. // root codegen falls through via genNode()
  1616. root.codegenNode = child;
  1617. }
  1618. }
  1619. else if (children.length > 1) {
  1620. // root has multiple nodes - return a fragment block.
  1621. let patchFlag = 64 /* STABLE_FRAGMENT */;
  1622. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  1623. // check if the fragment actually contains a single valid child with
  1624. // the rest being comments
  1625. if ((process.env.NODE_ENV !== 'production') &&
  1626. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  1627. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  1628. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  1629. }
  1630. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true);
  1631. }
  1632. else ;
  1633. }
  1634. function traverseChildren(parent, context) {
  1635. let i = 0;
  1636. const nodeRemoved = () => {
  1637. i--;
  1638. };
  1639. for (; i < parent.children.length; i++) {
  1640. const child = parent.children[i];
  1641. if (isString(child))
  1642. continue;
  1643. context.parent = parent;
  1644. context.childIndex = i;
  1645. context.onNodeRemoved = nodeRemoved;
  1646. traverseNode(child, context);
  1647. }
  1648. }
  1649. function traverseNode(node, context) {
  1650. context.currentNode = node;
  1651. // apply transform plugins
  1652. const { nodeTransforms } = context;
  1653. const exitFns = [];
  1654. for (let i = 0; i < nodeTransforms.length; i++) {
  1655. const onExit = nodeTransforms[i](node, context);
  1656. if (onExit) {
  1657. if (isArray(onExit)) {
  1658. exitFns.push(...onExit);
  1659. }
  1660. else {
  1661. exitFns.push(onExit);
  1662. }
  1663. }
  1664. if (!context.currentNode) {
  1665. // node was removed
  1666. return;
  1667. }
  1668. else {
  1669. // node may have been replaced
  1670. node = context.currentNode;
  1671. }
  1672. }
  1673. switch (node.type) {
  1674. case 3 /* COMMENT */:
  1675. if (!context.ssr) {
  1676. // inject import for the Comment symbol, which is needed for creating
  1677. // comment nodes with `createVNode`
  1678. context.helper(CREATE_COMMENT);
  1679. }
  1680. break;
  1681. case 5 /* INTERPOLATION */:
  1682. // no need to traverse, but we need to inject toString helper
  1683. if (!context.ssr) {
  1684. context.helper(TO_DISPLAY_STRING);
  1685. }
  1686. break;
  1687. // for container types, further traverse downwards
  1688. case 9 /* IF */:
  1689. for (let i = 0; i < node.branches.length; i++) {
  1690. traverseNode(node.branches[i], context);
  1691. }
  1692. break;
  1693. case 10 /* IF_BRANCH */:
  1694. case 11 /* FOR */:
  1695. case 1 /* ELEMENT */:
  1696. case 0 /* ROOT */:
  1697. traverseChildren(node, context);
  1698. break;
  1699. }
  1700. // exit transforms
  1701. context.currentNode = node;
  1702. let i = exitFns.length;
  1703. while (i--) {
  1704. exitFns[i]();
  1705. }
  1706. }
  1707. function createStructuralDirectiveTransform(name, fn) {
  1708. const matches = isString(name)
  1709. ? (n) => n === name
  1710. : (n) => name.test(n);
  1711. return (node, context) => {
  1712. if (node.type === 1 /* ELEMENT */) {
  1713. const { props } = node;
  1714. // structural directive transforms are not concerned with slots
  1715. // as they are handled separately in vSlot.ts
  1716. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  1717. return;
  1718. }
  1719. const exitFns = [];
  1720. for (let i = 0; i < props.length; i++) {
  1721. const prop = props[i];
  1722. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  1723. // structural directives are removed to avoid infinite recursion
  1724. // also we remove them *before* applying so that it can further
  1725. // traverse itself in case it moves the node around
  1726. props.splice(i, 1);
  1727. i--;
  1728. const onExit = fn(node, prop, context);
  1729. if (onExit)
  1730. exitFns.push(onExit);
  1731. }
  1732. }
  1733. return exitFns;
  1734. }
  1735. };
  1736. }
  1737. const PURE_ANNOTATION = `/*#__PURE__*/`;
  1738. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssr = false }) {
  1739. const context = {
  1740. mode,
  1741. prefixIdentifiers,
  1742. sourceMap,
  1743. filename,
  1744. scopeId,
  1745. optimizeImports,
  1746. runtimeGlobalName,
  1747. runtimeModuleName,
  1748. ssr,
  1749. source: ast.loc.source,
  1750. code: ``,
  1751. column: 1,
  1752. line: 1,
  1753. offset: 0,
  1754. indentLevel: 0,
  1755. pure: false,
  1756. map: undefined,
  1757. helper(key) {
  1758. return `_${helperNameMap[key]}`;
  1759. },
  1760. push(code, node) {
  1761. context.code += code;
  1762. },
  1763. indent() {
  1764. newline(++context.indentLevel);
  1765. },
  1766. deindent(withoutNewLine = false) {
  1767. if (withoutNewLine) {
  1768. --context.indentLevel;
  1769. }
  1770. else {
  1771. newline(--context.indentLevel);
  1772. }
  1773. },
  1774. newline() {
  1775. newline(context.indentLevel);
  1776. }
  1777. };
  1778. function newline(n) {
  1779. context.push('\n' + ` `.repeat(n));
  1780. }
  1781. return context;
  1782. }
  1783. function generate(ast, options = {}) {
  1784. const context = createCodegenContext(ast, options);
  1785. if (options.onContextCreated)
  1786. options.onContextCreated(context);
  1787. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  1788. const hasHelpers = ast.helpers.length > 0;
  1789. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  1790. // preambles
  1791. // in setup() inline mode, the preamble is generated in a sub context
  1792. // and returned separately.
  1793. const preambleContext = context;
  1794. {
  1795. genFunctionPreamble(ast, preambleContext);
  1796. }
  1797. // enter render function
  1798. const functionName = ssr ? `ssrRender` : `render`;
  1799. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  1800. const signature = args.join(', ');
  1801. {
  1802. push(`function ${functionName}(${signature}) {`);
  1803. }
  1804. indent();
  1805. if (useWithBlock) {
  1806. push(`with (_ctx) {`);
  1807. indent();
  1808. // function mode const declarations should be inside with block
  1809. // also they should be renamed to avoid collision with user properties
  1810. if (hasHelpers) {
  1811. push(`const { ${ast.helpers
  1812. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  1813. .join(', ')} } = _Vue`);
  1814. push(`\n`);
  1815. newline();
  1816. }
  1817. }
  1818. // generate asset resolution statements
  1819. if (ast.components.length) {
  1820. genAssets(ast.components, 'component', context);
  1821. if (ast.directives.length || ast.temps > 0) {
  1822. newline();
  1823. }
  1824. }
  1825. if (ast.directives.length) {
  1826. genAssets(ast.directives, 'directive', context);
  1827. if (ast.temps > 0) {
  1828. newline();
  1829. }
  1830. }
  1831. if (ast.temps > 0) {
  1832. push(`let `);
  1833. for (let i = 0; i < ast.temps; i++) {
  1834. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  1835. }
  1836. }
  1837. if (ast.components.length || ast.directives.length || ast.temps) {
  1838. push(`\n`);
  1839. newline();
  1840. }
  1841. // generate the VNode tree expression
  1842. if (!ssr) {
  1843. push(`return `);
  1844. }
  1845. if (ast.codegenNode) {
  1846. genNode(ast.codegenNode, context);
  1847. }
  1848. else {
  1849. push(`null`);
  1850. }
  1851. if (useWithBlock) {
  1852. deindent();
  1853. push(`}`);
  1854. }
  1855. deindent();
  1856. push(`}`);
  1857. return {
  1858. ast,
  1859. code: context.code,
  1860. preamble: ``,
  1861. // SourceMapGenerator does have toJSON() method but it's not in the types
  1862. map: context.map ? context.map.toJSON() : undefined
  1863. };
  1864. }
  1865. function genFunctionPreamble(ast, context) {
  1866. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName } = context;
  1867. const VueBinding = runtimeGlobalName;
  1868. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  1869. // Generate const declaration for helpers
  1870. // In prefix mode, we place the const declaration at top so it's done
  1871. // only once; But if we not prefixing, we place the declaration inside the
  1872. // with block so it doesn't incur the `in` check cost for every helper access.
  1873. if (ast.helpers.length > 0) {
  1874. {
  1875. // "with" mode.
  1876. // save Vue in a separate variable to avoid collision
  1877. push(`const _Vue = ${VueBinding}\n`);
  1878. // in "with" mode, helpers are declared inside the with block to avoid
  1879. // has check cost, but hoists are lifted out of the function - we need
  1880. // to provide the helper here.
  1881. if (ast.hoists.length) {
  1882. const staticHelpers = [
  1883. CREATE_VNODE,
  1884. CREATE_COMMENT,
  1885. CREATE_TEXT,
  1886. CREATE_STATIC
  1887. ]
  1888. .filter(helper => ast.helpers.includes(helper))
  1889. .map(aliasHelper)
  1890. .join(', ');
  1891. push(`const { ${staticHelpers} } = _Vue\n`);
  1892. }
  1893. }
  1894. }
  1895. genHoists(ast.hoists, context);
  1896. newline();
  1897. push(`return `);
  1898. }
  1899. function genAssets(assets, type, { helper, push, newline }) {
  1900. const resolver = helper(type === 'component' ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE);
  1901. for (let i = 0; i < assets.length; i++) {
  1902. const id = assets[i];
  1903. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)})`);
  1904. if (i < assets.length - 1) {
  1905. newline();
  1906. }
  1907. }
  1908. }
  1909. function genHoists(hoists, context) {
  1910. if (!hoists.length) {
  1911. return;
  1912. }
  1913. context.pure = true;
  1914. const { push, newline, helper, scopeId, mode } = context;
  1915. newline();
  1916. hoists.forEach((exp, i) => {
  1917. if (exp) {
  1918. push(`const _hoisted_${i + 1} = `);
  1919. genNode(exp, context);
  1920. newline();
  1921. }
  1922. });
  1923. context.pure = false;
  1924. }
  1925. function isText$1(n) {
  1926. return (isString(n) ||
  1927. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  1928. n.type === 2 /* TEXT */ ||
  1929. n.type === 5 /* INTERPOLATION */ ||
  1930. n.type === 8 /* COMPOUND_EXPRESSION */);
  1931. }
  1932. function genNodeListAsArray(nodes, context) {
  1933. const multilines = nodes.length > 3 ||
  1934. (((process.env.NODE_ENV !== 'production')) && nodes.some(n => isArray(n) || !isText$1(n)));
  1935. context.push(`[`);
  1936. multilines && context.indent();
  1937. genNodeList(nodes, context, multilines);
  1938. multilines && context.deindent();
  1939. context.push(`]`);
  1940. }
  1941. function genNodeList(nodes, context, multilines = false, comma = true) {
  1942. const { push, newline } = context;
  1943. for (let i = 0; i < nodes.length; i++) {
  1944. const node = nodes[i];
  1945. if (isString(node)) {
  1946. push(node);
  1947. }
  1948. else if (isArray(node)) {
  1949. genNodeListAsArray(node, context);
  1950. }
  1951. else {
  1952. genNode(node, context);
  1953. }
  1954. if (i < nodes.length - 1) {
  1955. if (multilines) {
  1956. comma && push(',');
  1957. newline();
  1958. }
  1959. else {
  1960. comma && push(', ');
  1961. }
  1962. }
  1963. }
  1964. }
  1965. function genNode(node, context) {
  1966. if (isString(node)) {
  1967. context.push(node);
  1968. return;
  1969. }
  1970. if (isSymbol(node)) {
  1971. context.push(context.helper(node));
  1972. return;
  1973. }
  1974. switch (node.type) {
  1975. case 1 /* ELEMENT */:
  1976. case 9 /* IF */:
  1977. case 11 /* FOR */:
  1978. (process.env.NODE_ENV !== 'production') &&
  1979. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  1980. `Apply appropriate transforms first.`);
  1981. genNode(node.codegenNode, context);
  1982. break;
  1983. case 2 /* TEXT */:
  1984. genText(node, context);
  1985. break;
  1986. case 4 /* SIMPLE_EXPRESSION */:
  1987. genExpression(node, context);
  1988. break;
  1989. case 5 /* INTERPOLATION */:
  1990. genInterpolation(node, context);
  1991. break;
  1992. case 12 /* TEXT_CALL */:
  1993. genNode(node.codegenNode, context);
  1994. break;
  1995. case 8 /* COMPOUND_EXPRESSION */:
  1996. genCompoundExpression(node, context);
  1997. break;
  1998. case 3 /* COMMENT */:
  1999. genComment(node, context);
  2000. break;
  2001. case 13 /* VNODE_CALL */:
  2002. genVNodeCall(node, context);
  2003. break;
  2004. case 14 /* JS_CALL_EXPRESSION */:
  2005. genCallExpression(node, context);
  2006. break;
  2007. case 15 /* JS_OBJECT_EXPRESSION */:
  2008. genObjectExpression(node, context);
  2009. break;
  2010. case 17 /* JS_ARRAY_EXPRESSION */:
  2011. genArrayExpression(node, context);
  2012. break;
  2013. case 18 /* JS_FUNCTION_EXPRESSION */:
  2014. genFunctionExpression(node, context);
  2015. break;
  2016. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  2017. genConditionalExpression(node, context);
  2018. break;
  2019. case 20 /* JS_CACHE_EXPRESSION */:
  2020. genCacheExpression(node, context);
  2021. break;
  2022. // SSR only types
  2023. case 21 /* JS_BLOCK_STATEMENT */:
  2024. break;
  2025. case 22 /* JS_TEMPLATE_LITERAL */:
  2026. break;
  2027. case 23 /* JS_IF_STATEMENT */:
  2028. break;
  2029. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  2030. break;
  2031. case 25 /* JS_SEQUENCE_EXPRESSION */:
  2032. break;
  2033. case 26 /* JS_RETURN_STATEMENT */:
  2034. break;
  2035. /* istanbul ignore next */
  2036. case 10 /* IF_BRANCH */:
  2037. // noop
  2038. break;
  2039. default:
  2040. if ((process.env.NODE_ENV !== 'production')) {
  2041. assert(false, `unhandled codegen node type: ${node.type}`);
  2042. // make sure we exhaust all possible types
  2043. const exhaustiveCheck = node;
  2044. return exhaustiveCheck;
  2045. }
  2046. }
  2047. }
  2048. function genText(node, context) {
  2049. context.push(JSON.stringify(node.content), node);
  2050. }
  2051. function genExpression(node, context) {
  2052. const { content, isStatic } = node;
  2053. context.push(isStatic ? JSON.stringify(content) : content, node);
  2054. }
  2055. function genInterpolation(node, context) {
  2056. const { push, helper, pure } = context;
  2057. if (pure)
  2058. push(PURE_ANNOTATION);
  2059. push(`${helper(TO_DISPLAY_STRING)}(`);
  2060. genNode(node.content, context);
  2061. push(`)`);
  2062. }
  2063. function genCompoundExpression(node, context) {
  2064. for (let i = 0; i < node.children.length; i++) {
  2065. const child = node.children[i];
  2066. if (isString(child)) {
  2067. context.push(child);
  2068. }
  2069. else {
  2070. genNode(child, context);
  2071. }
  2072. }
  2073. }
  2074. function genExpressionAsPropertyKey(node, context) {
  2075. const { push } = context;
  2076. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  2077. push(`[`);
  2078. genCompoundExpression(node, context);
  2079. push(`]`);
  2080. }
  2081. else if (node.isStatic) {
  2082. // only quote keys if necessary
  2083. const text = isSimpleIdentifier(node.content)
  2084. ? node.content
  2085. : JSON.stringify(node.content);
  2086. push(text, node);
  2087. }
  2088. else {
  2089. push(`[${node.content}]`, node);
  2090. }
  2091. }
  2092. function genComment(node, context) {
  2093. if ((process.env.NODE_ENV !== 'production')) {
  2094. const { push, helper, pure } = context;
  2095. if (pure) {
  2096. push(PURE_ANNOTATION);
  2097. }
  2098. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  2099. }
  2100. }
  2101. function genVNodeCall(node, context) {
  2102. const { push, helper, pure } = context;
  2103. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;
  2104. if (directives) {
  2105. push(helper(WITH_DIRECTIVES) + `(`);
  2106. }
  2107. if (isBlock) {
  2108. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  2109. }
  2110. if (pure) {
  2111. push(PURE_ANNOTATION);
  2112. }
  2113. push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);
  2114. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  2115. push(`)`);
  2116. if (isBlock) {
  2117. push(`)`);
  2118. }
  2119. if (directives) {
  2120. push(`, `);
  2121. genNode(directives, context);
  2122. push(`)`);
  2123. }
  2124. }
  2125. function genNullableArgs(args) {
  2126. let i = args.length;
  2127. while (i--) {
  2128. if (args[i] != null)
  2129. break;
  2130. }
  2131. return args.slice(0, i + 1).map(arg => arg || `null`);
  2132. }
  2133. // JavaScript
  2134. function genCallExpression(node, context) {
  2135. const { push, helper, pure } = context;
  2136. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  2137. if (pure) {
  2138. push(PURE_ANNOTATION);
  2139. }
  2140. push(callee + `(`, node);
  2141. genNodeList(node.arguments, context);
  2142. push(`)`);
  2143. }
  2144. function genObjectExpression(node, context) {
  2145. const { push, indent, deindent, newline } = context;
  2146. const { properties } = node;
  2147. if (!properties.length) {
  2148. push(`{}`, node);
  2149. return;
  2150. }
  2151. const multilines = properties.length > 1 ||
  2152. (((process.env.NODE_ENV !== 'production')) &&
  2153. properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  2154. push(multilines ? `{` : `{ `);
  2155. multilines && indent();
  2156. for (let i = 0; i < properties.length; i++) {
  2157. const { key, value } = properties[i];
  2158. // key
  2159. genExpressionAsPropertyKey(key, context);
  2160. push(`: `);
  2161. // value
  2162. genNode(value, context);
  2163. if (i < properties.length - 1) {
  2164. // will only reach this if it's multilines
  2165. push(`,`);
  2166. newline();
  2167. }
  2168. }
  2169. multilines && deindent();
  2170. push(multilines ? `}` : ` }`);
  2171. }
  2172. function genArrayExpression(node, context) {
  2173. genNodeListAsArray(node.elements, context);
  2174. }
  2175. function genFunctionExpression(node, context) {
  2176. const { push, indent, deindent, scopeId, mode } = context;
  2177. const { params, returns, body, newline, isSlot } = node;
  2178. if (isSlot) {
  2179. push(`_${helperNameMap[WITH_CTX]}(`);
  2180. }
  2181. push(`(`, node);
  2182. if (isArray(params)) {
  2183. genNodeList(params, context);
  2184. }
  2185. else if (params) {
  2186. genNode(params, context);
  2187. }
  2188. push(`) => `);
  2189. if (newline || body) {
  2190. push(`{`);
  2191. indent();
  2192. }
  2193. if (returns) {
  2194. if (newline) {
  2195. push(`return `);
  2196. }
  2197. if (isArray(returns)) {
  2198. genNodeListAsArray(returns, context);
  2199. }
  2200. else {
  2201. genNode(returns, context);
  2202. }
  2203. }
  2204. else if (body) {
  2205. genNode(body, context);
  2206. }
  2207. if (newline || body) {
  2208. deindent();
  2209. push(`}`);
  2210. }
  2211. if (isSlot) {
  2212. push(`)`);
  2213. }
  2214. }
  2215. function genConditionalExpression(node, context) {
  2216. const { test, consequent, alternate, newline: needNewline } = node;
  2217. const { push, indent, deindent, newline } = context;
  2218. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  2219. const needsParens = !isSimpleIdentifier(test.content);
  2220. needsParens && push(`(`);
  2221. genExpression(test, context);
  2222. needsParens && push(`)`);
  2223. }
  2224. else {
  2225. push(`(`);
  2226. genNode(test, context);
  2227. push(`)`);
  2228. }
  2229. needNewline && indent();
  2230. context.indentLevel++;
  2231. needNewline || push(` `);
  2232. push(`? `);
  2233. genNode(consequent, context);
  2234. context.indentLevel--;
  2235. needNewline && newline();
  2236. needNewline || push(` `);
  2237. push(`: `);
  2238. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  2239. if (!isNested) {
  2240. context.indentLevel++;
  2241. }
  2242. genNode(alternate, context);
  2243. if (!isNested) {
  2244. context.indentLevel--;
  2245. }
  2246. needNewline && deindent(true /* without newline */);
  2247. }
  2248. function genCacheExpression(node, context) {
  2249. const { push, helper, indent, deindent, newline } = context;
  2250. push(`_cache[${node.index}] || (`);
  2251. if (node.isVNode) {
  2252. indent();
  2253. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  2254. newline();
  2255. }
  2256. push(`_cache[${node.index}] = `);
  2257. genNode(node.value, context);
  2258. if (node.isVNode) {
  2259. push(`,`);
  2260. newline();
  2261. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  2262. newline();
  2263. push(`_cache[${node.index}]`);
  2264. deindent();
  2265. }
  2266. push(`)`);
  2267. }
  2268. // these keywords should not appear inside expressions, but operators like
  2269. // typeof, instanceof and in are allowed
  2270. const prohibitedKeywordRE = new RegExp('\\b' +
  2271. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  2272. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  2273. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  2274. .split(',')
  2275. .join('\\b|\\b') +
  2276. '\\b');
  2277. // strip strings in expressions
  2278. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  2279. /**
  2280. * Validate a non-prefixed expression.
  2281. * This is only called when using the in-browser runtime compiler since it
  2282. * doesn't prefix expressions.
  2283. */
  2284. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  2285. const exp = node.content;
  2286. // empty expressions are validated per-directive since some directives
  2287. // do allow empty expressions.
  2288. if (!exp.trim()) {
  2289. return;
  2290. }
  2291. try {
  2292. new Function(asRawStatements
  2293. ? ` ${exp} `
  2294. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  2295. }
  2296. catch (e) {
  2297. let message = e.message;
  2298. const keywordMatch = exp
  2299. .replace(stripStringRE, '')
  2300. .match(prohibitedKeywordRE);
  2301. if (keywordMatch) {
  2302. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  2303. }
  2304. context.onError(createCompilerError(43 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  2305. }
  2306. }
  2307. const transformExpression = (node, context) => {
  2308. if (node.type === 5 /* INTERPOLATION */) {
  2309. node.content = processExpression(node.content, context);
  2310. }
  2311. else if (node.type === 1 /* ELEMENT */) {
  2312. // handle directives on element
  2313. for (let i = 0; i < node.props.length; i++) {
  2314. const dir = node.props[i];
  2315. // do not process for v-on & v-for since they are special handled
  2316. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  2317. const exp = dir.exp;
  2318. const arg = dir.arg;
  2319. // do not process exp if this is v-on:arg - we need special handling
  2320. // for wrapping inline statements.
  2321. if (exp &&
  2322. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  2323. !(dir.name === 'on' && arg)) {
  2324. dir.exp = processExpression(exp, context,
  2325. // slot args must be processed as function params
  2326. dir.name === 'slot');
  2327. }
  2328. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  2329. dir.arg = processExpression(arg, context);
  2330. }
  2331. }
  2332. }
  2333. }
  2334. };
  2335. // Important: since this function uses Node.js only dependencies, it should
  2336. // always be used with a leading !true check so that it can be
  2337. // tree-shaken from the browser build.
  2338. function processExpression(node, context,
  2339. // some expressions like v-slot props & v-for aliases should be parsed as
  2340. // function params
  2341. asParams = false,
  2342. // v-on handler values may contain multiple statements
  2343. asRawStatements = false) {
  2344. {
  2345. if ((process.env.NODE_ENV !== 'production')) {
  2346. // simple in-browser validation (same logic in 2.x)
  2347. validateBrowserExpression(node, context, asParams, asRawStatements);
  2348. }
  2349. return node;
  2350. }
  2351. }
  2352. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  2353. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  2354. // #1587: We need to dynamically increment the key based on the current
  2355. // node's sibling nodes, since chained v-if/else branches are
  2356. // rendered at the same depth
  2357. const siblings = context.parent.children;
  2358. let i = siblings.indexOf(ifNode);
  2359. let key = 0;
  2360. while (i-- >= 0) {
  2361. const sibling = siblings[i];
  2362. if (sibling && sibling.type === 9 /* IF */) {
  2363. key += sibling.branches.length;
  2364. }
  2365. }
  2366. // Exit callback. Complete the codegenNode when all children have been
  2367. // transformed.
  2368. return () => {
  2369. if (isRoot) {
  2370. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  2371. }
  2372. else {
  2373. // attach this branch's codegen node to the v-if root.
  2374. const parentCondition = getParentCondition(ifNode.codegenNode);
  2375. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  2376. }
  2377. };
  2378. });
  2379. });
  2380. // target-agnostic transform used for both Client and SSR
  2381. function processIf(node, dir, context, processCodegen) {
  2382. if (dir.name !== 'else' &&
  2383. (!dir.exp || !dir.exp.content.trim())) {
  2384. const loc = dir.exp ? dir.exp.loc : node.loc;
  2385. context.onError(createCompilerError(27 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  2386. dir.exp = createSimpleExpression(`true`, false, loc);
  2387. }
  2388. if ((process.env.NODE_ENV !== 'production') && true && dir.exp) {
  2389. validateBrowserExpression(dir.exp, context);
  2390. }
  2391. if (dir.name === 'if') {
  2392. const branch = createIfBranch(node, dir);
  2393. const ifNode = {
  2394. type: 9 /* IF */,
  2395. loc: node.loc,
  2396. branches: [branch]
  2397. };
  2398. context.replaceNode(ifNode);
  2399. if (processCodegen) {
  2400. return processCodegen(ifNode, branch, true);
  2401. }
  2402. }
  2403. else {
  2404. // locate the adjacent v-if
  2405. const siblings = context.parent.children;
  2406. const comments = [];
  2407. let i = siblings.indexOf(node);
  2408. while (i-- >= -1) {
  2409. const sibling = siblings[i];
  2410. if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* COMMENT */) {
  2411. context.removeNode(sibling);
  2412. comments.unshift(sibling);
  2413. continue;
  2414. }
  2415. if (sibling &&
  2416. sibling.type === 2 /* TEXT */ &&
  2417. !sibling.content.trim().length) {
  2418. context.removeNode(sibling);
  2419. continue;
  2420. }
  2421. if (sibling && sibling.type === 9 /* IF */) {
  2422. // move the node to the if node's branches
  2423. context.removeNode();
  2424. const branch = createIfBranch(node, dir);
  2425. if ((process.env.NODE_ENV !== 'production') && comments.length) {
  2426. branch.children = [...comments, ...branch.children];
  2427. }
  2428. // check if user is forcing same key on different branches
  2429. if ((process.env.NODE_ENV !== 'production') || !true) {
  2430. const key = branch.userKey;
  2431. if (key) {
  2432. sibling.branches.forEach(({ userKey }) => {
  2433. if (isSameKey(userKey, key)) {
  2434. context.onError(createCompilerError(28 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  2435. }
  2436. });
  2437. }
  2438. }
  2439. sibling.branches.push(branch);
  2440. const onExit = processCodegen && processCodegen(sibling, branch, false);
  2441. // since the branch was removed, it will not be traversed.
  2442. // make sure to traverse here.
  2443. traverseNode(branch, context);
  2444. // call on exit
  2445. if (onExit)
  2446. onExit();
  2447. // make sure to reset currentNode after traversal to indicate this
  2448. // node has been removed.
  2449. context.currentNode = null;
  2450. }
  2451. else {
  2452. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  2453. }
  2454. break;
  2455. }
  2456. }
  2457. }
  2458. function createIfBranch(node, dir) {
  2459. return {
  2460. type: 10 /* IF_BRANCH */,
  2461. loc: node.loc,
  2462. condition: dir.name === 'else' ? undefined : dir.exp,
  2463. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  2464. ? node.children
  2465. : [node],
  2466. userKey: findProp(node, `key`)
  2467. };
  2468. }
  2469. function createCodegenNodeForBranch(branch, keyIndex, context) {
  2470. if (branch.condition) {
  2471. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  2472. // make sure to pass in asBlock: true so that the comment node call
  2473. // closes the current block.
  2474. createCallExpression(context.helper(CREATE_COMMENT), [
  2475. (process.env.NODE_ENV !== 'production') ? '"v-if"' : '""',
  2476. 'true'
  2477. ]));
  2478. }
  2479. else {
  2480. return createChildrenCodegenNode(branch, keyIndex, context);
  2481. }
  2482. }
  2483. function createChildrenCodegenNode(branch, keyIndex, context) {
  2484. const { helper } = context;
  2485. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  2486. const { children } = branch;
  2487. const firstChild = children[0];
  2488. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  2489. if (needFragmentWrapper) {
  2490. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  2491. // optimize away nested fragments when child is a ForNode
  2492. const vnodeCall = firstChild.codegenNode;
  2493. injectProp(vnodeCall, keyProperty, context);
  2494. return vnodeCall;
  2495. }
  2496. else {
  2497. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, 64 /* STABLE_FRAGMENT */ +
  2498. ((process.env.NODE_ENV !== 'production')
  2499. ? ` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  2500. : ``), undefined, undefined, true, false, branch.loc);
  2501. }
  2502. }
  2503. else {
  2504. const vnodeCall = firstChild
  2505. .codegenNode;
  2506. // Change createVNode to createBlock.
  2507. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  2508. vnodeCall.isBlock = true;
  2509. helper(OPEN_BLOCK);
  2510. helper(CREATE_BLOCK);
  2511. }
  2512. // inject branch key
  2513. injectProp(vnodeCall, keyProperty, context);
  2514. return vnodeCall;
  2515. }
  2516. }
  2517. function isSameKey(a, b) {
  2518. if (!a || a.type !== b.type) {
  2519. return false;
  2520. }
  2521. if (a.type === 6 /* ATTRIBUTE */) {
  2522. if (a.value.content !== b.value.content) {
  2523. return false;
  2524. }
  2525. }
  2526. else {
  2527. // directive
  2528. const exp = a.exp;
  2529. const branchExp = b.exp;
  2530. if (exp.type !== branchExp.type) {
  2531. return false;
  2532. }
  2533. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  2534. (exp.isStatic !== branchExp.isStatic ||
  2535. exp.content !== branchExp.content)) {
  2536. return false;
  2537. }
  2538. }
  2539. return true;
  2540. }
  2541. function getParentCondition(node) {
  2542. while (true) {
  2543. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  2544. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  2545. node = node.alternate;
  2546. }
  2547. else {
  2548. return node;
  2549. }
  2550. }
  2551. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  2552. node = node.value;
  2553. }
  2554. }
  2555. }
  2556. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  2557. const { helper } = context;
  2558. return processFor(node, dir, context, forNode => {
  2559. // create the loop render function expression now, and add the
  2560. // iterator on exit after all children have been traversed
  2561. const renderExp = createCallExpression(helper(RENDER_LIST), [
  2562. forNode.source
  2563. ]);
  2564. const keyProp = findProp(node, `key`);
  2565. const keyProperty = keyProp
  2566. ? createObjectProperty(`key`, keyProp.type === 6 /* ATTRIBUTE */
  2567. ? createSimpleExpression(keyProp.value.content, true)
  2568. : keyProp.exp)
  2569. : null;
  2570. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  2571. forNode.source.constType > 0 /* NOT_CONSTANT */;
  2572. const fragmentFlag = isStableFragment
  2573. ? 64 /* STABLE_FRAGMENT */
  2574. : keyProp
  2575. ? 128 /* KEYED_FRAGMENT */
  2576. : 256 /* UNKEYED_FRAGMENT */;
  2577. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  2578. ((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, node.loc);
  2579. return () => {
  2580. // finish the codegen now that all children have been traversed
  2581. let childBlock;
  2582. const isTemplate = isTemplateNode(node);
  2583. const { children } = forNode;
  2584. // check <template v-for> key placement
  2585. if (((process.env.NODE_ENV !== 'production') || !true) && isTemplate) {
  2586. node.children.some(c => {
  2587. if (c.type === 1 /* ELEMENT */) {
  2588. const key = findProp(c, 'key');
  2589. if (key) {
  2590. context.onError(createCompilerError(32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  2591. return true;
  2592. }
  2593. }
  2594. });
  2595. }
  2596. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  2597. const slotOutlet = isSlotOutlet(node)
  2598. ? node
  2599. : isTemplate &&
  2600. node.children.length === 1 &&
  2601. isSlotOutlet(node.children[0])
  2602. ? node.children[0] // api-extractor somehow fails to infer this
  2603. : null;
  2604. if (slotOutlet) {
  2605. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  2606. childBlock = slotOutlet.codegenNode;
  2607. if (isTemplate && keyProperty) {
  2608. // <template v-for="..." :key="..."><slot/></template>
  2609. // we need to inject the key to the renderSlot() call.
  2610. // the props for renderSlot is passed as the 3rd argument.
  2611. injectProp(childBlock, keyProperty, context);
  2612. }
  2613. }
  2614. else if (needFragmentWrapper) {
  2615. // <template v-for="..."> with text or multi-elements
  2616. // should generate a fragment block for each loop
  2617. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  2618. ((process.env.NODE_ENV !== 'production')
  2619. ? ` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  2620. : ``), undefined, undefined, true);
  2621. }
  2622. else {
  2623. // Normal element v-for. Directly use the child's codegenNode
  2624. // but mark it as a block.
  2625. childBlock = children[0]
  2626. .codegenNode;
  2627. if (isTemplate && keyProperty) {
  2628. injectProp(childBlock, keyProperty, context);
  2629. }
  2630. childBlock.isBlock = !isStableFragment;
  2631. if (childBlock.isBlock) {
  2632. helper(OPEN_BLOCK);
  2633. helper(CREATE_BLOCK);
  2634. }
  2635. else {
  2636. helper(CREATE_VNODE);
  2637. }
  2638. }
  2639. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  2640. };
  2641. });
  2642. });
  2643. // target-agnostic transform used for both Client and SSR
  2644. function processFor(node, dir, context, processCodegen) {
  2645. if (!dir.exp) {
  2646. context.onError(createCompilerError(30 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  2647. return;
  2648. }
  2649. const parseResult = parseForExpression(
  2650. // can only be simple expression because vFor transform is applied
  2651. // before expression transform.
  2652. dir.exp, context);
  2653. if (!parseResult) {
  2654. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  2655. return;
  2656. }
  2657. const { addIdentifiers, removeIdentifiers, scopes } = context;
  2658. const { source, value, key, index } = parseResult;
  2659. const forNode = {
  2660. type: 11 /* FOR */,
  2661. loc: dir.loc,
  2662. source,
  2663. valueAlias: value,
  2664. keyAlias: key,
  2665. objectIndexAlias: index,
  2666. parseResult,
  2667. children: isTemplateNode(node) ? node.children : [node]
  2668. };
  2669. context.replaceNode(forNode);
  2670. // bookkeeping
  2671. scopes.vFor++;
  2672. const onExit = processCodegen && processCodegen(forNode);
  2673. return () => {
  2674. scopes.vFor--;
  2675. if (onExit)
  2676. onExit();
  2677. };
  2678. }
  2679. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  2680. // This regex doesn't cover the case if key or index aliases have destructuring,
  2681. // but those do not make sense in the first place, so this works in practice.
  2682. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  2683. const stripParensRE = /^\(|\)$/g;
  2684. function parseForExpression(input, context) {
  2685. const loc = input.loc;
  2686. const exp = input.content;
  2687. const inMatch = exp.match(forAliasRE);
  2688. if (!inMatch)
  2689. return;
  2690. const [, LHS, RHS] = inMatch;
  2691. const result = {
  2692. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  2693. value: undefined,
  2694. key: undefined,
  2695. index: undefined
  2696. };
  2697. if ((process.env.NODE_ENV !== 'production') && true) {
  2698. validateBrowserExpression(result.source, context);
  2699. }
  2700. let valueContent = LHS.trim()
  2701. .replace(stripParensRE, '')
  2702. .trim();
  2703. const trimmedOffset = LHS.indexOf(valueContent);
  2704. const iteratorMatch = valueContent.match(forIteratorRE);
  2705. if (iteratorMatch) {
  2706. valueContent = valueContent.replace(forIteratorRE, '').trim();
  2707. const keyContent = iteratorMatch[1].trim();
  2708. let keyOffset;
  2709. if (keyContent) {
  2710. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  2711. result.key = createAliasExpression(loc, keyContent, keyOffset);
  2712. if ((process.env.NODE_ENV !== 'production') && true) {
  2713. validateBrowserExpression(result.key, context, true);
  2714. }
  2715. }
  2716. if (iteratorMatch[2]) {
  2717. const indexContent = iteratorMatch[2].trim();
  2718. if (indexContent) {
  2719. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  2720. ? keyOffset + keyContent.length
  2721. : trimmedOffset + valueContent.length));
  2722. if ((process.env.NODE_ENV !== 'production') && true) {
  2723. validateBrowserExpression(result.index, context, true);
  2724. }
  2725. }
  2726. }
  2727. }
  2728. if (valueContent) {
  2729. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  2730. if ((process.env.NODE_ENV !== 'production') && true) {
  2731. validateBrowserExpression(result.value, context, true);
  2732. }
  2733. }
  2734. return result;
  2735. }
  2736. function createAliasExpression(range, content, offset) {
  2737. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  2738. }
  2739. function createForLoopParams({ value, key, index }) {
  2740. const params = [];
  2741. if (value) {
  2742. params.push(value);
  2743. }
  2744. if (key) {
  2745. if (!value) {
  2746. params.push(createSimpleExpression(`_`, false));
  2747. }
  2748. params.push(key);
  2749. }
  2750. if (index) {
  2751. if (!key) {
  2752. if (!value) {
  2753. params.push(createSimpleExpression(`_`, false));
  2754. }
  2755. params.push(createSimpleExpression(`__`, false));
  2756. }
  2757. params.push(index);
  2758. }
  2759. return params;
  2760. }
  2761. const defaultFallback = createSimpleExpression(`undefined`, false);
  2762. // A NodeTransform that:
  2763. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  2764. // by transformExpression. This is only applied in non-browser builds with
  2765. // { prefixIdentifiers: true }.
  2766. // 2. Track v-slot depths so that we know a slot is inside another slot.
  2767. // Note the exit callback is executed before buildSlots() on the same node,
  2768. // so only nested slots see positive numbers.
  2769. const trackSlotScopes = (node, context) => {
  2770. if (node.type === 1 /* ELEMENT */ &&
  2771. (node.tagType === 1 /* COMPONENT */ ||
  2772. node.tagType === 3 /* TEMPLATE */)) {
  2773. // We are only checking non-empty v-slot here
  2774. // since we only care about slots that introduce scope variables.
  2775. const vSlot = findDir(node, 'slot');
  2776. if (vSlot) {
  2777. vSlot.exp;
  2778. context.scopes.vSlot++;
  2779. return () => {
  2780. context.scopes.vSlot--;
  2781. };
  2782. }
  2783. }
  2784. };
  2785. // A NodeTransform that tracks scope identifiers for scoped slots with v-for.
  2786. // This transform is only applied in non-browser builds with { prefixIdentifiers: true }
  2787. const trackVForSlotScopes = (node, context) => {
  2788. let vFor;
  2789. if (isTemplateNode(node) &&
  2790. node.props.some(isVSlot) &&
  2791. (vFor = findDir(node, 'for'))) {
  2792. const result = (vFor.parseResult = parseForExpression(vFor.exp, context));
  2793. if (result) {
  2794. const { value, key, index } = result;
  2795. const { addIdentifiers, removeIdentifiers } = context;
  2796. value && addIdentifiers(value);
  2797. key && addIdentifiers(key);
  2798. index && addIdentifiers(index);
  2799. return () => {
  2800. value && removeIdentifiers(value);
  2801. key && removeIdentifiers(key);
  2802. index && removeIdentifiers(index);
  2803. };
  2804. }
  2805. }
  2806. };
  2807. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  2808. // Instead of being a DirectiveTransform, v-slot processing is called during
  2809. // transformElement to build the slots object for a component.
  2810. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  2811. context.helper(WITH_CTX);
  2812. const { children, loc } = node;
  2813. const slotsProperties = [];
  2814. const dynamicSlots = [];
  2815. const buildDefaultSlotProperty = (props, children) => createObjectProperty(`default`, buildSlotFn(props, children, loc));
  2816. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  2817. // since it likely uses a scope variable.
  2818. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  2819. // 1. Check for slot with slotProps on component itself.
  2820. // <Comp v-slot="{ prop }"/>
  2821. const onComponentSlot = findDir(node, 'slot', true);
  2822. if (onComponentSlot) {
  2823. const { arg, exp } = onComponentSlot;
  2824. if (arg && !isStaticExp(arg)) {
  2825. hasDynamicSlots = true;
  2826. }
  2827. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  2828. }
  2829. // 2. Iterate through children and check for template slots
  2830. // <template v-slot:foo="{ prop }">
  2831. let hasTemplateSlots = false;
  2832. let hasNamedDefaultSlot = false;
  2833. const implicitDefaultChildren = [];
  2834. const seenSlotNames = new Set();
  2835. for (let i = 0; i < children.length; i++) {
  2836. const slotElement = children[i];
  2837. let slotDir;
  2838. if (!isTemplateNode(slotElement) ||
  2839. !(slotDir = findDir(slotElement, 'slot', true))) {
  2840. // not a <template v-slot>, skip.
  2841. if (slotElement.type !== 3 /* COMMENT */) {
  2842. implicitDefaultChildren.push(slotElement);
  2843. }
  2844. continue;
  2845. }
  2846. if (onComponentSlot) {
  2847. // already has on-component slot - this is incorrect usage.
  2848. context.onError(createCompilerError(36 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  2849. break;
  2850. }
  2851. hasTemplateSlots = true;
  2852. const { children: slotChildren, loc: slotLoc } = slotElement;
  2853. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  2854. // check if name is dynamic.
  2855. let staticSlotName;
  2856. if (isStaticExp(slotName)) {
  2857. staticSlotName = slotName ? slotName.content : `default`;
  2858. }
  2859. else {
  2860. hasDynamicSlots = true;
  2861. }
  2862. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  2863. // check if this slot is conditional (v-if/v-for)
  2864. let vIf;
  2865. let vElse;
  2866. let vFor;
  2867. if ((vIf = findDir(slotElement, 'if'))) {
  2868. hasDynamicSlots = true;
  2869. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  2870. }
  2871. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  2872. // find adjacent v-if
  2873. let j = i;
  2874. let prev;
  2875. while (j--) {
  2876. prev = children[j];
  2877. if (prev.type !== 3 /* COMMENT */) {
  2878. break;
  2879. }
  2880. }
  2881. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  2882. // remove node
  2883. children.splice(i, 1);
  2884. i--;
  2885. // attach this slot to previous conditional
  2886. let conditional = dynamicSlots[dynamicSlots.length - 1];
  2887. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  2888. conditional = conditional.alternate;
  2889. }
  2890. conditional.alternate = vElse.exp
  2891. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  2892. : buildDynamicSlot(slotName, slotFunction);
  2893. }
  2894. else {
  2895. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  2896. }
  2897. }
  2898. else if ((vFor = findDir(slotElement, 'for'))) {
  2899. hasDynamicSlots = true;
  2900. const parseResult = vFor.parseResult ||
  2901. parseForExpression(vFor.exp, context);
  2902. if (parseResult) {
  2903. // Render the dynamic slots as an array and add it to the createSlot()
  2904. // args. The runtime knows how to handle it appropriately.
  2905. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  2906. parseResult.source,
  2907. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  2908. ]));
  2909. }
  2910. else {
  2911. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  2912. }
  2913. }
  2914. else {
  2915. // check duplicate static names
  2916. if (staticSlotName) {
  2917. if (seenSlotNames.has(staticSlotName)) {
  2918. context.onError(createCompilerError(37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  2919. continue;
  2920. }
  2921. seenSlotNames.add(staticSlotName);
  2922. if (staticSlotName === 'default') {
  2923. hasNamedDefaultSlot = true;
  2924. }
  2925. }
  2926. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  2927. }
  2928. }
  2929. if (!onComponentSlot) {
  2930. if (!hasTemplateSlots) {
  2931. // implicit default slot (on component)
  2932. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  2933. }
  2934. else if (implicitDefaultChildren.length) {
  2935. // implicit default slot (mixed with named slots)
  2936. if (hasNamedDefaultSlot) {
  2937. context.onError(createCompilerError(38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  2938. }
  2939. else {
  2940. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  2941. }
  2942. }
  2943. }
  2944. const slotFlag = hasDynamicSlots
  2945. ? 2 /* DYNAMIC */
  2946. : hasForwardedSlots(node.children)
  2947. ? 3 /* FORWARDED */
  2948. : 1 /* STABLE */;
  2949. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  2950. // 2 = compiled but dynamic = can skip normalization, but must run diff
  2951. // 1 = compiled and static = can skip normalization AND diff as optimized
  2952. createSimpleExpression(slotFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${slotFlagsText[slotFlag]} */` : ``), false))), loc);
  2953. if (dynamicSlots.length) {
  2954. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  2955. slots,
  2956. createArrayExpression(dynamicSlots)
  2957. ]);
  2958. }
  2959. return {
  2960. slots,
  2961. hasDynamicSlots
  2962. };
  2963. }
  2964. function buildDynamicSlot(name, fn) {
  2965. return createObjectExpression([
  2966. createObjectProperty(`name`, name),
  2967. createObjectProperty(`fn`, fn)
  2968. ]);
  2969. }
  2970. function hasForwardedSlots(children) {
  2971. for (let i = 0; i < children.length; i++) {
  2972. const child = children[i];
  2973. if (child.type === 1 /* ELEMENT */) {
  2974. if (child.tagType === 2 /* SLOT */ ||
  2975. (child.tagType === 0 /* ELEMENT */ &&
  2976. hasForwardedSlots(child.children))) {
  2977. return true;
  2978. }
  2979. }
  2980. }
  2981. return false;
  2982. }
  2983. // some directive transforms (e.g. v-model) may return a symbol for runtime
  2984. // import, which should be used instead of a resolveDirective call.
  2985. const directiveImportMap = new WeakMap();
  2986. // generate a JavaScript AST for this element's codegen
  2987. const transformElement = (node, context) => {
  2988. if (!(node.type === 1 /* ELEMENT */ &&
  2989. (node.tagType === 0 /* ELEMENT */ ||
  2990. node.tagType === 1 /* COMPONENT */))) {
  2991. return;
  2992. }
  2993. // perform the work on exit, after all child expressions have been
  2994. // processed and merged.
  2995. return function postTransformElement() {
  2996. const { tag, props } = node;
  2997. const isComponent = node.tagType === 1 /* COMPONENT */;
  2998. // The goal of the transform is to create a codegenNode implementing the
  2999. // VNodeCall interface.
  3000. const vnodeTag = isComponent
  3001. ? resolveComponentType(node, context)
  3002. : `"${tag}"`;
  3003. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  3004. let vnodeProps;
  3005. let vnodeChildren;
  3006. let vnodePatchFlag;
  3007. let patchFlag = 0;
  3008. let vnodeDynamicProps;
  3009. let dynamicPropNames;
  3010. let vnodeDirectives;
  3011. let shouldUseBlock =
  3012. // dynamic component may resolve to plain elements
  3013. isDynamicComponent ||
  3014. vnodeTag === TELEPORT ||
  3015. vnodeTag === SUSPENSE ||
  3016. (!isComponent &&
  3017. // <svg> and <foreignObject> must be forced into blocks so that block
  3018. // updates inside get proper isSVG flag at runtime. (#639, #643)
  3019. // This is technically web-specific, but splitting the logic out of core
  3020. // leads to too much unnecessary complexity.
  3021. (tag === 'svg' ||
  3022. tag === 'foreignObject' ||
  3023. // #938: elements with dynamic keys should be forced into blocks
  3024. findProp(node, 'key', true)));
  3025. // props
  3026. if (props.length > 0) {
  3027. const propsBuildResult = buildProps(node, context);
  3028. vnodeProps = propsBuildResult.props;
  3029. patchFlag = propsBuildResult.patchFlag;
  3030. dynamicPropNames = propsBuildResult.dynamicPropNames;
  3031. const directives = propsBuildResult.directives;
  3032. vnodeDirectives =
  3033. directives && directives.length
  3034. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  3035. : undefined;
  3036. }
  3037. // children
  3038. if (node.children.length > 0) {
  3039. if (vnodeTag === KEEP_ALIVE) {
  3040. // Although a built-in component, we compile KeepAlive with raw children
  3041. // instead of slot functions so that it can be used inside Transition
  3042. // or other Transition-wrapping HOCs.
  3043. // To ensure correct updates with block optimizations, we need to:
  3044. // 1. Force keep-alive into a block. This avoids its children being
  3045. // collected by a parent block.
  3046. shouldUseBlock = true;
  3047. // 2. Force keep-alive to always be updated, since it uses raw children.
  3048. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  3049. if ((process.env.NODE_ENV !== 'production') && node.children.length > 1) {
  3050. context.onError(createCompilerError(44 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  3051. start: node.children[0].loc.start,
  3052. end: node.children[node.children.length - 1].loc.end,
  3053. source: ''
  3054. }));
  3055. }
  3056. }
  3057. const shouldBuildAsSlots = isComponent &&
  3058. // Teleport is not a real component and has dedicated runtime handling
  3059. vnodeTag !== TELEPORT &&
  3060. // explained above.
  3061. vnodeTag !== KEEP_ALIVE;
  3062. if (shouldBuildAsSlots) {
  3063. const { slots, hasDynamicSlots } = buildSlots(node, context);
  3064. vnodeChildren = slots;
  3065. if (hasDynamicSlots) {
  3066. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  3067. }
  3068. }
  3069. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  3070. const child = node.children[0];
  3071. const type = child.type;
  3072. // check for dynamic text children
  3073. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  3074. type === 8 /* COMPOUND_EXPRESSION */;
  3075. if (hasDynamicTextChild &&
  3076. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  3077. patchFlag |= 1 /* TEXT */;
  3078. }
  3079. // pass directly if the only child is a text node
  3080. // (plain / interpolation / expression)
  3081. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  3082. vnodeChildren = child;
  3083. }
  3084. else {
  3085. vnodeChildren = node.children;
  3086. }
  3087. }
  3088. else {
  3089. vnodeChildren = node.children;
  3090. }
  3091. }
  3092. // patchFlag & dynamicPropNames
  3093. if (patchFlag !== 0) {
  3094. if ((process.env.NODE_ENV !== 'production')) {
  3095. if (patchFlag < 0) {
  3096. // special flags (negative and mutually exclusive)
  3097. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3098. }
  3099. else {
  3100. // bitwise flags
  3101. const flagNames = Object.keys(PatchFlagNames)
  3102. .map(Number)
  3103. .filter(n => n > 0 && patchFlag & n)
  3104. .map(n => PatchFlagNames[n])
  3105. .join(`, `);
  3106. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  3107. }
  3108. }
  3109. else {
  3110. vnodePatchFlag = String(patchFlag);
  3111. }
  3112. if (dynamicPropNames && dynamicPropNames.length) {
  3113. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  3114. }
  3115. }
  3116. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, node.loc);
  3117. };
  3118. };
  3119. function resolveComponentType(node, context, ssr = false) {
  3120. const { tag } = node;
  3121. // 1. dynamic component
  3122. const isProp = node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is');
  3123. if (isProp) {
  3124. const exp = isProp.type === 6 /* ATTRIBUTE */
  3125. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  3126. : isProp.exp;
  3127. if (exp) {
  3128. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3129. exp
  3130. ]);
  3131. }
  3132. }
  3133. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  3134. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  3135. if (builtIn) {
  3136. // built-ins are simply fallthroughs / have special handling during ssr
  3137. // so we don't need to import their runtime equivalents
  3138. if (!ssr)
  3139. context.helper(builtIn);
  3140. return builtIn;
  3141. }
  3142. // 5. user component (resolve)
  3143. context.helper(RESOLVE_COMPONENT);
  3144. context.components.add(tag);
  3145. return toValidAssetId(tag, `component`);
  3146. }
  3147. function buildProps(node, context, props = node.props, ssr = false) {
  3148. const { tag, loc: elementLoc } = node;
  3149. const isComponent = node.tagType === 1 /* COMPONENT */;
  3150. let properties = [];
  3151. const mergeArgs = [];
  3152. const runtimeDirectives = [];
  3153. // patchFlag analysis
  3154. let patchFlag = 0;
  3155. let hasRef = false;
  3156. let hasClassBinding = false;
  3157. let hasStyleBinding = false;
  3158. let hasHydrationEventBinding = false;
  3159. let hasDynamicKeys = false;
  3160. let hasVnodeHook = false;
  3161. const dynamicPropNames = [];
  3162. const analyzePatchFlag = ({ key, value }) => {
  3163. if (isStaticExp(key)) {
  3164. const name = key.content;
  3165. const isEventHandler = isOn(name);
  3166. if (!isComponent &&
  3167. isEventHandler &&
  3168. // omit the flag for click handlers because hydration gives click
  3169. // dedicated fast path.
  3170. name.toLowerCase() !== 'onclick' &&
  3171. // omit v-model handlers
  3172. name !== 'onUpdate:modelValue' &&
  3173. // omit onVnodeXXX hooks
  3174. !isReservedProp(name)) {
  3175. hasHydrationEventBinding = true;
  3176. }
  3177. if (isEventHandler && isReservedProp(name)) {
  3178. hasVnodeHook = true;
  3179. }
  3180. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  3181. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  3182. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  3183. getConstantType(value, context) > 0)) {
  3184. // skip if the prop is a cached handler or has constant value
  3185. return;
  3186. }
  3187. if (name === 'ref') {
  3188. hasRef = true;
  3189. }
  3190. else if (name === 'class' && !isComponent) {
  3191. hasClassBinding = true;
  3192. }
  3193. else if (name === 'style' && !isComponent) {
  3194. hasStyleBinding = true;
  3195. }
  3196. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  3197. dynamicPropNames.push(name);
  3198. }
  3199. }
  3200. else {
  3201. hasDynamicKeys = true;
  3202. }
  3203. };
  3204. for (let i = 0; i < props.length; i++) {
  3205. // static attribute
  3206. const prop = props[i];
  3207. if (prop.type === 6 /* ATTRIBUTE */) {
  3208. const { loc, name, value } = prop;
  3209. let isStatic = true;
  3210. if (name === 'ref') {
  3211. hasRef = true;
  3212. }
  3213. // skip :is on <component>
  3214. if (name === 'is' && tag === 'component') {
  3215. continue;
  3216. }
  3217. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  3218. }
  3219. else {
  3220. // directives
  3221. const { name, arg, exp, loc } = prop;
  3222. const isBind = name === 'bind';
  3223. const isOn = name === 'on';
  3224. // skip v-slot - it is handled by its dedicated transform.
  3225. if (name === 'slot') {
  3226. if (!isComponent) {
  3227. context.onError(createCompilerError(39 /* X_V_SLOT_MISPLACED */, loc));
  3228. }
  3229. continue;
  3230. }
  3231. // skip v-once - it is handled by its dedicated transform.
  3232. if (name === 'once') {
  3233. continue;
  3234. }
  3235. // skip v-is and :is on <component>
  3236. if (name === 'is' ||
  3237. (isBind && tag === 'component' && isBindKey(arg, 'is'))) {
  3238. continue;
  3239. }
  3240. // skip v-on in SSR compilation
  3241. if (isOn && ssr) {
  3242. continue;
  3243. }
  3244. // special case for v-bind and v-on with no argument
  3245. if (!arg && (isBind || isOn)) {
  3246. hasDynamicKeys = true;
  3247. if (exp) {
  3248. if (properties.length) {
  3249. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  3250. properties = [];
  3251. }
  3252. if (isBind) {
  3253. mergeArgs.push(exp);
  3254. }
  3255. else {
  3256. // v-on="obj" -> toHandlers(obj)
  3257. mergeArgs.push({
  3258. type: 14 /* JS_CALL_EXPRESSION */,
  3259. loc,
  3260. callee: context.helper(TO_HANDLERS),
  3261. arguments: [exp]
  3262. });
  3263. }
  3264. }
  3265. else {
  3266. context.onError(createCompilerError(isBind
  3267. ? 33 /* X_V_BIND_NO_EXPRESSION */
  3268. : 34 /* X_V_ON_NO_EXPRESSION */, loc));
  3269. }
  3270. continue;
  3271. }
  3272. const directiveTransform = context.directiveTransforms[name];
  3273. if (directiveTransform) {
  3274. // has built-in directive transform.
  3275. const { props, needRuntime } = directiveTransform(prop, node, context);
  3276. !ssr && props.forEach(analyzePatchFlag);
  3277. properties.push(...props);
  3278. if (needRuntime) {
  3279. runtimeDirectives.push(prop);
  3280. if (isSymbol(needRuntime)) {
  3281. directiveImportMap.set(prop, needRuntime);
  3282. }
  3283. }
  3284. }
  3285. else {
  3286. // no built-in transform, this is a user custom directive.
  3287. runtimeDirectives.push(prop);
  3288. }
  3289. }
  3290. }
  3291. let propsExpression = undefined;
  3292. // has v-bind="object" or v-on="object", wrap with mergeProps
  3293. if (mergeArgs.length) {
  3294. if (properties.length) {
  3295. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  3296. }
  3297. if (mergeArgs.length > 1) {
  3298. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  3299. }
  3300. else {
  3301. // single v-bind with nothing else - no need for a mergeProps call
  3302. propsExpression = mergeArgs[0];
  3303. }
  3304. }
  3305. else if (properties.length) {
  3306. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  3307. }
  3308. // patchFlag analysis
  3309. if (hasDynamicKeys) {
  3310. patchFlag |= 16 /* FULL_PROPS */;
  3311. }
  3312. else {
  3313. if (hasClassBinding) {
  3314. patchFlag |= 2 /* CLASS */;
  3315. }
  3316. if (hasStyleBinding) {
  3317. patchFlag |= 4 /* STYLE */;
  3318. }
  3319. if (dynamicPropNames.length) {
  3320. patchFlag |= 8 /* PROPS */;
  3321. }
  3322. if (hasHydrationEventBinding) {
  3323. patchFlag |= 32 /* HYDRATE_EVENTS */;
  3324. }
  3325. }
  3326. if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  3327. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  3328. patchFlag |= 512 /* NEED_PATCH */;
  3329. }
  3330. return {
  3331. props: propsExpression,
  3332. directives: runtimeDirectives,
  3333. patchFlag,
  3334. dynamicPropNames
  3335. };
  3336. }
  3337. // Dedupe props in an object literal.
  3338. // Literal duplicated attributes would have been warned during the parse phase,
  3339. // however, it's possible to encounter duplicated `onXXX` handlers with different
  3340. // modifiers. We also need to merge static and dynamic class / style attributes.
  3341. // - onXXX handlers / style: merge into array
  3342. // - class: merge into single expression with concatenation
  3343. function dedupeProperties(properties) {
  3344. const knownProps = new Map();
  3345. const deduped = [];
  3346. for (let i = 0; i < properties.length; i++) {
  3347. const prop = properties[i];
  3348. // dynamic keys are always allowed
  3349. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  3350. deduped.push(prop);
  3351. continue;
  3352. }
  3353. const name = prop.key.content;
  3354. const existing = knownProps.get(name);
  3355. if (existing) {
  3356. if (name === 'style' || name === 'class' || name.startsWith('on')) {
  3357. mergeAsArray(existing, prop);
  3358. }
  3359. // unexpected duplicate, should have emitted error during parse
  3360. }
  3361. else {
  3362. knownProps.set(name, prop);
  3363. deduped.push(prop);
  3364. }
  3365. }
  3366. return deduped;
  3367. }
  3368. function mergeAsArray(existing, incoming) {
  3369. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  3370. existing.value.elements.push(incoming.value);
  3371. }
  3372. else {
  3373. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  3374. }
  3375. }
  3376. function buildDirectiveArgs(dir, context) {
  3377. const dirArgs = [];
  3378. const runtime = directiveImportMap.get(dir);
  3379. if (runtime) {
  3380. // built-in directive with runtime
  3381. dirArgs.push(context.helperString(runtime));
  3382. }
  3383. else {
  3384. {
  3385. // inject statement for resolving directive
  3386. context.helper(RESOLVE_DIRECTIVE);
  3387. context.directives.add(dir.name);
  3388. dirArgs.push(toValidAssetId(dir.name, `directive`));
  3389. }
  3390. }
  3391. const { loc } = dir;
  3392. if (dir.exp)
  3393. dirArgs.push(dir.exp);
  3394. if (dir.arg) {
  3395. if (!dir.exp) {
  3396. dirArgs.push(`void 0`);
  3397. }
  3398. dirArgs.push(dir.arg);
  3399. }
  3400. if (Object.keys(dir.modifiers).length) {
  3401. if (!dir.arg) {
  3402. if (!dir.exp) {
  3403. dirArgs.push(`void 0`);
  3404. }
  3405. dirArgs.push(`void 0`);
  3406. }
  3407. const trueExpression = createSimpleExpression(`true`, false, loc);
  3408. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  3409. }
  3410. return createArrayExpression(dirArgs, dir.loc);
  3411. }
  3412. function stringifyDynamicPropNames(props) {
  3413. let propsNamesString = `[`;
  3414. for (let i = 0, l = props.length; i < l; i++) {
  3415. propsNamesString += JSON.stringify(props[i]);
  3416. if (i < l - 1)
  3417. propsNamesString += ', ';
  3418. }
  3419. return propsNamesString + `]`;
  3420. }
  3421. (process.env.NODE_ENV !== 'production')
  3422. ? Object.freeze({})
  3423. : {};
  3424. (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
  3425. const cacheStringFunction = (fn) => {
  3426. const cache = Object.create(null);
  3427. return ((str) => {
  3428. const hit = cache[str];
  3429. return hit || (cache[str] = fn(str));
  3430. });
  3431. };
  3432. const camelizeRE = /-(\w)/g;
  3433. /**
  3434. * @private
  3435. */
  3436. const camelize = cacheStringFunction((str) => {
  3437. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  3438. });
  3439. const transformSlotOutlet = (node, context) => {
  3440. if (isSlotOutlet(node)) {
  3441. const { children, loc } = node;
  3442. const { slotName, slotProps } = processSlotOutlet(node, context);
  3443. const slotArgs = [
  3444. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  3445. slotName
  3446. ];
  3447. if (slotProps) {
  3448. slotArgs.push(slotProps);
  3449. }
  3450. if (children.length) {
  3451. if (!slotProps) {
  3452. slotArgs.push(`{}`);
  3453. }
  3454. slotArgs.push(createFunctionExpression([], children, false, false, loc));
  3455. }
  3456. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  3457. }
  3458. };
  3459. function processSlotOutlet(node, context) {
  3460. let slotName = `"default"`;
  3461. let slotProps = undefined;
  3462. const nonNameProps = [];
  3463. for (let i = 0; i < node.props.length; i++) {
  3464. const p = node.props[i];
  3465. if (p.type === 6 /* ATTRIBUTE */) {
  3466. if (p.value) {
  3467. if (p.name === 'name') {
  3468. slotName = JSON.stringify(p.value.content);
  3469. }
  3470. else {
  3471. p.name = camelize(p.name);
  3472. nonNameProps.push(p);
  3473. }
  3474. }
  3475. }
  3476. else {
  3477. if (p.name === 'bind' && isBindKey(p.arg, 'name')) {
  3478. if (p.exp)
  3479. slotName = p.exp;
  3480. }
  3481. else {
  3482. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  3483. p.arg.content = camelize(p.arg.content);
  3484. }
  3485. nonNameProps.push(p);
  3486. }
  3487. }
  3488. }
  3489. if (nonNameProps.length > 0) {
  3490. const { props, directives } = buildProps(node, context, nonNameProps);
  3491. slotProps = props;
  3492. if (directives.length) {
  3493. context.onError(createCompilerError(35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  3494. }
  3495. }
  3496. return {
  3497. slotName,
  3498. slotProps
  3499. };
  3500. }
  3501. const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
  3502. const transformOn = (dir, node, context, augmentor) => {
  3503. const { loc, modifiers, arg } = dir;
  3504. if (!dir.exp && !modifiers.length) {
  3505. context.onError(createCompilerError(34 /* X_V_ON_NO_EXPRESSION */, loc));
  3506. }
  3507. let eventName;
  3508. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  3509. if (arg.isStatic) {
  3510. const rawName = arg.content;
  3511. // for all event listeners, auto convert it to camelCase. See issue #2249
  3512. eventName = createSimpleExpression(toHandlerKey(camelize$1(rawName)), true, arg.loc);
  3513. }
  3514. else {
  3515. // #2388
  3516. eventName = createCompoundExpression([
  3517. `${context.helperString(TO_HANDLER_KEY)}(`,
  3518. arg,
  3519. `)`
  3520. ]);
  3521. }
  3522. }
  3523. else {
  3524. // already a compound expression.
  3525. eventName = arg;
  3526. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  3527. eventName.children.push(`)`);
  3528. }
  3529. // handler processing
  3530. let exp = dir.exp;
  3531. if (exp && !exp.content.trim()) {
  3532. exp = undefined;
  3533. }
  3534. let shouldCache = context.cacheHandlers && !exp;
  3535. if (exp) {
  3536. const isMemberExp = isMemberExpression(exp.content);
  3537. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  3538. const hasMultipleStatements = exp.content.includes(`;`);
  3539. if ((process.env.NODE_ENV !== 'production') && true) {
  3540. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  3541. }
  3542. if (isInlineStatement || (shouldCache && isMemberExp)) {
  3543. // wrap inline statement in a function expression
  3544. exp = createCompoundExpression([
  3545. `${isInlineStatement
  3546. ? `$event`
  3547. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  3548. exp,
  3549. hasMultipleStatements ? `}` : `)`
  3550. ]);
  3551. }
  3552. }
  3553. let ret = {
  3554. props: [
  3555. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  3556. ]
  3557. };
  3558. // apply extended compiler augmentor
  3559. if (augmentor) {
  3560. ret = augmentor(ret);
  3561. }
  3562. if (shouldCache) {
  3563. // cache handlers so that it's always the same handler being passed down.
  3564. // this avoids unnecessary re-renders when users use inline handlers on
  3565. // components.
  3566. ret.props[0].value = context.cache(ret.props[0].value);
  3567. }
  3568. return ret;
  3569. };
  3570. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  3571. // codegen for the entire props object. This transform here is only for v-bind
  3572. // *with* args.
  3573. const transformBind = (dir, node, context) => {
  3574. const { exp, modifiers, loc } = dir;
  3575. const arg = dir.arg;
  3576. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  3577. arg.children.unshift(`(`);
  3578. arg.children.push(`) || ""`);
  3579. }
  3580. else if (!arg.isStatic) {
  3581. arg.content = `${arg.content} || ""`;
  3582. }
  3583. // .prop is no longer necessary due to new patch behavior
  3584. // .sync is replaced by v-model:arg
  3585. if (modifiers.includes('camel')) {
  3586. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  3587. if (arg.isStatic) {
  3588. arg.content = camelize$1(arg.content);
  3589. }
  3590. else {
  3591. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  3592. }
  3593. }
  3594. else {
  3595. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  3596. arg.children.push(`)`);
  3597. }
  3598. }
  3599. if (!exp ||
  3600. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  3601. context.onError(createCompilerError(33 /* X_V_BIND_NO_EXPRESSION */, loc));
  3602. return {
  3603. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  3604. };
  3605. }
  3606. return {
  3607. props: [createObjectProperty(arg, exp)]
  3608. };
  3609. };
  3610. // Merge adjacent text nodes and expressions into a single expression
  3611. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  3612. const transformText = (node, context) => {
  3613. if (node.type === 0 /* ROOT */ ||
  3614. node.type === 1 /* ELEMENT */ ||
  3615. node.type === 11 /* FOR */ ||
  3616. node.type === 10 /* IF_BRANCH */) {
  3617. // perform the transform on node exit so that all expressions have already
  3618. // been processed.
  3619. return () => {
  3620. const children = node.children;
  3621. let currentContainer = undefined;
  3622. let hasText = false;
  3623. for (let i = 0; i < children.length; i++) {
  3624. const child = children[i];
  3625. if (isText(child)) {
  3626. hasText = true;
  3627. for (let j = i + 1; j < children.length; j++) {
  3628. const next = children[j];
  3629. if (isText(next)) {
  3630. if (!currentContainer) {
  3631. currentContainer = children[i] = {
  3632. type: 8 /* COMPOUND_EXPRESSION */,
  3633. loc: child.loc,
  3634. children: [child]
  3635. };
  3636. }
  3637. // merge adjacent text node into current
  3638. currentContainer.children.push(` + `, next);
  3639. children.splice(j, 1);
  3640. j--;
  3641. }
  3642. else {
  3643. currentContainer = undefined;
  3644. break;
  3645. }
  3646. }
  3647. }
  3648. }
  3649. if (!hasText ||
  3650. // if this is a plain element with a single text child, leave it
  3651. // as-is since the runtime has dedicated fast path for this by directly
  3652. // setting textContent of the element.
  3653. // for component root it's always normalized anyway.
  3654. (children.length === 1 &&
  3655. (node.type === 0 /* ROOT */ ||
  3656. (node.type === 1 /* ELEMENT */ &&
  3657. node.tagType === 0 /* ELEMENT */)))) {
  3658. return;
  3659. }
  3660. // pre-convert text nodes into createTextVNode(text) calls to avoid
  3661. // runtime normalization.
  3662. for (let i = 0; i < children.length; i++) {
  3663. const child = children[i];
  3664. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  3665. const callArgs = [];
  3666. // createTextVNode defaults to single whitespace, so if it is a
  3667. // single space the code could be an empty call to save bytes.
  3668. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  3669. callArgs.push(child);
  3670. }
  3671. // mark dynamic text with flag so it gets patched inside a block
  3672. if (!context.ssr &&
  3673. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  3674. callArgs.push(1 /* TEXT */ +
  3675. ((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[1 /* TEXT */]} */` : ``));
  3676. }
  3677. children[i] = {
  3678. type: 12 /* TEXT_CALL */,
  3679. content: child,
  3680. loc: child.loc,
  3681. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  3682. };
  3683. }
  3684. }
  3685. };
  3686. }
  3687. };
  3688. const seen = new WeakSet();
  3689. const transformOnce = (node, context) => {
  3690. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  3691. if (seen.has(node)) {
  3692. return;
  3693. }
  3694. seen.add(node);
  3695. context.helper(SET_BLOCK_TRACKING);
  3696. return () => {
  3697. const cur = context.currentNode;
  3698. if (cur.codegenNode) {
  3699. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  3700. }
  3701. };
  3702. }
  3703. };
  3704. const transformModel = (dir, node, context) => {
  3705. const { exp, arg } = dir;
  3706. if (!exp) {
  3707. context.onError(createCompilerError(40 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  3708. return createTransformProps();
  3709. }
  3710. const rawExp = exp.loc.source;
  3711. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  3712. // im SFC <script setup> inline mode, the exp may have been transformed into
  3713. // _unref(exp)
  3714. context.bindingMetadata[rawExp];
  3715. const maybeRef = !true /* SETUP_CONST */;
  3716. if (!isMemberExpression(expString) && !maybeRef) {
  3717. context.onError(createCompilerError(41 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  3718. return createTransformProps();
  3719. }
  3720. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  3721. const eventName = arg
  3722. ? isStaticExp(arg)
  3723. ? `onUpdate:${arg.content}`
  3724. : createCompoundExpression(['"onUpdate:" + ', arg])
  3725. : `onUpdate:modelValue`;
  3726. let assignmentExp;
  3727. const eventArg = context.isTS ? `($event: any)` : `$event`;
  3728. {
  3729. assignmentExp = createCompoundExpression([
  3730. `${eventArg} => (`,
  3731. exp,
  3732. ` = $event)`
  3733. ]);
  3734. }
  3735. const props = [
  3736. // modelValue: foo
  3737. createObjectProperty(propName, dir.exp),
  3738. // "onUpdate:modelValue": $event => (foo = $event)
  3739. createObjectProperty(eventName, assignmentExp)
  3740. ];
  3741. // modelModifiers: { foo: true, "bar-baz": true }
  3742. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  3743. const modifiers = dir.modifiers
  3744. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  3745. .join(`, `);
  3746. const modifiersKey = arg
  3747. ? isStaticExp(arg)
  3748. ? `${arg.content}Modifiers`
  3749. : createCompoundExpression([arg, ' + "Modifiers"'])
  3750. : `modelModifiers`;
  3751. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  3752. }
  3753. return createTransformProps(props);
  3754. };
  3755. function createTransformProps(props = []) {
  3756. return { props };
  3757. }
  3758. function getBaseTransformPreset(prefixIdentifiers) {
  3759. return [
  3760. [
  3761. transformOnce,
  3762. transformIf,
  3763. transformFor,
  3764. ...((process.env.NODE_ENV !== 'production')
  3765. ? [transformExpression]
  3766. : []),
  3767. transformSlotOutlet,
  3768. transformElement,
  3769. trackSlotScopes,
  3770. transformText
  3771. ],
  3772. {
  3773. on: transformOn,
  3774. bind: transformBind,
  3775. model: transformModel
  3776. }
  3777. ];
  3778. }
  3779. // we name it `baseCompile` so that higher order compilers like
  3780. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  3781. function baseCompile(template, options = {}) {
  3782. const onError = options.onError || defaultOnError;
  3783. const isModuleMode = options.mode === 'module';
  3784. /* istanbul ignore if */
  3785. {
  3786. if (options.prefixIdentifiers === true) {
  3787. onError(createCompilerError(45 /* X_PREFIX_ID_NOT_SUPPORTED */));
  3788. }
  3789. else if (isModuleMode) {
  3790. onError(createCompilerError(46 /* X_MODULE_MODE_NOT_SUPPORTED */));
  3791. }
  3792. }
  3793. const prefixIdentifiers = !true ;
  3794. if (options.cacheHandlers) {
  3795. onError(createCompilerError(47 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  3796. }
  3797. if (options.scopeId && !isModuleMode) {
  3798. onError(createCompilerError(48 /* X_SCOPE_ID_NOT_SUPPORTED */));
  3799. }
  3800. const ast = isString(template) ? baseParse(template, options) : template;
  3801. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  3802. transform(ast, extend({}, options, {
  3803. prefixIdentifiers,
  3804. nodeTransforms: [
  3805. ...nodeTransforms,
  3806. ...(options.nodeTransforms || []) // user transforms
  3807. ],
  3808. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  3809. )
  3810. }));
  3811. return generate(ast, extend({}, options, {
  3812. prefixIdentifiers
  3813. }));
  3814. }
  3815. const noopDirectiveTransform = () => ({ props: [] });
  3816. export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, IS_REF, KEEP_ALIVE, MERGE_PROPS, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_SCOPE_ID, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildProps, buildSlots, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, findDir, findProp, generate, getBaseTransformPreset, getInnerRange, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBindKey, isBuiltInType, isCoreComponent, isMemberExpression, isSimpleIdentifier, isSlotOutlet, isStaticExp, isTemplateNode, isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode };