compiler-core.esm-bundler.js 170 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814
  1. /**
  2. * @vue/compiler-core v3.5.22
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. import { isString, NOOP, isObject, extend, NO, isSymbol, PatchFlagNames, isArray, capitalize, camelize, EMPTY_OBJ, slotFlagsText, isOn, isBuiltInDirective, isReservedProp, toHandlerKey } from '@vue/shared';
  7. export { generateCodeFrame } from '@vue/shared';
  8. const FRAGMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Fragment` : ``);
  9. const TELEPORT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Teleport` : ``);
  10. const SUSPENSE = Symbol(!!(process.env.NODE_ENV !== "production") ? `Suspense` : ``);
  11. const KEEP_ALIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `KeepAlive` : ``);
  12. const BASE_TRANSITION = Symbol(
  13. !!(process.env.NODE_ENV !== "production") ? `BaseTransition` : ``
  14. );
  15. const OPEN_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `openBlock` : ``);
  16. const CREATE_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createBlock` : ``);
  17. const CREATE_ELEMENT_BLOCK = Symbol(
  18. !!(process.env.NODE_ENV !== "production") ? `createElementBlock` : ``
  19. );
  20. const CREATE_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createVNode` : ``);
  21. const CREATE_ELEMENT_VNODE = Symbol(
  22. !!(process.env.NODE_ENV !== "production") ? `createElementVNode` : ``
  23. );
  24. const CREATE_COMMENT = Symbol(
  25. !!(process.env.NODE_ENV !== "production") ? `createCommentVNode` : ``
  26. );
  27. const CREATE_TEXT = Symbol(
  28. !!(process.env.NODE_ENV !== "production") ? `createTextVNode` : ``
  29. );
  30. const CREATE_STATIC = Symbol(
  31. !!(process.env.NODE_ENV !== "production") ? `createStaticVNode` : ``
  32. );
  33. const RESOLVE_COMPONENT = Symbol(
  34. !!(process.env.NODE_ENV !== "production") ? `resolveComponent` : ``
  35. );
  36. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  37. !!(process.env.NODE_ENV !== "production") ? `resolveDynamicComponent` : ``
  38. );
  39. const RESOLVE_DIRECTIVE = Symbol(
  40. !!(process.env.NODE_ENV !== "production") ? `resolveDirective` : ``
  41. );
  42. const RESOLVE_FILTER = Symbol(
  43. !!(process.env.NODE_ENV !== "production") ? `resolveFilter` : ``
  44. );
  45. const WITH_DIRECTIVES = Symbol(
  46. !!(process.env.NODE_ENV !== "production") ? `withDirectives` : ``
  47. );
  48. const RENDER_LIST = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderList` : ``);
  49. const RENDER_SLOT = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderSlot` : ``);
  50. const CREATE_SLOTS = Symbol(!!(process.env.NODE_ENV !== "production") ? `createSlots` : ``);
  51. const TO_DISPLAY_STRING = Symbol(
  52. !!(process.env.NODE_ENV !== "production") ? `toDisplayString` : ``
  53. );
  54. const MERGE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `mergeProps` : ``);
  55. const NORMALIZE_CLASS = Symbol(
  56. !!(process.env.NODE_ENV !== "production") ? `normalizeClass` : ``
  57. );
  58. const NORMALIZE_STYLE = Symbol(
  59. !!(process.env.NODE_ENV !== "production") ? `normalizeStyle` : ``
  60. );
  61. const NORMALIZE_PROPS = Symbol(
  62. !!(process.env.NODE_ENV !== "production") ? `normalizeProps` : ``
  63. );
  64. const GUARD_REACTIVE_PROPS = Symbol(
  65. !!(process.env.NODE_ENV !== "production") ? `guardReactiveProps` : ``
  66. );
  67. const TO_HANDLERS = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlers` : ``);
  68. const CAMELIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `camelize` : ``);
  69. const CAPITALIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `capitalize` : ``);
  70. const TO_HANDLER_KEY = Symbol(
  71. !!(process.env.NODE_ENV !== "production") ? `toHandlerKey` : ``
  72. );
  73. const SET_BLOCK_TRACKING = Symbol(
  74. !!(process.env.NODE_ENV !== "production") ? `setBlockTracking` : ``
  75. );
  76. const PUSH_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `pushScopeId` : ``);
  77. const POP_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `popScopeId` : ``);
  78. const WITH_CTX = Symbol(!!(process.env.NODE_ENV !== "production") ? `withCtx` : ``);
  79. const UNREF = Symbol(!!(process.env.NODE_ENV !== "production") ? `unref` : ``);
  80. const IS_REF = Symbol(!!(process.env.NODE_ENV !== "production") ? `isRef` : ``);
  81. const WITH_MEMO = Symbol(!!(process.env.NODE_ENV !== "production") ? `withMemo` : ``);
  82. const IS_MEMO_SAME = Symbol(!!(process.env.NODE_ENV !== "production") ? `isMemoSame` : ``);
  83. const helperNameMap = {
  84. [FRAGMENT]: `Fragment`,
  85. [TELEPORT]: `Teleport`,
  86. [SUSPENSE]: `Suspense`,
  87. [KEEP_ALIVE]: `KeepAlive`,
  88. [BASE_TRANSITION]: `BaseTransition`,
  89. [OPEN_BLOCK]: `openBlock`,
  90. [CREATE_BLOCK]: `createBlock`,
  91. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  92. [CREATE_VNODE]: `createVNode`,
  93. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  94. [CREATE_COMMENT]: `createCommentVNode`,
  95. [CREATE_TEXT]: `createTextVNode`,
  96. [CREATE_STATIC]: `createStaticVNode`,
  97. [RESOLVE_COMPONENT]: `resolveComponent`,
  98. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  99. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  100. [RESOLVE_FILTER]: `resolveFilter`,
  101. [WITH_DIRECTIVES]: `withDirectives`,
  102. [RENDER_LIST]: `renderList`,
  103. [RENDER_SLOT]: `renderSlot`,
  104. [CREATE_SLOTS]: `createSlots`,
  105. [TO_DISPLAY_STRING]: `toDisplayString`,
  106. [MERGE_PROPS]: `mergeProps`,
  107. [NORMALIZE_CLASS]: `normalizeClass`,
  108. [NORMALIZE_STYLE]: `normalizeStyle`,
  109. [NORMALIZE_PROPS]: `normalizeProps`,
  110. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  111. [TO_HANDLERS]: `toHandlers`,
  112. [CAMELIZE]: `camelize`,
  113. [CAPITALIZE]: `capitalize`,
  114. [TO_HANDLER_KEY]: `toHandlerKey`,
  115. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  116. [PUSH_SCOPE_ID]: `pushScopeId`,
  117. [POP_SCOPE_ID]: `popScopeId`,
  118. [WITH_CTX]: `withCtx`,
  119. [UNREF]: `unref`,
  120. [IS_REF]: `isRef`,
  121. [WITH_MEMO]: `withMemo`,
  122. [IS_MEMO_SAME]: `isMemoSame`
  123. };
  124. function registerRuntimeHelpers(helpers) {
  125. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  126. helperNameMap[s] = helpers[s];
  127. });
  128. }
  129. const Namespaces = {
  130. "HTML": 0,
  131. "0": "HTML",
  132. "SVG": 1,
  133. "1": "SVG",
  134. "MATH_ML": 2,
  135. "2": "MATH_ML"
  136. };
  137. const NodeTypes = {
  138. "ROOT": 0,
  139. "0": "ROOT",
  140. "ELEMENT": 1,
  141. "1": "ELEMENT",
  142. "TEXT": 2,
  143. "2": "TEXT",
  144. "COMMENT": 3,
  145. "3": "COMMENT",
  146. "SIMPLE_EXPRESSION": 4,
  147. "4": "SIMPLE_EXPRESSION",
  148. "INTERPOLATION": 5,
  149. "5": "INTERPOLATION",
  150. "ATTRIBUTE": 6,
  151. "6": "ATTRIBUTE",
  152. "DIRECTIVE": 7,
  153. "7": "DIRECTIVE",
  154. "COMPOUND_EXPRESSION": 8,
  155. "8": "COMPOUND_EXPRESSION",
  156. "IF": 9,
  157. "9": "IF",
  158. "IF_BRANCH": 10,
  159. "10": "IF_BRANCH",
  160. "FOR": 11,
  161. "11": "FOR",
  162. "TEXT_CALL": 12,
  163. "12": "TEXT_CALL",
  164. "VNODE_CALL": 13,
  165. "13": "VNODE_CALL",
  166. "JS_CALL_EXPRESSION": 14,
  167. "14": "JS_CALL_EXPRESSION",
  168. "JS_OBJECT_EXPRESSION": 15,
  169. "15": "JS_OBJECT_EXPRESSION",
  170. "JS_PROPERTY": 16,
  171. "16": "JS_PROPERTY",
  172. "JS_ARRAY_EXPRESSION": 17,
  173. "17": "JS_ARRAY_EXPRESSION",
  174. "JS_FUNCTION_EXPRESSION": 18,
  175. "18": "JS_FUNCTION_EXPRESSION",
  176. "JS_CONDITIONAL_EXPRESSION": 19,
  177. "19": "JS_CONDITIONAL_EXPRESSION",
  178. "JS_CACHE_EXPRESSION": 20,
  179. "20": "JS_CACHE_EXPRESSION",
  180. "JS_BLOCK_STATEMENT": 21,
  181. "21": "JS_BLOCK_STATEMENT",
  182. "JS_TEMPLATE_LITERAL": 22,
  183. "22": "JS_TEMPLATE_LITERAL",
  184. "JS_IF_STATEMENT": 23,
  185. "23": "JS_IF_STATEMENT",
  186. "JS_ASSIGNMENT_EXPRESSION": 24,
  187. "24": "JS_ASSIGNMENT_EXPRESSION",
  188. "JS_SEQUENCE_EXPRESSION": 25,
  189. "25": "JS_SEQUENCE_EXPRESSION",
  190. "JS_RETURN_STATEMENT": 26,
  191. "26": "JS_RETURN_STATEMENT"
  192. };
  193. const ElementTypes = {
  194. "ELEMENT": 0,
  195. "0": "ELEMENT",
  196. "COMPONENT": 1,
  197. "1": "COMPONENT",
  198. "SLOT": 2,
  199. "2": "SLOT",
  200. "TEMPLATE": 3,
  201. "3": "TEMPLATE"
  202. };
  203. const ConstantTypes = {
  204. "NOT_CONSTANT": 0,
  205. "0": "NOT_CONSTANT",
  206. "CAN_SKIP_PATCH": 1,
  207. "1": "CAN_SKIP_PATCH",
  208. "CAN_CACHE": 2,
  209. "2": "CAN_CACHE",
  210. "CAN_STRINGIFY": 3,
  211. "3": "CAN_STRINGIFY"
  212. };
  213. const locStub = {
  214. start: { line: 1, column: 1, offset: 0 },
  215. end: { line: 1, column: 1, offset: 0 },
  216. source: ""
  217. };
  218. function createRoot(children, source = "") {
  219. return {
  220. type: 0,
  221. source,
  222. children,
  223. helpers: /* @__PURE__ */ new Set(),
  224. components: [],
  225. directives: [],
  226. hoists: [],
  227. imports: [],
  228. cached: [],
  229. temps: 0,
  230. codegenNode: void 0,
  231. loc: locStub
  232. };
  233. }
  234. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  235. if (context) {
  236. if (isBlock) {
  237. context.helper(OPEN_BLOCK);
  238. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  239. } else {
  240. context.helper(getVNodeHelper(context.inSSR, isComponent));
  241. }
  242. if (directives) {
  243. context.helper(WITH_DIRECTIVES);
  244. }
  245. }
  246. return {
  247. type: 13,
  248. tag,
  249. props,
  250. children,
  251. patchFlag,
  252. dynamicProps,
  253. directives,
  254. isBlock,
  255. disableTracking,
  256. isComponent,
  257. loc
  258. };
  259. }
  260. function createArrayExpression(elements, loc = locStub) {
  261. return {
  262. type: 17,
  263. loc,
  264. elements
  265. };
  266. }
  267. function createObjectExpression(properties, loc = locStub) {
  268. return {
  269. type: 15,
  270. loc,
  271. properties
  272. };
  273. }
  274. function createObjectProperty(key, value) {
  275. return {
  276. type: 16,
  277. loc: locStub,
  278. key: isString(key) ? createSimpleExpression(key, true) : key,
  279. value
  280. };
  281. }
  282. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  283. return {
  284. type: 4,
  285. loc,
  286. content,
  287. isStatic,
  288. constType: isStatic ? 3 : constType
  289. };
  290. }
  291. function createInterpolation(content, loc) {
  292. return {
  293. type: 5,
  294. loc,
  295. content: isString(content) ? createSimpleExpression(content, false, loc) : content
  296. };
  297. }
  298. function createCompoundExpression(children, loc = locStub) {
  299. return {
  300. type: 8,
  301. loc,
  302. children
  303. };
  304. }
  305. function createCallExpression(callee, args = [], loc = locStub) {
  306. return {
  307. type: 14,
  308. loc,
  309. callee,
  310. arguments: args
  311. };
  312. }
  313. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  314. return {
  315. type: 18,
  316. params,
  317. returns,
  318. newline,
  319. isSlot,
  320. loc
  321. };
  322. }
  323. function createConditionalExpression(test, consequent, alternate, newline = true) {
  324. return {
  325. type: 19,
  326. test,
  327. consequent,
  328. alternate,
  329. newline,
  330. loc: locStub
  331. };
  332. }
  333. function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
  334. return {
  335. type: 20,
  336. index,
  337. value,
  338. needPauseTracking,
  339. inVOnce,
  340. needArraySpread: false,
  341. loc: locStub
  342. };
  343. }
  344. function createBlockStatement(body) {
  345. return {
  346. type: 21,
  347. body,
  348. loc: locStub
  349. };
  350. }
  351. function createTemplateLiteral(elements) {
  352. return {
  353. type: 22,
  354. elements,
  355. loc: locStub
  356. };
  357. }
  358. function createIfStatement(test, consequent, alternate) {
  359. return {
  360. type: 23,
  361. test,
  362. consequent,
  363. alternate,
  364. loc: locStub
  365. };
  366. }
  367. function createAssignmentExpression(left, right) {
  368. return {
  369. type: 24,
  370. left,
  371. right,
  372. loc: locStub
  373. };
  374. }
  375. function createSequenceExpression(expressions) {
  376. return {
  377. type: 25,
  378. expressions,
  379. loc: locStub
  380. };
  381. }
  382. function createReturnStatement(returns) {
  383. return {
  384. type: 26,
  385. returns,
  386. loc: locStub
  387. };
  388. }
  389. function getVNodeHelper(ssr, isComponent) {
  390. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  391. }
  392. function getVNodeBlockHelper(ssr, isComponent) {
  393. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  394. }
  395. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  396. if (!node.isBlock) {
  397. node.isBlock = true;
  398. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  399. helper(OPEN_BLOCK);
  400. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  401. }
  402. }
  403. const defaultDelimitersOpen = new Uint8Array([123, 123]);
  404. const defaultDelimitersClose = new Uint8Array([125, 125]);
  405. function isTagStartChar(c) {
  406. return c >= 97 && c <= 122 || c >= 65 && c <= 90;
  407. }
  408. function isWhitespace(c) {
  409. return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
  410. }
  411. function isEndOfTagSection(c) {
  412. return c === 47 || c === 62 || isWhitespace(c);
  413. }
  414. function toCharCodes(str) {
  415. const ret = new Uint8Array(str.length);
  416. for (let i = 0; i < str.length; i++) {
  417. ret[i] = str.charCodeAt(i);
  418. }
  419. return ret;
  420. }
  421. const Sequences = {
  422. Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
  423. // CDATA[
  424. CdataEnd: new Uint8Array([93, 93, 62]),
  425. // ]]>
  426. CommentEnd: new Uint8Array([45, 45, 62]),
  427. // `-->`
  428. ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
  429. // `<\/script`
  430. StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
  431. // `</style`
  432. TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
  433. // `</title`
  434. TextareaEnd: new Uint8Array([
  435. 60,
  436. 47,
  437. 116,
  438. 101,
  439. 120,
  440. 116,
  441. 97,
  442. 114,
  443. 101,
  444. 97
  445. ])
  446. // `</textarea
  447. };
  448. class Tokenizer {
  449. constructor(stack, cbs) {
  450. this.stack = stack;
  451. this.cbs = cbs;
  452. /** The current state the tokenizer is in. */
  453. this.state = 1;
  454. /** The read buffer. */
  455. this.buffer = "";
  456. /** The beginning of the section that is currently being read. */
  457. this.sectionStart = 0;
  458. /** The index within the buffer that we are currently looking at. */
  459. this.index = 0;
  460. /** The start of the last entity. */
  461. this.entityStart = 0;
  462. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  463. this.baseState = 1;
  464. /** For special parsing behavior inside of script and style tags. */
  465. this.inRCDATA = false;
  466. /** For disabling RCDATA tags handling */
  467. this.inXML = false;
  468. /** For disabling interpolation parsing in v-pre */
  469. this.inVPre = false;
  470. /** Record newline positions for fast line / column calculation */
  471. this.newlines = [];
  472. this.mode = 0;
  473. this.delimiterOpen = defaultDelimitersOpen;
  474. this.delimiterClose = defaultDelimitersClose;
  475. this.delimiterIndex = -1;
  476. this.currentSequence = void 0;
  477. this.sequenceIndex = 0;
  478. }
  479. get inSFCRoot() {
  480. return this.mode === 2 && this.stack.length === 0;
  481. }
  482. reset() {
  483. this.state = 1;
  484. this.mode = 0;
  485. this.buffer = "";
  486. this.sectionStart = 0;
  487. this.index = 0;
  488. this.baseState = 1;
  489. this.inRCDATA = false;
  490. this.currentSequence = void 0;
  491. this.newlines.length = 0;
  492. this.delimiterOpen = defaultDelimitersOpen;
  493. this.delimiterClose = defaultDelimitersClose;
  494. }
  495. /**
  496. * Generate Position object with line / column information using recorded
  497. * newline positions. We know the index is always going to be an already
  498. * processed index, so all the newlines up to this index should have been
  499. * recorded.
  500. */
  501. getPos(index) {
  502. let line = 1;
  503. let column = index + 1;
  504. for (let i = this.newlines.length - 1; i >= 0; i--) {
  505. const newlineIndex = this.newlines[i];
  506. if (index > newlineIndex) {
  507. line = i + 2;
  508. column = index - newlineIndex;
  509. break;
  510. }
  511. }
  512. return {
  513. column,
  514. line,
  515. offset: index
  516. };
  517. }
  518. peek() {
  519. return this.buffer.charCodeAt(this.index + 1);
  520. }
  521. stateText(c) {
  522. if (c === 60) {
  523. if (this.index > this.sectionStart) {
  524. this.cbs.ontext(this.sectionStart, this.index);
  525. }
  526. this.state = 5;
  527. this.sectionStart = this.index;
  528. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  529. this.state = 2;
  530. this.delimiterIndex = 0;
  531. this.stateInterpolationOpen(c);
  532. }
  533. }
  534. stateInterpolationOpen(c) {
  535. if (c === this.delimiterOpen[this.delimiterIndex]) {
  536. if (this.delimiterIndex === this.delimiterOpen.length - 1) {
  537. const start = this.index + 1 - this.delimiterOpen.length;
  538. if (start > this.sectionStart) {
  539. this.cbs.ontext(this.sectionStart, start);
  540. }
  541. this.state = 3;
  542. this.sectionStart = start;
  543. } else {
  544. this.delimiterIndex++;
  545. }
  546. } else if (this.inRCDATA) {
  547. this.state = 32;
  548. this.stateInRCDATA(c);
  549. } else {
  550. this.state = 1;
  551. this.stateText(c);
  552. }
  553. }
  554. stateInterpolation(c) {
  555. if (c === this.delimiterClose[0]) {
  556. this.state = 4;
  557. this.delimiterIndex = 0;
  558. this.stateInterpolationClose(c);
  559. }
  560. }
  561. stateInterpolationClose(c) {
  562. if (c === this.delimiterClose[this.delimiterIndex]) {
  563. if (this.delimiterIndex === this.delimiterClose.length - 1) {
  564. this.cbs.oninterpolation(this.sectionStart, this.index + 1);
  565. if (this.inRCDATA) {
  566. this.state = 32;
  567. } else {
  568. this.state = 1;
  569. }
  570. this.sectionStart = this.index + 1;
  571. } else {
  572. this.delimiterIndex++;
  573. }
  574. } else {
  575. this.state = 3;
  576. this.stateInterpolation(c);
  577. }
  578. }
  579. stateSpecialStartSequence(c) {
  580. const isEnd = this.sequenceIndex === this.currentSequence.length;
  581. const isMatch = isEnd ? (
  582. // If we are at the end of the sequence, make sure the tag name has ended
  583. isEndOfTagSection(c)
  584. ) : (
  585. // Otherwise, do a case-insensitive comparison
  586. (c | 32) === this.currentSequence[this.sequenceIndex]
  587. );
  588. if (!isMatch) {
  589. this.inRCDATA = false;
  590. } else if (!isEnd) {
  591. this.sequenceIndex++;
  592. return;
  593. }
  594. this.sequenceIndex = 0;
  595. this.state = 6;
  596. this.stateInTagName(c);
  597. }
  598. /** Look for an end tag. For <title> and <textarea>, also decode entities. */
  599. stateInRCDATA(c) {
  600. if (this.sequenceIndex === this.currentSequence.length) {
  601. if (c === 62 || isWhitespace(c)) {
  602. const endOfText = this.index - this.currentSequence.length;
  603. if (this.sectionStart < endOfText) {
  604. const actualIndex = this.index;
  605. this.index = endOfText;
  606. this.cbs.ontext(this.sectionStart, endOfText);
  607. this.index = actualIndex;
  608. }
  609. this.sectionStart = endOfText + 2;
  610. this.stateInClosingTagName(c);
  611. this.inRCDATA = false;
  612. return;
  613. }
  614. this.sequenceIndex = 0;
  615. }
  616. if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
  617. this.sequenceIndex += 1;
  618. } else if (this.sequenceIndex === 0) {
  619. if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
  620. if (!this.inVPre && c === this.delimiterOpen[0]) {
  621. this.state = 2;
  622. this.delimiterIndex = 0;
  623. this.stateInterpolationOpen(c);
  624. }
  625. } else if (this.fastForwardTo(60)) {
  626. this.sequenceIndex = 1;
  627. }
  628. } else {
  629. this.sequenceIndex = Number(c === 60);
  630. }
  631. }
  632. stateCDATASequence(c) {
  633. if (c === Sequences.Cdata[this.sequenceIndex]) {
  634. if (++this.sequenceIndex === Sequences.Cdata.length) {
  635. this.state = 28;
  636. this.currentSequence = Sequences.CdataEnd;
  637. this.sequenceIndex = 0;
  638. this.sectionStart = this.index + 1;
  639. }
  640. } else {
  641. this.sequenceIndex = 0;
  642. this.state = 23;
  643. this.stateInDeclaration(c);
  644. }
  645. }
  646. /**
  647. * When we wait for one specific character, we can speed things up
  648. * by skipping through the buffer until we find it.
  649. *
  650. * @returns Whether the character was found.
  651. */
  652. fastForwardTo(c) {
  653. while (++this.index < this.buffer.length) {
  654. const cc = this.buffer.charCodeAt(this.index);
  655. if (cc === 10) {
  656. this.newlines.push(this.index);
  657. }
  658. if (cc === c) {
  659. return true;
  660. }
  661. }
  662. this.index = this.buffer.length - 1;
  663. return false;
  664. }
  665. /**
  666. * Comments and CDATA end with `-->` and `]]>`.
  667. *
  668. * Their common qualities are:
  669. * - Their end sequences have a distinct character they start with.
  670. * - That character is then repeated, so we have to check multiple repeats.
  671. * - All characters but the start character of the sequence can be skipped.
  672. */
  673. stateInCommentLike(c) {
  674. if (c === this.currentSequence[this.sequenceIndex]) {
  675. if (++this.sequenceIndex === this.currentSequence.length) {
  676. if (this.currentSequence === Sequences.CdataEnd) {
  677. this.cbs.oncdata(this.sectionStart, this.index - 2);
  678. } else {
  679. this.cbs.oncomment(this.sectionStart, this.index - 2);
  680. }
  681. this.sequenceIndex = 0;
  682. this.sectionStart = this.index + 1;
  683. this.state = 1;
  684. }
  685. } else if (this.sequenceIndex === 0) {
  686. if (this.fastForwardTo(this.currentSequence[0])) {
  687. this.sequenceIndex = 1;
  688. }
  689. } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
  690. this.sequenceIndex = 0;
  691. }
  692. }
  693. startSpecial(sequence, offset) {
  694. this.enterRCDATA(sequence, offset);
  695. this.state = 31;
  696. }
  697. enterRCDATA(sequence, offset) {
  698. this.inRCDATA = true;
  699. this.currentSequence = sequence;
  700. this.sequenceIndex = offset;
  701. }
  702. stateBeforeTagName(c) {
  703. if (c === 33) {
  704. this.state = 22;
  705. this.sectionStart = this.index + 1;
  706. } else if (c === 63) {
  707. this.state = 24;
  708. this.sectionStart = this.index + 1;
  709. } else if (isTagStartChar(c)) {
  710. this.sectionStart = this.index;
  711. if (this.mode === 0) {
  712. this.state = 6;
  713. } else if (this.inSFCRoot) {
  714. this.state = 34;
  715. } else if (!this.inXML) {
  716. if (c === 116) {
  717. this.state = 30;
  718. } else {
  719. this.state = c === 115 ? 29 : 6;
  720. }
  721. } else {
  722. this.state = 6;
  723. }
  724. } else if (c === 47) {
  725. this.state = 8;
  726. } else {
  727. this.state = 1;
  728. this.stateText(c);
  729. }
  730. }
  731. stateInTagName(c) {
  732. if (isEndOfTagSection(c)) {
  733. this.handleTagName(c);
  734. }
  735. }
  736. stateInSFCRootTagName(c) {
  737. if (isEndOfTagSection(c)) {
  738. const tag = this.buffer.slice(this.sectionStart, this.index);
  739. if (tag !== "template") {
  740. this.enterRCDATA(toCharCodes(`</` + tag), 0);
  741. }
  742. this.handleTagName(c);
  743. }
  744. }
  745. handleTagName(c) {
  746. this.cbs.onopentagname(this.sectionStart, this.index);
  747. this.sectionStart = -1;
  748. this.state = 11;
  749. this.stateBeforeAttrName(c);
  750. }
  751. stateBeforeClosingTagName(c) {
  752. if (isWhitespace(c)) ; else if (c === 62) {
  753. if (!!(process.env.NODE_ENV !== "production") || false) {
  754. this.cbs.onerr(14, this.index);
  755. }
  756. this.state = 1;
  757. this.sectionStart = this.index + 1;
  758. } else {
  759. this.state = isTagStartChar(c) ? 9 : 27;
  760. this.sectionStart = this.index;
  761. }
  762. }
  763. stateInClosingTagName(c) {
  764. if (c === 62 || isWhitespace(c)) {
  765. this.cbs.onclosetag(this.sectionStart, this.index);
  766. this.sectionStart = -1;
  767. this.state = 10;
  768. this.stateAfterClosingTagName(c);
  769. }
  770. }
  771. stateAfterClosingTagName(c) {
  772. if (c === 62) {
  773. this.state = 1;
  774. this.sectionStart = this.index + 1;
  775. }
  776. }
  777. stateBeforeAttrName(c) {
  778. if (c === 62) {
  779. this.cbs.onopentagend(this.index);
  780. if (this.inRCDATA) {
  781. this.state = 32;
  782. } else {
  783. this.state = 1;
  784. }
  785. this.sectionStart = this.index + 1;
  786. } else if (c === 47) {
  787. this.state = 7;
  788. if ((!!(process.env.NODE_ENV !== "production") || false) && this.peek() !== 62) {
  789. this.cbs.onerr(22, this.index);
  790. }
  791. } else if (c === 60 && this.peek() === 47) {
  792. this.cbs.onopentagend(this.index);
  793. this.state = 5;
  794. this.sectionStart = this.index;
  795. } else if (!isWhitespace(c)) {
  796. if ((!!(process.env.NODE_ENV !== "production") || false) && c === 61) {
  797. this.cbs.onerr(
  798. 19,
  799. this.index
  800. );
  801. }
  802. this.handleAttrStart(c);
  803. }
  804. }
  805. handleAttrStart(c) {
  806. if (c === 118 && this.peek() === 45) {
  807. this.state = 13;
  808. this.sectionStart = this.index;
  809. } else if (c === 46 || c === 58 || c === 64 || c === 35) {
  810. this.cbs.ondirname(this.index, this.index + 1);
  811. this.state = 14;
  812. this.sectionStart = this.index + 1;
  813. } else {
  814. this.state = 12;
  815. this.sectionStart = this.index;
  816. }
  817. }
  818. stateInSelfClosingTag(c) {
  819. if (c === 62) {
  820. this.cbs.onselfclosingtag(this.index);
  821. this.state = 1;
  822. this.sectionStart = this.index + 1;
  823. this.inRCDATA = false;
  824. } else if (!isWhitespace(c)) {
  825. this.state = 11;
  826. this.stateBeforeAttrName(c);
  827. }
  828. }
  829. stateInAttrName(c) {
  830. if (c === 61 || isEndOfTagSection(c)) {
  831. this.cbs.onattribname(this.sectionStart, this.index);
  832. this.handleAttrNameEnd(c);
  833. } else if ((!!(process.env.NODE_ENV !== "production") || false) && (c === 34 || c === 39 || c === 60)) {
  834. this.cbs.onerr(
  835. 17,
  836. this.index
  837. );
  838. }
  839. }
  840. stateInDirName(c) {
  841. if (c === 61 || isEndOfTagSection(c)) {
  842. this.cbs.ondirname(this.sectionStart, this.index);
  843. this.handleAttrNameEnd(c);
  844. } else if (c === 58) {
  845. this.cbs.ondirname(this.sectionStart, this.index);
  846. this.state = 14;
  847. this.sectionStart = this.index + 1;
  848. } else if (c === 46) {
  849. this.cbs.ondirname(this.sectionStart, this.index);
  850. this.state = 16;
  851. this.sectionStart = this.index + 1;
  852. }
  853. }
  854. stateInDirArg(c) {
  855. if (c === 61 || isEndOfTagSection(c)) {
  856. this.cbs.ondirarg(this.sectionStart, this.index);
  857. this.handleAttrNameEnd(c);
  858. } else if (c === 91) {
  859. this.state = 15;
  860. } else if (c === 46) {
  861. this.cbs.ondirarg(this.sectionStart, this.index);
  862. this.state = 16;
  863. this.sectionStart = this.index + 1;
  864. }
  865. }
  866. stateInDynamicDirArg(c) {
  867. if (c === 93) {
  868. this.state = 14;
  869. } else if (c === 61 || isEndOfTagSection(c)) {
  870. this.cbs.ondirarg(this.sectionStart, this.index + 1);
  871. this.handleAttrNameEnd(c);
  872. if (!!(process.env.NODE_ENV !== "production") || false) {
  873. this.cbs.onerr(
  874. 27,
  875. this.index
  876. );
  877. }
  878. }
  879. }
  880. stateInDirModifier(c) {
  881. if (c === 61 || isEndOfTagSection(c)) {
  882. this.cbs.ondirmodifier(this.sectionStart, this.index);
  883. this.handleAttrNameEnd(c);
  884. } else if (c === 46) {
  885. this.cbs.ondirmodifier(this.sectionStart, this.index);
  886. this.sectionStart = this.index + 1;
  887. }
  888. }
  889. handleAttrNameEnd(c) {
  890. this.sectionStart = this.index;
  891. this.state = 17;
  892. this.cbs.onattribnameend(this.index);
  893. this.stateAfterAttrName(c);
  894. }
  895. stateAfterAttrName(c) {
  896. if (c === 61) {
  897. this.state = 18;
  898. } else if (c === 47 || c === 62) {
  899. this.cbs.onattribend(0, this.sectionStart);
  900. this.sectionStart = -1;
  901. this.state = 11;
  902. this.stateBeforeAttrName(c);
  903. } else if (!isWhitespace(c)) {
  904. this.cbs.onattribend(0, this.sectionStart);
  905. this.handleAttrStart(c);
  906. }
  907. }
  908. stateBeforeAttrValue(c) {
  909. if (c === 34) {
  910. this.state = 19;
  911. this.sectionStart = this.index + 1;
  912. } else if (c === 39) {
  913. this.state = 20;
  914. this.sectionStart = this.index + 1;
  915. } else if (!isWhitespace(c)) {
  916. this.sectionStart = this.index;
  917. this.state = 21;
  918. this.stateInAttrValueNoQuotes(c);
  919. }
  920. }
  921. handleInAttrValue(c, quote) {
  922. if (c === quote || this.fastForwardTo(quote)) {
  923. this.cbs.onattribdata(this.sectionStart, this.index);
  924. this.sectionStart = -1;
  925. this.cbs.onattribend(
  926. quote === 34 ? 3 : 2,
  927. this.index + 1
  928. );
  929. this.state = 11;
  930. }
  931. }
  932. stateInAttrValueDoubleQuotes(c) {
  933. this.handleInAttrValue(c, 34);
  934. }
  935. stateInAttrValueSingleQuotes(c) {
  936. this.handleInAttrValue(c, 39);
  937. }
  938. stateInAttrValueNoQuotes(c) {
  939. if (isWhitespace(c) || c === 62) {
  940. this.cbs.onattribdata(this.sectionStart, this.index);
  941. this.sectionStart = -1;
  942. this.cbs.onattribend(1, this.index);
  943. this.state = 11;
  944. this.stateBeforeAttrName(c);
  945. } else if ((!!(process.env.NODE_ENV !== "production") || false) && c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
  946. this.cbs.onerr(
  947. 18,
  948. this.index
  949. );
  950. } else ;
  951. }
  952. stateBeforeDeclaration(c) {
  953. if (c === 91) {
  954. this.state = 26;
  955. this.sequenceIndex = 0;
  956. } else {
  957. this.state = c === 45 ? 25 : 23;
  958. }
  959. }
  960. stateInDeclaration(c) {
  961. if (c === 62 || this.fastForwardTo(62)) {
  962. this.state = 1;
  963. this.sectionStart = this.index + 1;
  964. }
  965. }
  966. stateInProcessingInstruction(c) {
  967. if (c === 62 || this.fastForwardTo(62)) {
  968. this.cbs.onprocessinginstruction(this.sectionStart, this.index);
  969. this.state = 1;
  970. this.sectionStart = this.index + 1;
  971. }
  972. }
  973. stateBeforeComment(c) {
  974. if (c === 45) {
  975. this.state = 28;
  976. this.currentSequence = Sequences.CommentEnd;
  977. this.sequenceIndex = 2;
  978. this.sectionStart = this.index + 1;
  979. } else {
  980. this.state = 23;
  981. }
  982. }
  983. stateInSpecialComment(c) {
  984. if (c === 62 || this.fastForwardTo(62)) {
  985. this.cbs.oncomment(this.sectionStart, this.index);
  986. this.state = 1;
  987. this.sectionStart = this.index + 1;
  988. }
  989. }
  990. stateBeforeSpecialS(c) {
  991. if (c === Sequences.ScriptEnd[3]) {
  992. this.startSpecial(Sequences.ScriptEnd, 4);
  993. } else if (c === Sequences.StyleEnd[3]) {
  994. this.startSpecial(Sequences.StyleEnd, 4);
  995. } else {
  996. this.state = 6;
  997. this.stateInTagName(c);
  998. }
  999. }
  1000. stateBeforeSpecialT(c) {
  1001. if (c === Sequences.TitleEnd[3]) {
  1002. this.startSpecial(Sequences.TitleEnd, 4);
  1003. } else if (c === Sequences.TextareaEnd[3]) {
  1004. this.startSpecial(Sequences.TextareaEnd, 4);
  1005. } else {
  1006. this.state = 6;
  1007. this.stateInTagName(c);
  1008. }
  1009. }
  1010. startEntity() {
  1011. }
  1012. stateInEntity() {
  1013. }
  1014. /**
  1015. * Iterates through the buffer, calling the function corresponding to the current state.
  1016. *
  1017. * States that are more likely to be hit are higher up, as a performance improvement.
  1018. */
  1019. parse(input) {
  1020. this.buffer = input;
  1021. while (this.index < this.buffer.length) {
  1022. const c = this.buffer.charCodeAt(this.index);
  1023. if (c === 10 && this.state !== 33) {
  1024. this.newlines.push(this.index);
  1025. }
  1026. switch (this.state) {
  1027. case 1: {
  1028. this.stateText(c);
  1029. break;
  1030. }
  1031. case 2: {
  1032. this.stateInterpolationOpen(c);
  1033. break;
  1034. }
  1035. case 3: {
  1036. this.stateInterpolation(c);
  1037. break;
  1038. }
  1039. case 4: {
  1040. this.stateInterpolationClose(c);
  1041. break;
  1042. }
  1043. case 31: {
  1044. this.stateSpecialStartSequence(c);
  1045. break;
  1046. }
  1047. case 32: {
  1048. this.stateInRCDATA(c);
  1049. break;
  1050. }
  1051. case 26: {
  1052. this.stateCDATASequence(c);
  1053. break;
  1054. }
  1055. case 19: {
  1056. this.stateInAttrValueDoubleQuotes(c);
  1057. break;
  1058. }
  1059. case 12: {
  1060. this.stateInAttrName(c);
  1061. break;
  1062. }
  1063. case 13: {
  1064. this.stateInDirName(c);
  1065. break;
  1066. }
  1067. case 14: {
  1068. this.stateInDirArg(c);
  1069. break;
  1070. }
  1071. case 15: {
  1072. this.stateInDynamicDirArg(c);
  1073. break;
  1074. }
  1075. case 16: {
  1076. this.stateInDirModifier(c);
  1077. break;
  1078. }
  1079. case 28: {
  1080. this.stateInCommentLike(c);
  1081. break;
  1082. }
  1083. case 27: {
  1084. this.stateInSpecialComment(c);
  1085. break;
  1086. }
  1087. case 11: {
  1088. this.stateBeforeAttrName(c);
  1089. break;
  1090. }
  1091. case 6: {
  1092. this.stateInTagName(c);
  1093. break;
  1094. }
  1095. case 34: {
  1096. this.stateInSFCRootTagName(c);
  1097. break;
  1098. }
  1099. case 9: {
  1100. this.stateInClosingTagName(c);
  1101. break;
  1102. }
  1103. case 5: {
  1104. this.stateBeforeTagName(c);
  1105. break;
  1106. }
  1107. case 17: {
  1108. this.stateAfterAttrName(c);
  1109. break;
  1110. }
  1111. case 20: {
  1112. this.stateInAttrValueSingleQuotes(c);
  1113. break;
  1114. }
  1115. case 18: {
  1116. this.stateBeforeAttrValue(c);
  1117. break;
  1118. }
  1119. case 8: {
  1120. this.stateBeforeClosingTagName(c);
  1121. break;
  1122. }
  1123. case 10: {
  1124. this.stateAfterClosingTagName(c);
  1125. break;
  1126. }
  1127. case 29: {
  1128. this.stateBeforeSpecialS(c);
  1129. break;
  1130. }
  1131. case 30: {
  1132. this.stateBeforeSpecialT(c);
  1133. break;
  1134. }
  1135. case 21: {
  1136. this.stateInAttrValueNoQuotes(c);
  1137. break;
  1138. }
  1139. case 7: {
  1140. this.stateInSelfClosingTag(c);
  1141. break;
  1142. }
  1143. case 23: {
  1144. this.stateInDeclaration(c);
  1145. break;
  1146. }
  1147. case 22: {
  1148. this.stateBeforeDeclaration(c);
  1149. break;
  1150. }
  1151. case 25: {
  1152. this.stateBeforeComment(c);
  1153. break;
  1154. }
  1155. case 24: {
  1156. this.stateInProcessingInstruction(c);
  1157. break;
  1158. }
  1159. case 33: {
  1160. this.stateInEntity();
  1161. break;
  1162. }
  1163. }
  1164. this.index++;
  1165. }
  1166. this.cleanup();
  1167. this.finish();
  1168. }
  1169. /**
  1170. * Remove data that has already been consumed from the buffer.
  1171. */
  1172. cleanup() {
  1173. if (this.sectionStart !== this.index) {
  1174. if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
  1175. this.cbs.ontext(this.sectionStart, this.index);
  1176. this.sectionStart = this.index;
  1177. } else if (this.state === 19 || this.state === 20 || this.state === 21) {
  1178. this.cbs.onattribdata(this.sectionStart, this.index);
  1179. this.sectionStart = this.index;
  1180. }
  1181. }
  1182. }
  1183. finish() {
  1184. this.handleTrailingData();
  1185. this.cbs.onend();
  1186. }
  1187. /** Handle any trailing data. */
  1188. handleTrailingData() {
  1189. const endIndex = this.buffer.length;
  1190. if (this.sectionStart >= endIndex) {
  1191. return;
  1192. }
  1193. if (this.state === 28) {
  1194. if (this.currentSequence === Sequences.CdataEnd) {
  1195. this.cbs.oncdata(this.sectionStart, endIndex);
  1196. } else {
  1197. this.cbs.oncomment(this.sectionStart, endIndex);
  1198. }
  1199. } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
  1200. this.cbs.ontext(this.sectionStart, endIndex);
  1201. }
  1202. }
  1203. emitCodePoint(cp, consumed) {
  1204. }
  1205. }
  1206. const CompilerDeprecationTypes = {
  1207. "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
  1208. "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
  1209. "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
  1210. "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
  1211. "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1212. "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
  1213. "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
  1214. "COMPILER_FILTERS": "COMPILER_FILTERS"
  1215. };
  1216. const deprecationData = {
  1217. ["COMPILER_IS_ON_ELEMENT"]: {
  1218. message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
  1219. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  1220. },
  1221. ["COMPILER_V_BIND_SYNC"]: {
  1222. message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
  1223. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  1224. },
  1225. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  1226. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
  1227. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  1228. },
  1229. ["COMPILER_V_ON_NATIVE"]: {
  1230. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  1231. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  1232. },
  1233. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  1234. message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
  1235. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  1236. },
  1237. ["COMPILER_NATIVE_TEMPLATE"]: {
  1238. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  1239. },
  1240. ["COMPILER_INLINE_TEMPLATE"]: {
  1241. message: `"inline-template" has been removed in Vue 3.`,
  1242. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  1243. },
  1244. ["COMPILER_FILTERS"]: {
  1245. message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
  1246. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  1247. }
  1248. };
  1249. function getCompatValue(key, { compatConfig }) {
  1250. const value = compatConfig && compatConfig[key];
  1251. if (key === "MODE") {
  1252. return value || 3;
  1253. } else {
  1254. return value;
  1255. }
  1256. }
  1257. function isCompatEnabled(key, context) {
  1258. const mode = getCompatValue("MODE", context);
  1259. const value = getCompatValue(key, context);
  1260. return mode === 3 ? value === true : value !== false;
  1261. }
  1262. function checkCompatEnabled(key, context, loc, ...args) {
  1263. const enabled = isCompatEnabled(key, context);
  1264. if (!!(process.env.NODE_ENV !== "production") && enabled) {
  1265. warnDeprecation(key, context, loc, ...args);
  1266. }
  1267. return enabled;
  1268. }
  1269. function warnDeprecation(key, context, loc, ...args) {
  1270. const val = getCompatValue(key, context);
  1271. if (val === "suppress-warning") {
  1272. return;
  1273. }
  1274. const { message, link } = deprecationData[key];
  1275. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  1276. Details: ${link}` : ``}`;
  1277. const err = new SyntaxError(msg);
  1278. err.code = key;
  1279. if (loc) err.loc = loc;
  1280. context.onWarn(err);
  1281. }
  1282. function defaultOnError(error) {
  1283. throw error;
  1284. }
  1285. function defaultOnWarn(msg) {
  1286. !!(process.env.NODE_ENV !== "production") && console.warn(`[Vue warn] ${msg.message}`);
  1287. }
  1288. function createCompilerError(code, loc, messages, additionalMessage) {
  1289. const msg = !!(process.env.NODE_ENV !== "production") || false ? (messages || errorMessages)[code] + (additionalMessage || ``) : `https://vuejs.org/error-reference/#compiler-${code}`;
  1290. const error = new SyntaxError(String(msg));
  1291. error.code = code;
  1292. error.loc = loc;
  1293. return error;
  1294. }
  1295. const ErrorCodes = {
  1296. "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
  1297. "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
  1298. "CDATA_IN_HTML_CONTENT": 1,
  1299. "1": "CDATA_IN_HTML_CONTENT",
  1300. "DUPLICATE_ATTRIBUTE": 2,
  1301. "2": "DUPLICATE_ATTRIBUTE",
  1302. "END_TAG_WITH_ATTRIBUTES": 3,
  1303. "3": "END_TAG_WITH_ATTRIBUTES",
  1304. "END_TAG_WITH_TRAILING_SOLIDUS": 4,
  1305. "4": "END_TAG_WITH_TRAILING_SOLIDUS",
  1306. "EOF_BEFORE_TAG_NAME": 5,
  1307. "5": "EOF_BEFORE_TAG_NAME",
  1308. "EOF_IN_CDATA": 6,
  1309. "6": "EOF_IN_CDATA",
  1310. "EOF_IN_COMMENT": 7,
  1311. "7": "EOF_IN_COMMENT",
  1312. "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
  1313. "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
  1314. "EOF_IN_TAG": 9,
  1315. "9": "EOF_IN_TAG",
  1316. "INCORRECTLY_CLOSED_COMMENT": 10,
  1317. "10": "INCORRECTLY_CLOSED_COMMENT",
  1318. "INCORRECTLY_OPENED_COMMENT": 11,
  1319. "11": "INCORRECTLY_OPENED_COMMENT",
  1320. "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
  1321. "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
  1322. "MISSING_ATTRIBUTE_VALUE": 13,
  1323. "13": "MISSING_ATTRIBUTE_VALUE",
  1324. "MISSING_END_TAG_NAME": 14,
  1325. "14": "MISSING_END_TAG_NAME",
  1326. "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
  1327. "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
  1328. "NESTED_COMMENT": 16,
  1329. "16": "NESTED_COMMENT",
  1330. "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
  1331. "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
  1332. "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
  1333. "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
  1334. "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
  1335. "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
  1336. "UNEXPECTED_NULL_CHARACTER": 20,
  1337. "20": "UNEXPECTED_NULL_CHARACTER",
  1338. "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
  1339. "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
  1340. "UNEXPECTED_SOLIDUS_IN_TAG": 22,
  1341. "22": "UNEXPECTED_SOLIDUS_IN_TAG",
  1342. "X_INVALID_END_TAG": 23,
  1343. "23": "X_INVALID_END_TAG",
  1344. "X_MISSING_END_TAG": 24,
  1345. "24": "X_MISSING_END_TAG",
  1346. "X_MISSING_INTERPOLATION_END": 25,
  1347. "25": "X_MISSING_INTERPOLATION_END",
  1348. "X_MISSING_DIRECTIVE_NAME": 26,
  1349. "26": "X_MISSING_DIRECTIVE_NAME",
  1350. "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
  1351. "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
  1352. "X_V_IF_NO_EXPRESSION": 28,
  1353. "28": "X_V_IF_NO_EXPRESSION",
  1354. "X_V_IF_SAME_KEY": 29,
  1355. "29": "X_V_IF_SAME_KEY",
  1356. "X_V_ELSE_NO_ADJACENT_IF": 30,
  1357. "30": "X_V_ELSE_NO_ADJACENT_IF",
  1358. "X_V_FOR_NO_EXPRESSION": 31,
  1359. "31": "X_V_FOR_NO_EXPRESSION",
  1360. "X_V_FOR_MALFORMED_EXPRESSION": 32,
  1361. "32": "X_V_FOR_MALFORMED_EXPRESSION",
  1362. "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
  1363. "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
  1364. "X_V_BIND_NO_EXPRESSION": 34,
  1365. "34": "X_V_BIND_NO_EXPRESSION",
  1366. "X_V_ON_NO_EXPRESSION": 35,
  1367. "35": "X_V_ON_NO_EXPRESSION",
  1368. "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
  1369. "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
  1370. "X_V_SLOT_MIXED_SLOT_USAGE": 37,
  1371. "37": "X_V_SLOT_MIXED_SLOT_USAGE",
  1372. "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
  1373. "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
  1374. "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
  1375. "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
  1376. "X_V_SLOT_MISPLACED": 40,
  1377. "40": "X_V_SLOT_MISPLACED",
  1378. "X_V_MODEL_NO_EXPRESSION": 41,
  1379. "41": "X_V_MODEL_NO_EXPRESSION",
  1380. "X_V_MODEL_MALFORMED_EXPRESSION": 42,
  1381. "42": "X_V_MODEL_MALFORMED_EXPRESSION",
  1382. "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
  1383. "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
  1384. "X_V_MODEL_ON_PROPS": 44,
  1385. "44": "X_V_MODEL_ON_PROPS",
  1386. "X_INVALID_EXPRESSION": 45,
  1387. "45": "X_INVALID_EXPRESSION",
  1388. "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
  1389. "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
  1390. "X_PREFIX_ID_NOT_SUPPORTED": 47,
  1391. "47": "X_PREFIX_ID_NOT_SUPPORTED",
  1392. "X_MODULE_MODE_NOT_SUPPORTED": 48,
  1393. "48": "X_MODULE_MODE_NOT_SUPPORTED",
  1394. "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
  1395. "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
  1396. "X_SCOPE_ID_NOT_SUPPORTED": 50,
  1397. "50": "X_SCOPE_ID_NOT_SUPPORTED",
  1398. "X_VNODE_HOOKS": 51,
  1399. "51": "X_VNODE_HOOKS",
  1400. "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
  1401. "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
  1402. "__EXTEND_POINT__": 53,
  1403. "53": "__EXTEND_POINT__"
  1404. };
  1405. const errorMessages = {
  1406. // parse errors
  1407. [0]: "Illegal comment.",
  1408. [1]: "CDATA section is allowed only in XML context.",
  1409. [2]: "Duplicate attribute.",
  1410. [3]: "End tag cannot have attributes.",
  1411. [4]: "Illegal '/' in tags.",
  1412. [5]: "Unexpected EOF in tag.",
  1413. [6]: "Unexpected EOF in CDATA section.",
  1414. [7]: "Unexpected EOF in comment.",
  1415. [8]: "Unexpected EOF in script.",
  1416. [9]: "Unexpected EOF in tag.",
  1417. [10]: "Incorrectly closed comment.",
  1418. [11]: "Incorrectly opened comment.",
  1419. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  1420. [13]: "Attribute value was expected.",
  1421. [14]: "End tag name was expected.",
  1422. [15]: "Whitespace was expected.",
  1423. [16]: "Unexpected '<!--' in comment.",
  1424. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  1425. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  1426. [19]: "Attribute name cannot start with '='.",
  1427. [21]: "'<?' is allowed only in XML context.",
  1428. [20]: `Unexpected null character.`,
  1429. [22]: "Illegal '/' in tags.",
  1430. // Vue-specific parse errors
  1431. [23]: "Invalid end tag.",
  1432. [24]: "Element is missing end tag.",
  1433. [25]: "Interpolation end sign was not found.",
  1434. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  1435. [26]: "Legal directive name was expected.",
  1436. // transform errors
  1437. [28]: `v-if/v-else-if is missing expression.`,
  1438. [29]: `v-if/else branches must use unique keys.`,
  1439. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  1440. [31]: `v-for is missing expression.`,
  1441. [32]: `v-for has invalid expression.`,
  1442. [33]: `<template v-for> key should be placed on the <template> tag.`,
  1443. [34]: `v-bind is missing expression.`,
  1444. [52]: `v-bind with same-name shorthand only allows static argument.`,
  1445. [35]: `v-on is missing expression.`,
  1446. [36]: `Unexpected custom directive on <slot> outlet.`,
  1447. [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
  1448. [38]: `Duplicate slot names found. `,
  1449. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  1450. [40]: `v-slot can only be used on components or <template> tags.`,
  1451. [41]: `v-model is missing expression.`,
  1452. [42]: `v-model value must be a valid JavaScript member expression.`,
  1453. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  1454. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  1455. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  1456. [45]: `Error parsing JavaScript expression: `,
  1457. [46]: `<KeepAlive> expects exactly one child component.`,
  1458. [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
  1459. // generic errors
  1460. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  1461. [48]: `ES module mode is not supported in this build of compiler.`,
  1462. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  1463. [50]: `"scopeId" option is only supported in module mode.`,
  1464. // just to fulfill types
  1465. [53]: ``
  1466. };
  1467. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  1468. {
  1469. return;
  1470. }
  1471. }
  1472. function isReferencedIdentifier(id, parent, parentStack) {
  1473. {
  1474. return false;
  1475. }
  1476. }
  1477. function isInDestructureAssignment(parent, parentStack) {
  1478. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  1479. let i = parentStack.length;
  1480. while (i--) {
  1481. const p = parentStack[i];
  1482. if (p.type === "AssignmentExpression") {
  1483. return true;
  1484. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  1485. break;
  1486. }
  1487. }
  1488. }
  1489. return false;
  1490. }
  1491. function isInNewExpression(parentStack) {
  1492. let i = parentStack.length;
  1493. while (i--) {
  1494. const p = parentStack[i];
  1495. if (p.type === "NewExpression") {
  1496. return true;
  1497. } else if (p.type !== "MemberExpression") {
  1498. break;
  1499. }
  1500. }
  1501. return false;
  1502. }
  1503. function walkFunctionParams(node, onIdent) {
  1504. for (const p of node.params) {
  1505. for (const id of extractIdentifiers(p)) {
  1506. onIdent(id);
  1507. }
  1508. }
  1509. }
  1510. function walkBlockDeclarations(block, onIdent) {
  1511. const body = block.type === "SwitchCase" ? block.consequent : block.body;
  1512. for (const stmt of body) {
  1513. if (stmt.type === "VariableDeclaration") {
  1514. if (stmt.declare) continue;
  1515. for (const decl of stmt.declarations) {
  1516. for (const id of extractIdentifiers(decl.id)) {
  1517. onIdent(id);
  1518. }
  1519. }
  1520. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  1521. if (stmt.declare || !stmt.id) continue;
  1522. onIdent(stmt.id);
  1523. } else if (isForStatement(stmt)) {
  1524. walkForStatement(stmt, true, onIdent);
  1525. } else if (stmt.type === "SwitchStatement") {
  1526. walkSwitchStatement(stmt, true, onIdent);
  1527. }
  1528. }
  1529. }
  1530. function isForStatement(stmt) {
  1531. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  1532. }
  1533. function walkForStatement(stmt, isVar, onIdent) {
  1534. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  1535. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  1536. for (const decl of variable.declarations) {
  1537. for (const id of extractIdentifiers(decl.id)) {
  1538. onIdent(id);
  1539. }
  1540. }
  1541. }
  1542. }
  1543. function walkSwitchStatement(stmt, isVar, onIdent) {
  1544. for (const cs of stmt.cases) {
  1545. for (const stmt2 of cs.consequent) {
  1546. if (stmt2.type === "VariableDeclaration" && (stmt2.kind === "var" ? isVar : !isVar)) {
  1547. for (const decl of stmt2.declarations) {
  1548. for (const id of extractIdentifiers(decl.id)) {
  1549. onIdent(id);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. walkBlockDeclarations(cs, onIdent);
  1555. }
  1556. }
  1557. function extractIdentifiers(param, nodes = []) {
  1558. switch (param.type) {
  1559. case "Identifier":
  1560. nodes.push(param);
  1561. break;
  1562. case "MemberExpression":
  1563. let object = param;
  1564. while (object.type === "MemberExpression") {
  1565. object = object.object;
  1566. }
  1567. nodes.push(object);
  1568. break;
  1569. case "ObjectPattern":
  1570. for (const prop of param.properties) {
  1571. if (prop.type === "RestElement") {
  1572. extractIdentifiers(prop.argument, nodes);
  1573. } else {
  1574. extractIdentifiers(prop.value, nodes);
  1575. }
  1576. }
  1577. break;
  1578. case "ArrayPattern":
  1579. param.elements.forEach((element) => {
  1580. if (element) extractIdentifiers(element, nodes);
  1581. });
  1582. break;
  1583. case "RestElement":
  1584. extractIdentifiers(param.argument, nodes);
  1585. break;
  1586. case "AssignmentPattern":
  1587. extractIdentifiers(param.left, nodes);
  1588. break;
  1589. }
  1590. return nodes;
  1591. }
  1592. const isFunctionType = (node) => {
  1593. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  1594. };
  1595. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  1596. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  1597. const TS_NODE_TYPES = [
  1598. "TSAsExpression",
  1599. // foo as number
  1600. "TSTypeAssertion",
  1601. // (<number>foo)
  1602. "TSNonNullExpression",
  1603. // foo!
  1604. "TSInstantiationExpression",
  1605. // foo<string>
  1606. "TSSatisfiesExpression"
  1607. // foo satisfies T
  1608. ];
  1609. function unwrapTSNode(node) {
  1610. if (TS_NODE_TYPES.includes(node.type)) {
  1611. return unwrapTSNode(node.expression);
  1612. } else {
  1613. return node;
  1614. }
  1615. }
  1616. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  1617. function isCoreComponent(tag) {
  1618. switch (tag) {
  1619. case "Teleport":
  1620. case "teleport":
  1621. return TELEPORT;
  1622. case "Suspense":
  1623. case "suspense":
  1624. return SUSPENSE;
  1625. case "KeepAlive":
  1626. case "keep-alive":
  1627. return KEEP_ALIVE;
  1628. case "BaseTransition":
  1629. case "base-transition":
  1630. return BASE_TRANSITION;
  1631. }
  1632. }
  1633. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  1634. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  1635. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  1636. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  1637. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  1638. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  1639. const isMemberExpressionBrowser = (exp) => {
  1640. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  1641. let state = 0 /* inMemberExp */;
  1642. let stateStack = [];
  1643. let currentOpenBracketCount = 0;
  1644. let currentOpenParensCount = 0;
  1645. let currentStringType = null;
  1646. for (let i = 0; i < path.length; i++) {
  1647. const char = path.charAt(i);
  1648. switch (state) {
  1649. case 0 /* inMemberExp */:
  1650. if (char === "[") {
  1651. stateStack.push(state);
  1652. state = 1 /* inBrackets */;
  1653. currentOpenBracketCount++;
  1654. } else if (char === "(") {
  1655. stateStack.push(state);
  1656. state = 2 /* inParens */;
  1657. currentOpenParensCount++;
  1658. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  1659. return false;
  1660. }
  1661. break;
  1662. case 1 /* inBrackets */:
  1663. if (char === `'` || char === `"` || char === "`") {
  1664. stateStack.push(state);
  1665. state = 3 /* inString */;
  1666. currentStringType = char;
  1667. } else if (char === `[`) {
  1668. currentOpenBracketCount++;
  1669. } else if (char === `]`) {
  1670. if (!--currentOpenBracketCount) {
  1671. state = stateStack.pop();
  1672. }
  1673. }
  1674. break;
  1675. case 2 /* inParens */:
  1676. if (char === `'` || char === `"` || char === "`") {
  1677. stateStack.push(state);
  1678. state = 3 /* inString */;
  1679. currentStringType = char;
  1680. } else if (char === `(`) {
  1681. currentOpenParensCount++;
  1682. } else if (char === `)`) {
  1683. if (i === path.length - 1) {
  1684. return false;
  1685. }
  1686. if (!--currentOpenParensCount) {
  1687. state = stateStack.pop();
  1688. }
  1689. }
  1690. break;
  1691. case 3 /* inString */:
  1692. if (char === currentStringType) {
  1693. state = stateStack.pop();
  1694. currentStringType = null;
  1695. }
  1696. break;
  1697. }
  1698. }
  1699. return !currentOpenBracketCount && !currentOpenParensCount;
  1700. };
  1701. const isMemberExpressionNode = NOOP ;
  1702. const isMemberExpression = isMemberExpressionBrowser ;
  1703. const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  1704. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  1705. const isFnExpressionNode = NOOP ;
  1706. const isFnExpression = isFnExpressionBrowser ;
  1707. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  1708. return advancePositionWithMutation(
  1709. {
  1710. offset: pos.offset,
  1711. line: pos.line,
  1712. column: pos.column
  1713. },
  1714. source,
  1715. numberOfCharacters
  1716. );
  1717. }
  1718. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  1719. let linesCount = 0;
  1720. let lastNewLinePos = -1;
  1721. for (let i = 0; i < numberOfCharacters; i++) {
  1722. if (source.charCodeAt(i) === 10) {
  1723. linesCount++;
  1724. lastNewLinePos = i;
  1725. }
  1726. }
  1727. pos.offset += numberOfCharacters;
  1728. pos.line += linesCount;
  1729. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  1730. return pos;
  1731. }
  1732. function assert(condition, msg) {
  1733. if (!condition) {
  1734. throw new Error(msg || `unexpected compiler condition`);
  1735. }
  1736. }
  1737. function findDir(node, name, allowEmpty = false) {
  1738. for (let i = 0; i < node.props.length; i++) {
  1739. const p = node.props[i];
  1740. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  1741. return p;
  1742. }
  1743. }
  1744. }
  1745. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  1746. for (let i = 0; i < node.props.length; i++) {
  1747. const p = node.props[i];
  1748. if (p.type === 6) {
  1749. if (dynamicOnly) continue;
  1750. if (p.name === name && (p.value || allowEmpty)) {
  1751. return p;
  1752. }
  1753. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  1754. return p;
  1755. }
  1756. }
  1757. }
  1758. function isStaticArgOf(arg, name) {
  1759. return !!(arg && isStaticExp(arg) && arg.content === name);
  1760. }
  1761. function hasDynamicKeyVBind(node) {
  1762. return node.props.some(
  1763. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  1764. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  1765. !p.arg.isStatic)
  1766. // v-bind:[foo]
  1767. );
  1768. }
  1769. function isText$1(node) {
  1770. return node.type === 5 || node.type === 2;
  1771. }
  1772. function isVPre(p) {
  1773. return p.type === 7 && p.name === "pre";
  1774. }
  1775. function isVSlot(p) {
  1776. return p.type === 7 && p.name === "slot";
  1777. }
  1778. function isTemplateNode(node) {
  1779. return node.type === 1 && node.tagType === 3;
  1780. }
  1781. function isSlotOutlet(node) {
  1782. return node.type === 1 && node.tagType === 2;
  1783. }
  1784. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  1785. function getUnnormalizedProps(props, callPath = []) {
  1786. if (props && !isString(props) && props.type === 14) {
  1787. const callee = props.callee;
  1788. if (!isString(callee) && propsHelperSet.has(callee)) {
  1789. return getUnnormalizedProps(
  1790. props.arguments[0],
  1791. callPath.concat(props)
  1792. );
  1793. }
  1794. }
  1795. return [props, callPath];
  1796. }
  1797. function injectProp(node, prop, context) {
  1798. let propsWithInjection;
  1799. let props = node.type === 13 ? node.props : node.arguments[2];
  1800. let callPath = [];
  1801. let parentCall;
  1802. if (props && !isString(props) && props.type === 14) {
  1803. const ret = getUnnormalizedProps(props);
  1804. props = ret[0];
  1805. callPath = ret[1];
  1806. parentCall = callPath[callPath.length - 1];
  1807. }
  1808. if (props == null || isString(props)) {
  1809. propsWithInjection = createObjectExpression([prop]);
  1810. } else if (props.type === 14) {
  1811. const first = props.arguments[0];
  1812. if (!isString(first) && first.type === 15) {
  1813. if (!hasProp(prop, first)) {
  1814. first.properties.unshift(prop);
  1815. }
  1816. } else {
  1817. if (props.callee === TO_HANDLERS) {
  1818. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1819. createObjectExpression([prop]),
  1820. props
  1821. ]);
  1822. } else {
  1823. props.arguments.unshift(createObjectExpression([prop]));
  1824. }
  1825. }
  1826. !propsWithInjection && (propsWithInjection = props);
  1827. } else if (props.type === 15) {
  1828. if (!hasProp(prop, props)) {
  1829. props.properties.unshift(prop);
  1830. }
  1831. propsWithInjection = props;
  1832. } else {
  1833. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1834. createObjectExpression([prop]),
  1835. props
  1836. ]);
  1837. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  1838. parentCall = callPath[callPath.length - 2];
  1839. }
  1840. }
  1841. if (node.type === 13) {
  1842. if (parentCall) {
  1843. parentCall.arguments[0] = propsWithInjection;
  1844. } else {
  1845. node.props = propsWithInjection;
  1846. }
  1847. } else {
  1848. if (parentCall) {
  1849. parentCall.arguments[0] = propsWithInjection;
  1850. } else {
  1851. node.arguments[2] = propsWithInjection;
  1852. }
  1853. }
  1854. }
  1855. function hasProp(prop, props) {
  1856. let result = false;
  1857. if (prop.key.type === 4) {
  1858. const propKeyName = prop.key.content;
  1859. result = props.properties.some(
  1860. (p) => p.key.type === 4 && p.key.content === propKeyName
  1861. );
  1862. }
  1863. return result;
  1864. }
  1865. function toValidAssetId(name, type) {
  1866. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  1867. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  1868. })}`;
  1869. }
  1870. function hasScopeRef(node, ids) {
  1871. if (!node || Object.keys(ids).length === 0) {
  1872. return false;
  1873. }
  1874. switch (node.type) {
  1875. case 1:
  1876. for (let i = 0; i < node.props.length; i++) {
  1877. const p = node.props[i];
  1878. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  1879. return true;
  1880. }
  1881. }
  1882. return node.children.some((c) => hasScopeRef(c, ids));
  1883. case 11:
  1884. if (hasScopeRef(node.source, ids)) {
  1885. return true;
  1886. }
  1887. return node.children.some((c) => hasScopeRef(c, ids));
  1888. case 9:
  1889. return node.branches.some((b) => hasScopeRef(b, ids));
  1890. case 10:
  1891. if (hasScopeRef(node.condition, ids)) {
  1892. return true;
  1893. }
  1894. return node.children.some((c) => hasScopeRef(c, ids));
  1895. case 4:
  1896. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  1897. case 8:
  1898. return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
  1899. case 5:
  1900. case 12:
  1901. return hasScopeRef(node.content, ids);
  1902. case 2:
  1903. case 3:
  1904. case 20:
  1905. return false;
  1906. default:
  1907. if (!!(process.env.NODE_ENV !== "production")) ;
  1908. return false;
  1909. }
  1910. }
  1911. function getMemoedVNodeCall(node) {
  1912. if (node.type === 14 && node.callee === WITH_MEMO) {
  1913. return node.arguments[1].returns;
  1914. } else {
  1915. return node;
  1916. }
  1917. }
  1918. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  1919. const defaultParserOptions = {
  1920. parseMode: "base",
  1921. ns: 0,
  1922. delimiters: [`{{`, `}}`],
  1923. getNamespace: () => 0,
  1924. isVoidTag: NO,
  1925. isPreTag: NO,
  1926. isIgnoreNewlineTag: NO,
  1927. isCustomElement: NO,
  1928. onError: defaultOnError,
  1929. onWarn: defaultOnWarn,
  1930. comments: !!(process.env.NODE_ENV !== "production"),
  1931. prefixIdentifiers: false
  1932. };
  1933. let currentOptions = defaultParserOptions;
  1934. let currentRoot = null;
  1935. let currentInput = "";
  1936. let currentOpenTag = null;
  1937. let currentProp = null;
  1938. let currentAttrValue = "";
  1939. let currentAttrStartIndex = -1;
  1940. let currentAttrEndIndex = -1;
  1941. let inPre = 0;
  1942. let inVPre = false;
  1943. let currentVPreBoundary = null;
  1944. const stack = [];
  1945. const tokenizer = new Tokenizer(stack, {
  1946. onerr: emitError,
  1947. ontext(start, end) {
  1948. onText(getSlice(start, end), start, end);
  1949. },
  1950. ontextentity(char, start, end) {
  1951. onText(char, start, end);
  1952. },
  1953. oninterpolation(start, end) {
  1954. if (inVPre) {
  1955. return onText(getSlice(start, end), start, end);
  1956. }
  1957. let innerStart = start + tokenizer.delimiterOpen.length;
  1958. let innerEnd = end - tokenizer.delimiterClose.length;
  1959. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  1960. innerStart++;
  1961. }
  1962. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  1963. innerEnd--;
  1964. }
  1965. let exp = getSlice(innerStart, innerEnd);
  1966. if (exp.includes("&")) {
  1967. {
  1968. exp = currentOptions.decodeEntities(exp, false);
  1969. }
  1970. }
  1971. addNode({
  1972. type: 5,
  1973. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  1974. loc: getLoc(start, end)
  1975. });
  1976. },
  1977. onopentagname(start, end) {
  1978. const name = getSlice(start, end);
  1979. currentOpenTag = {
  1980. type: 1,
  1981. tag: name,
  1982. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  1983. tagType: 0,
  1984. // will be refined on tag close
  1985. props: [],
  1986. children: [],
  1987. loc: getLoc(start - 1, end),
  1988. codegenNode: void 0
  1989. };
  1990. },
  1991. onopentagend(end) {
  1992. endOpenTag(end);
  1993. },
  1994. onclosetag(start, end) {
  1995. const name = getSlice(start, end);
  1996. if (!currentOptions.isVoidTag(name)) {
  1997. let found = false;
  1998. for (let i = 0; i < stack.length; i++) {
  1999. const e = stack[i];
  2000. if (e.tag.toLowerCase() === name.toLowerCase()) {
  2001. found = true;
  2002. if (i > 0) {
  2003. emitError(24, stack[0].loc.start.offset);
  2004. }
  2005. for (let j = 0; j <= i; j++) {
  2006. const el = stack.shift();
  2007. onCloseTag(el, end, j < i);
  2008. }
  2009. break;
  2010. }
  2011. }
  2012. if (!found) {
  2013. emitError(23, backTrack(start, 60));
  2014. }
  2015. }
  2016. },
  2017. onselfclosingtag(end) {
  2018. const name = currentOpenTag.tag;
  2019. currentOpenTag.isSelfClosing = true;
  2020. endOpenTag(end);
  2021. if (stack[0] && stack[0].tag === name) {
  2022. onCloseTag(stack.shift(), end);
  2023. }
  2024. },
  2025. onattribname(start, end) {
  2026. currentProp = {
  2027. type: 6,
  2028. name: getSlice(start, end),
  2029. nameLoc: getLoc(start, end),
  2030. value: void 0,
  2031. loc: getLoc(start)
  2032. };
  2033. },
  2034. ondirname(start, end) {
  2035. const raw = getSlice(start, end);
  2036. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  2037. if (!inVPre && name === "") {
  2038. emitError(26, start);
  2039. }
  2040. if (inVPre || name === "") {
  2041. currentProp = {
  2042. type: 6,
  2043. name: raw,
  2044. nameLoc: getLoc(start, end),
  2045. value: void 0,
  2046. loc: getLoc(start)
  2047. };
  2048. } else {
  2049. currentProp = {
  2050. type: 7,
  2051. name,
  2052. rawName: raw,
  2053. exp: void 0,
  2054. arg: void 0,
  2055. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  2056. loc: getLoc(start)
  2057. };
  2058. if (name === "pre") {
  2059. inVPre = tokenizer.inVPre = true;
  2060. currentVPreBoundary = currentOpenTag;
  2061. const props = currentOpenTag.props;
  2062. for (let i = 0; i < props.length; i++) {
  2063. if (props[i].type === 7) {
  2064. props[i] = dirToAttr(props[i]);
  2065. }
  2066. }
  2067. }
  2068. }
  2069. },
  2070. ondirarg(start, end) {
  2071. if (start === end) return;
  2072. const arg = getSlice(start, end);
  2073. if (inVPre && !isVPre(currentProp)) {
  2074. currentProp.name += arg;
  2075. setLocEnd(currentProp.nameLoc, end);
  2076. } else {
  2077. const isStatic = arg[0] !== `[`;
  2078. currentProp.arg = createExp(
  2079. isStatic ? arg : arg.slice(1, -1),
  2080. isStatic,
  2081. getLoc(start, end),
  2082. isStatic ? 3 : 0
  2083. );
  2084. }
  2085. },
  2086. ondirmodifier(start, end) {
  2087. const mod = getSlice(start, end);
  2088. if (inVPre && !isVPre(currentProp)) {
  2089. currentProp.name += "." + mod;
  2090. setLocEnd(currentProp.nameLoc, end);
  2091. } else if (currentProp.name === "slot") {
  2092. const arg = currentProp.arg;
  2093. if (arg) {
  2094. arg.content += "." + mod;
  2095. setLocEnd(arg.loc, end);
  2096. }
  2097. } else {
  2098. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  2099. currentProp.modifiers.push(exp);
  2100. }
  2101. },
  2102. onattribdata(start, end) {
  2103. currentAttrValue += getSlice(start, end);
  2104. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2105. currentAttrEndIndex = end;
  2106. },
  2107. onattribentity(char, start, end) {
  2108. currentAttrValue += char;
  2109. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2110. currentAttrEndIndex = end;
  2111. },
  2112. onattribnameend(end) {
  2113. const start = currentProp.loc.start.offset;
  2114. const name = getSlice(start, end);
  2115. if (currentProp.type === 7) {
  2116. currentProp.rawName = name;
  2117. }
  2118. if (currentOpenTag.props.some(
  2119. (p) => (p.type === 7 ? p.rawName : p.name) === name
  2120. )) {
  2121. emitError(2, start);
  2122. }
  2123. },
  2124. onattribend(quote, end) {
  2125. if (currentOpenTag && currentProp) {
  2126. setLocEnd(currentProp.loc, end);
  2127. if (quote !== 0) {
  2128. if (currentAttrValue.includes("&")) {
  2129. currentAttrValue = currentOptions.decodeEntities(
  2130. currentAttrValue,
  2131. true
  2132. );
  2133. }
  2134. if (currentProp.type === 6) {
  2135. if (currentProp.name === "class") {
  2136. currentAttrValue = condense(currentAttrValue).trim();
  2137. }
  2138. if (quote === 1 && !currentAttrValue) {
  2139. emitError(13, end);
  2140. }
  2141. currentProp.value = {
  2142. type: 2,
  2143. content: currentAttrValue,
  2144. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  2145. };
  2146. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  2147. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  2148. }
  2149. } else {
  2150. let expParseMode = 0 /* Normal */;
  2151. currentProp.exp = createExp(
  2152. currentAttrValue,
  2153. false,
  2154. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  2155. 0,
  2156. expParseMode
  2157. );
  2158. if (currentProp.name === "for") {
  2159. currentProp.forParseResult = parseForExpression(currentProp.exp);
  2160. }
  2161. let syncIndex = -1;
  2162. if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
  2163. (mod) => mod.content === "sync"
  2164. )) > -1 && checkCompatEnabled(
  2165. "COMPILER_V_BIND_SYNC",
  2166. currentOptions,
  2167. currentProp.loc,
  2168. currentProp.arg.loc.source
  2169. )) {
  2170. currentProp.name = "model";
  2171. currentProp.modifiers.splice(syncIndex, 1);
  2172. }
  2173. }
  2174. }
  2175. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  2176. currentOpenTag.props.push(currentProp);
  2177. }
  2178. }
  2179. currentAttrValue = "";
  2180. currentAttrStartIndex = currentAttrEndIndex = -1;
  2181. },
  2182. oncomment(start, end) {
  2183. if (currentOptions.comments) {
  2184. addNode({
  2185. type: 3,
  2186. content: getSlice(start, end),
  2187. loc: getLoc(start - 4, end + 3)
  2188. });
  2189. }
  2190. },
  2191. onend() {
  2192. const end = currentInput.length;
  2193. if ((!!(process.env.NODE_ENV !== "production") || false) && tokenizer.state !== 1) {
  2194. switch (tokenizer.state) {
  2195. case 5:
  2196. case 8:
  2197. emitError(5, end);
  2198. break;
  2199. case 3:
  2200. case 4:
  2201. emitError(
  2202. 25,
  2203. tokenizer.sectionStart
  2204. );
  2205. break;
  2206. case 28:
  2207. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  2208. emitError(6, end);
  2209. } else {
  2210. emitError(7, end);
  2211. }
  2212. break;
  2213. case 6:
  2214. case 7:
  2215. case 9:
  2216. case 11:
  2217. case 12:
  2218. case 13:
  2219. case 14:
  2220. case 15:
  2221. case 16:
  2222. case 17:
  2223. case 18:
  2224. case 19:
  2225. // "
  2226. case 20:
  2227. // '
  2228. case 21:
  2229. emitError(9, end);
  2230. break;
  2231. }
  2232. }
  2233. for (let index = 0; index < stack.length; index++) {
  2234. onCloseTag(stack[index], end - 1);
  2235. emitError(24, stack[index].loc.start.offset);
  2236. }
  2237. },
  2238. oncdata(start, end) {
  2239. if (stack[0].ns !== 0) {
  2240. onText(getSlice(start, end), start, end);
  2241. } else {
  2242. emitError(1, start - 9);
  2243. }
  2244. },
  2245. onprocessinginstruction(start) {
  2246. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2247. emitError(
  2248. 21,
  2249. start - 1
  2250. );
  2251. }
  2252. }
  2253. });
  2254. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  2255. const stripParensRE = /^\(|\)$/g;
  2256. function parseForExpression(input) {
  2257. const loc = input.loc;
  2258. const exp = input.content;
  2259. const inMatch = exp.match(forAliasRE);
  2260. if (!inMatch) return;
  2261. const [, LHS, RHS] = inMatch;
  2262. const createAliasExpression = (content, offset, asParam = false) => {
  2263. const start = loc.start.offset + offset;
  2264. const end = start + content.length;
  2265. return createExp(
  2266. content,
  2267. false,
  2268. getLoc(start, end),
  2269. 0,
  2270. asParam ? 1 /* Params */ : 0 /* Normal */
  2271. );
  2272. };
  2273. const result = {
  2274. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  2275. value: void 0,
  2276. key: void 0,
  2277. index: void 0,
  2278. finalized: false
  2279. };
  2280. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  2281. const trimmedOffset = LHS.indexOf(valueContent);
  2282. const iteratorMatch = valueContent.match(forIteratorRE);
  2283. if (iteratorMatch) {
  2284. valueContent = valueContent.replace(forIteratorRE, "").trim();
  2285. const keyContent = iteratorMatch[1].trim();
  2286. let keyOffset;
  2287. if (keyContent) {
  2288. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  2289. result.key = createAliasExpression(keyContent, keyOffset, true);
  2290. }
  2291. if (iteratorMatch[2]) {
  2292. const indexContent = iteratorMatch[2].trim();
  2293. if (indexContent) {
  2294. result.index = createAliasExpression(
  2295. indexContent,
  2296. exp.indexOf(
  2297. indexContent,
  2298. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  2299. ),
  2300. true
  2301. );
  2302. }
  2303. }
  2304. }
  2305. if (valueContent) {
  2306. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  2307. }
  2308. return result;
  2309. }
  2310. function getSlice(start, end) {
  2311. return currentInput.slice(start, end);
  2312. }
  2313. function endOpenTag(end) {
  2314. if (tokenizer.inSFCRoot) {
  2315. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  2316. }
  2317. addNode(currentOpenTag);
  2318. const { tag, ns } = currentOpenTag;
  2319. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2320. inPre++;
  2321. }
  2322. if (currentOptions.isVoidTag(tag)) {
  2323. onCloseTag(currentOpenTag, end);
  2324. } else {
  2325. stack.unshift(currentOpenTag);
  2326. if (ns === 1 || ns === 2) {
  2327. tokenizer.inXML = true;
  2328. }
  2329. }
  2330. currentOpenTag = null;
  2331. }
  2332. function onText(content, start, end) {
  2333. {
  2334. const tag = stack[0] && stack[0].tag;
  2335. if (tag !== "script" && tag !== "style" && content.includes("&")) {
  2336. content = currentOptions.decodeEntities(content, false);
  2337. }
  2338. }
  2339. const parent = stack[0] || currentRoot;
  2340. const lastNode = parent.children[parent.children.length - 1];
  2341. if (lastNode && lastNode.type === 2) {
  2342. lastNode.content += content;
  2343. setLocEnd(lastNode.loc, end);
  2344. } else {
  2345. parent.children.push({
  2346. type: 2,
  2347. content,
  2348. loc: getLoc(start, end)
  2349. });
  2350. }
  2351. }
  2352. function onCloseTag(el, end, isImplied = false) {
  2353. if (isImplied) {
  2354. setLocEnd(el.loc, backTrack(end, 60));
  2355. } else {
  2356. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  2357. }
  2358. if (tokenizer.inSFCRoot) {
  2359. if (el.children.length) {
  2360. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  2361. } else {
  2362. el.innerLoc.end = extend({}, el.innerLoc.start);
  2363. }
  2364. el.innerLoc.source = getSlice(
  2365. el.innerLoc.start.offset,
  2366. el.innerLoc.end.offset
  2367. );
  2368. }
  2369. const { tag, ns, children } = el;
  2370. if (!inVPre) {
  2371. if (tag === "slot") {
  2372. el.tagType = 2;
  2373. } else if (isFragmentTemplate(el)) {
  2374. el.tagType = 3;
  2375. } else if (isComponent(el)) {
  2376. el.tagType = 1;
  2377. }
  2378. }
  2379. if (!tokenizer.inRCDATA) {
  2380. el.children = condenseWhitespace(children);
  2381. }
  2382. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  2383. const first = children[0];
  2384. if (first && first.type === 2) {
  2385. first.content = first.content.replace(/^\r?\n/, "");
  2386. }
  2387. }
  2388. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2389. inPre--;
  2390. }
  2391. if (currentVPreBoundary === el) {
  2392. inVPre = tokenizer.inVPre = false;
  2393. currentVPreBoundary = null;
  2394. }
  2395. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2396. tokenizer.inXML = false;
  2397. }
  2398. {
  2399. const props = el.props;
  2400. if (!!(process.env.NODE_ENV !== "production") && isCompatEnabled(
  2401. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2402. currentOptions
  2403. )) {
  2404. let hasIf = false;
  2405. let hasFor = false;
  2406. for (let i = 0; i < props.length; i++) {
  2407. const p = props[i];
  2408. if (p.type === 7) {
  2409. if (p.name === "if") {
  2410. hasIf = true;
  2411. } else if (p.name === "for") {
  2412. hasFor = true;
  2413. }
  2414. }
  2415. if (hasIf && hasFor) {
  2416. warnDeprecation(
  2417. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2418. currentOptions,
  2419. el.loc
  2420. );
  2421. break;
  2422. }
  2423. }
  2424. }
  2425. if (!tokenizer.inSFCRoot && isCompatEnabled(
  2426. "COMPILER_NATIVE_TEMPLATE",
  2427. currentOptions
  2428. ) && el.tag === "template" && !isFragmentTemplate(el)) {
  2429. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  2430. "COMPILER_NATIVE_TEMPLATE",
  2431. currentOptions,
  2432. el.loc
  2433. );
  2434. const parent = stack[0] || currentRoot;
  2435. const index = parent.children.indexOf(el);
  2436. parent.children.splice(index, 1, ...el.children);
  2437. }
  2438. const inlineTemplateProp = props.find(
  2439. (p) => p.type === 6 && p.name === "inline-template"
  2440. );
  2441. if (inlineTemplateProp && checkCompatEnabled(
  2442. "COMPILER_INLINE_TEMPLATE",
  2443. currentOptions,
  2444. inlineTemplateProp.loc
  2445. ) && el.children.length) {
  2446. inlineTemplateProp.value = {
  2447. type: 2,
  2448. content: getSlice(
  2449. el.children[0].loc.start.offset,
  2450. el.children[el.children.length - 1].loc.end.offset
  2451. ),
  2452. loc: inlineTemplateProp.loc
  2453. };
  2454. }
  2455. }
  2456. }
  2457. function lookAhead(index, c) {
  2458. let i = index;
  2459. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  2460. return i;
  2461. }
  2462. function backTrack(index, c) {
  2463. let i = index;
  2464. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  2465. return i;
  2466. }
  2467. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  2468. function isFragmentTemplate({ tag, props }) {
  2469. if (tag === "template") {
  2470. for (let i = 0; i < props.length; i++) {
  2471. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  2472. return true;
  2473. }
  2474. }
  2475. }
  2476. return false;
  2477. }
  2478. function isComponent({ tag, props }) {
  2479. if (currentOptions.isCustomElement(tag)) {
  2480. return false;
  2481. }
  2482. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  2483. return true;
  2484. }
  2485. for (let i = 0; i < props.length; i++) {
  2486. const p = props[i];
  2487. if (p.type === 6) {
  2488. if (p.name === "is" && p.value) {
  2489. if (p.value.content.startsWith("vue:")) {
  2490. return true;
  2491. } else if (checkCompatEnabled(
  2492. "COMPILER_IS_ON_ELEMENT",
  2493. currentOptions,
  2494. p.loc
  2495. )) {
  2496. return true;
  2497. }
  2498. }
  2499. } else if (// :is on plain element - only treat as component in compat mode
  2500. p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
  2501. "COMPILER_IS_ON_ELEMENT",
  2502. currentOptions,
  2503. p.loc
  2504. )) {
  2505. return true;
  2506. }
  2507. }
  2508. return false;
  2509. }
  2510. function isUpperCase(c) {
  2511. return c > 64 && c < 91;
  2512. }
  2513. const windowsNewlineRE = /\r\n/g;
  2514. function condenseWhitespace(nodes) {
  2515. const shouldCondense = currentOptions.whitespace !== "preserve";
  2516. let removedWhitespace = false;
  2517. for (let i = 0; i < nodes.length; i++) {
  2518. const node = nodes[i];
  2519. if (node.type === 2) {
  2520. if (!inPre) {
  2521. if (isAllWhitespace(node.content)) {
  2522. const prev = nodes[i - 1] && nodes[i - 1].type;
  2523. const next = nodes[i + 1] && nodes[i + 1].type;
  2524. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  2525. removedWhitespace = true;
  2526. nodes[i] = null;
  2527. } else {
  2528. node.content = " ";
  2529. }
  2530. } else if (shouldCondense) {
  2531. node.content = condense(node.content);
  2532. }
  2533. } else {
  2534. node.content = node.content.replace(windowsNewlineRE, "\n");
  2535. }
  2536. }
  2537. }
  2538. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  2539. }
  2540. function isAllWhitespace(str) {
  2541. for (let i = 0; i < str.length; i++) {
  2542. if (!isWhitespace(str.charCodeAt(i))) {
  2543. return false;
  2544. }
  2545. }
  2546. return true;
  2547. }
  2548. function hasNewlineChar(str) {
  2549. for (let i = 0; i < str.length; i++) {
  2550. const c = str.charCodeAt(i);
  2551. if (c === 10 || c === 13) {
  2552. return true;
  2553. }
  2554. }
  2555. return false;
  2556. }
  2557. function condense(str) {
  2558. let ret = "";
  2559. let prevCharIsWhitespace = false;
  2560. for (let i = 0; i < str.length; i++) {
  2561. if (isWhitespace(str.charCodeAt(i))) {
  2562. if (!prevCharIsWhitespace) {
  2563. ret += " ";
  2564. prevCharIsWhitespace = true;
  2565. }
  2566. } else {
  2567. ret += str[i];
  2568. prevCharIsWhitespace = false;
  2569. }
  2570. }
  2571. return ret;
  2572. }
  2573. function addNode(node) {
  2574. (stack[0] || currentRoot).children.push(node);
  2575. }
  2576. function getLoc(start, end) {
  2577. return {
  2578. start: tokenizer.getPos(start),
  2579. // @ts-expect-error allow late attachment
  2580. end: end == null ? end : tokenizer.getPos(end),
  2581. // @ts-expect-error allow late attachment
  2582. source: end == null ? end : getSlice(start, end)
  2583. };
  2584. }
  2585. function cloneLoc(loc) {
  2586. return getLoc(loc.start.offset, loc.end.offset);
  2587. }
  2588. function setLocEnd(loc, end) {
  2589. loc.end = tokenizer.getPos(end);
  2590. loc.source = getSlice(loc.start.offset, end);
  2591. }
  2592. function dirToAttr(dir) {
  2593. const attr = {
  2594. type: 6,
  2595. name: dir.rawName,
  2596. nameLoc: getLoc(
  2597. dir.loc.start.offset,
  2598. dir.loc.start.offset + dir.rawName.length
  2599. ),
  2600. value: void 0,
  2601. loc: dir.loc
  2602. };
  2603. if (dir.exp) {
  2604. const loc = dir.exp.loc;
  2605. if (loc.end.offset < dir.loc.end.offset) {
  2606. loc.start.offset--;
  2607. loc.start.column--;
  2608. loc.end.offset++;
  2609. loc.end.column++;
  2610. }
  2611. attr.value = {
  2612. type: 2,
  2613. content: dir.exp.content,
  2614. loc
  2615. };
  2616. }
  2617. return attr;
  2618. }
  2619. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  2620. const exp = createSimpleExpression(content, isStatic, loc, constType);
  2621. return exp;
  2622. }
  2623. function emitError(code, index, message) {
  2624. currentOptions.onError(
  2625. createCompilerError(code, getLoc(index, index), void 0, message)
  2626. );
  2627. }
  2628. function reset() {
  2629. tokenizer.reset();
  2630. currentOpenTag = null;
  2631. currentProp = null;
  2632. currentAttrValue = "";
  2633. currentAttrStartIndex = -1;
  2634. currentAttrEndIndex = -1;
  2635. stack.length = 0;
  2636. }
  2637. function baseParse(input, options) {
  2638. reset();
  2639. currentInput = input;
  2640. currentOptions = extend({}, defaultParserOptions);
  2641. if (options) {
  2642. let key;
  2643. for (key in options) {
  2644. if (options[key] != null) {
  2645. currentOptions[key] = options[key];
  2646. }
  2647. }
  2648. }
  2649. if (!!(process.env.NODE_ENV !== "production")) {
  2650. if (!currentOptions.decodeEntities) {
  2651. throw new Error(
  2652. `[@vue/compiler-core] decodeEntities option is required in browser builds.`
  2653. );
  2654. }
  2655. }
  2656. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  2657. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  2658. const delimiters = options && options.delimiters;
  2659. if (delimiters) {
  2660. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  2661. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  2662. }
  2663. const root = currentRoot = createRoot([], input);
  2664. tokenizer.parse(currentInput);
  2665. root.loc = getLoc(0, input.length);
  2666. root.children = condenseWhitespace(root.children);
  2667. currentRoot = null;
  2668. return root;
  2669. }
  2670. function cacheStatic(root, context) {
  2671. walk(
  2672. root,
  2673. void 0,
  2674. context,
  2675. // Root node is unfortunately non-hoistable due to potential parent
  2676. // fallthrough attributes.
  2677. !!getSingleElementRoot(root)
  2678. );
  2679. }
  2680. function getSingleElementRoot(root) {
  2681. const children = root.children.filter((x) => x.type !== 3);
  2682. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  2683. }
  2684. function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
  2685. const { children } = node;
  2686. const toCache = [];
  2687. for (let i = 0; i < children.length; i++) {
  2688. const child = children[i];
  2689. if (child.type === 1 && child.tagType === 0) {
  2690. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2691. if (constantType > 0) {
  2692. if (constantType >= 2) {
  2693. child.codegenNode.patchFlag = -1;
  2694. toCache.push(child);
  2695. continue;
  2696. }
  2697. } else {
  2698. const codegenNode = child.codegenNode;
  2699. if (codegenNode.type === 13) {
  2700. const flag = codegenNode.patchFlag;
  2701. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  2702. const props = getNodeProps(child);
  2703. if (props) {
  2704. codegenNode.props = context.hoist(props);
  2705. }
  2706. }
  2707. if (codegenNode.dynamicProps) {
  2708. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  2709. }
  2710. }
  2711. }
  2712. } else if (child.type === 12) {
  2713. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2714. if (constantType >= 2) {
  2715. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  2716. child.codegenNode.arguments.push(
  2717. -1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[-1]} */` : ``)
  2718. );
  2719. }
  2720. toCache.push(child);
  2721. continue;
  2722. }
  2723. }
  2724. if (child.type === 1) {
  2725. const isComponent = child.tagType === 1;
  2726. if (isComponent) {
  2727. context.scopes.vSlot++;
  2728. }
  2729. walk(child, node, context, false, inFor);
  2730. if (isComponent) {
  2731. context.scopes.vSlot--;
  2732. }
  2733. } else if (child.type === 11) {
  2734. walk(child, node, context, child.children.length === 1, true);
  2735. } else if (child.type === 9) {
  2736. for (let i2 = 0; i2 < child.branches.length; i2++) {
  2737. walk(
  2738. child.branches[i2],
  2739. node,
  2740. context,
  2741. child.branches[i2].children.length === 1,
  2742. inFor
  2743. );
  2744. }
  2745. }
  2746. }
  2747. let cachedAsArray = false;
  2748. if (toCache.length === children.length && node.type === 1) {
  2749. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  2750. node.codegenNode.children = getCacheExpression(
  2751. createArrayExpression(node.codegenNode.children)
  2752. );
  2753. cachedAsArray = true;
  2754. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  2755. const slot = getSlotNode(node.codegenNode, "default");
  2756. if (slot) {
  2757. slot.returns = getCacheExpression(
  2758. createArrayExpression(slot.returns)
  2759. );
  2760. cachedAsArray = true;
  2761. }
  2762. } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
  2763. const slotName = findDir(node, "slot", true);
  2764. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  2765. if (slot) {
  2766. slot.returns = getCacheExpression(
  2767. createArrayExpression(slot.returns)
  2768. );
  2769. cachedAsArray = true;
  2770. }
  2771. }
  2772. }
  2773. if (!cachedAsArray) {
  2774. for (const child of toCache) {
  2775. child.codegenNode = context.cache(child.codegenNode);
  2776. }
  2777. }
  2778. function getCacheExpression(value) {
  2779. const exp = context.cache(value);
  2780. exp.needArraySpread = true;
  2781. return exp;
  2782. }
  2783. function getSlotNode(node2, name) {
  2784. if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
  2785. const slot = node2.children.properties.find(
  2786. (p) => p.key === name || p.key.content === name
  2787. );
  2788. return slot && slot.value;
  2789. }
  2790. }
  2791. if (toCache.length && context.transformHoist) {
  2792. context.transformHoist(children, context, node);
  2793. }
  2794. }
  2795. function getConstantType(node, context) {
  2796. const { constantCache } = context;
  2797. switch (node.type) {
  2798. case 1:
  2799. if (node.tagType !== 0) {
  2800. return 0;
  2801. }
  2802. const cached = constantCache.get(node);
  2803. if (cached !== void 0) {
  2804. return cached;
  2805. }
  2806. const codegenNode = node.codegenNode;
  2807. if (codegenNode.type !== 13) {
  2808. return 0;
  2809. }
  2810. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  2811. return 0;
  2812. }
  2813. if (codegenNode.patchFlag === void 0) {
  2814. let returnType2 = 3;
  2815. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  2816. if (generatedPropsType === 0) {
  2817. constantCache.set(node, 0);
  2818. return 0;
  2819. }
  2820. if (generatedPropsType < returnType2) {
  2821. returnType2 = generatedPropsType;
  2822. }
  2823. for (let i = 0; i < node.children.length; i++) {
  2824. const childType = getConstantType(node.children[i], context);
  2825. if (childType === 0) {
  2826. constantCache.set(node, 0);
  2827. return 0;
  2828. }
  2829. if (childType < returnType2) {
  2830. returnType2 = childType;
  2831. }
  2832. }
  2833. if (returnType2 > 1) {
  2834. for (let i = 0; i < node.props.length; i++) {
  2835. const p = node.props[i];
  2836. if (p.type === 7 && p.name === "bind" && p.exp) {
  2837. const expType = getConstantType(p.exp, context);
  2838. if (expType === 0) {
  2839. constantCache.set(node, 0);
  2840. return 0;
  2841. }
  2842. if (expType < returnType2) {
  2843. returnType2 = expType;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. if (codegenNode.isBlock) {
  2849. for (let i = 0; i < node.props.length; i++) {
  2850. const p = node.props[i];
  2851. if (p.type === 7) {
  2852. constantCache.set(node, 0);
  2853. return 0;
  2854. }
  2855. }
  2856. context.removeHelper(OPEN_BLOCK);
  2857. context.removeHelper(
  2858. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  2859. );
  2860. codegenNode.isBlock = false;
  2861. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  2862. }
  2863. constantCache.set(node, returnType2);
  2864. return returnType2;
  2865. } else {
  2866. constantCache.set(node, 0);
  2867. return 0;
  2868. }
  2869. case 2:
  2870. case 3:
  2871. return 3;
  2872. case 9:
  2873. case 11:
  2874. case 10:
  2875. return 0;
  2876. case 5:
  2877. case 12:
  2878. return getConstantType(node.content, context);
  2879. case 4:
  2880. return node.constType;
  2881. case 8:
  2882. let returnType = 3;
  2883. for (let i = 0; i < node.children.length; i++) {
  2884. const child = node.children[i];
  2885. if (isString(child) || isSymbol(child)) {
  2886. continue;
  2887. }
  2888. const childType = getConstantType(child, context);
  2889. if (childType === 0) {
  2890. return 0;
  2891. } else if (childType < returnType) {
  2892. returnType = childType;
  2893. }
  2894. }
  2895. return returnType;
  2896. case 20:
  2897. return 2;
  2898. default:
  2899. if (!!(process.env.NODE_ENV !== "production")) ;
  2900. return 0;
  2901. }
  2902. }
  2903. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  2904. NORMALIZE_CLASS,
  2905. NORMALIZE_STYLE,
  2906. NORMALIZE_PROPS,
  2907. GUARD_REACTIVE_PROPS
  2908. ]);
  2909. function getConstantTypeOfHelperCall(value, context) {
  2910. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  2911. const arg = value.arguments[0];
  2912. if (arg.type === 4) {
  2913. return getConstantType(arg, context);
  2914. } else if (arg.type === 14) {
  2915. return getConstantTypeOfHelperCall(arg, context);
  2916. }
  2917. }
  2918. return 0;
  2919. }
  2920. function getGeneratedPropsConstantType(node, context) {
  2921. let returnType = 3;
  2922. const props = getNodeProps(node);
  2923. if (props && props.type === 15) {
  2924. const { properties } = props;
  2925. for (let i = 0; i < properties.length; i++) {
  2926. const { key, value } = properties[i];
  2927. const keyType = getConstantType(key, context);
  2928. if (keyType === 0) {
  2929. return keyType;
  2930. }
  2931. if (keyType < returnType) {
  2932. returnType = keyType;
  2933. }
  2934. let valueType;
  2935. if (value.type === 4) {
  2936. valueType = getConstantType(value, context);
  2937. } else if (value.type === 14) {
  2938. valueType = getConstantTypeOfHelperCall(value, context);
  2939. } else {
  2940. valueType = 0;
  2941. }
  2942. if (valueType === 0) {
  2943. return valueType;
  2944. }
  2945. if (valueType < returnType) {
  2946. returnType = valueType;
  2947. }
  2948. }
  2949. }
  2950. return returnType;
  2951. }
  2952. function getNodeProps(node) {
  2953. const codegenNode = node.codegenNode;
  2954. if (codegenNode.type === 13) {
  2955. return codegenNode.props;
  2956. }
  2957. }
  2958. function createTransformContext(root, {
  2959. filename = "",
  2960. prefixIdentifiers = false,
  2961. hoistStatic = false,
  2962. hmr = false,
  2963. cacheHandlers = false,
  2964. nodeTransforms = [],
  2965. directiveTransforms = {},
  2966. transformHoist = null,
  2967. isBuiltInComponent = NOOP,
  2968. isCustomElement = NOOP,
  2969. expressionPlugins = [],
  2970. scopeId = null,
  2971. slotted = true,
  2972. ssr = false,
  2973. inSSR = false,
  2974. ssrCssVars = ``,
  2975. bindingMetadata = EMPTY_OBJ,
  2976. inline = false,
  2977. isTS = false,
  2978. onError = defaultOnError,
  2979. onWarn = defaultOnWarn,
  2980. compatConfig
  2981. }) {
  2982. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  2983. const context = {
  2984. // options
  2985. filename,
  2986. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  2987. prefixIdentifiers,
  2988. hoistStatic,
  2989. hmr,
  2990. cacheHandlers,
  2991. nodeTransforms,
  2992. directiveTransforms,
  2993. transformHoist,
  2994. isBuiltInComponent,
  2995. isCustomElement,
  2996. expressionPlugins,
  2997. scopeId,
  2998. slotted,
  2999. ssr,
  3000. inSSR,
  3001. ssrCssVars,
  3002. bindingMetadata,
  3003. inline,
  3004. isTS,
  3005. onError,
  3006. onWarn,
  3007. compatConfig,
  3008. // state
  3009. root,
  3010. helpers: /* @__PURE__ */ new Map(),
  3011. components: /* @__PURE__ */ new Set(),
  3012. directives: /* @__PURE__ */ new Set(),
  3013. hoists: [],
  3014. imports: [],
  3015. cached: [],
  3016. constantCache: /* @__PURE__ */ new WeakMap(),
  3017. temps: 0,
  3018. identifiers: /* @__PURE__ */ Object.create(null),
  3019. scopes: {
  3020. vFor: 0,
  3021. vSlot: 0,
  3022. vPre: 0,
  3023. vOnce: 0
  3024. },
  3025. parent: null,
  3026. grandParent: null,
  3027. currentNode: root,
  3028. childIndex: 0,
  3029. inVOnce: false,
  3030. // methods
  3031. helper(name) {
  3032. const count = context.helpers.get(name) || 0;
  3033. context.helpers.set(name, count + 1);
  3034. return name;
  3035. },
  3036. removeHelper(name) {
  3037. const count = context.helpers.get(name);
  3038. if (count) {
  3039. const currentCount = count - 1;
  3040. if (!currentCount) {
  3041. context.helpers.delete(name);
  3042. } else {
  3043. context.helpers.set(name, currentCount);
  3044. }
  3045. }
  3046. },
  3047. helperString(name) {
  3048. return `_${helperNameMap[context.helper(name)]}`;
  3049. },
  3050. replaceNode(node) {
  3051. if (!!(process.env.NODE_ENV !== "production")) {
  3052. if (!context.currentNode) {
  3053. throw new Error(`Node being replaced is already removed.`);
  3054. }
  3055. if (!context.parent) {
  3056. throw new Error(`Cannot replace root node.`);
  3057. }
  3058. }
  3059. context.parent.children[context.childIndex] = context.currentNode = node;
  3060. },
  3061. removeNode(node) {
  3062. if (!!(process.env.NODE_ENV !== "production") && !context.parent) {
  3063. throw new Error(`Cannot remove root node.`);
  3064. }
  3065. const list = context.parent.children;
  3066. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  3067. if (!!(process.env.NODE_ENV !== "production") && removalIndex < 0) {
  3068. throw new Error(`node being removed is not a child of current parent`);
  3069. }
  3070. if (!node || node === context.currentNode) {
  3071. context.currentNode = null;
  3072. context.onNodeRemoved();
  3073. } else {
  3074. if (context.childIndex > removalIndex) {
  3075. context.childIndex--;
  3076. context.onNodeRemoved();
  3077. }
  3078. }
  3079. context.parent.children.splice(removalIndex, 1);
  3080. },
  3081. onNodeRemoved: NOOP,
  3082. addIdentifiers(exp) {
  3083. },
  3084. removeIdentifiers(exp) {
  3085. },
  3086. hoist(exp) {
  3087. if (isString(exp)) exp = createSimpleExpression(exp);
  3088. context.hoists.push(exp);
  3089. const identifier = createSimpleExpression(
  3090. `_hoisted_${context.hoists.length}`,
  3091. false,
  3092. exp.loc,
  3093. 2
  3094. );
  3095. identifier.hoisted = exp;
  3096. return identifier;
  3097. },
  3098. cache(exp, isVNode = false, inVOnce = false) {
  3099. const cacheExp = createCacheExpression(
  3100. context.cached.length,
  3101. exp,
  3102. isVNode,
  3103. inVOnce
  3104. );
  3105. context.cached.push(cacheExp);
  3106. return cacheExp;
  3107. }
  3108. };
  3109. {
  3110. context.filters = /* @__PURE__ */ new Set();
  3111. }
  3112. return context;
  3113. }
  3114. function transform(root, options) {
  3115. const context = createTransformContext(root, options);
  3116. traverseNode(root, context);
  3117. if (options.hoistStatic) {
  3118. cacheStatic(root, context);
  3119. }
  3120. if (!options.ssr) {
  3121. createRootCodegen(root, context);
  3122. }
  3123. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  3124. root.components = [...context.components];
  3125. root.directives = [...context.directives];
  3126. root.imports = context.imports;
  3127. root.hoists = context.hoists;
  3128. root.temps = context.temps;
  3129. root.cached = context.cached;
  3130. root.transformed = true;
  3131. {
  3132. root.filters = [...context.filters];
  3133. }
  3134. }
  3135. function createRootCodegen(root, context) {
  3136. const { helper } = context;
  3137. const { children } = root;
  3138. if (children.length === 1) {
  3139. const singleElementRootChild = getSingleElementRoot(root);
  3140. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  3141. const codegenNode = singleElementRootChild.codegenNode;
  3142. if (codegenNode.type === 13) {
  3143. convertToBlock(codegenNode, context);
  3144. }
  3145. root.codegenNode = codegenNode;
  3146. } else {
  3147. root.codegenNode = children[0];
  3148. }
  3149. } else if (children.length > 1) {
  3150. let patchFlag = 64;
  3151. if (!!(process.env.NODE_ENV !== "production") && children.filter((c) => c.type !== 3).length === 1) {
  3152. patchFlag |= 2048;
  3153. }
  3154. root.codegenNode = createVNodeCall(
  3155. context,
  3156. helper(FRAGMENT),
  3157. void 0,
  3158. root.children,
  3159. patchFlag,
  3160. void 0,
  3161. void 0,
  3162. true,
  3163. void 0,
  3164. false
  3165. );
  3166. } else ;
  3167. }
  3168. function traverseChildren(parent, context) {
  3169. let i = 0;
  3170. const nodeRemoved = () => {
  3171. i--;
  3172. };
  3173. for (; i < parent.children.length; i++) {
  3174. const child = parent.children[i];
  3175. if (isString(child)) continue;
  3176. context.grandParent = context.parent;
  3177. context.parent = parent;
  3178. context.childIndex = i;
  3179. context.onNodeRemoved = nodeRemoved;
  3180. traverseNode(child, context);
  3181. }
  3182. }
  3183. function traverseNode(node, context) {
  3184. context.currentNode = node;
  3185. const { nodeTransforms } = context;
  3186. const exitFns = [];
  3187. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  3188. const onExit = nodeTransforms[i2](node, context);
  3189. if (onExit) {
  3190. if (isArray(onExit)) {
  3191. exitFns.push(...onExit);
  3192. } else {
  3193. exitFns.push(onExit);
  3194. }
  3195. }
  3196. if (!context.currentNode) {
  3197. return;
  3198. } else {
  3199. node = context.currentNode;
  3200. }
  3201. }
  3202. switch (node.type) {
  3203. case 3:
  3204. if (!context.ssr) {
  3205. context.helper(CREATE_COMMENT);
  3206. }
  3207. break;
  3208. case 5:
  3209. if (!context.ssr) {
  3210. context.helper(TO_DISPLAY_STRING);
  3211. }
  3212. break;
  3213. // for container types, further traverse downwards
  3214. case 9:
  3215. for (let i2 = 0; i2 < node.branches.length; i2++) {
  3216. traverseNode(node.branches[i2], context);
  3217. }
  3218. break;
  3219. case 10:
  3220. case 11:
  3221. case 1:
  3222. case 0:
  3223. traverseChildren(node, context);
  3224. break;
  3225. }
  3226. context.currentNode = node;
  3227. let i = exitFns.length;
  3228. while (i--) {
  3229. exitFns[i]();
  3230. }
  3231. }
  3232. function createStructuralDirectiveTransform(name, fn) {
  3233. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  3234. return (node, context) => {
  3235. if (node.type === 1) {
  3236. const { props } = node;
  3237. if (node.tagType === 3 && props.some(isVSlot)) {
  3238. return;
  3239. }
  3240. const exitFns = [];
  3241. for (let i = 0; i < props.length; i++) {
  3242. const prop = props[i];
  3243. if (prop.type === 7 && matches(prop.name)) {
  3244. props.splice(i, 1);
  3245. i--;
  3246. const onExit = fn(node, prop, context);
  3247. if (onExit) exitFns.push(onExit);
  3248. }
  3249. }
  3250. return exitFns;
  3251. }
  3252. };
  3253. }
  3254. const PURE_ANNOTATION = `/*@__PURE__*/`;
  3255. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  3256. function createCodegenContext(ast, {
  3257. mode = "function",
  3258. prefixIdentifiers = mode === "module",
  3259. sourceMap = false,
  3260. filename = `template.vue.html`,
  3261. scopeId = null,
  3262. optimizeImports = false,
  3263. runtimeGlobalName = `Vue`,
  3264. runtimeModuleName = `vue`,
  3265. ssrRuntimeModuleName = "vue/server-renderer",
  3266. ssr = false,
  3267. isTS = false,
  3268. inSSR = false
  3269. }) {
  3270. const context = {
  3271. mode,
  3272. prefixIdentifiers,
  3273. sourceMap,
  3274. filename,
  3275. scopeId,
  3276. optimizeImports,
  3277. runtimeGlobalName,
  3278. runtimeModuleName,
  3279. ssrRuntimeModuleName,
  3280. ssr,
  3281. isTS,
  3282. inSSR,
  3283. source: ast.source,
  3284. code: ``,
  3285. column: 1,
  3286. line: 1,
  3287. offset: 0,
  3288. indentLevel: 0,
  3289. pure: false,
  3290. map: void 0,
  3291. helper(key) {
  3292. return `_${helperNameMap[key]}`;
  3293. },
  3294. push(code, newlineIndex = -2 /* None */, node) {
  3295. context.code += code;
  3296. },
  3297. indent() {
  3298. newline(++context.indentLevel);
  3299. },
  3300. deindent(withoutNewLine = false) {
  3301. if (withoutNewLine) {
  3302. --context.indentLevel;
  3303. } else {
  3304. newline(--context.indentLevel);
  3305. }
  3306. },
  3307. newline() {
  3308. newline(context.indentLevel);
  3309. }
  3310. };
  3311. function newline(n) {
  3312. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  3313. }
  3314. return context;
  3315. }
  3316. function generate(ast, options = {}) {
  3317. const context = createCodegenContext(ast, options);
  3318. if (options.onContextCreated) options.onContextCreated(context);
  3319. const {
  3320. mode,
  3321. push,
  3322. prefixIdentifiers,
  3323. indent,
  3324. deindent,
  3325. newline,
  3326. scopeId,
  3327. ssr
  3328. } = context;
  3329. const helpers = Array.from(ast.helpers);
  3330. const hasHelpers = helpers.length > 0;
  3331. const useWithBlock = !prefixIdentifiers && mode !== "module";
  3332. const preambleContext = context;
  3333. {
  3334. genFunctionPreamble(ast, preambleContext);
  3335. }
  3336. const functionName = ssr ? `ssrRender` : `render`;
  3337. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  3338. const signature = args.join(", ");
  3339. {
  3340. push(`function ${functionName}(${signature}) {`);
  3341. }
  3342. indent();
  3343. if (useWithBlock) {
  3344. push(`with (_ctx) {`);
  3345. indent();
  3346. if (hasHelpers) {
  3347. push(
  3348. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  3349. `,
  3350. -1 /* End */
  3351. );
  3352. newline();
  3353. }
  3354. }
  3355. if (ast.components.length) {
  3356. genAssets(ast.components, "component", context);
  3357. if (ast.directives.length || ast.temps > 0) {
  3358. newline();
  3359. }
  3360. }
  3361. if (ast.directives.length) {
  3362. genAssets(ast.directives, "directive", context);
  3363. if (ast.temps > 0) {
  3364. newline();
  3365. }
  3366. }
  3367. if (ast.filters && ast.filters.length) {
  3368. newline();
  3369. genAssets(ast.filters, "filter", context);
  3370. newline();
  3371. }
  3372. if (ast.temps > 0) {
  3373. push(`let `);
  3374. for (let i = 0; i < ast.temps; i++) {
  3375. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  3376. }
  3377. }
  3378. if (ast.components.length || ast.directives.length || ast.temps) {
  3379. push(`
  3380. `, 0 /* Start */);
  3381. newline();
  3382. }
  3383. if (!ssr) {
  3384. push(`return `);
  3385. }
  3386. if (ast.codegenNode) {
  3387. genNode(ast.codegenNode, context);
  3388. } else {
  3389. push(`null`);
  3390. }
  3391. if (useWithBlock) {
  3392. deindent();
  3393. push(`}`);
  3394. }
  3395. deindent();
  3396. push(`}`);
  3397. return {
  3398. ast,
  3399. code: context.code,
  3400. preamble: ``,
  3401. map: context.map ? context.map.toJSON() : void 0
  3402. };
  3403. }
  3404. function genFunctionPreamble(ast, context) {
  3405. const {
  3406. ssr,
  3407. prefixIdentifiers,
  3408. push,
  3409. newline,
  3410. runtimeModuleName,
  3411. runtimeGlobalName,
  3412. ssrRuntimeModuleName
  3413. } = context;
  3414. const VueBinding = runtimeGlobalName;
  3415. const helpers = Array.from(ast.helpers);
  3416. if (helpers.length > 0) {
  3417. {
  3418. push(`const _Vue = ${VueBinding}
  3419. `, -1 /* End */);
  3420. if (ast.hoists.length) {
  3421. const staticHelpers = [
  3422. CREATE_VNODE,
  3423. CREATE_ELEMENT_VNODE,
  3424. CREATE_COMMENT,
  3425. CREATE_TEXT,
  3426. CREATE_STATIC
  3427. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  3428. push(`const { ${staticHelpers} } = _Vue
  3429. `, -1 /* End */);
  3430. }
  3431. }
  3432. }
  3433. genHoists(ast.hoists, context);
  3434. newline();
  3435. push(`return `);
  3436. }
  3437. function genAssets(assets, type, { helper, push, newline, isTS }) {
  3438. const resolver = helper(
  3439. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  3440. );
  3441. for (let i = 0; i < assets.length; i++) {
  3442. let id = assets[i];
  3443. const maybeSelfReference = id.endsWith("__self");
  3444. if (maybeSelfReference) {
  3445. id = id.slice(0, -6);
  3446. }
  3447. push(
  3448. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  3449. );
  3450. if (i < assets.length - 1) {
  3451. newline();
  3452. }
  3453. }
  3454. }
  3455. function genHoists(hoists, context) {
  3456. if (!hoists.length) {
  3457. return;
  3458. }
  3459. context.pure = true;
  3460. const { push, newline } = context;
  3461. newline();
  3462. for (let i = 0; i < hoists.length; i++) {
  3463. const exp = hoists[i];
  3464. if (exp) {
  3465. push(`const _hoisted_${i + 1} = `);
  3466. genNode(exp, context);
  3467. newline();
  3468. }
  3469. }
  3470. context.pure = false;
  3471. }
  3472. function isText(n) {
  3473. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  3474. }
  3475. function genNodeListAsArray(nodes, context) {
  3476. const multilines = nodes.length > 3 || !!(process.env.NODE_ENV !== "production") && nodes.some((n) => isArray(n) || !isText(n));
  3477. context.push(`[`);
  3478. multilines && context.indent();
  3479. genNodeList(nodes, context, multilines);
  3480. multilines && context.deindent();
  3481. context.push(`]`);
  3482. }
  3483. function genNodeList(nodes, context, multilines = false, comma = true) {
  3484. const { push, newline } = context;
  3485. for (let i = 0; i < nodes.length; i++) {
  3486. const node = nodes[i];
  3487. if (isString(node)) {
  3488. push(node, -3 /* Unknown */);
  3489. } else if (isArray(node)) {
  3490. genNodeListAsArray(node, context);
  3491. } else {
  3492. genNode(node, context);
  3493. }
  3494. if (i < nodes.length - 1) {
  3495. if (multilines) {
  3496. comma && push(",");
  3497. newline();
  3498. } else {
  3499. comma && push(", ");
  3500. }
  3501. }
  3502. }
  3503. }
  3504. function genNode(node, context) {
  3505. if (isString(node)) {
  3506. context.push(node, -3 /* Unknown */);
  3507. return;
  3508. }
  3509. if (isSymbol(node)) {
  3510. context.push(context.helper(node));
  3511. return;
  3512. }
  3513. switch (node.type) {
  3514. case 1:
  3515. case 9:
  3516. case 11:
  3517. !!(process.env.NODE_ENV !== "production") && assert(
  3518. node.codegenNode != null,
  3519. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  3520. );
  3521. genNode(node.codegenNode, context);
  3522. break;
  3523. case 2:
  3524. genText(node, context);
  3525. break;
  3526. case 4:
  3527. genExpression(node, context);
  3528. break;
  3529. case 5:
  3530. genInterpolation(node, context);
  3531. break;
  3532. case 12:
  3533. genNode(node.codegenNode, context);
  3534. break;
  3535. case 8:
  3536. genCompoundExpression(node, context);
  3537. break;
  3538. case 3:
  3539. genComment(node, context);
  3540. break;
  3541. case 13:
  3542. genVNodeCall(node, context);
  3543. break;
  3544. case 14:
  3545. genCallExpression(node, context);
  3546. break;
  3547. case 15:
  3548. genObjectExpression(node, context);
  3549. break;
  3550. case 17:
  3551. genArrayExpression(node, context);
  3552. break;
  3553. case 18:
  3554. genFunctionExpression(node, context);
  3555. break;
  3556. case 19:
  3557. genConditionalExpression(node, context);
  3558. break;
  3559. case 20:
  3560. genCacheExpression(node, context);
  3561. break;
  3562. case 21:
  3563. genNodeList(node.body, context, true, false);
  3564. break;
  3565. // SSR only types
  3566. case 22:
  3567. break;
  3568. case 23:
  3569. break;
  3570. case 24:
  3571. break;
  3572. case 25:
  3573. break;
  3574. case 26:
  3575. break;
  3576. /* v8 ignore start */
  3577. case 10:
  3578. break;
  3579. default:
  3580. if (!!(process.env.NODE_ENV !== "production")) {
  3581. assert(false, `unhandled codegen node type: ${node.type}`);
  3582. const exhaustiveCheck = node;
  3583. return exhaustiveCheck;
  3584. }
  3585. }
  3586. }
  3587. function genText(node, context) {
  3588. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  3589. }
  3590. function genExpression(node, context) {
  3591. const { content, isStatic } = node;
  3592. context.push(
  3593. isStatic ? JSON.stringify(content) : content,
  3594. -3 /* Unknown */,
  3595. node
  3596. );
  3597. }
  3598. function genInterpolation(node, context) {
  3599. const { push, helper, pure } = context;
  3600. if (pure) push(PURE_ANNOTATION);
  3601. push(`${helper(TO_DISPLAY_STRING)}(`);
  3602. genNode(node.content, context);
  3603. push(`)`);
  3604. }
  3605. function genCompoundExpression(node, context) {
  3606. for (let i = 0; i < node.children.length; i++) {
  3607. const child = node.children[i];
  3608. if (isString(child)) {
  3609. context.push(child, -3 /* Unknown */);
  3610. } else {
  3611. genNode(child, context);
  3612. }
  3613. }
  3614. }
  3615. function genExpressionAsPropertyKey(node, context) {
  3616. const { push } = context;
  3617. if (node.type === 8) {
  3618. push(`[`);
  3619. genCompoundExpression(node, context);
  3620. push(`]`);
  3621. } else if (node.isStatic) {
  3622. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  3623. push(text, -2 /* None */, node);
  3624. } else {
  3625. push(`[${node.content}]`, -3 /* Unknown */, node);
  3626. }
  3627. }
  3628. function genComment(node, context) {
  3629. const { push, helper, pure } = context;
  3630. if (pure) {
  3631. push(PURE_ANNOTATION);
  3632. }
  3633. push(
  3634. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  3635. -3 /* Unknown */,
  3636. node
  3637. );
  3638. }
  3639. function genVNodeCall(node, context) {
  3640. const { push, helper, pure } = context;
  3641. const {
  3642. tag,
  3643. props,
  3644. children,
  3645. patchFlag,
  3646. dynamicProps,
  3647. directives,
  3648. isBlock,
  3649. disableTracking,
  3650. isComponent
  3651. } = node;
  3652. let patchFlagString;
  3653. if (patchFlag) {
  3654. if (!!(process.env.NODE_ENV !== "production")) {
  3655. if (patchFlag < 0) {
  3656. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3657. } else {
  3658. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3659. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  3660. }
  3661. } else {
  3662. patchFlagString = String(patchFlag);
  3663. }
  3664. }
  3665. if (directives) {
  3666. push(helper(WITH_DIRECTIVES) + `(`);
  3667. }
  3668. if (isBlock) {
  3669. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  3670. }
  3671. if (pure) {
  3672. push(PURE_ANNOTATION);
  3673. }
  3674. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  3675. push(helper(callHelper) + `(`, -2 /* None */, node);
  3676. genNodeList(
  3677. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  3678. context
  3679. );
  3680. push(`)`);
  3681. if (isBlock) {
  3682. push(`)`);
  3683. }
  3684. if (directives) {
  3685. push(`, `);
  3686. genNode(directives, context);
  3687. push(`)`);
  3688. }
  3689. }
  3690. function genNullableArgs(args) {
  3691. let i = args.length;
  3692. while (i--) {
  3693. if (args[i] != null) break;
  3694. }
  3695. return args.slice(0, i + 1).map((arg) => arg || `null`);
  3696. }
  3697. function genCallExpression(node, context) {
  3698. const { push, helper, pure } = context;
  3699. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  3700. if (pure) {
  3701. push(PURE_ANNOTATION);
  3702. }
  3703. push(callee + `(`, -2 /* None */, node);
  3704. genNodeList(node.arguments, context);
  3705. push(`)`);
  3706. }
  3707. function genObjectExpression(node, context) {
  3708. const { push, indent, deindent, newline } = context;
  3709. const { properties } = node;
  3710. if (!properties.length) {
  3711. push(`{}`, -2 /* None */, node);
  3712. return;
  3713. }
  3714. const multilines = properties.length > 1 || !!(process.env.NODE_ENV !== "production") && properties.some((p) => p.value.type !== 4);
  3715. push(multilines ? `{` : `{ `);
  3716. multilines && indent();
  3717. for (let i = 0; i < properties.length; i++) {
  3718. const { key, value } = properties[i];
  3719. genExpressionAsPropertyKey(key, context);
  3720. push(`: `);
  3721. genNode(value, context);
  3722. if (i < properties.length - 1) {
  3723. push(`,`);
  3724. newline();
  3725. }
  3726. }
  3727. multilines && deindent();
  3728. push(multilines ? `}` : ` }`);
  3729. }
  3730. function genArrayExpression(node, context) {
  3731. genNodeListAsArray(node.elements, context);
  3732. }
  3733. function genFunctionExpression(node, context) {
  3734. const { push, indent, deindent } = context;
  3735. const { params, returns, body, newline, isSlot } = node;
  3736. if (isSlot) {
  3737. push(`_${helperNameMap[WITH_CTX]}(`);
  3738. }
  3739. push(`(`, -2 /* None */, node);
  3740. if (isArray(params)) {
  3741. genNodeList(params, context);
  3742. } else if (params) {
  3743. genNode(params, context);
  3744. }
  3745. push(`) => `);
  3746. if (newline || body) {
  3747. push(`{`);
  3748. indent();
  3749. }
  3750. if (returns) {
  3751. if (newline) {
  3752. push(`return `);
  3753. }
  3754. if (isArray(returns)) {
  3755. genNodeListAsArray(returns, context);
  3756. } else {
  3757. genNode(returns, context);
  3758. }
  3759. } else if (body) {
  3760. genNode(body, context);
  3761. }
  3762. if (newline || body) {
  3763. deindent();
  3764. push(`}`);
  3765. }
  3766. if (isSlot) {
  3767. if (node.isNonScopedSlot) {
  3768. push(`, undefined, true`);
  3769. }
  3770. push(`)`);
  3771. }
  3772. }
  3773. function genConditionalExpression(node, context) {
  3774. const { test, consequent, alternate, newline: needNewline } = node;
  3775. const { push, indent, deindent, newline } = context;
  3776. if (test.type === 4) {
  3777. const needsParens = !isSimpleIdentifier(test.content);
  3778. needsParens && push(`(`);
  3779. genExpression(test, context);
  3780. needsParens && push(`)`);
  3781. } else {
  3782. push(`(`);
  3783. genNode(test, context);
  3784. push(`)`);
  3785. }
  3786. needNewline && indent();
  3787. context.indentLevel++;
  3788. needNewline || push(` `);
  3789. push(`? `);
  3790. genNode(consequent, context);
  3791. context.indentLevel--;
  3792. needNewline && newline();
  3793. needNewline || push(` `);
  3794. push(`: `);
  3795. const isNested = alternate.type === 19;
  3796. if (!isNested) {
  3797. context.indentLevel++;
  3798. }
  3799. genNode(alternate, context);
  3800. if (!isNested) {
  3801. context.indentLevel--;
  3802. }
  3803. needNewline && deindent(
  3804. true
  3805. /* without newline */
  3806. );
  3807. }
  3808. function genCacheExpression(node, context) {
  3809. const { push, helper, indent, deindent, newline } = context;
  3810. const { needPauseTracking, needArraySpread } = node;
  3811. if (needArraySpread) {
  3812. push(`[...(`);
  3813. }
  3814. push(`_cache[${node.index}] || (`);
  3815. if (needPauseTracking) {
  3816. indent();
  3817. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  3818. if (node.inVOnce) push(`, true`);
  3819. push(`),`);
  3820. newline();
  3821. push(`(`);
  3822. }
  3823. push(`_cache[${node.index}] = `);
  3824. genNode(node.value, context);
  3825. if (needPauseTracking) {
  3826. push(`).cacheIndex = ${node.index},`);
  3827. newline();
  3828. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  3829. newline();
  3830. push(`_cache[${node.index}]`);
  3831. deindent();
  3832. }
  3833. push(`)`);
  3834. if (needArraySpread) {
  3835. push(`)]`);
  3836. }
  3837. }
  3838. const prohibitedKeywordRE = new RegExp(
  3839. "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
  3840. );
  3841. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  3842. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  3843. const exp = node.content;
  3844. if (!exp.trim()) {
  3845. return;
  3846. }
  3847. try {
  3848. new Function(
  3849. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  3850. );
  3851. } catch (e) {
  3852. let message = e.message;
  3853. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  3854. if (keywordMatch) {
  3855. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  3856. }
  3857. context.onError(
  3858. createCompilerError(
  3859. 45,
  3860. node.loc,
  3861. void 0,
  3862. message
  3863. )
  3864. );
  3865. }
  3866. }
  3867. const transformExpression = (node, context) => {
  3868. if (node.type === 5) {
  3869. node.content = processExpression(
  3870. node.content,
  3871. context
  3872. );
  3873. } else if (node.type === 1) {
  3874. const memo = findDir(node, "memo");
  3875. for (let i = 0; i < node.props.length; i++) {
  3876. const dir = node.props[i];
  3877. if (dir.type === 7 && dir.name !== "for") {
  3878. const exp = dir.exp;
  3879. const arg = dir.arg;
  3880. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  3881. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  3882. dir.exp = processExpression(
  3883. exp,
  3884. context,
  3885. // slot args must be processed as function params
  3886. dir.name === "slot"
  3887. );
  3888. }
  3889. if (arg && arg.type === 4 && !arg.isStatic) {
  3890. dir.arg = processExpression(arg, context);
  3891. }
  3892. }
  3893. }
  3894. }
  3895. };
  3896. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  3897. {
  3898. if (!!(process.env.NODE_ENV !== "production")) {
  3899. validateBrowserExpression(node, context, asParams, asRawStatements);
  3900. }
  3901. return node;
  3902. }
  3903. }
  3904. function stringifyExpression(exp) {
  3905. if (isString(exp)) {
  3906. return exp;
  3907. } else if (exp.type === 4) {
  3908. return exp.content;
  3909. } else {
  3910. return exp.children.map(stringifyExpression).join("");
  3911. }
  3912. }
  3913. const transformIf = createStructuralDirectiveTransform(
  3914. /^(?:if|else|else-if)$/,
  3915. (node, dir, context) => {
  3916. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  3917. const siblings = context.parent.children;
  3918. let i = siblings.indexOf(ifNode);
  3919. let key = 0;
  3920. while (i-- >= 0) {
  3921. const sibling = siblings[i];
  3922. if (sibling && sibling.type === 9) {
  3923. key += sibling.branches.length;
  3924. }
  3925. }
  3926. return () => {
  3927. if (isRoot) {
  3928. ifNode.codegenNode = createCodegenNodeForBranch(
  3929. branch,
  3930. key,
  3931. context
  3932. );
  3933. } else {
  3934. const parentCondition = getParentCondition(ifNode.codegenNode);
  3935. parentCondition.alternate = createCodegenNodeForBranch(
  3936. branch,
  3937. key + ifNode.branches.length - 1,
  3938. context
  3939. );
  3940. }
  3941. };
  3942. });
  3943. }
  3944. );
  3945. function processIf(node, dir, context, processCodegen) {
  3946. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  3947. const loc = dir.exp ? dir.exp.loc : node.loc;
  3948. context.onError(
  3949. createCompilerError(28, dir.loc)
  3950. );
  3951. dir.exp = createSimpleExpression(`true`, false, loc);
  3952. }
  3953. if (!!(process.env.NODE_ENV !== "production") && true && dir.exp) {
  3954. validateBrowserExpression(dir.exp, context);
  3955. }
  3956. if (dir.name === "if") {
  3957. const branch = createIfBranch(node, dir);
  3958. const ifNode = {
  3959. type: 9,
  3960. loc: cloneLoc(node.loc),
  3961. branches: [branch]
  3962. };
  3963. context.replaceNode(ifNode);
  3964. if (processCodegen) {
  3965. return processCodegen(ifNode, branch, true);
  3966. }
  3967. } else {
  3968. const siblings = context.parent.children;
  3969. const comments = [];
  3970. let i = siblings.indexOf(node);
  3971. while (i-- >= -1) {
  3972. const sibling = siblings[i];
  3973. if (sibling && sibling.type === 3) {
  3974. context.removeNode(sibling);
  3975. !!(process.env.NODE_ENV !== "production") && comments.unshift(sibling);
  3976. continue;
  3977. }
  3978. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  3979. context.removeNode(sibling);
  3980. continue;
  3981. }
  3982. if (sibling && sibling.type === 9) {
  3983. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  3984. context.onError(
  3985. createCompilerError(30, node.loc)
  3986. );
  3987. }
  3988. context.removeNode();
  3989. const branch = createIfBranch(node, dir);
  3990. if (!!(process.env.NODE_ENV !== "production") && comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  3991. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  3992. branch.children = [...comments, ...branch.children];
  3993. }
  3994. if (!!(process.env.NODE_ENV !== "production") || false) {
  3995. const key = branch.userKey;
  3996. if (key) {
  3997. sibling.branches.forEach(({ userKey }) => {
  3998. if (isSameKey(userKey, key)) {
  3999. context.onError(
  4000. createCompilerError(
  4001. 29,
  4002. branch.userKey.loc
  4003. )
  4004. );
  4005. }
  4006. });
  4007. }
  4008. }
  4009. sibling.branches.push(branch);
  4010. const onExit = processCodegen && processCodegen(sibling, branch, false);
  4011. traverseNode(branch, context);
  4012. if (onExit) onExit();
  4013. context.currentNode = null;
  4014. } else {
  4015. context.onError(
  4016. createCompilerError(30, node.loc)
  4017. );
  4018. }
  4019. break;
  4020. }
  4021. }
  4022. }
  4023. function createIfBranch(node, dir) {
  4024. const isTemplateIf = node.tagType === 3;
  4025. return {
  4026. type: 10,
  4027. loc: node.loc,
  4028. condition: dir.name === "else" ? void 0 : dir.exp,
  4029. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  4030. userKey: findProp(node, `key`),
  4031. isTemplateIf
  4032. };
  4033. }
  4034. function createCodegenNodeForBranch(branch, keyIndex, context) {
  4035. if (branch.condition) {
  4036. return createConditionalExpression(
  4037. branch.condition,
  4038. createChildrenCodegenNode(branch, keyIndex, context),
  4039. // make sure to pass in asBlock: true so that the comment node call
  4040. // closes the current block.
  4041. createCallExpression(context.helper(CREATE_COMMENT), [
  4042. !!(process.env.NODE_ENV !== "production") ? '"v-if"' : '""',
  4043. "true"
  4044. ])
  4045. );
  4046. } else {
  4047. return createChildrenCodegenNode(branch, keyIndex, context);
  4048. }
  4049. }
  4050. function createChildrenCodegenNode(branch, keyIndex, context) {
  4051. const { helper } = context;
  4052. const keyProperty = createObjectProperty(
  4053. `key`,
  4054. createSimpleExpression(
  4055. `${keyIndex}`,
  4056. false,
  4057. locStub,
  4058. 2
  4059. )
  4060. );
  4061. const { children } = branch;
  4062. const firstChild = children[0];
  4063. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  4064. if (needFragmentWrapper) {
  4065. if (children.length === 1 && firstChild.type === 11) {
  4066. const vnodeCall = firstChild.codegenNode;
  4067. injectProp(vnodeCall, keyProperty, context);
  4068. return vnodeCall;
  4069. } else {
  4070. let patchFlag = 64;
  4071. if (!!(process.env.NODE_ENV !== "production") && !branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  4072. patchFlag |= 2048;
  4073. }
  4074. return createVNodeCall(
  4075. context,
  4076. helper(FRAGMENT),
  4077. createObjectExpression([keyProperty]),
  4078. children,
  4079. patchFlag,
  4080. void 0,
  4081. void 0,
  4082. true,
  4083. false,
  4084. false,
  4085. branch.loc
  4086. );
  4087. }
  4088. } else {
  4089. const ret = firstChild.codegenNode;
  4090. const vnodeCall = getMemoedVNodeCall(ret);
  4091. if (vnodeCall.type === 13) {
  4092. convertToBlock(vnodeCall, context);
  4093. }
  4094. injectProp(vnodeCall, keyProperty, context);
  4095. return ret;
  4096. }
  4097. }
  4098. function isSameKey(a, b) {
  4099. if (!a || a.type !== b.type) {
  4100. return false;
  4101. }
  4102. if (a.type === 6) {
  4103. if (a.value.content !== b.value.content) {
  4104. return false;
  4105. }
  4106. } else {
  4107. const exp = a.exp;
  4108. const branchExp = b.exp;
  4109. if (exp.type !== branchExp.type) {
  4110. return false;
  4111. }
  4112. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  4113. return false;
  4114. }
  4115. }
  4116. return true;
  4117. }
  4118. function getParentCondition(node) {
  4119. while (true) {
  4120. if (node.type === 19) {
  4121. if (node.alternate.type === 19) {
  4122. node = node.alternate;
  4123. } else {
  4124. return node;
  4125. }
  4126. } else if (node.type === 20) {
  4127. node = node.value;
  4128. }
  4129. }
  4130. }
  4131. const transformFor = createStructuralDirectiveTransform(
  4132. "for",
  4133. (node, dir, context) => {
  4134. const { helper, removeHelper } = context;
  4135. return processFor(node, dir, context, (forNode) => {
  4136. const renderExp = createCallExpression(helper(RENDER_LIST), [
  4137. forNode.source
  4138. ]);
  4139. const isTemplate = isTemplateNode(node);
  4140. const memo = findDir(node, "memo");
  4141. const keyProp = findProp(node, `key`, false, true);
  4142. keyProp && keyProp.type === 7;
  4143. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  4144. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  4145. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  4146. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  4147. forNode.codegenNode = createVNodeCall(
  4148. context,
  4149. helper(FRAGMENT),
  4150. void 0,
  4151. renderExp,
  4152. fragmentFlag,
  4153. void 0,
  4154. void 0,
  4155. true,
  4156. !isStableFragment,
  4157. false,
  4158. node.loc
  4159. );
  4160. return () => {
  4161. let childBlock;
  4162. const { children } = forNode;
  4163. if ((!!(process.env.NODE_ENV !== "production") || false) && isTemplate) {
  4164. node.children.some((c) => {
  4165. if (c.type === 1) {
  4166. const key = findProp(c, "key");
  4167. if (key) {
  4168. context.onError(
  4169. createCompilerError(
  4170. 33,
  4171. key.loc
  4172. )
  4173. );
  4174. return true;
  4175. }
  4176. }
  4177. });
  4178. }
  4179. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  4180. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  4181. if (slotOutlet) {
  4182. childBlock = slotOutlet.codegenNode;
  4183. if (isTemplate && keyProperty) {
  4184. injectProp(childBlock, keyProperty, context);
  4185. }
  4186. } else if (needFragmentWrapper) {
  4187. childBlock = createVNodeCall(
  4188. context,
  4189. helper(FRAGMENT),
  4190. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  4191. node.children,
  4192. 64,
  4193. void 0,
  4194. void 0,
  4195. true,
  4196. void 0,
  4197. false
  4198. );
  4199. } else {
  4200. childBlock = children[0].codegenNode;
  4201. if (isTemplate && keyProperty) {
  4202. injectProp(childBlock, keyProperty, context);
  4203. }
  4204. if (childBlock.isBlock !== !isStableFragment) {
  4205. if (childBlock.isBlock) {
  4206. removeHelper(OPEN_BLOCK);
  4207. removeHelper(
  4208. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  4209. );
  4210. } else {
  4211. removeHelper(
  4212. getVNodeHelper(context.inSSR, childBlock.isComponent)
  4213. );
  4214. }
  4215. }
  4216. childBlock.isBlock = !isStableFragment;
  4217. if (childBlock.isBlock) {
  4218. helper(OPEN_BLOCK);
  4219. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  4220. } else {
  4221. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  4222. }
  4223. }
  4224. if (memo) {
  4225. const loop = createFunctionExpression(
  4226. createForLoopParams(forNode.parseResult, [
  4227. createSimpleExpression(`_cached`)
  4228. ])
  4229. );
  4230. loop.body = createBlockStatement([
  4231. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  4232. createCompoundExpression([
  4233. `if (_cached`,
  4234. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  4235. ` && ${context.helperString(
  4236. IS_MEMO_SAME
  4237. )}(_cached, _memo)) return _cached`
  4238. ]),
  4239. createCompoundExpression([`const _item = `, childBlock]),
  4240. createSimpleExpression(`_item.memo = _memo`),
  4241. createSimpleExpression(`return _item`)
  4242. ]);
  4243. renderExp.arguments.push(
  4244. loop,
  4245. createSimpleExpression(`_cache`),
  4246. createSimpleExpression(String(context.cached.length))
  4247. );
  4248. context.cached.push(null);
  4249. } else {
  4250. renderExp.arguments.push(
  4251. createFunctionExpression(
  4252. createForLoopParams(forNode.parseResult),
  4253. childBlock,
  4254. true
  4255. )
  4256. );
  4257. }
  4258. };
  4259. });
  4260. }
  4261. );
  4262. function processFor(node, dir, context, processCodegen) {
  4263. if (!dir.exp) {
  4264. context.onError(
  4265. createCompilerError(31, dir.loc)
  4266. );
  4267. return;
  4268. }
  4269. const parseResult = dir.forParseResult;
  4270. if (!parseResult) {
  4271. context.onError(
  4272. createCompilerError(32, dir.loc)
  4273. );
  4274. return;
  4275. }
  4276. finalizeForParseResult(parseResult, context);
  4277. const { addIdentifiers, removeIdentifiers, scopes } = context;
  4278. const { source, value, key, index } = parseResult;
  4279. const forNode = {
  4280. type: 11,
  4281. loc: dir.loc,
  4282. source,
  4283. valueAlias: value,
  4284. keyAlias: key,
  4285. objectIndexAlias: index,
  4286. parseResult,
  4287. children: isTemplateNode(node) ? node.children : [node]
  4288. };
  4289. context.replaceNode(forNode);
  4290. scopes.vFor++;
  4291. const onExit = processCodegen && processCodegen(forNode);
  4292. return () => {
  4293. scopes.vFor--;
  4294. if (onExit) onExit();
  4295. };
  4296. }
  4297. function finalizeForParseResult(result, context) {
  4298. if (result.finalized) return;
  4299. if (!!(process.env.NODE_ENV !== "production") && true) {
  4300. validateBrowserExpression(result.source, context);
  4301. if (result.key) {
  4302. validateBrowserExpression(
  4303. result.key,
  4304. context,
  4305. true
  4306. );
  4307. }
  4308. if (result.index) {
  4309. validateBrowserExpression(
  4310. result.index,
  4311. context,
  4312. true
  4313. );
  4314. }
  4315. if (result.value) {
  4316. validateBrowserExpression(
  4317. result.value,
  4318. context,
  4319. true
  4320. );
  4321. }
  4322. }
  4323. result.finalized = true;
  4324. }
  4325. function createForLoopParams({ value, key, index }, memoArgs = []) {
  4326. return createParamsList([value, key, index, ...memoArgs]);
  4327. }
  4328. function createParamsList(args) {
  4329. let i = args.length;
  4330. while (i--) {
  4331. if (args[i]) break;
  4332. }
  4333. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  4334. }
  4335. const defaultFallback = createSimpleExpression(`undefined`, false);
  4336. const trackSlotScopes = (node, context) => {
  4337. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  4338. const vSlot = findDir(node, "slot");
  4339. if (vSlot) {
  4340. vSlot.exp;
  4341. context.scopes.vSlot++;
  4342. return () => {
  4343. context.scopes.vSlot--;
  4344. };
  4345. }
  4346. }
  4347. };
  4348. const trackVForSlotScopes = (node, context) => {
  4349. let vFor;
  4350. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  4351. const result = vFor.forParseResult;
  4352. if (result) {
  4353. finalizeForParseResult(result, context);
  4354. const { value, key, index } = result;
  4355. const { addIdentifiers, removeIdentifiers } = context;
  4356. value && addIdentifiers(value);
  4357. key && addIdentifiers(key);
  4358. index && addIdentifiers(index);
  4359. return () => {
  4360. value && removeIdentifiers(value);
  4361. key && removeIdentifiers(key);
  4362. index && removeIdentifiers(index);
  4363. };
  4364. }
  4365. }
  4366. };
  4367. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  4368. props,
  4369. children,
  4370. false,
  4371. true,
  4372. children.length ? children[0].loc : loc
  4373. );
  4374. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  4375. context.helper(WITH_CTX);
  4376. const { children, loc } = node;
  4377. const slotsProperties = [];
  4378. const dynamicSlots = [];
  4379. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  4380. const onComponentSlot = findDir(node, "slot", true);
  4381. if (onComponentSlot) {
  4382. const { arg, exp } = onComponentSlot;
  4383. if (arg && !isStaticExp(arg)) {
  4384. hasDynamicSlots = true;
  4385. }
  4386. slotsProperties.push(
  4387. createObjectProperty(
  4388. arg || createSimpleExpression("default", true),
  4389. buildSlotFn(exp, void 0, children, loc)
  4390. )
  4391. );
  4392. }
  4393. let hasTemplateSlots = false;
  4394. let hasNamedDefaultSlot = false;
  4395. const implicitDefaultChildren = [];
  4396. const seenSlotNames = /* @__PURE__ */ new Set();
  4397. let conditionalBranchIndex = 0;
  4398. for (let i = 0; i < children.length; i++) {
  4399. const slotElement = children[i];
  4400. let slotDir;
  4401. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  4402. if (slotElement.type !== 3) {
  4403. implicitDefaultChildren.push(slotElement);
  4404. }
  4405. continue;
  4406. }
  4407. if (onComponentSlot) {
  4408. context.onError(
  4409. createCompilerError(37, slotDir.loc)
  4410. );
  4411. break;
  4412. }
  4413. hasTemplateSlots = true;
  4414. const { children: slotChildren, loc: slotLoc } = slotElement;
  4415. const {
  4416. arg: slotName = createSimpleExpression(`default`, true),
  4417. exp: slotProps,
  4418. loc: dirLoc
  4419. } = slotDir;
  4420. let staticSlotName;
  4421. if (isStaticExp(slotName)) {
  4422. staticSlotName = slotName ? slotName.content : `default`;
  4423. } else {
  4424. hasDynamicSlots = true;
  4425. }
  4426. const vFor = findDir(slotElement, "for");
  4427. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  4428. let vIf;
  4429. let vElse;
  4430. if (vIf = findDir(slotElement, "if")) {
  4431. hasDynamicSlots = true;
  4432. dynamicSlots.push(
  4433. createConditionalExpression(
  4434. vIf.exp,
  4435. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  4436. defaultFallback
  4437. )
  4438. );
  4439. } else if (vElse = findDir(
  4440. slotElement,
  4441. /^else(?:-if)?$/,
  4442. true
  4443. /* allowEmpty */
  4444. )) {
  4445. let j = i;
  4446. let prev;
  4447. while (j--) {
  4448. prev = children[j];
  4449. if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
  4450. break;
  4451. }
  4452. }
  4453. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  4454. let conditional = dynamicSlots[dynamicSlots.length - 1];
  4455. while (conditional.alternate.type === 19) {
  4456. conditional = conditional.alternate;
  4457. }
  4458. conditional.alternate = vElse.exp ? createConditionalExpression(
  4459. vElse.exp,
  4460. buildDynamicSlot(
  4461. slotName,
  4462. slotFunction,
  4463. conditionalBranchIndex++
  4464. ),
  4465. defaultFallback
  4466. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  4467. } else {
  4468. context.onError(
  4469. createCompilerError(30, vElse.loc)
  4470. );
  4471. }
  4472. } else if (vFor) {
  4473. hasDynamicSlots = true;
  4474. const parseResult = vFor.forParseResult;
  4475. if (parseResult) {
  4476. finalizeForParseResult(parseResult, context);
  4477. dynamicSlots.push(
  4478. createCallExpression(context.helper(RENDER_LIST), [
  4479. parseResult.source,
  4480. createFunctionExpression(
  4481. createForLoopParams(parseResult),
  4482. buildDynamicSlot(slotName, slotFunction),
  4483. true
  4484. )
  4485. ])
  4486. );
  4487. } else {
  4488. context.onError(
  4489. createCompilerError(
  4490. 32,
  4491. vFor.loc
  4492. )
  4493. );
  4494. }
  4495. } else {
  4496. if (staticSlotName) {
  4497. if (seenSlotNames.has(staticSlotName)) {
  4498. context.onError(
  4499. createCompilerError(
  4500. 38,
  4501. dirLoc
  4502. )
  4503. );
  4504. continue;
  4505. }
  4506. seenSlotNames.add(staticSlotName);
  4507. if (staticSlotName === "default") {
  4508. hasNamedDefaultSlot = true;
  4509. }
  4510. }
  4511. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  4512. }
  4513. }
  4514. if (!onComponentSlot) {
  4515. const buildDefaultSlotProperty = (props, children2) => {
  4516. const fn = buildSlotFn(props, void 0, children2, loc);
  4517. if (context.compatConfig) {
  4518. fn.isNonScopedSlot = true;
  4519. }
  4520. return createObjectProperty(`default`, fn);
  4521. };
  4522. if (!hasTemplateSlots) {
  4523. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  4524. } else if (implicitDefaultChildren.length && // #3766
  4525. // with whitespace: 'preserve', whitespaces between slots will end up in
  4526. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  4527. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  4528. if (hasNamedDefaultSlot) {
  4529. context.onError(
  4530. createCompilerError(
  4531. 39,
  4532. implicitDefaultChildren[0].loc
  4533. )
  4534. );
  4535. } else {
  4536. slotsProperties.push(
  4537. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  4538. );
  4539. }
  4540. }
  4541. }
  4542. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  4543. let slots = createObjectExpression(
  4544. slotsProperties.concat(
  4545. createObjectProperty(
  4546. `_`,
  4547. // 2 = compiled but dynamic = can skip normalization, but must run diff
  4548. // 1 = compiled and static = can skip normalization AND diff as optimized
  4549. createSimpleExpression(
  4550. slotFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${slotFlagsText[slotFlag]} */` : ``),
  4551. false
  4552. )
  4553. )
  4554. ),
  4555. loc
  4556. );
  4557. if (dynamicSlots.length) {
  4558. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  4559. slots,
  4560. createArrayExpression(dynamicSlots)
  4561. ]);
  4562. }
  4563. return {
  4564. slots,
  4565. hasDynamicSlots
  4566. };
  4567. }
  4568. function buildDynamicSlot(name, fn, index) {
  4569. const props = [
  4570. createObjectProperty(`name`, name),
  4571. createObjectProperty(`fn`, fn)
  4572. ];
  4573. if (index != null) {
  4574. props.push(
  4575. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  4576. );
  4577. }
  4578. return createObjectExpression(props);
  4579. }
  4580. function hasForwardedSlots(children) {
  4581. for (let i = 0; i < children.length; i++) {
  4582. const child = children[i];
  4583. switch (child.type) {
  4584. case 1:
  4585. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  4586. return true;
  4587. }
  4588. break;
  4589. case 9:
  4590. if (hasForwardedSlots(child.branches)) return true;
  4591. break;
  4592. case 10:
  4593. case 11:
  4594. if (hasForwardedSlots(child.children)) return true;
  4595. break;
  4596. }
  4597. }
  4598. return false;
  4599. }
  4600. function isNonWhitespaceContent(node) {
  4601. if (node.type !== 2 && node.type !== 12)
  4602. return true;
  4603. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  4604. }
  4605. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  4606. const transformElement = (node, context) => {
  4607. return function postTransformElement() {
  4608. node = context.currentNode;
  4609. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  4610. return;
  4611. }
  4612. const { tag, props } = node;
  4613. const isComponent = node.tagType === 1;
  4614. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  4615. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  4616. let vnodeProps;
  4617. let vnodeChildren;
  4618. let patchFlag = 0;
  4619. let vnodeDynamicProps;
  4620. let dynamicPropNames;
  4621. let vnodeDirectives;
  4622. let shouldUseBlock = (
  4623. // dynamic component may resolve to plain elements
  4624. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  4625. // updates inside get proper isSVG flag at runtime. (#639, #643)
  4626. // This is technically web-specific, but splitting the logic out of core
  4627. // leads to too much unnecessary complexity.
  4628. (tag === "svg" || tag === "foreignObject" || tag === "math")
  4629. );
  4630. if (props.length > 0) {
  4631. const propsBuildResult = buildProps(
  4632. node,
  4633. context,
  4634. void 0,
  4635. isComponent,
  4636. isDynamicComponent
  4637. );
  4638. vnodeProps = propsBuildResult.props;
  4639. patchFlag = propsBuildResult.patchFlag;
  4640. dynamicPropNames = propsBuildResult.dynamicPropNames;
  4641. const directives = propsBuildResult.directives;
  4642. vnodeDirectives = directives && directives.length ? createArrayExpression(
  4643. directives.map((dir) => buildDirectiveArgs(dir, context))
  4644. ) : void 0;
  4645. if (propsBuildResult.shouldUseBlock) {
  4646. shouldUseBlock = true;
  4647. }
  4648. }
  4649. if (node.children.length > 0) {
  4650. if (vnodeTag === KEEP_ALIVE) {
  4651. shouldUseBlock = true;
  4652. patchFlag |= 1024;
  4653. if (!!(process.env.NODE_ENV !== "production") && node.children.length > 1) {
  4654. context.onError(
  4655. createCompilerError(46, {
  4656. start: node.children[0].loc.start,
  4657. end: node.children[node.children.length - 1].loc.end,
  4658. source: ""
  4659. })
  4660. );
  4661. }
  4662. }
  4663. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  4664. vnodeTag !== TELEPORT && // explained above.
  4665. vnodeTag !== KEEP_ALIVE;
  4666. if (shouldBuildAsSlots) {
  4667. const { slots, hasDynamicSlots } = buildSlots(node, context);
  4668. vnodeChildren = slots;
  4669. if (hasDynamicSlots) {
  4670. patchFlag |= 1024;
  4671. }
  4672. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  4673. const child = node.children[0];
  4674. const type = child.type;
  4675. const hasDynamicTextChild = type === 5 || type === 8;
  4676. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  4677. patchFlag |= 1;
  4678. }
  4679. if (hasDynamicTextChild || type === 2) {
  4680. vnodeChildren = child;
  4681. } else {
  4682. vnodeChildren = node.children;
  4683. }
  4684. } else {
  4685. vnodeChildren = node.children;
  4686. }
  4687. }
  4688. if (dynamicPropNames && dynamicPropNames.length) {
  4689. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  4690. }
  4691. node.codegenNode = createVNodeCall(
  4692. context,
  4693. vnodeTag,
  4694. vnodeProps,
  4695. vnodeChildren,
  4696. patchFlag === 0 ? void 0 : patchFlag,
  4697. vnodeDynamicProps,
  4698. vnodeDirectives,
  4699. !!shouldUseBlock,
  4700. false,
  4701. isComponent,
  4702. node.loc
  4703. );
  4704. };
  4705. };
  4706. function resolveComponentType(node, context, ssr = false) {
  4707. let { tag } = node;
  4708. const isExplicitDynamic = isComponentTag(tag);
  4709. const isProp = findProp(
  4710. node,
  4711. "is",
  4712. false,
  4713. true
  4714. /* allow empty */
  4715. );
  4716. if (isProp) {
  4717. if (isExplicitDynamic || isCompatEnabled(
  4718. "COMPILER_IS_ON_ELEMENT",
  4719. context
  4720. )) {
  4721. let exp;
  4722. if (isProp.type === 6) {
  4723. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  4724. } else {
  4725. exp = isProp.exp;
  4726. if (!exp) {
  4727. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  4728. }
  4729. }
  4730. if (exp) {
  4731. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  4732. exp
  4733. ]);
  4734. }
  4735. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  4736. tag = isProp.value.content.slice(4);
  4737. }
  4738. }
  4739. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  4740. if (builtIn) {
  4741. if (!ssr) context.helper(builtIn);
  4742. return builtIn;
  4743. }
  4744. context.helper(RESOLVE_COMPONENT);
  4745. context.components.add(tag);
  4746. return toValidAssetId(tag, `component`);
  4747. }
  4748. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  4749. const { tag, loc: elementLoc, children } = node;
  4750. let properties = [];
  4751. const mergeArgs = [];
  4752. const runtimeDirectives = [];
  4753. const hasChildren = children.length > 0;
  4754. let shouldUseBlock = false;
  4755. let patchFlag = 0;
  4756. let hasRef = false;
  4757. let hasClassBinding = false;
  4758. let hasStyleBinding = false;
  4759. let hasHydrationEventBinding = false;
  4760. let hasDynamicKeys = false;
  4761. let hasVnodeHook = false;
  4762. const dynamicPropNames = [];
  4763. const pushMergeArg = (arg) => {
  4764. if (properties.length) {
  4765. mergeArgs.push(
  4766. createObjectExpression(dedupeProperties(properties), elementLoc)
  4767. );
  4768. properties = [];
  4769. }
  4770. if (arg) mergeArgs.push(arg);
  4771. };
  4772. const pushRefVForMarker = () => {
  4773. if (context.scopes.vFor > 0) {
  4774. properties.push(
  4775. createObjectProperty(
  4776. createSimpleExpression("ref_for", true),
  4777. createSimpleExpression("true")
  4778. )
  4779. );
  4780. }
  4781. };
  4782. const analyzePatchFlag = ({ key, value }) => {
  4783. if (isStaticExp(key)) {
  4784. const name = key.content;
  4785. const isEventHandler = isOn(name);
  4786. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  4787. // dedicated fast path.
  4788. name.toLowerCase() !== "onclick" && // omit v-model handlers
  4789. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  4790. !isReservedProp(name)) {
  4791. hasHydrationEventBinding = true;
  4792. }
  4793. if (isEventHandler && isReservedProp(name)) {
  4794. hasVnodeHook = true;
  4795. }
  4796. if (isEventHandler && value.type === 14) {
  4797. value = value.arguments[0];
  4798. }
  4799. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  4800. return;
  4801. }
  4802. if (name === "ref") {
  4803. hasRef = true;
  4804. } else if (name === "class") {
  4805. hasClassBinding = true;
  4806. } else if (name === "style") {
  4807. hasStyleBinding = true;
  4808. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  4809. dynamicPropNames.push(name);
  4810. }
  4811. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  4812. dynamicPropNames.push(name);
  4813. }
  4814. } else {
  4815. hasDynamicKeys = true;
  4816. }
  4817. };
  4818. for (let i = 0; i < props.length; i++) {
  4819. const prop = props[i];
  4820. if (prop.type === 6) {
  4821. const { loc, name, nameLoc, value } = prop;
  4822. let isStatic = true;
  4823. if (name === "ref") {
  4824. hasRef = true;
  4825. pushRefVForMarker();
  4826. }
  4827. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  4828. "COMPILER_IS_ON_ELEMENT",
  4829. context
  4830. ))) {
  4831. continue;
  4832. }
  4833. properties.push(
  4834. createObjectProperty(
  4835. createSimpleExpression(name, true, nameLoc),
  4836. createSimpleExpression(
  4837. value ? value.content : "",
  4838. isStatic,
  4839. value ? value.loc : loc
  4840. )
  4841. )
  4842. );
  4843. } else {
  4844. const { name, arg, exp, loc, modifiers } = prop;
  4845. const isVBind = name === "bind";
  4846. const isVOn = name === "on";
  4847. if (name === "slot") {
  4848. if (!isComponent) {
  4849. context.onError(
  4850. createCompilerError(40, loc)
  4851. );
  4852. }
  4853. continue;
  4854. }
  4855. if (name === "once" || name === "memo") {
  4856. continue;
  4857. }
  4858. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  4859. "COMPILER_IS_ON_ELEMENT",
  4860. context
  4861. ))) {
  4862. continue;
  4863. }
  4864. if (isVOn && ssr) {
  4865. continue;
  4866. }
  4867. if (
  4868. // #938: elements with dynamic keys should be forced into blocks
  4869. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  4870. // before children
  4871. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  4872. ) {
  4873. shouldUseBlock = true;
  4874. }
  4875. if (isVBind && isStaticArgOf(arg, "ref")) {
  4876. pushRefVForMarker();
  4877. }
  4878. if (!arg && (isVBind || isVOn)) {
  4879. hasDynamicKeys = true;
  4880. if (exp) {
  4881. if (isVBind) {
  4882. {
  4883. pushMergeArg();
  4884. if (!!(process.env.NODE_ENV !== "production")) {
  4885. const hasOverridableKeys = mergeArgs.some((arg2) => {
  4886. if (arg2.type === 15) {
  4887. return arg2.properties.some(({ key }) => {
  4888. if (key.type !== 4 || !key.isStatic) {
  4889. return true;
  4890. }
  4891. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  4892. });
  4893. } else {
  4894. return true;
  4895. }
  4896. });
  4897. if (hasOverridableKeys) {
  4898. checkCompatEnabled(
  4899. "COMPILER_V_BIND_OBJECT_ORDER",
  4900. context,
  4901. loc
  4902. );
  4903. }
  4904. }
  4905. if (isCompatEnabled(
  4906. "COMPILER_V_BIND_OBJECT_ORDER",
  4907. context
  4908. )) {
  4909. mergeArgs.unshift(exp);
  4910. continue;
  4911. }
  4912. }
  4913. pushRefVForMarker();
  4914. pushMergeArg();
  4915. mergeArgs.push(exp);
  4916. } else {
  4917. pushMergeArg({
  4918. type: 14,
  4919. loc,
  4920. callee: context.helper(TO_HANDLERS),
  4921. arguments: isComponent ? [exp] : [exp, `true`]
  4922. });
  4923. }
  4924. } else {
  4925. context.onError(
  4926. createCompilerError(
  4927. isVBind ? 34 : 35,
  4928. loc
  4929. )
  4930. );
  4931. }
  4932. continue;
  4933. }
  4934. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  4935. patchFlag |= 32;
  4936. }
  4937. const directiveTransform = context.directiveTransforms[name];
  4938. if (directiveTransform) {
  4939. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  4940. !ssr && props2.forEach(analyzePatchFlag);
  4941. if (isVOn && arg && !isStaticExp(arg)) {
  4942. pushMergeArg(createObjectExpression(props2, elementLoc));
  4943. } else {
  4944. properties.push(...props2);
  4945. }
  4946. if (needRuntime) {
  4947. runtimeDirectives.push(prop);
  4948. if (isSymbol(needRuntime)) {
  4949. directiveImportMap.set(prop, needRuntime);
  4950. }
  4951. }
  4952. } else if (!isBuiltInDirective(name)) {
  4953. runtimeDirectives.push(prop);
  4954. if (hasChildren) {
  4955. shouldUseBlock = true;
  4956. }
  4957. }
  4958. }
  4959. }
  4960. let propsExpression = void 0;
  4961. if (mergeArgs.length) {
  4962. pushMergeArg();
  4963. if (mergeArgs.length > 1) {
  4964. propsExpression = createCallExpression(
  4965. context.helper(MERGE_PROPS),
  4966. mergeArgs,
  4967. elementLoc
  4968. );
  4969. } else {
  4970. propsExpression = mergeArgs[0];
  4971. }
  4972. } else if (properties.length) {
  4973. propsExpression = createObjectExpression(
  4974. dedupeProperties(properties),
  4975. elementLoc
  4976. );
  4977. }
  4978. if (hasDynamicKeys) {
  4979. patchFlag |= 16;
  4980. } else {
  4981. if (hasClassBinding && !isComponent) {
  4982. patchFlag |= 2;
  4983. }
  4984. if (hasStyleBinding && !isComponent) {
  4985. patchFlag |= 4;
  4986. }
  4987. if (dynamicPropNames.length) {
  4988. patchFlag |= 8;
  4989. }
  4990. if (hasHydrationEventBinding) {
  4991. patchFlag |= 32;
  4992. }
  4993. }
  4994. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  4995. patchFlag |= 512;
  4996. }
  4997. if (!context.inSSR && propsExpression) {
  4998. switch (propsExpression.type) {
  4999. case 15:
  5000. let classKeyIndex = -1;
  5001. let styleKeyIndex = -1;
  5002. let hasDynamicKey = false;
  5003. for (let i = 0; i < propsExpression.properties.length; i++) {
  5004. const key = propsExpression.properties[i].key;
  5005. if (isStaticExp(key)) {
  5006. if (key.content === "class") {
  5007. classKeyIndex = i;
  5008. } else if (key.content === "style") {
  5009. styleKeyIndex = i;
  5010. }
  5011. } else if (!key.isHandlerKey) {
  5012. hasDynamicKey = true;
  5013. }
  5014. }
  5015. const classProp = propsExpression.properties[classKeyIndex];
  5016. const styleProp = propsExpression.properties[styleKeyIndex];
  5017. if (!hasDynamicKey) {
  5018. if (classProp && !isStaticExp(classProp.value)) {
  5019. classProp.value = createCallExpression(
  5020. context.helper(NORMALIZE_CLASS),
  5021. [classProp.value]
  5022. );
  5023. }
  5024. if (styleProp && // the static style is compiled into an object,
  5025. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  5026. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  5027. // v-bind:style with static literal object
  5028. styleProp.value.type === 17)) {
  5029. styleProp.value = createCallExpression(
  5030. context.helper(NORMALIZE_STYLE),
  5031. [styleProp.value]
  5032. );
  5033. }
  5034. } else {
  5035. propsExpression = createCallExpression(
  5036. context.helper(NORMALIZE_PROPS),
  5037. [propsExpression]
  5038. );
  5039. }
  5040. break;
  5041. case 14:
  5042. break;
  5043. default:
  5044. propsExpression = createCallExpression(
  5045. context.helper(NORMALIZE_PROPS),
  5046. [
  5047. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  5048. propsExpression
  5049. ])
  5050. ]
  5051. );
  5052. break;
  5053. }
  5054. }
  5055. return {
  5056. props: propsExpression,
  5057. directives: runtimeDirectives,
  5058. patchFlag,
  5059. dynamicPropNames,
  5060. shouldUseBlock
  5061. };
  5062. }
  5063. function dedupeProperties(properties) {
  5064. const knownProps = /* @__PURE__ */ new Map();
  5065. const deduped = [];
  5066. for (let i = 0; i < properties.length; i++) {
  5067. const prop = properties[i];
  5068. if (prop.key.type === 8 || !prop.key.isStatic) {
  5069. deduped.push(prop);
  5070. continue;
  5071. }
  5072. const name = prop.key.content;
  5073. const existing = knownProps.get(name);
  5074. if (existing) {
  5075. if (name === "style" || name === "class" || isOn(name)) {
  5076. mergeAsArray(existing, prop);
  5077. }
  5078. } else {
  5079. knownProps.set(name, prop);
  5080. deduped.push(prop);
  5081. }
  5082. }
  5083. return deduped;
  5084. }
  5085. function mergeAsArray(existing, incoming) {
  5086. if (existing.value.type === 17) {
  5087. existing.value.elements.push(incoming.value);
  5088. } else {
  5089. existing.value = createArrayExpression(
  5090. [existing.value, incoming.value],
  5091. existing.loc
  5092. );
  5093. }
  5094. }
  5095. function buildDirectiveArgs(dir, context) {
  5096. const dirArgs = [];
  5097. const runtime = directiveImportMap.get(dir);
  5098. if (runtime) {
  5099. dirArgs.push(context.helperString(runtime));
  5100. } else {
  5101. {
  5102. context.helper(RESOLVE_DIRECTIVE);
  5103. context.directives.add(dir.name);
  5104. dirArgs.push(toValidAssetId(dir.name, `directive`));
  5105. }
  5106. }
  5107. const { loc } = dir;
  5108. if (dir.exp) dirArgs.push(dir.exp);
  5109. if (dir.arg) {
  5110. if (!dir.exp) {
  5111. dirArgs.push(`void 0`);
  5112. }
  5113. dirArgs.push(dir.arg);
  5114. }
  5115. if (Object.keys(dir.modifiers).length) {
  5116. if (!dir.arg) {
  5117. if (!dir.exp) {
  5118. dirArgs.push(`void 0`);
  5119. }
  5120. dirArgs.push(`void 0`);
  5121. }
  5122. const trueExpression = createSimpleExpression(`true`, false, loc);
  5123. dirArgs.push(
  5124. createObjectExpression(
  5125. dir.modifiers.map(
  5126. (modifier) => createObjectProperty(modifier, trueExpression)
  5127. ),
  5128. loc
  5129. )
  5130. );
  5131. }
  5132. return createArrayExpression(dirArgs, dir.loc);
  5133. }
  5134. function stringifyDynamicPropNames(props) {
  5135. let propsNamesString = `[`;
  5136. for (let i = 0, l = props.length; i < l; i++) {
  5137. propsNamesString += JSON.stringify(props[i]);
  5138. if (i < l - 1) propsNamesString += ", ";
  5139. }
  5140. return propsNamesString + `]`;
  5141. }
  5142. function isComponentTag(tag) {
  5143. return tag === "component" || tag === "Component";
  5144. }
  5145. const transformSlotOutlet = (node, context) => {
  5146. if (isSlotOutlet(node)) {
  5147. const { children, loc } = node;
  5148. const { slotName, slotProps } = processSlotOutlet(node, context);
  5149. const slotArgs = [
  5150. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  5151. slotName,
  5152. "{}",
  5153. "undefined",
  5154. "true"
  5155. ];
  5156. let expectedLen = 2;
  5157. if (slotProps) {
  5158. slotArgs[2] = slotProps;
  5159. expectedLen = 3;
  5160. }
  5161. if (children.length) {
  5162. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  5163. expectedLen = 4;
  5164. }
  5165. if (context.scopeId && !context.slotted) {
  5166. expectedLen = 5;
  5167. }
  5168. slotArgs.splice(expectedLen);
  5169. node.codegenNode = createCallExpression(
  5170. context.helper(RENDER_SLOT),
  5171. slotArgs,
  5172. loc
  5173. );
  5174. }
  5175. };
  5176. function processSlotOutlet(node, context) {
  5177. let slotName = `"default"`;
  5178. let slotProps = void 0;
  5179. const nonNameProps = [];
  5180. for (let i = 0; i < node.props.length; i++) {
  5181. const p = node.props[i];
  5182. if (p.type === 6) {
  5183. if (p.value) {
  5184. if (p.name === "name") {
  5185. slotName = JSON.stringify(p.value.content);
  5186. } else {
  5187. p.name = camelize(p.name);
  5188. nonNameProps.push(p);
  5189. }
  5190. }
  5191. } else {
  5192. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  5193. if (p.exp) {
  5194. slotName = p.exp;
  5195. } else if (p.arg && p.arg.type === 4) {
  5196. const name = camelize(p.arg.content);
  5197. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  5198. }
  5199. } else {
  5200. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  5201. p.arg.content = camelize(p.arg.content);
  5202. }
  5203. nonNameProps.push(p);
  5204. }
  5205. }
  5206. }
  5207. if (nonNameProps.length > 0) {
  5208. const { props, directives } = buildProps(
  5209. node,
  5210. context,
  5211. nonNameProps,
  5212. false,
  5213. false
  5214. );
  5215. slotProps = props;
  5216. if (directives.length) {
  5217. context.onError(
  5218. createCompilerError(
  5219. 36,
  5220. directives[0].loc
  5221. )
  5222. );
  5223. }
  5224. }
  5225. return {
  5226. slotName,
  5227. slotProps
  5228. };
  5229. }
  5230. const transformOn = (dir, node, context, augmentor) => {
  5231. const { loc, modifiers, arg } = dir;
  5232. if (!dir.exp && !modifiers.length) {
  5233. context.onError(createCompilerError(35, loc));
  5234. }
  5235. let eventName;
  5236. if (arg.type === 4) {
  5237. if (arg.isStatic) {
  5238. let rawName = arg.content;
  5239. if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) {
  5240. context.onError(createCompilerError(51, arg.loc));
  5241. }
  5242. if (rawName.startsWith("vue:")) {
  5243. rawName = `vnode-${rawName.slice(4)}`;
  5244. }
  5245. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  5246. // for non-element and vnode lifecycle event listeners, auto convert
  5247. // it to camelCase. See issue #2249
  5248. toHandlerKey(camelize(rawName))
  5249. ) : (
  5250. // preserve case for plain element listeners that have uppercase
  5251. // letters, as these may be custom elements' custom events
  5252. `on:${rawName}`
  5253. );
  5254. eventName = createSimpleExpression(eventString, true, arg.loc);
  5255. } else {
  5256. eventName = createCompoundExpression([
  5257. `${context.helperString(TO_HANDLER_KEY)}(`,
  5258. arg,
  5259. `)`
  5260. ]);
  5261. }
  5262. } else {
  5263. eventName = arg;
  5264. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  5265. eventName.children.push(`)`);
  5266. }
  5267. let exp = dir.exp;
  5268. if (exp && !exp.content.trim()) {
  5269. exp = void 0;
  5270. }
  5271. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  5272. if (exp) {
  5273. const isMemberExp = isMemberExpression(exp);
  5274. const isInlineStatement = !(isMemberExp || isFnExpression(exp));
  5275. const hasMultipleStatements = exp.content.includes(`;`);
  5276. if (!!(process.env.NODE_ENV !== "production") && true) {
  5277. validateBrowserExpression(
  5278. exp,
  5279. context,
  5280. false,
  5281. hasMultipleStatements
  5282. );
  5283. }
  5284. if (isInlineStatement || shouldCache && isMemberExp) {
  5285. exp = createCompoundExpression([
  5286. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  5287. exp,
  5288. hasMultipleStatements ? `}` : `)`
  5289. ]);
  5290. }
  5291. }
  5292. let ret = {
  5293. props: [
  5294. createObjectProperty(
  5295. eventName,
  5296. exp || createSimpleExpression(`() => {}`, false, loc)
  5297. )
  5298. ]
  5299. };
  5300. if (augmentor) {
  5301. ret = augmentor(ret);
  5302. }
  5303. if (shouldCache) {
  5304. ret.props[0].value = context.cache(ret.props[0].value);
  5305. }
  5306. ret.props.forEach((p) => p.key.isHandlerKey = true);
  5307. return ret;
  5308. };
  5309. const transformBind = (dir, _node, context) => {
  5310. const { modifiers, loc } = dir;
  5311. const arg = dir.arg;
  5312. let { exp } = dir;
  5313. if (exp && exp.type === 4 && !exp.content.trim()) {
  5314. {
  5315. exp = void 0;
  5316. }
  5317. }
  5318. if (arg.type !== 4) {
  5319. arg.children.unshift(`(`);
  5320. arg.children.push(`) || ""`);
  5321. } else if (!arg.isStatic) {
  5322. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  5323. }
  5324. if (modifiers.some((mod) => mod.content === "camel")) {
  5325. if (arg.type === 4) {
  5326. if (arg.isStatic) {
  5327. arg.content = camelize(arg.content);
  5328. } else {
  5329. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  5330. }
  5331. } else {
  5332. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  5333. arg.children.push(`)`);
  5334. }
  5335. }
  5336. if (!context.inSSR) {
  5337. if (modifiers.some((mod) => mod.content === "prop")) {
  5338. injectPrefix(arg, ".");
  5339. }
  5340. if (modifiers.some((mod) => mod.content === "attr")) {
  5341. injectPrefix(arg, "^");
  5342. }
  5343. }
  5344. return {
  5345. props: [createObjectProperty(arg, exp)]
  5346. };
  5347. };
  5348. const injectPrefix = (arg, prefix) => {
  5349. if (arg.type === 4) {
  5350. if (arg.isStatic) {
  5351. arg.content = prefix + arg.content;
  5352. } else {
  5353. arg.content = `\`${prefix}\${${arg.content}}\``;
  5354. }
  5355. } else {
  5356. arg.children.unshift(`'${prefix}' + (`);
  5357. arg.children.push(`)`);
  5358. }
  5359. };
  5360. const transformText = (node, context) => {
  5361. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  5362. return () => {
  5363. const children = node.children;
  5364. let currentContainer = void 0;
  5365. let hasText = false;
  5366. for (let i = 0; i < children.length; i++) {
  5367. const child = children[i];
  5368. if (isText$1(child)) {
  5369. hasText = true;
  5370. for (let j = i + 1; j < children.length; j++) {
  5371. const next = children[j];
  5372. if (isText$1(next)) {
  5373. if (!currentContainer) {
  5374. currentContainer = children[i] = createCompoundExpression(
  5375. [child],
  5376. child.loc
  5377. );
  5378. }
  5379. currentContainer.children.push(` + `, next);
  5380. children.splice(j, 1);
  5381. j--;
  5382. } else {
  5383. currentContainer = void 0;
  5384. break;
  5385. }
  5386. }
  5387. }
  5388. }
  5389. if (!hasText || // if this is a plain element with a single text child, leave it
  5390. // as-is since the runtime has dedicated fast path for this by directly
  5391. // setting textContent of the element.
  5392. // for component root it's always normalized anyway.
  5393. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  5394. // custom directives can potentially add DOM elements arbitrarily,
  5395. // we need to avoid setting textContent of the element at runtime
  5396. // to avoid accidentally overwriting the DOM elements added
  5397. // by the user through custom directives.
  5398. !node.props.find(
  5399. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  5400. ) && // in compat mode, <template> tags with no special directives
  5401. // will be rendered as a fragment so its children must be
  5402. // converted into vnodes.
  5403. !(node.tag === "template"))) {
  5404. return;
  5405. }
  5406. for (let i = 0; i < children.length; i++) {
  5407. const child = children[i];
  5408. if (isText$1(child) || child.type === 8) {
  5409. const callArgs = [];
  5410. if (child.type !== 2 || child.content !== " ") {
  5411. callArgs.push(child);
  5412. }
  5413. if (!context.ssr && getConstantType(child, context) === 0) {
  5414. callArgs.push(
  5415. 1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[1]} */` : ``)
  5416. );
  5417. }
  5418. children[i] = {
  5419. type: 12,
  5420. content: child,
  5421. loc: child.loc,
  5422. codegenNode: createCallExpression(
  5423. context.helper(CREATE_TEXT),
  5424. callArgs
  5425. )
  5426. };
  5427. }
  5428. }
  5429. };
  5430. }
  5431. };
  5432. const seen$1 = /* @__PURE__ */ new WeakSet();
  5433. const transformOnce = (node, context) => {
  5434. if (node.type === 1 && findDir(node, "once", true)) {
  5435. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  5436. return;
  5437. }
  5438. seen$1.add(node);
  5439. context.inVOnce = true;
  5440. context.helper(SET_BLOCK_TRACKING);
  5441. return () => {
  5442. context.inVOnce = false;
  5443. const cur = context.currentNode;
  5444. if (cur.codegenNode) {
  5445. cur.codegenNode = context.cache(
  5446. cur.codegenNode,
  5447. true,
  5448. true
  5449. );
  5450. }
  5451. };
  5452. }
  5453. };
  5454. const transformModel = (dir, node, context) => {
  5455. const { exp, arg } = dir;
  5456. if (!exp) {
  5457. context.onError(
  5458. createCompilerError(41, dir.loc)
  5459. );
  5460. return createTransformProps();
  5461. }
  5462. const rawExp = exp.loc.source.trim();
  5463. const expString = exp.type === 4 ? exp.content : rawExp;
  5464. const bindingType = context.bindingMetadata[rawExp];
  5465. if (bindingType === "props" || bindingType === "props-aliased") {
  5466. context.onError(createCompilerError(44, exp.loc));
  5467. return createTransformProps();
  5468. }
  5469. if (!expString.trim() || !isMemberExpression(exp) && true) {
  5470. context.onError(
  5471. createCompilerError(42, exp.loc)
  5472. );
  5473. return createTransformProps();
  5474. }
  5475. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  5476. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  5477. let assignmentExp;
  5478. const eventArg = context.isTS ? `($event: any)` : `$event`;
  5479. {
  5480. assignmentExp = createCompoundExpression([
  5481. `${eventArg} => ((`,
  5482. exp,
  5483. `) = $event)`
  5484. ]);
  5485. }
  5486. const props = [
  5487. // modelValue: foo
  5488. createObjectProperty(propName, dir.exp),
  5489. // "onUpdate:modelValue": $event => (foo = $event)
  5490. createObjectProperty(eventName, assignmentExp)
  5491. ];
  5492. if (dir.modifiers.length && node.tagType === 1) {
  5493. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  5494. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  5495. props.push(
  5496. createObjectProperty(
  5497. modifiersKey,
  5498. createSimpleExpression(
  5499. `{ ${modifiers} }`,
  5500. false,
  5501. dir.loc,
  5502. 2
  5503. )
  5504. )
  5505. );
  5506. }
  5507. return createTransformProps(props);
  5508. };
  5509. function createTransformProps(props = []) {
  5510. return { props };
  5511. }
  5512. const validDivisionCharRE = /[\w).+\-_$\]]/;
  5513. const transformFilter = (node, context) => {
  5514. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  5515. return;
  5516. }
  5517. if (node.type === 5) {
  5518. rewriteFilter(node.content, context);
  5519. } else if (node.type === 1) {
  5520. node.props.forEach((prop) => {
  5521. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  5522. rewriteFilter(prop.exp, context);
  5523. }
  5524. });
  5525. }
  5526. };
  5527. function rewriteFilter(node, context) {
  5528. if (node.type === 4) {
  5529. parseFilter(node, context);
  5530. } else {
  5531. for (let i = 0; i < node.children.length; i++) {
  5532. const child = node.children[i];
  5533. if (typeof child !== "object") continue;
  5534. if (child.type === 4) {
  5535. parseFilter(child, context);
  5536. } else if (child.type === 8) {
  5537. rewriteFilter(node, context);
  5538. } else if (child.type === 5) {
  5539. rewriteFilter(child.content, context);
  5540. }
  5541. }
  5542. }
  5543. }
  5544. function parseFilter(node, context) {
  5545. const exp = node.content;
  5546. let inSingle = false;
  5547. let inDouble = false;
  5548. let inTemplateString = false;
  5549. let inRegex = false;
  5550. let curly = 0;
  5551. let square = 0;
  5552. let paren = 0;
  5553. let lastFilterIndex = 0;
  5554. let c, prev, i, expression, filters = [];
  5555. for (i = 0; i < exp.length; i++) {
  5556. prev = c;
  5557. c = exp.charCodeAt(i);
  5558. if (inSingle) {
  5559. if (c === 39 && prev !== 92) inSingle = false;
  5560. } else if (inDouble) {
  5561. if (c === 34 && prev !== 92) inDouble = false;
  5562. } else if (inTemplateString) {
  5563. if (c === 96 && prev !== 92) inTemplateString = false;
  5564. } else if (inRegex) {
  5565. if (c === 47 && prev !== 92) inRegex = false;
  5566. } else if (c === 124 && // pipe
  5567. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  5568. if (expression === void 0) {
  5569. lastFilterIndex = i + 1;
  5570. expression = exp.slice(0, i).trim();
  5571. } else {
  5572. pushFilter();
  5573. }
  5574. } else {
  5575. switch (c) {
  5576. case 34:
  5577. inDouble = true;
  5578. break;
  5579. // "
  5580. case 39:
  5581. inSingle = true;
  5582. break;
  5583. // '
  5584. case 96:
  5585. inTemplateString = true;
  5586. break;
  5587. // `
  5588. case 40:
  5589. paren++;
  5590. break;
  5591. // (
  5592. case 41:
  5593. paren--;
  5594. break;
  5595. // )
  5596. case 91:
  5597. square++;
  5598. break;
  5599. // [
  5600. case 93:
  5601. square--;
  5602. break;
  5603. // ]
  5604. case 123:
  5605. curly++;
  5606. break;
  5607. // {
  5608. case 125:
  5609. curly--;
  5610. break;
  5611. }
  5612. if (c === 47) {
  5613. let j = i - 1;
  5614. let p;
  5615. for (; j >= 0; j--) {
  5616. p = exp.charAt(j);
  5617. if (p !== " ") break;
  5618. }
  5619. if (!p || !validDivisionCharRE.test(p)) {
  5620. inRegex = true;
  5621. }
  5622. }
  5623. }
  5624. }
  5625. if (expression === void 0) {
  5626. expression = exp.slice(0, i).trim();
  5627. } else if (lastFilterIndex !== 0) {
  5628. pushFilter();
  5629. }
  5630. function pushFilter() {
  5631. filters.push(exp.slice(lastFilterIndex, i).trim());
  5632. lastFilterIndex = i + 1;
  5633. }
  5634. if (filters.length) {
  5635. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  5636. "COMPILER_FILTERS",
  5637. context,
  5638. node.loc
  5639. );
  5640. for (i = 0; i < filters.length; i++) {
  5641. expression = wrapFilter(expression, filters[i], context);
  5642. }
  5643. node.content = expression;
  5644. node.ast = void 0;
  5645. }
  5646. }
  5647. function wrapFilter(exp, filter, context) {
  5648. context.helper(RESOLVE_FILTER);
  5649. const i = filter.indexOf("(");
  5650. if (i < 0) {
  5651. context.filters.add(filter);
  5652. return `${toValidAssetId(filter, "filter")}(${exp})`;
  5653. } else {
  5654. const name = filter.slice(0, i);
  5655. const args = filter.slice(i + 1);
  5656. context.filters.add(name);
  5657. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  5658. }
  5659. }
  5660. const seen = /* @__PURE__ */ new WeakSet();
  5661. const transformMemo = (node, context) => {
  5662. if (node.type === 1) {
  5663. const dir = findDir(node, "memo");
  5664. if (!dir || seen.has(node) || context.inSSR) {
  5665. return;
  5666. }
  5667. seen.add(node);
  5668. return () => {
  5669. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  5670. if (codegenNode && codegenNode.type === 13) {
  5671. if (node.tagType !== 1) {
  5672. convertToBlock(codegenNode, context);
  5673. }
  5674. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  5675. dir.exp,
  5676. createFunctionExpression(void 0, codegenNode),
  5677. `_cache`,
  5678. String(context.cached.length)
  5679. ]);
  5680. context.cached.push(null);
  5681. }
  5682. };
  5683. }
  5684. };
  5685. const transformVBindShorthand = (node, context) => {
  5686. if (node.type === 1) {
  5687. for (const prop of node.props) {
  5688. if (prop.type === 7 && prop.name === "bind" && !prop.exp) {
  5689. const arg = prop.arg;
  5690. if (arg.type !== 4 || !arg.isStatic) {
  5691. context.onError(
  5692. createCompilerError(
  5693. 52,
  5694. arg.loc
  5695. )
  5696. );
  5697. prop.exp = createSimpleExpression("", true, arg.loc);
  5698. } else {
  5699. const propName = camelize(arg.content);
  5700. if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
  5701. propName[0] === "-") {
  5702. prop.exp = createSimpleExpression(propName, false, arg.loc);
  5703. }
  5704. }
  5705. }
  5706. }
  5707. }
  5708. };
  5709. function getBaseTransformPreset(prefixIdentifiers) {
  5710. return [
  5711. [
  5712. transformVBindShorthand,
  5713. transformOnce,
  5714. transformIf,
  5715. transformMemo,
  5716. transformFor,
  5717. ...[transformFilter] ,
  5718. ...!!(process.env.NODE_ENV !== "production") ? [transformExpression] : [],
  5719. transformSlotOutlet,
  5720. transformElement,
  5721. trackSlotScopes,
  5722. transformText
  5723. ],
  5724. {
  5725. on: transformOn,
  5726. bind: transformBind,
  5727. model: transformModel
  5728. }
  5729. ];
  5730. }
  5731. function baseCompile(source, options = {}) {
  5732. const onError = options.onError || defaultOnError;
  5733. const isModuleMode = options.mode === "module";
  5734. {
  5735. if (options.prefixIdentifiers === true) {
  5736. onError(createCompilerError(47));
  5737. } else if (isModuleMode) {
  5738. onError(createCompilerError(48));
  5739. }
  5740. }
  5741. const prefixIdentifiers = false;
  5742. if (options.cacheHandlers) {
  5743. onError(createCompilerError(49));
  5744. }
  5745. if (options.scopeId && !isModuleMode) {
  5746. onError(createCompilerError(50));
  5747. }
  5748. const resolvedOptions = extend({}, options, {
  5749. prefixIdentifiers
  5750. });
  5751. const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
  5752. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  5753. transform(
  5754. ast,
  5755. extend({}, resolvedOptions, {
  5756. nodeTransforms: [
  5757. ...nodeTransforms,
  5758. ...options.nodeTransforms || []
  5759. // user transforms
  5760. ],
  5761. directiveTransforms: extend(
  5762. {},
  5763. directiveTransforms,
  5764. options.directiveTransforms || {}
  5765. // user transforms
  5766. )
  5767. })
  5768. );
  5769. return generate(ast, resolvedOptions);
  5770. }
  5771. const BindingTypes = {
  5772. "DATA": "data",
  5773. "PROPS": "props",
  5774. "PROPS_ALIASED": "props-aliased",
  5775. "SETUP_LET": "setup-let",
  5776. "SETUP_CONST": "setup-const",
  5777. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  5778. "SETUP_MAYBE_REF": "setup-maybe-ref",
  5779. "SETUP_REF": "setup-ref",
  5780. "OPTIONS": "options",
  5781. "LITERAL_CONST": "literal-const"
  5782. };
  5783. const noopDirectiveTransform = () => ({ props: [] });
  5784. export { BASE_TRANSITION, BindingTypes, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, CompilerDeprecationTypes, ConstantTypes, ElementTypes, ErrorCodes, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, Namespaces, NodeTypes, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, forAliasRE, generate, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isCoreComponent, isFnExpression, isFnExpressionBrowser, isFnExpressionNode, isFunctionType, isInDestructureAssignment, isInNewExpression, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVPre, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, transformVBindShorthand, traverseNode, unwrapTSNode, validFirstIdentCharRE, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };