compiler-core.esm-bundler.js 190 KB

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