53c09455ab579e7c184314086caa4f9a55e86d6ef205caa725a16b3160183027fb78d2902f3e01ca51b7ede0b79debe0d5c49f33cc99b341319f941d146dc1 169 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796
  1. /**
  2. * @vue/compiler-core v3.5.21
  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. for (const stmt of block.body) {
  1512. if (stmt.type === "VariableDeclaration") {
  1513. if (stmt.declare) continue;
  1514. for (const decl of stmt.declarations) {
  1515. for (const id of extractIdentifiers(decl.id)) {
  1516. onIdent(id);
  1517. }
  1518. }
  1519. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  1520. if (stmt.declare || !stmt.id) continue;
  1521. onIdent(stmt.id);
  1522. } else if (isForStatement(stmt)) {
  1523. walkForStatement(stmt, true, onIdent);
  1524. }
  1525. }
  1526. }
  1527. function isForStatement(stmt) {
  1528. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  1529. }
  1530. function walkForStatement(stmt, isVar, onIdent) {
  1531. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  1532. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  1533. for (const decl of variable.declarations) {
  1534. for (const id of extractIdentifiers(decl.id)) {
  1535. onIdent(id);
  1536. }
  1537. }
  1538. }
  1539. }
  1540. function extractIdentifiers(param, nodes = []) {
  1541. switch (param.type) {
  1542. case "Identifier":
  1543. nodes.push(param);
  1544. break;
  1545. case "MemberExpression":
  1546. let object = param;
  1547. while (object.type === "MemberExpression") {
  1548. object = object.object;
  1549. }
  1550. nodes.push(object);
  1551. break;
  1552. case "ObjectPattern":
  1553. for (const prop of param.properties) {
  1554. if (prop.type === "RestElement") {
  1555. extractIdentifiers(prop.argument, nodes);
  1556. } else {
  1557. extractIdentifiers(prop.value, nodes);
  1558. }
  1559. }
  1560. break;
  1561. case "ArrayPattern":
  1562. param.elements.forEach((element) => {
  1563. if (element) extractIdentifiers(element, nodes);
  1564. });
  1565. break;
  1566. case "RestElement":
  1567. extractIdentifiers(param.argument, nodes);
  1568. break;
  1569. case "AssignmentPattern":
  1570. extractIdentifiers(param.left, nodes);
  1571. break;
  1572. }
  1573. return nodes;
  1574. }
  1575. const isFunctionType = (node) => {
  1576. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  1577. };
  1578. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  1579. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  1580. const TS_NODE_TYPES = [
  1581. "TSAsExpression",
  1582. // foo as number
  1583. "TSTypeAssertion",
  1584. // (<number>foo)
  1585. "TSNonNullExpression",
  1586. // foo!
  1587. "TSInstantiationExpression",
  1588. // foo<string>
  1589. "TSSatisfiesExpression"
  1590. // foo satisfies T
  1591. ];
  1592. function unwrapTSNode(node) {
  1593. if (TS_NODE_TYPES.includes(node.type)) {
  1594. return unwrapTSNode(node.expression);
  1595. } else {
  1596. return node;
  1597. }
  1598. }
  1599. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  1600. function isCoreComponent(tag) {
  1601. switch (tag) {
  1602. case "Teleport":
  1603. case "teleport":
  1604. return TELEPORT;
  1605. case "Suspense":
  1606. case "suspense":
  1607. return SUSPENSE;
  1608. case "KeepAlive":
  1609. case "keep-alive":
  1610. return KEEP_ALIVE;
  1611. case "BaseTransition":
  1612. case "base-transition":
  1613. return BASE_TRANSITION;
  1614. }
  1615. }
  1616. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  1617. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  1618. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  1619. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  1620. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  1621. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  1622. const isMemberExpressionBrowser = (exp) => {
  1623. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  1624. let state = 0 /* inMemberExp */;
  1625. let stateStack = [];
  1626. let currentOpenBracketCount = 0;
  1627. let currentOpenParensCount = 0;
  1628. let currentStringType = null;
  1629. for (let i = 0; i < path.length; i++) {
  1630. const char = path.charAt(i);
  1631. switch (state) {
  1632. case 0 /* inMemberExp */:
  1633. if (char === "[") {
  1634. stateStack.push(state);
  1635. state = 1 /* inBrackets */;
  1636. currentOpenBracketCount++;
  1637. } else if (char === "(") {
  1638. stateStack.push(state);
  1639. state = 2 /* inParens */;
  1640. currentOpenParensCount++;
  1641. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  1642. return false;
  1643. }
  1644. break;
  1645. case 1 /* inBrackets */:
  1646. if (char === `'` || char === `"` || char === "`") {
  1647. stateStack.push(state);
  1648. state = 3 /* inString */;
  1649. currentStringType = char;
  1650. } else if (char === `[`) {
  1651. currentOpenBracketCount++;
  1652. } else if (char === `]`) {
  1653. if (!--currentOpenBracketCount) {
  1654. state = stateStack.pop();
  1655. }
  1656. }
  1657. break;
  1658. case 2 /* inParens */:
  1659. if (char === `'` || char === `"` || char === "`") {
  1660. stateStack.push(state);
  1661. state = 3 /* inString */;
  1662. currentStringType = char;
  1663. } else if (char === `(`) {
  1664. currentOpenParensCount++;
  1665. } else if (char === `)`) {
  1666. if (i === path.length - 1) {
  1667. return false;
  1668. }
  1669. if (!--currentOpenParensCount) {
  1670. state = stateStack.pop();
  1671. }
  1672. }
  1673. break;
  1674. case 3 /* inString */:
  1675. if (char === currentStringType) {
  1676. state = stateStack.pop();
  1677. currentStringType = null;
  1678. }
  1679. break;
  1680. }
  1681. }
  1682. return !currentOpenBracketCount && !currentOpenParensCount;
  1683. };
  1684. const isMemberExpressionNode = NOOP ;
  1685. const isMemberExpression = isMemberExpressionBrowser ;
  1686. const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  1687. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  1688. const isFnExpressionNode = NOOP ;
  1689. const isFnExpression = isFnExpressionBrowser ;
  1690. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  1691. return advancePositionWithMutation(
  1692. {
  1693. offset: pos.offset,
  1694. line: pos.line,
  1695. column: pos.column
  1696. },
  1697. source,
  1698. numberOfCharacters
  1699. );
  1700. }
  1701. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  1702. let linesCount = 0;
  1703. let lastNewLinePos = -1;
  1704. for (let i = 0; i < numberOfCharacters; i++) {
  1705. if (source.charCodeAt(i) === 10) {
  1706. linesCount++;
  1707. lastNewLinePos = i;
  1708. }
  1709. }
  1710. pos.offset += numberOfCharacters;
  1711. pos.line += linesCount;
  1712. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  1713. return pos;
  1714. }
  1715. function assert(condition, msg) {
  1716. if (!condition) {
  1717. throw new Error(msg || `unexpected compiler condition`);
  1718. }
  1719. }
  1720. function findDir(node, name, allowEmpty = false) {
  1721. for (let i = 0; i < node.props.length; i++) {
  1722. const p = node.props[i];
  1723. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  1724. return p;
  1725. }
  1726. }
  1727. }
  1728. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  1729. for (let i = 0; i < node.props.length; i++) {
  1730. const p = node.props[i];
  1731. if (p.type === 6) {
  1732. if (dynamicOnly) continue;
  1733. if (p.name === name && (p.value || allowEmpty)) {
  1734. return p;
  1735. }
  1736. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  1737. return p;
  1738. }
  1739. }
  1740. }
  1741. function isStaticArgOf(arg, name) {
  1742. return !!(arg && isStaticExp(arg) && arg.content === name);
  1743. }
  1744. function hasDynamicKeyVBind(node) {
  1745. return node.props.some(
  1746. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  1747. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  1748. !p.arg.isStatic)
  1749. // v-bind:[foo]
  1750. );
  1751. }
  1752. function isText$1(node) {
  1753. return node.type === 5 || node.type === 2;
  1754. }
  1755. function isVPre(p) {
  1756. return p.type === 7 && p.name === "pre";
  1757. }
  1758. function isVSlot(p) {
  1759. return p.type === 7 && p.name === "slot";
  1760. }
  1761. function isTemplateNode(node) {
  1762. return node.type === 1 && node.tagType === 3;
  1763. }
  1764. function isSlotOutlet(node) {
  1765. return node.type === 1 && node.tagType === 2;
  1766. }
  1767. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  1768. function getUnnormalizedProps(props, callPath = []) {
  1769. if (props && !isString(props) && props.type === 14) {
  1770. const callee = props.callee;
  1771. if (!isString(callee) && propsHelperSet.has(callee)) {
  1772. return getUnnormalizedProps(
  1773. props.arguments[0],
  1774. callPath.concat(props)
  1775. );
  1776. }
  1777. }
  1778. return [props, callPath];
  1779. }
  1780. function injectProp(node, prop, context) {
  1781. let propsWithInjection;
  1782. let props = node.type === 13 ? node.props : node.arguments[2];
  1783. let callPath = [];
  1784. let parentCall;
  1785. if (props && !isString(props) && props.type === 14) {
  1786. const ret = getUnnormalizedProps(props);
  1787. props = ret[0];
  1788. callPath = ret[1];
  1789. parentCall = callPath[callPath.length - 1];
  1790. }
  1791. if (props == null || isString(props)) {
  1792. propsWithInjection = createObjectExpression([prop]);
  1793. } else if (props.type === 14) {
  1794. const first = props.arguments[0];
  1795. if (!isString(first) && first.type === 15) {
  1796. if (!hasProp(prop, first)) {
  1797. first.properties.unshift(prop);
  1798. }
  1799. } else {
  1800. if (props.callee === TO_HANDLERS) {
  1801. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1802. createObjectExpression([prop]),
  1803. props
  1804. ]);
  1805. } else {
  1806. props.arguments.unshift(createObjectExpression([prop]));
  1807. }
  1808. }
  1809. !propsWithInjection && (propsWithInjection = props);
  1810. } else if (props.type === 15) {
  1811. if (!hasProp(prop, props)) {
  1812. props.properties.unshift(prop);
  1813. }
  1814. propsWithInjection = props;
  1815. } else {
  1816. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1817. createObjectExpression([prop]),
  1818. props
  1819. ]);
  1820. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  1821. parentCall = callPath[callPath.length - 2];
  1822. }
  1823. }
  1824. if (node.type === 13) {
  1825. if (parentCall) {
  1826. parentCall.arguments[0] = propsWithInjection;
  1827. } else {
  1828. node.props = propsWithInjection;
  1829. }
  1830. } else {
  1831. if (parentCall) {
  1832. parentCall.arguments[0] = propsWithInjection;
  1833. } else {
  1834. node.arguments[2] = propsWithInjection;
  1835. }
  1836. }
  1837. }
  1838. function hasProp(prop, props) {
  1839. let result = false;
  1840. if (prop.key.type === 4) {
  1841. const propKeyName = prop.key.content;
  1842. result = props.properties.some(
  1843. (p) => p.key.type === 4 && p.key.content === propKeyName
  1844. );
  1845. }
  1846. return result;
  1847. }
  1848. function toValidAssetId(name, type) {
  1849. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  1850. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  1851. })}`;
  1852. }
  1853. function hasScopeRef(node, ids) {
  1854. if (!node || Object.keys(ids).length === 0) {
  1855. return false;
  1856. }
  1857. switch (node.type) {
  1858. case 1:
  1859. for (let i = 0; i < node.props.length; i++) {
  1860. const p = node.props[i];
  1861. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  1862. return true;
  1863. }
  1864. }
  1865. return node.children.some((c) => hasScopeRef(c, ids));
  1866. case 11:
  1867. if (hasScopeRef(node.source, ids)) {
  1868. return true;
  1869. }
  1870. return node.children.some((c) => hasScopeRef(c, ids));
  1871. case 9:
  1872. return node.branches.some((b) => hasScopeRef(b, ids));
  1873. case 10:
  1874. if (hasScopeRef(node.condition, ids)) {
  1875. return true;
  1876. }
  1877. return node.children.some((c) => hasScopeRef(c, ids));
  1878. case 4:
  1879. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  1880. case 8:
  1881. return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
  1882. case 5:
  1883. case 12:
  1884. return hasScopeRef(node.content, ids);
  1885. case 2:
  1886. case 3:
  1887. case 20:
  1888. return false;
  1889. default:
  1890. if (!!(process.env.NODE_ENV !== "production")) ;
  1891. return false;
  1892. }
  1893. }
  1894. function getMemoedVNodeCall(node) {
  1895. if (node.type === 14 && node.callee === WITH_MEMO) {
  1896. return node.arguments[1].returns;
  1897. } else {
  1898. return node;
  1899. }
  1900. }
  1901. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  1902. const defaultParserOptions = {
  1903. parseMode: "base",
  1904. ns: 0,
  1905. delimiters: [`{{`, `}}`],
  1906. getNamespace: () => 0,
  1907. isVoidTag: NO,
  1908. isPreTag: NO,
  1909. isIgnoreNewlineTag: NO,
  1910. isCustomElement: NO,
  1911. onError: defaultOnError,
  1912. onWarn: defaultOnWarn,
  1913. comments: !!(process.env.NODE_ENV !== "production"),
  1914. prefixIdentifiers: false
  1915. };
  1916. let currentOptions = defaultParserOptions;
  1917. let currentRoot = null;
  1918. let currentInput = "";
  1919. let currentOpenTag = null;
  1920. let currentProp = null;
  1921. let currentAttrValue = "";
  1922. let currentAttrStartIndex = -1;
  1923. let currentAttrEndIndex = -1;
  1924. let inPre = 0;
  1925. let inVPre = false;
  1926. let currentVPreBoundary = null;
  1927. const stack = [];
  1928. const tokenizer = new Tokenizer(stack, {
  1929. onerr: emitError,
  1930. ontext(start, end) {
  1931. onText(getSlice(start, end), start, end);
  1932. },
  1933. ontextentity(char, start, end) {
  1934. onText(char, start, end);
  1935. },
  1936. oninterpolation(start, end) {
  1937. if (inVPre) {
  1938. return onText(getSlice(start, end), start, end);
  1939. }
  1940. let innerStart = start + tokenizer.delimiterOpen.length;
  1941. let innerEnd = end - tokenizer.delimiterClose.length;
  1942. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  1943. innerStart++;
  1944. }
  1945. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  1946. innerEnd--;
  1947. }
  1948. let exp = getSlice(innerStart, innerEnd);
  1949. if (exp.includes("&")) {
  1950. {
  1951. exp = currentOptions.decodeEntities(exp, false);
  1952. }
  1953. }
  1954. addNode({
  1955. type: 5,
  1956. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  1957. loc: getLoc(start, end)
  1958. });
  1959. },
  1960. onopentagname(start, end) {
  1961. const name = getSlice(start, end);
  1962. currentOpenTag = {
  1963. type: 1,
  1964. tag: name,
  1965. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  1966. tagType: 0,
  1967. // will be refined on tag close
  1968. props: [],
  1969. children: [],
  1970. loc: getLoc(start - 1, end),
  1971. codegenNode: void 0
  1972. };
  1973. },
  1974. onopentagend(end) {
  1975. endOpenTag(end);
  1976. },
  1977. onclosetag(start, end) {
  1978. const name = getSlice(start, end);
  1979. if (!currentOptions.isVoidTag(name)) {
  1980. let found = false;
  1981. for (let i = 0; i < stack.length; i++) {
  1982. const e = stack[i];
  1983. if (e.tag.toLowerCase() === name.toLowerCase()) {
  1984. found = true;
  1985. if (i > 0) {
  1986. emitError(24, stack[0].loc.start.offset);
  1987. }
  1988. for (let j = 0; j <= i; j++) {
  1989. const el = stack.shift();
  1990. onCloseTag(el, end, j < i);
  1991. }
  1992. break;
  1993. }
  1994. }
  1995. if (!found) {
  1996. emitError(23, backTrack(start, 60));
  1997. }
  1998. }
  1999. },
  2000. onselfclosingtag(end) {
  2001. const name = currentOpenTag.tag;
  2002. currentOpenTag.isSelfClosing = true;
  2003. endOpenTag(end);
  2004. if (stack[0] && stack[0].tag === name) {
  2005. onCloseTag(stack.shift(), end);
  2006. }
  2007. },
  2008. onattribname(start, end) {
  2009. currentProp = {
  2010. type: 6,
  2011. name: getSlice(start, end),
  2012. nameLoc: getLoc(start, end),
  2013. value: void 0,
  2014. loc: getLoc(start)
  2015. };
  2016. },
  2017. ondirname(start, end) {
  2018. const raw = getSlice(start, end);
  2019. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  2020. if (!inVPre && name === "") {
  2021. emitError(26, start);
  2022. }
  2023. if (inVPre || name === "") {
  2024. currentProp = {
  2025. type: 6,
  2026. name: raw,
  2027. nameLoc: getLoc(start, end),
  2028. value: void 0,
  2029. loc: getLoc(start)
  2030. };
  2031. } else {
  2032. currentProp = {
  2033. type: 7,
  2034. name,
  2035. rawName: raw,
  2036. exp: void 0,
  2037. arg: void 0,
  2038. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  2039. loc: getLoc(start)
  2040. };
  2041. if (name === "pre") {
  2042. inVPre = tokenizer.inVPre = true;
  2043. currentVPreBoundary = currentOpenTag;
  2044. const props = currentOpenTag.props;
  2045. for (let i = 0; i < props.length; i++) {
  2046. if (props[i].type === 7) {
  2047. props[i] = dirToAttr(props[i]);
  2048. }
  2049. }
  2050. }
  2051. }
  2052. },
  2053. ondirarg(start, end) {
  2054. if (start === end) return;
  2055. const arg = getSlice(start, end);
  2056. if (inVPre && !isVPre(currentProp)) {
  2057. currentProp.name += arg;
  2058. setLocEnd(currentProp.nameLoc, end);
  2059. } else {
  2060. const isStatic = arg[0] !== `[`;
  2061. currentProp.arg = createExp(
  2062. isStatic ? arg : arg.slice(1, -1),
  2063. isStatic,
  2064. getLoc(start, end),
  2065. isStatic ? 3 : 0
  2066. );
  2067. }
  2068. },
  2069. ondirmodifier(start, end) {
  2070. const mod = getSlice(start, end);
  2071. if (inVPre && !isVPre(currentProp)) {
  2072. currentProp.name += "." + mod;
  2073. setLocEnd(currentProp.nameLoc, end);
  2074. } else if (currentProp.name === "slot") {
  2075. const arg = currentProp.arg;
  2076. if (arg) {
  2077. arg.content += "." + mod;
  2078. setLocEnd(arg.loc, end);
  2079. }
  2080. } else {
  2081. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  2082. currentProp.modifiers.push(exp);
  2083. }
  2084. },
  2085. onattribdata(start, end) {
  2086. currentAttrValue += getSlice(start, end);
  2087. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2088. currentAttrEndIndex = end;
  2089. },
  2090. onattribentity(char, start, end) {
  2091. currentAttrValue += char;
  2092. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2093. currentAttrEndIndex = end;
  2094. },
  2095. onattribnameend(end) {
  2096. const start = currentProp.loc.start.offset;
  2097. const name = getSlice(start, end);
  2098. if (currentProp.type === 7) {
  2099. currentProp.rawName = name;
  2100. }
  2101. if (currentOpenTag.props.some(
  2102. (p) => (p.type === 7 ? p.rawName : p.name) === name
  2103. )) {
  2104. emitError(2, start);
  2105. }
  2106. },
  2107. onattribend(quote, end) {
  2108. if (currentOpenTag && currentProp) {
  2109. setLocEnd(currentProp.loc, end);
  2110. if (quote !== 0) {
  2111. if (currentAttrValue.includes("&")) {
  2112. currentAttrValue = currentOptions.decodeEntities(
  2113. currentAttrValue,
  2114. true
  2115. );
  2116. }
  2117. if (currentProp.type === 6) {
  2118. if (currentProp.name === "class") {
  2119. currentAttrValue = condense(currentAttrValue).trim();
  2120. }
  2121. if (quote === 1 && !currentAttrValue) {
  2122. emitError(13, end);
  2123. }
  2124. currentProp.value = {
  2125. type: 2,
  2126. content: currentAttrValue,
  2127. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  2128. };
  2129. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  2130. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  2131. }
  2132. } else {
  2133. let expParseMode = 0 /* Normal */;
  2134. currentProp.exp = createExp(
  2135. currentAttrValue,
  2136. false,
  2137. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  2138. 0,
  2139. expParseMode
  2140. );
  2141. if (currentProp.name === "for") {
  2142. currentProp.forParseResult = parseForExpression(currentProp.exp);
  2143. }
  2144. let syncIndex = -1;
  2145. if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
  2146. (mod) => mod.content === "sync"
  2147. )) > -1 && checkCompatEnabled(
  2148. "COMPILER_V_BIND_SYNC",
  2149. currentOptions,
  2150. currentProp.loc,
  2151. currentProp.arg.loc.source
  2152. )) {
  2153. currentProp.name = "model";
  2154. currentProp.modifiers.splice(syncIndex, 1);
  2155. }
  2156. }
  2157. }
  2158. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  2159. currentOpenTag.props.push(currentProp);
  2160. }
  2161. }
  2162. currentAttrValue = "";
  2163. currentAttrStartIndex = currentAttrEndIndex = -1;
  2164. },
  2165. oncomment(start, end) {
  2166. if (currentOptions.comments) {
  2167. addNode({
  2168. type: 3,
  2169. content: getSlice(start, end),
  2170. loc: getLoc(start - 4, end + 3)
  2171. });
  2172. }
  2173. },
  2174. onend() {
  2175. const end = currentInput.length;
  2176. if ((!!(process.env.NODE_ENV !== "production") || false) && tokenizer.state !== 1) {
  2177. switch (tokenizer.state) {
  2178. case 5:
  2179. case 8:
  2180. emitError(5, end);
  2181. break;
  2182. case 3:
  2183. case 4:
  2184. emitError(
  2185. 25,
  2186. tokenizer.sectionStart
  2187. );
  2188. break;
  2189. case 28:
  2190. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  2191. emitError(6, end);
  2192. } else {
  2193. emitError(7, end);
  2194. }
  2195. break;
  2196. case 6:
  2197. case 7:
  2198. case 9:
  2199. case 11:
  2200. case 12:
  2201. case 13:
  2202. case 14:
  2203. case 15:
  2204. case 16:
  2205. case 17:
  2206. case 18:
  2207. case 19:
  2208. // "
  2209. case 20:
  2210. // '
  2211. case 21:
  2212. emitError(9, end);
  2213. break;
  2214. }
  2215. }
  2216. for (let index = 0; index < stack.length; index++) {
  2217. onCloseTag(stack[index], end - 1);
  2218. emitError(24, stack[index].loc.start.offset);
  2219. }
  2220. },
  2221. oncdata(start, end) {
  2222. if (stack[0].ns !== 0) {
  2223. onText(getSlice(start, end), start, end);
  2224. } else {
  2225. emitError(1, start - 9);
  2226. }
  2227. },
  2228. onprocessinginstruction(start) {
  2229. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2230. emitError(
  2231. 21,
  2232. start - 1
  2233. );
  2234. }
  2235. }
  2236. });
  2237. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  2238. const stripParensRE = /^\(|\)$/g;
  2239. function parseForExpression(input) {
  2240. const loc = input.loc;
  2241. const exp = input.content;
  2242. const inMatch = exp.match(forAliasRE);
  2243. if (!inMatch) return;
  2244. const [, LHS, RHS] = inMatch;
  2245. const createAliasExpression = (content, offset, asParam = false) => {
  2246. const start = loc.start.offset + offset;
  2247. const end = start + content.length;
  2248. return createExp(
  2249. content,
  2250. false,
  2251. getLoc(start, end),
  2252. 0,
  2253. asParam ? 1 /* Params */ : 0 /* Normal */
  2254. );
  2255. };
  2256. const result = {
  2257. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  2258. value: void 0,
  2259. key: void 0,
  2260. index: void 0,
  2261. finalized: false
  2262. };
  2263. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  2264. const trimmedOffset = LHS.indexOf(valueContent);
  2265. const iteratorMatch = valueContent.match(forIteratorRE);
  2266. if (iteratorMatch) {
  2267. valueContent = valueContent.replace(forIteratorRE, "").trim();
  2268. const keyContent = iteratorMatch[1].trim();
  2269. let keyOffset;
  2270. if (keyContent) {
  2271. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  2272. result.key = createAliasExpression(keyContent, keyOffset, true);
  2273. }
  2274. if (iteratorMatch[2]) {
  2275. const indexContent = iteratorMatch[2].trim();
  2276. if (indexContent) {
  2277. result.index = createAliasExpression(
  2278. indexContent,
  2279. exp.indexOf(
  2280. indexContent,
  2281. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  2282. ),
  2283. true
  2284. );
  2285. }
  2286. }
  2287. }
  2288. if (valueContent) {
  2289. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  2290. }
  2291. return result;
  2292. }
  2293. function getSlice(start, end) {
  2294. return currentInput.slice(start, end);
  2295. }
  2296. function endOpenTag(end) {
  2297. if (tokenizer.inSFCRoot) {
  2298. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  2299. }
  2300. addNode(currentOpenTag);
  2301. const { tag, ns } = currentOpenTag;
  2302. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2303. inPre++;
  2304. }
  2305. if (currentOptions.isVoidTag(tag)) {
  2306. onCloseTag(currentOpenTag, end);
  2307. } else {
  2308. stack.unshift(currentOpenTag);
  2309. if (ns === 1 || ns === 2) {
  2310. tokenizer.inXML = true;
  2311. }
  2312. }
  2313. currentOpenTag = null;
  2314. }
  2315. function onText(content, start, end) {
  2316. {
  2317. const tag = stack[0] && stack[0].tag;
  2318. if (tag !== "script" && tag !== "style" && content.includes("&")) {
  2319. content = currentOptions.decodeEntities(content, false);
  2320. }
  2321. }
  2322. const parent = stack[0] || currentRoot;
  2323. const lastNode = parent.children[parent.children.length - 1];
  2324. if (lastNode && lastNode.type === 2) {
  2325. lastNode.content += content;
  2326. setLocEnd(lastNode.loc, end);
  2327. } else {
  2328. parent.children.push({
  2329. type: 2,
  2330. content,
  2331. loc: getLoc(start, end)
  2332. });
  2333. }
  2334. }
  2335. function onCloseTag(el, end, isImplied = false) {
  2336. if (isImplied) {
  2337. setLocEnd(el.loc, backTrack(end, 60));
  2338. } else {
  2339. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  2340. }
  2341. if (tokenizer.inSFCRoot) {
  2342. if (el.children.length) {
  2343. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  2344. } else {
  2345. el.innerLoc.end = extend({}, el.innerLoc.start);
  2346. }
  2347. el.innerLoc.source = getSlice(
  2348. el.innerLoc.start.offset,
  2349. el.innerLoc.end.offset
  2350. );
  2351. }
  2352. const { tag, ns, children } = el;
  2353. if (!inVPre) {
  2354. if (tag === "slot") {
  2355. el.tagType = 2;
  2356. } else if (isFragmentTemplate(el)) {
  2357. el.tagType = 3;
  2358. } else if (isComponent(el)) {
  2359. el.tagType = 1;
  2360. }
  2361. }
  2362. if (!tokenizer.inRCDATA) {
  2363. el.children = condenseWhitespace(children);
  2364. }
  2365. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  2366. const first = children[0];
  2367. if (first && first.type === 2) {
  2368. first.content = first.content.replace(/^\r?\n/, "");
  2369. }
  2370. }
  2371. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2372. inPre--;
  2373. }
  2374. if (currentVPreBoundary === el) {
  2375. inVPre = tokenizer.inVPre = false;
  2376. currentVPreBoundary = null;
  2377. }
  2378. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2379. tokenizer.inXML = false;
  2380. }
  2381. {
  2382. const props = el.props;
  2383. if (!!(process.env.NODE_ENV !== "production") && isCompatEnabled(
  2384. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2385. currentOptions
  2386. )) {
  2387. let hasIf = false;
  2388. let hasFor = false;
  2389. for (let i = 0; i < props.length; i++) {
  2390. const p = props[i];
  2391. if (p.type === 7) {
  2392. if (p.name === "if") {
  2393. hasIf = true;
  2394. } else if (p.name === "for") {
  2395. hasFor = true;
  2396. }
  2397. }
  2398. if (hasIf && hasFor) {
  2399. warnDeprecation(
  2400. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2401. currentOptions,
  2402. el.loc
  2403. );
  2404. break;
  2405. }
  2406. }
  2407. }
  2408. if (!tokenizer.inSFCRoot && isCompatEnabled(
  2409. "COMPILER_NATIVE_TEMPLATE",
  2410. currentOptions
  2411. ) && el.tag === "template" && !isFragmentTemplate(el)) {
  2412. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  2413. "COMPILER_NATIVE_TEMPLATE",
  2414. currentOptions,
  2415. el.loc
  2416. );
  2417. const parent = stack[0] || currentRoot;
  2418. const index = parent.children.indexOf(el);
  2419. parent.children.splice(index, 1, ...el.children);
  2420. }
  2421. const inlineTemplateProp = props.find(
  2422. (p) => p.type === 6 && p.name === "inline-template"
  2423. );
  2424. if (inlineTemplateProp && checkCompatEnabled(
  2425. "COMPILER_INLINE_TEMPLATE",
  2426. currentOptions,
  2427. inlineTemplateProp.loc
  2428. ) && el.children.length) {
  2429. inlineTemplateProp.value = {
  2430. type: 2,
  2431. content: getSlice(
  2432. el.children[0].loc.start.offset,
  2433. el.children[el.children.length - 1].loc.end.offset
  2434. ),
  2435. loc: inlineTemplateProp.loc
  2436. };
  2437. }
  2438. }
  2439. }
  2440. function lookAhead(index, c) {
  2441. let i = index;
  2442. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  2443. return i;
  2444. }
  2445. function backTrack(index, c) {
  2446. let i = index;
  2447. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  2448. return i;
  2449. }
  2450. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  2451. function isFragmentTemplate({ tag, props }) {
  2452. if (tag === "template") {
  2453. for (let i = 0; i < props.length; i++) {
  2454. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  2455. return true;
  2456. }
  2457. }
  2458. }
  2459. return false;
  2460. }
  2461. function isComponent({ tag, props }) {
  2462. if (currentOptions.isCustomElement(tag)) {
  2463. return false;
  2464. }
  2465. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  2466. return true;
  2467. }
  2468. for (let i = 0; i < props.length; i++) {
  2469. const p = props[i];
  2470. if (p.type === 6) {
  2471. if (p.name === "is" && p.value) {
  2472. if (p.value.content.startsWith("vue:")) {
  2473. return true;
  2474. } else if (checkCompatEnabled(
  2475. "COMPILER_IS_ON_ELEMENT",
  2476. currentOptions,
  2477. p.loc
  2478. )) {
  2479. return true;
  2480. }
  2481. }
  2482. } else if (// :is on plain element - only treat as component in compat mode
  2483. p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
  2484. "COMPILER_IS_ON_ELEMENT",
  2485. currentOptions,
  2486. p.loc
  2487. )) {
  2488. return true;
  2489. }
  2490. }
  2491. return false;
  2492. }
  2493. function isUpperCase(c) {
  2494. return c > 64 && c < 91;
  2495. }
  2496. const windowsNewlineRE = /\r\n/g;
  2497. function condenseWhitespace(nodes) {
  2498. const shouldCondense = currentOptions.whitespace !== "preserve";
  2499. let removedWhitespace = false;
  2500. for (let i = 0; i < nodes.length; i++) {
  2501. const node = nodes[i];
  2502. if (node.type === 2) {
  2503. if (!inPre) {
  2504. if (isAllWhitespace(node.content)) {
  2505. const prev = nodes[i - 1] && nodes[i - 1].type;
  2506. const next = nodes[i + 1] && nodes[i + 1].type;
  2507. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  2508. removedWhitespace = true;
  2509. nodes[i] = null;
  2510. } else {
  2511. node.content = " ";
  2512. }
  2513. } else if (shouldCondense) {
  2514. node.content = condense(node.content);
  2515. }
  2516. } else {
  2517. node.content = node.content.replace(windowsNewlineRE, "\n");
  2518. }
  2519. }
  2520. }
  2521. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  2522. }
  2523. function isAllWhitespace(str) {
  2524. for (let i = 0; i < str.length; i++) {
  2525. if (!isWhitespace(str.charCodeAt(i))) {
  2526. return false;
  2527. }
  2528. }
  2529. return true;
  2530. }
  2531. function hasNewlineChar(str) {
  2532. for (let i = 0; i < str.length; i++) {
  2533. const c = str.charCodeAt(i);
  2534. if (c === 10 || c === 13) {
  2535. return true;
  2536. }
  2537. }
  2538. return false;
  2539. }
  2540. function condense(str) {
  2541. let ret = "";
  2542. let prevCharIsWhitespace = false;
  2543. for (let i = 0; i < str.length; i++) {
  2544. if (isWhitespace(str.charCodeAt(i))) {
  2545. if (!prevCharIsWhitespace) {
  2546. ret += " ";
  2547. prevCharIsWhitespace = true;
  2548. }
  2549. } else {
  2550. ret += str[i];
  2551. prevCharIsWhitespace = false;
  2552. }
  2553. }
  2554. return ret;
  2555. }
  2556. function addNode(node) {
  2557. (stack[0] || currentRoot).children.push(node);
  2558. }
  2559. function getLoc(start, end) {
  2560. return {
  2561. start: tokenizer.getPos(start),
  2562. // @ts-expect-error allow late attachment
  2563. end: end == null ? end : tokenizer.getPos(end),
  2564. // @ts-expect-error allow late attachment
  2565. source: end == null ? end : getSlice(start, end)
  2566. };
  2567. }
  2568. function cloneLoc(loc) {
  2569. return getLoc(loc.start.offset, loc.end.offset);
  2570. }
  2571. function setLocEnd(loc, end) {
  2572. loc.end = tokenizer.getPos(end);
  2573. loc.source = getSlice(loc.start.offset, end);
  2574. }
  2575. function dirToAttr(dir) {
  2576. const attr = {
  2577. type: 6,
  2578. name: dir.rawName,
  2579. nameLoc: getLoc(
  2580. dir.loc.start.offset,
  2581. dir.loc.start.offset + dir.rawName.length
  2582. ),
  2583. value: void 0,
  2584. loc: dir.loc
  2585. };
  2586. if (dir.exp) {
  2587. const loc = dir.exp.loc;
  2588. if (loc.end.offset < dir.loc.end.offset) {
  2589. loc.start.offset--;
  2590. loc.start.column--;
  2591. loc.end.offset++;
  2592. loc.end.column++;
  2593. }
  2594. attr.value = {
  2595. type: 2,
  2596. content: dir.exp.content,
  2597. loc
  2598. };
  2599. }
  2600. return attr;
  2601. }
  2602. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  2603. const exp = createSimpleExpression(content, isStatic, loc, constType);
  2604. return exp;
  2605. }
  2606. function emitError(code, index, message) {
  2607. currentOptions.onError(
  2608. createCompilerError(code, getLoc(index, index), void 0, message)
  2609. );
  2610. }
  2611. function reset() {
  2612. tokenizer.reset();
  2613. currentOpenTag = null;
  2614. currentProp = null;
  2615. currentAttrValue = "";
  2616. currentAttrStartIndex = -1;
  2617. currentAttrEndIndex = -1;
  2618. stack.length = 0;
  2619. }
  2620. function baseParse(input, options) {
  2621. reset();
  2622. currentInput = input;
  2623. currentOptions = extend({}, defaultParserOptions);
  2624. if (options) {
  2625. let key;
  2626. for (key in options) {
  2627. if (options[key] != null) {
  2628. currentOptions[key] = options[key];
  2629. }
  2630. }
  2631. }
  2632. if (!!(process.env.NODE_ENV !== "production")) {
  2633. if (!currentOptions.decodeEntities) {
  2634. throw new Error(
  2635. `[@vue/compiler-core] decodeEntities option is required in browser builds.`
  2636. );
  2637. }
  2638. }
  2639. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  2640. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  2641. const delimiters = options && options.delimiters;
  2642. if (delimiters) {
  2643. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  2644. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  2645. }
  2646. const root = currentRoot = createRoot([], input);
  2647. tokenizer.parse(currentInput);
  2648. root.loc = getLoc(0, input.length);
  2649. root.children = condenseWhitespace(root.children);
  2650. currentRoot = null;
  2651. return root;
  2652. }
  2653. function cacheStatic(root, context) {
  2654. walk(
  2655. root,
  2656. void 0,
  2657. context,
  2658. // Root node is unfortunately non-hoistable due to potential parent
  2659. // fallthrough attributes.
  2660. !!getSingleElementRoot(root)
  2661. );
  2662. }
  2663. function getSingleElementRoot(root) {
  2664. const children = root.children.filter((x) => x.type !== 3);
  2665. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  2666. }
  2667. function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
  2668. const { children } = node;
  2669. const toCache = [];
  2670. for (let i = 0; i < children.length; i++) {
  2671. const child = children[i];
  2672. if (child.type === 1 && child.tagType === 0) {
  2673. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2674. if (constantType > 0) {
  2675. if (constantType >= 2) {
  2676. child.codegenNode.patchFlag = -1;
  2677. toCache.push(child);
  2678. continue;
  2679. }
  2680. } else {
  2681. const codegenNode = child.codegenNode;
  2682. if (codegenNode.type === 13) {
  2683. const flag = codegenNode.patchFlag;
  2684. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  2685. const props = getNodeProps(child);
  2686. if (props) {
  2687. codegenNode.props = context.hoist(props);
  2688. }
  2689. }
  2690. if (codegenNode.dynamicProps) {
  2691. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  2692. }
  2693. }
  2694. }
  2695. } else if (child.type === 12) {
  2696. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2697. if (constantType >= 2) {
  2698. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  2699. child.codegenNode.arguments.push(
  2700. -1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[-1]} */` : ``)
  2701. );
  2702. }
  2703. toCache.push(child);
  2704. continue;
  2705. }
  2706. }
  2707. if (child.type === 1) {
  2708. const isComponent = child.tagType === 1;
  2709. if (isComponent) {
  2710. context.scopes.vSlot++;
  2711. }
  2712. walk(child, node, context, false, inFor);
  2713. if (isComponent) {
  2714. context.scopes.vSlot--;
  2715. }
  2716. } else if (child.type === 11) {
  2717. walk(child, node, context, child.children.length === 1, true);
  2718. } else if (child.type === 9) {
  2719. for (let i2 = 0; i2 < child.branches.length; i2++) {
  2720. walk(
  2721. child.branches[i2],
  2722. node,
  2723. context,
  2724. child.branches[i2].children.length === 1,
  2725. inFor
  2726. );
  2727. }
  2728. }
  2729. }
  2730. let cachedAsArray = false;
  2731. if (toCache.length === children.length && node.type === 1) {
  2732. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  2733. node.codegenNode.children = getCacheExpression(
  2734. createArrayExpression(node.codegenNode.children)
  2735. );
  2736. cachedAsArray = true;
  2737. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  2738. const slot = getSlotNode(node.codegenNode, "default");
  2739. if (slot) {
  2740. slot.returns = getCacheExpression(
  2741. createArrayExpression(slot.returns)
  2742. );
  2743. cachedAsArray = true;
  2744. }
  2745. } 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) {
  2746. const slotName = findDir(node, "slot", true);
  2747. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  2748. if (slot) {
  2749. slot.returns = getCacheExpression(
  2750. createArrayExpression(slot.returns)
  2751. );
  2752. cachedAsArray = true;
  2753. }
  2754. }
  2755. }
  2756. if (!cachedAsArray) {
  2757. for (const child of toCache) {
  2758. child.codegenNode = context.cache(child.codegenNode);
  2759. }
  2760. }
  2761. function getCacheExpression(value) {
  2762. const exp = context.cache(value);
  2763. exp.needArraySpread = true;
  2764. return exp;
  2765. }
  2766. function getSlotNode(node2, name) {
  2767. if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
  2768. const slot = node2.children.properties.find(
  2769. (p) => p.key === name || p.key.content === name
  2770. );
  2771. return slot && slot.value;
  2772. }
  2773. }
  2774. if (toCache.length && context.transformHoist) {
  2775. context.transformHoist(children, context, node);
  2776. }
  2777. }
  2778. function getConstantType(node, context) {
  2779. const { constantCache } = context;
  2780. switch (node.type) {
  2781. case 1:
  2782. if (node.tagType !== 0) {
  2783. return 0;
  2784. }
  2785. const cached = constantCache.get(node);
  2786. if (cached !== void 0) {
  2787. return cached;
  2788. }
  2789. const codegenNode = node.codegenNode;
  2790. if (codegenNode.type !== 13) {
  2791. return 0;
  2792. }
  2793. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  2794. return 0;
  2795. }
  2796. if (codegenNode.patchFlag === void 0) {
  2797. let returnType2 = 3;
  2798. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  2799. if (generatedPropsType === 0) {
  2800. constantCache.set(node, 0);
  2801. return 0;
  2802. }
  2803. if (generatedPropsType < returnType2) {
  2804. returnType2 = generatedPropsType;
  2805. }
  2806. for (let i = 0; i < node.children.length; i++) {
  2807. const childType = getConstantType(node.children[i], context);
  2808. if (childType === 0) {
  2809. constantCache.set(node, 0);
  2810. return 0;
  2811. }
  2812. if (childType < returnType2) {
  2813. returnType2 = childType;
  2814. }
  2815. }
  2816. if (returnType2 > 1) {
  2817. for (let i = 0; i < node.props.length; i++) {
  2818. const p = node.props[i];
  2819. if (p.type === 7 && p.name === "bind" && p.exp) {
  2820. const expType = getConstantType(p.exp, context);
  2821. if (expType === 0) {
  2822. constantCache.set(node, 0);
  2823. return 0;
  2824. }
  2825. if (expType < returnType2) {
  2826. returnType2 = expType;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. if (codegenNode.isBlock) {
  2832. for (let i = 0; i < node.props.length; i++) {
  2833. const p = node.props[i];
  2834. if (p.type === 7) {
  2835. constantCache.set(node, 0);
  2836. return 0;
  2837. }
  2838. }
  2839. context.removeHelper(OPEN_BLOCK);
  2840. context.removeHelper(
  2841. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  2842. );
  2843. codegenNode.isBlock = false;
  2844. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  2845. }
  2846. constantCache.set(node, returnType2);
  2847. return returnType2;
  2848. } else {
  2849. constantCache.set(node, 0);
  2850. return 0;
  2851. }
  2852. case 2:
  2853. case 3:
  2854. return 3;
  2855. case 9:
  2856. case 11:
  2857. case 10:
  2858. return 0;
  2859. case 5:
  2860. case 12:
  2861. return getConstantType(node.content, context);
  2862. case 4:
  2863. return node.constType;
  2864. case 8:
  2865. let returnType = 3;
  2866. for (let i = 0; i < node.children.length; i++) {
  2867. const child = node.children[i];
  2868. if (isString(child) || isSymbol(child)) {
  2869. continue;
  2870. }
  2871. const childType = getConstantType(child, context);
  2872. if (childType === 0) {
  2873. return 0;
  2874. } else if (childType < returnType) {
  2875. returnType = childType;
  2876. }
  2877. }
  2878. return returnType;
  2879. case 20:
  2880. return 2;
  2881. default:
  2882. if (!!(process.env.NODE_ENV !== "production")) ;
  2883. return 0;
  2884. }
  2885. }
  2886. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  2887. NORMALIZE_CLASS,
  2888. NORMALIZE_STYLE,
  2889. NORMALIZE_PROPS,
  2890. GUARD_REACTIVE_PROPS
  2891. ]);
  2892. function getConstantTypeOfHelperCall(value, context) {
  2893. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  2894. const arg = value.arguments[0];
  2895. if (arg.type === 4) {
  2896. return getConstantType(arg, context);
  2897. } else if (arg.type === 14) {
  2898. return getConstantTypeOfHelperCall(arg, context);
  2899. }
  2900. }
  2901. return 0;
  2902. }
  2903. function getGeneratedPropsConstantType(node, context) {
  2904. let returnType = 3;
  2905. const props = getNodeProps(node);
  2906. if (props && props.type === 15) {
  2907. const { properties } = props;
  2908. for (let i = 0; i < properties.length; i++) {
  2909. const { key, value } = properties[i];
  2910. const keyType = getConstantType(key, context);
  2911. if (keyType === 0) {
  2912. return keyType;
  2913. }
  2914. if (keyType < returnType) {
  2915. returnType = keyType;
  2916. }
  2917. let valueType;
  2918. if (value.type === 4) {
  2919. valueType = getConstantType(value, context);
  2920. } else if (value.type === 14) {
  2921. valueType = getConstantTypeOfHelperCall(value, context);
  2922. } else {
  2923. valueType = 0;
  2924. }
  2925. if (valueType === 0) {
  2926. return valueType;
  2927. }
  2928. if (valueType < returnType) {
  2929. returnType = valueType;
  2930. }
  2931. }
  2932. }
  2933. return returnType;
  2934. }
  2935. function getNodeProps(node) {
  2936. const codegenNode = node.codegenNode;
  2937. if (codegenNode.type === 13) {
  2938. return codegenNode.props;
  2939. }
  2940. }
  2941. function createTransformContext(root, {
  2942. filename = "",
  2943. prefixIdentifiers = false,
  2944. hoistStatic = false,
  2945. hmr = false,
  2946. cacheHandlers = false,
  2947. nodeTransforms = [],
  2948. directiveTransforms = {},
  2949. transformHoist = null,
  2950. isBuiltInComponent = NOOP,
  2951. isCustomElement = NOOP,
  2952. expressionPlugins = [],
  2953. scopeId = null,
  2954. slotted = true,
  2955. ssr = false,
  2956. inSSR = false,
  2957. ssrCssVars = ``,
  2958. bindingMetadata = EMPTY_OBJ,
  2959. inline = false,
  2960. isTS = false,
  2961. onError = defaultOnError,
  2962. onWarn = defaultOnWarn,
  2963. compatConfig
  2964. }) {
  2965. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  2966. const context = {
  2967. // options
  2968. filename,
  2969. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  2970. prefixIdentifiers,
  2971. hoistStatic,
  2972. hmr,
  2973. cacheHandlers,
  2974. nodeTransforms,
  2975. directiveTransforms,
  2976. transformHoist,
  2977. isBuiltInComponent,
  2978. isCustomElement,
  2979. expressionPlugins,
  2980. scopeId,
  2981. slotted,
  2982. ssr,
  2983. inSSR,
  2984. ssrCssVars,
  2985. bindingMetadata,
  2986. inline,
  2987. isTS,
  2988. onError,
  2989. onWarn,
  2990. compatConfig,
  2991. // state
  2992. root,
  2993. helpers: /* @__PURE__ */ new Map(),
  2994. components: /* @__PURE__ */ new Set(),
  2995. directives: /* @__PURE__ */ new Set(),
  2996. hoists: [],
  2997. imports: [],
  2998. cached: [],
  2999. constantCache: /* @__PURE__ */ new WeakMap(),
  3000. temps: 0,
  3001. identifiers: /* @__PURE__ */ Object.create(null),
  3002. scopes: {
  3003. vFor: 0,
  3004. vSlot: 0,
  3005. vPre: 0,
  3006. vOnce: 0
  3007. },
  3008. parent: null,
  3009. grandParent: null,
  3010. currentNode: root,
  3011. childIndex: 0,
  3012. inVOnce: false,
  3013. // methods
  3014. helper(name) {
  3015. const count = context.helpers.get(name) || 0;
  3016. context.helpers.set(name, count + 1);
  3017. return name;
  3018. },
  3019. removeHelper(name) {
  3020. const count = context.helpers.get(name);
  3021. if (count) {
  3022. const currentCount = count - 1;
  3023. if (!currentCount) {
  3024. context.helpers.delete(name);
  3025. } else {
  3026. context.helpers.set(name, currentCount);
  3027. }
  3028. }
  3029. },
  3030. helperString(name) {
  3031. return `_${helperNameMap[context.helper(name)]}`;
  3032. },
  3033. replaceNode(node) {
  3034. if (!!(process.env.NODE_ENV !== "production")) {
  3035. if (!context.currentNode) {
  3036. throw new Error(`Node being replaced is already removed.`);
  3037. }
  3038. if (!context.parent) {
  3039. throw new Error(`Cannot replace root node.`);
  3040. }
  3041. }
  3042. context.parent.children[context.childIndex] = context.currentNode = node;
  3043. },
  3044. removeNode(node) {
  3045. if (!!(process.env.NODE_ENV !== "production") && !context.parent) {
  3046. throw new Error(`Cannot remove root node.`);
  3047. }
  3048. const list = context.parent.children;
  3049. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  3050. if (!!(process.env.NODE_ENV !== "production") && removalIndex < 0) {
  3051. throw new Error(`node being removed is not a child of current parent`);
  3052. }
  3053. if (!node || node === context.currentNode) {
  3054. context.currentNode = null;
  3055. context.onNodeRemoved();
  3056. } else {
  3057. if (context.childIndex > removalIndex) {
  3058. context.childIndex--;
  3059. context.onNodeRemoved();
  3060. }
  3061. }
  3062. context.parent.children.splice(removalIndex, 1);
  3063. },
  3064. onNodeRemoved: NOOP,
  3065. addIdentifiers(exp) {
  3066. },
  3067. removeIdentifiers(exp) {
  3068. },
  3069. hoist(exp) {
  3070. if (isString(exp)) exp = createSimpleExpression(exp);
  3071. context.hoists.push(exp);
  3072. const identifier = createSimpleExpression(
  3073. `_hoisted_${context.hoists.length}`,
  3074. false,
  3075. exp.loc,
  3076. 2
  3077. );
  3078. identifier.hoisted = exp;
  3079. return identifier;
  3080. },
  3081. cache(exp, isVNode = false, inVOnce = false) {
  3082. const cacheExp = createCacheExpression(
  3083. context.cached.length,
  3084. exp,
  3085. isVNode,
  3086. inVOnce
  3087. );
  3088. context.cached.push(cacheExp);
  3089. return cacheExp;
  3090. }
  3091. };
  3092. {
  3093. context.filters = /* @__PURE__ */ new Set();
  3094. }
  3095. return context;
  3096. }
  3097. function transform(root, options) {
  3098. const context = createTransformContext(root, options);
  3099. traverseNode(root, context);
  3100. if (options.hoistStatic) {
  3101. cacheStatic(root, context);
  3102. }
  3103. if (!options.ssr) {
  3104. createRootCodegen(root, context);
  3105. }
  3106. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  3107. root.components = [...context.components];
  3108. root.directives = [...context.directives];
  3109. root.imports = context.imports;
  3110. root.hoists = context.hoists;
  3111. root.temps = context.temps;
  3112. root.cached = context.cached;
  3113. root.transformed = true;
  3114. {
  3115. root.filters = [...context.filters];
  3116. }
  3117. }
  3118. function createRootCodegen(root, context) {
  3119. const { helper } = context;
  3120. const { children } = root;
  3121. if (children.length === 1) {
  3122. const singleElementRootChild = getSingleElementRoot(root);
  3123. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  3124. const codegenNode = singleElementRootChild.codegenNode;
  3125. if (codegenNode.type === 13) {
  3126. convertToBlock(codegenNode, context);
  3127. }
  3128. root.codegenNode = codegenNode;
  3129. } else {
  3130. root.codegenNode = children[0];
  3131. }
  3132. } else if (children.length > 1) {
  3133. let patchFlag = 64;
  3134. if (!!(process.env.NODE_ENV !== "production") && children.filter((c) => c.type !== 3).length === 1) {
  3135. patchFlag |= 2048;
  3136. }
  3137. root.codegenNode = createVNodeCall(
  3138. context,
  3139. helper(FRAGMENT),
  3140. void 0,
  3141. root.children,
  3142. patchFlag,
  3143. void 0,
  3144. void 0,
  3145. true,
  3146. void 0,
  3147. false
  3148. );
  3149. } else ;
  3150. }
  3151. function traverseChildren(parent, context) {
  3152. let i = 0;
  3153. const nodeRemoved = () => {
  3154. i--;
  3155. };
  3156. for (; i < parent.children.length; i++) {
  3157. const child = parent.children[i];
  3158. if (isString(child)) continue;
  3159. context.grandParent = context.parent;
  3160. context.parent = parent;
  3161. context.childIndex = i;
  3162. context.onNodeRemoved = nodeRemoved;
  3163. traverseNode(child, context);
  3164. }
  3165. }
  3166. function traverseNode(node, context) {
  3167. context.currentNode = node;
  3168. const { nodeTransforms } = context;
  3169. const exitFns = [];
  3170. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  3171. const onExit = nodeTransforms[i2](node, context);
  3172. if (onExit) {
  3173. if (isArray(onExit)) {
  3174. exitFns.push(...onExit);
  3175. } else {
  3176. exitFns.push(onExit);
  3177. }
  3178. }
  3179. if (!context.currentNode) {
  3180. return;
  3181. } else {
  3182. node = context.currentNode;
  3183. }
  3184. }
  3185. switch (node.type) {
  3186. case 3:
  3187. if (!context.ssr) {
  3188. context.helper(CREATE_COMMENT);
  3189. }
  3190. break;
  3191. case 5:
  3192. if (!context.ssr) {
  3193. context.helper(TO_DISPLAY_STRING);
  3194. }
  3195. break;
  3196. // for container types, further traverse downwards
  3197. case 9:
  3198. for (let i2 = 0; i2 < node.branches.length; i2++) {
  3199. traverseNode(node.branches[i2], context);
  3200. }
  3201. break;
  3202. case 10:
  3203. case 11:
  3204. case 1:
  3205. case 0:
  3206. traverseChildren(node, context);
  3207. break;
  3208. }
  3209. context.currentNode = node;
  3210. let i = exitFns.length;
  3211. while (i--) {
  3212. exitFns[i]();
  3213. }
  3214. }
  3215. function createStructuralDirectiveTransform(name, fn) {
  3216. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  3217. return (node, context) => {
  3218. if (node.type === 1) {
  3219. const { props } = node;
  3220. if (node.tagType === 3 && props.some(isVSlot)) {
  3221. return;
  3222. }
  3223. const exitFns = [];
  3224. for (let i = 0; i < props.length; i++) {
  3225. const prop = props[i];
  3226. if (prop.type === 7 && matches(prop.name)) {
  3227. props.splice(i, 1);
  3228. i--;
  3229. const onExit = fn(node, prop, context);
  3230. if (onExit) exitFns.push(onExit);
  3231. }
  3232. }
  3233. return exitFns;
  3234. }
  3235. };
  3236. }
  3237. const PURE_ANNOTATION = `/*@__PURE__*/`;
  3238. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  3239. function createCodegenContext(ast, {
  3240. mode = "function",
  3241. prefixIdentifiers = mode === "module",
  3242. sourceMap = false,
  3243. filename = `template.vue.html`,
  3244. scopeId = null,
  3245. optimizeImports = false,
  3246. runtimeGlobalName = `Vue`,
  3247. runtimeModuleName = `vue`,
  3248. ssrRuntimeModuleName = "vue/server-renderer",
  3249. ssr = false,
  3250. isTS = false,
  3251. inSSR = false
  3252. }) {
  3253. const context = {
  3254. mode,
  3255. prefixIdentifiers,
  3256. sourceMap,
  3257. filename,
  3258. scopeId,
  3259. optimizeImports,
  3260. runtimeGlobalName,
  3261. runtimeModuleName,
  3262. ssrRuntimeModuleName,
  3263. ssr,
  3264. isTS,
  3265. inSSR,
  3266. source: ast.source,
  3267. code: ``,
  3268. column: 1,
  3269. line: 1,
  3270. offset: 0,
  3271. indentLevel: 0,
  3272. pure: false,
  3273. map: void 0,
  3274. helper(key) {
  3275. return `_${helperNameMap[key]}`;
  3276. },
  3277. push(code, newlineIndex = -2 /* None */, node) {
  3278. context.code += code;
  3279. },
  3280. indent() {
  3281. newline(++context.indentLevel);
  3282. },
  3283. deindent(withoutNewLine = false) {
  3284. if (withoutNewLine) {
  3285. --context.indentLevel;
  3286. } else {
  3287. newline(--context.indentLevel);
  3288. }
  3289. },
  3290. newline() {
  3291. newline(context.indentLevel);
  3292. }
  3293. };
  3294. function newline(n) {
  3295. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  3296. }
  3297. return context;
  3298. }
  3299. function generate(ast, options = {}) {
  3300. const context = createCodegenContext(ast, options);
  3301. if (options.onContextCreated) options.onContextCreated(context);
  3302. const {
  3303. mode,
  3304. push,
  3305. prefixIdentifiers,
  3306. indent,
  3307. deindent,
  3308. newline,
  3309. scopeId,
  3310. ssr
  3311. } = context;
  3312. const helpers = Array.from(ast.helpers);
  3313. const hasHelpers = helpers.length > 0;
  3314. const useWithBlock = !prefixIdentifiers && mode !== "module";
  3315. const preambleContext = context;
  3316. {
  3317. genFunctionPreamble(ast, preambleContext);
  3318. }
  3319. const functionName = ssr ? `ssrRender` : `render`;
  3320. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  3321. const signature = args.join(", ");
  3322. {
  3323. push(`function ${functionName}(${signature}) {`);
  3324. }
  3325. indent();
  3326. if (useWithBlock) {
  3327. push(`with (_ctx) {`);
  3328. indent();
  3329. if (hasHelpers) {
  3330. push(
  3331. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  3332. `,
  3333. -1 /* End */
  3334. );
  3335. newline();
  3336. }
  3337. }
  3338. if (ast.components.length) {
  3339. genAssets(ast.components, "component", context);
  3340. if (ast.directives.length || ast.temps > 0) {
  3341. newline();
  3342. }
  3343. }
  3344. if (ast.directives.length) {
  3345. genAssets(ast.directives, "directive", context);
  3346. if (ast.temps > 0) {
  3347. newline();
  3348. }
  3349. }
  3350. if (ast.filters && ast.filters.length) {
  3351. newline();
  3352. genAssets(ast.filters, "filter", context);
  3353. newline();
  3354. }
  3355. if (ast.temps > 0) {
  3356. push(`let `);
  3357. for (let i = 0; i < ast.temps; i++) {
  3358. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  3359. }
  3360. }
  3361. if (ast.components.length || ast.directives.length || ast.temps) {
  3362. push(`
  3363. `, 0 /* Start */);
  3364. newline();
  3365. }
  3366. if (!ssr) {
  3367. push(`return `);
  3368. }
  3369. if (ast.codegenNode) {
  3370. genNode(ast.codegenNode, context);
  3371. } else {
  3372. push(`null`);
  3373. }
  3374. if (useWithBlock) {
  3375. deindent();
  3376. push(`}`);
  3377. }
  3378. deindent();
  3379. push(`}`);
  3380. return {
  3381. ast,
  3382. code: context.code,
  3383. preamble: ``,
  3384. map: context.map ? context.map.toJSON() : void 0
  3385. };
  3386. }
  3387. function genFunctionPreamble(ast, context) {
  3388. const {
  3389. ssr,
  3390. prefixIdentifiers,
  3391. push,
  3392. newline,
  3393. runtimeModuleName,
  3394. runtimeGlobalName,
  3395. ssrRuntimeModuleName
  3396. } = context;
  3397. const VueBinding = runtimeGlobalName;
  3398. const helpers = Array.from(ast.helpers);
  3399. if (helpers.length > 0) {
  3400. {
  3401. push(`const _Vue = ${VueBinding}
  3402. `, -1 /* End */);
  3403. if (ast.hoists.length) {
  3404. const staticHelpers = [
  3405. CREATE_VNODE,
  3406. CREATE_ELEMENT_VNODE,
  3407. CREATE_COMMENT,
  3408. CREATE_TEXT,
  3409. CREATE_STATIC
  3410. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  3411. push(`const { ${staticHelpers} } = _Vue
  3412. `, -1 /* End */);
  3413. }
  3414. }
  3415. }
  3416. genHoists(ast.hoists, context);
  3417. newline();
  3418. push(`return `);
  3419. }
  3420. function genAssets(assets, type, { helper, push, newline, isTS }) {
  3421. const resolver = helper(
  3422. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  3423. );
  3424. for (let i = 0; i < assets.length; i++) {
  3425. let id = assets[i];
  3426. const maybeSelfReference = id.endsWith("__self");
  3427. if (maybeSelfReference) {
  3428. id = id.slice(0, -6);
  3429. }
  3430. push(
  3431. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  3432. );
  3433. if (i < assets.length - 1) {
  3434. newline();
  3435. }
  3436. }
  3437. }
  3438. function genHoists(hoists, context) {
  3439. if (!hoists.length) {
  3440. return;
  3441. }
  3442. context.pure = true;
  3443. const { push, newline } = context;
  3444. newline();
  3445. for (let i = 0; i < hoists.length; i++) {
  3446. const exp = hoists[i];
  3447. if (exp) {
  3448. push(`const _hoisted_${i + 1} = `);
  3449. genNode(exp, context);
  3450. newline();
  3451. }
  3452. }
  3453. context.pure = false;
  3454. }
  3455. function isText(n) {
  3456. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  3457. }
  3458. function genNodeListAsArray(nodes, context) {
  3459. const multilines = nodes.length > 3 || !!(process.env.NODE_ENV !== "production") && nodes.some((n) => isArray(n) || !isText(n));
  3460. context.push(`[`);
  3461. multilines && context.indent();
  3462. genNodeList(nodes, context, multilines);
  3463. multilines && context.deindent();
  3464. context.push(`]`);
  3465. }
  3466. function genNodeList(nodes, context, multilines = false, comma = true) {
  3467. const { push, newline } = context;
  3468. for (let i = 0; i < nodes.length; i++) {
  3469. const node = nodes[i];
  3470. if (isString(node)) {
  3471. push(node, -3 /* Unknown */);
  3472. } else if (isArray(node)) {
  3473. genNodeListAsArray(node, context);
  3474. } else {
  3475. genNode(node, context);
  3476. }
  3477. if (i < nodes.length - 1) {
  3478. if (multilines) {
  3479. comma && push(",");
  3480. newline();
  3481. } else {
  3482. comma && push(", ");
  3483. }
  3484. }
  3485. }
  3486. }
  3487. function genNode(node, context) {
  3488. if (isString(node)) {
  3489. context.push(node, -3 /* Unknown */);
  3490. return;
  3491. }
  3492. if (isSymbol(node)) {
  3493. context.push(context.helper(node));
  3494. return;
  3495. }
  3496. switch (node.type) {
  3497. case 1:
  3498. case 9:
  3499. case 11:
  3500. !!(process.env.NODE_ENV !== "production") && assert(
  3501. node.codegenNode != null,
  3502. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  3503. );
  3504. genNode(node.codegenNode, context);
  3505. break;
  3506. case 2:
  3507. genText(node, context);
  3508. break;
  3509. case 4:
  3510. genExpression(node, context);
  3511. break;
  3512. case 5:
  3513. genInterpolation(node, context);
  3514. break;
  3515. case 12:
  3516. genNode(node.codegenNode, context);
  3517. break;
  3518. case 8:
  3519. genCompoundExpression(node, context);
  3520. break;
  3521. case 3:
  3522. genComment(node, context);
  3523. break;
  3524. case 13:
  3525. genVNodeCall(node, context);
  3526. break;
  3527. case 14:
  3528. genCallExpression(node, context);
  3529. break;
  3530. case 15:
  3531. genObjectExpression(node, context);
  3532. break;
  3533. case 17:
  3534. genArrayExpression(node, context);
  3535. break;
  3536. case 18:
  3537. genFunctionExpression(node, context);
  3538. break;
  3539. case 19:
  3540. genConditionalExpression(node, context);
  3541. break;
  3542. case 20:
  3543. genCacheExpression(node, context);
  3544. break;
  3545. case 21:
  3546. genNodeList(node.body, context, true, false);
  3547. break;
  3548. // SSR only types
  3549. case 22:
  3550. break;
  3551. case 23:
  3552. break;
  3553. case 24:
  3554. break;
  3555. case 25:
  3556. break;
  3557. case 26:
  3558. break;
  3559. /* v8 ignore start */
  3560. case 10:
  3561. break;
  3562. default:
  3563. if (!!(process.env.NODE_ENV !== "production")) {
  3564. assert(false, `unhandled codegen node type: ${node.type}`);
  3565. const exhaustiveCheck = node;
  3566. return exhaustiveCheck;
  3567. }
  3568. }
  3569. }
  3570. function genText(node, context) {
  3571. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  3572. }
  3573. function genExpression(node, context) {
  3574. const { content, isStatic } = node;
  3575. context.push(
  3576. isStatic ? JSON.stringify(content) : content,
  3577. -3 /* Unknown */,
  3578. node
  3579. );
  3580. }
  3581. function genInterpolation(node, context) {
  3582. const { push, helper, pure } = context;
  3583. if (pure) push(PURE_ANNOTATION);
  3584. push(`${helper(TO_DISPLAY_STRING)}(`);
  3585. genNode(node.content, context);
  3586. push(`)`);
  3587. }
  3588. function genCompoundExpression(node, context) {
  3589. for (let i = 0; i < node.children.length; i++) {
  3590. const child = node.children[i];
  3591. if (isString(child)) {
  3592. context.push(child, -3 /* Unknown */);
  3593. } else {
  3594. genNode(child, context);
  3595. }
  3596. }
  3597. }
  3598. function genExpressionAsPropertyKey(node, context) {
  3599. const { push } = context;
  3600. if (node.type === 8) {
  3601. push(`[`);
  3602. genCompoundExpression(node, context);
  3603. push(`]`);
  3604. } else if (node.isStatic) {
  3605. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  3606. push(text, -2 /* None */, node);
  3607. } else {
  3608. push(`[${node.content}]`, -3 /* Unknown */, node);
  3609. }
  3610. }
  3611. function genComment(node, context) {
  3612. const { push, helper, pure } = context;
  3613. if (pure) {
  3614. push(PURE_ANNOTATION);
  3615. }
  3616. push(
  3617. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  3618. -3 /* Unknown */,
  3619. node
  3620. );
  3621. }
  3622. function genVNodeCall(node, context) {
  3623. const { push, helper, pure } = context;
  3624. const {
  3625. tag,
  3626. props,
  3627. children,
  3628. patchFlag,
  3629. dynamicProps,
  3630. directives,
  3631. isBlock,
  3632. disableTracking,
  3633. isComponent
  3634. } = node;
  3635. let patchFlagString;
  3636. if (patchFlag) {
  3637. if (!!(process.env.NODE_ENV !== "production")) {
  3638. if (patchFlag < 0) {
  3639. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3640. } else {
  3641. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3642. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  3643. }
  3644. } else {
  3645. patchFlagString = String(patchFlag);
  3646. }
  3647. }
  3648. if (directives) {
  3649. push(helper(WITH_DIRECTIVES) + `(`);
  3650. }
  3651. if (isBlock) {
  3652. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  3653. }
  3654. if (pure) {
  3655. push(PURE_ANNOTATION);
  3656. }
  3657. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  3658. push(helper(callHelper) + `(`, -2 /* None */, node);
  3659. genNodeList(
  3660. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  3661. context
  3662. );
  3663. push(`)`);
  3664. if (isBlock) {
  3665. push(`)`);
  3666. }
  3667. if (directives) {
  3668. push(`, `);
  3669. genNode(directives, context);
  3670. push(`)`);
  3671. }
  3672. }
  3673. function genNullableArgs(args) {
  3674. let i = args.length;
  3675. while (i--) {
  3676. if (args[i] != null) break;
  3677. }
  3678. return args.slice(0, i + 1).map((arg) => arg || `null`);
  3679. }
  3680. function genCallExpression(node, context) {
  3681. const { push, helper, pure } = context;
  3682. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  3683. if (pure) {
  3684. push(PURE_ANNOTATION);
  3685. }
  3686. push(callee + `(`, -2 /* None */, node);
  3687. genNodeList(node.arguments, context);
  3688. push(`)`);
  3689. }
  3690. function genObjectExpression(node, context) {
  3691. const { push, indent, deindent, newline } = context;
  3692. const { properties } = node;
  3693. if (!properties.length) {
  3694. push(`{}`, -2 /* None */, node);
  3695. return;
  3696. }
  3697. const multilines = properties.length > 1 || !!(process.env.NODE_ENV !== "production") && properties.some((p) => p.value.type !== 4);
  3698. push(multilines ? `{` : `{ `);
  3699. multilines && indent();
  3700. for (let i = 0; i < properties.length; i++) {
  3701. const { key, value } = properties[i];
  3702. genExpressionAsPropertyKey(key, context);
  3703. push(`: `);
  3704. genNode(value, context);
  3705. if (i < properties.length - 1) {
  3706. push(`,`);
  3707. newline();
  3708. }
  3709. }
  3710. multilines && deindent();
  3711. push(multilines ? `}` : ` }`);
  3712. }
  3713. function genArrayExpression(node, context) {
  3714. genNodeListAsArray(node.elements, context);
  3715. }
  3716. function genFunctionExpression(node, context) {
  3717. const { push, indent, deindent } = context;
  3718. const { params, returns, body, newline, isSlot } = node;
  3719. if (isSlot) {
  3720. push(`_${helperNameMap[WITH_CTX]}(`);
  3721. }
  3722. push(`(`, -2 /* None */, node);
  3723. if (isArray(params)) {
  3724. genNodeList(params, context);
  3725. } else if (params) {
  3726. genNode(params, context);
  3727. }
  3728. push(`) => `);
  3729. if (newline || body) {
  3730. push(`{`);
  3731. indent();
  3732. }
  3733. if (returns) {
  3734. if (newline) {
  3735. push(`return `);
  3736. }
  3737. if (isArray(returns)) {
  3738. genNodeListAsArray(returns, context);
  3739. } else {
  3740. genNode(returns, context);
  3741. }
  3742. } else if (body) {
  3743. genNode(body, context);
  3744. }
  3745. if (newline || body) {
  3746. deindent();
  3747. push(`}`);
  3748. }
  3749. if (isSlot) {
  3750. if (node.isNonScopedSlot) {
  3751. push(`, undefined, true`);
  3752. }
  3753. push(`)`);
  3754. }
  3755. }
  3756. function genConditionalExpression(node, context) {
  3757. const { test, consequent, alternate, newline: needNewline } = node;
  3758. const { push, indent, deindent, newline } = context;
  3759. if (test.type === 4) {
  3760. const needsParens = !isSimpleIdentifier(test.content);
  3761. needsParens && push(`(`);
  3762. genExpression(test, context);
  3763. needsParens && push(`)`);
  3764. } else {
  3765. push(`(`);
  3766. genNode(test, context);
  3767. push(`)`);
  3768. }
  3769. needNewline && indent();
  3770. context.indentLevel++;
  3771. needNewline || push(` `);
  3772. push(`? `);
  3773. genNode(consequent, context);
  3774. context.indentLevel--;
  3775. needNewline && newline();
  3776. needNewline || push(` `);
  3777. push(`: `);
  3778. const isNested = alternate.type === 19;
  3779. if (!isNested) {
  3780. context.indentLevel++;
  3781. }
  3782. genNode(alternate, context);
  3783. if (!isNested) {
  3784. context.indentLevel--;
  3785. }
  3786. needNewline && deindent(
  3787. true
  3788. /* without newline */
  3789. );
  3790. }
  3791. function genCacheExpression(node, context) {
  3792. const { push, helper, indent, deindent, newline } = context;
  3793. const { needPauseTracking, needArraySpread } = node;
  3794. if (needArraySpread) {
  3795. push(`[...(`);
  3796. }
  3797. push(`_cache[${node.index}] || (`);
  3798. if (needPauseTracking) {
  3799. indent();
  3800. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  3801. if (node.inVOnce) push(`, true`);
  3802. push(`),`);
  3803. newline();
  3804. push(`(`);
  3805. }
  3806. push(`_cache[${node.index}] = `);
  3807. genNode(node.value, context);
  3808. if (needPauseTracking) {
  3809. push(`).cacheIndex = ${node.index},`);
  3810. newline();
  3811. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  3812. newline();
  3813. push(`_cache[${node.index}]`);
  3814. deindent();
  3815. }
  3816. push(`)`);
  3817. if (needArraySpread) {
  3818. push(`)]`);
  3819. }
  3820. }
  3821. const prohibitedKeywordRE = new RegExp(
  3822. "\\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"
  3823. );
  3824. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  3825. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  3826. const exp = node.content;
  3827. if (!exp.trim()) {
  3828. return;
  3829. }
  3830. try {
  3831. new Function(
  3832. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  3833. );
  3834. } catch (e) {
  3835. let message = e.message;
  3836. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  3837. if (keywordMatch) {
  3838. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  3839. }
  3840. context.onError(
  3841. createCompilerError(
  3842. 45,
  3843. node.loc,
  3844. void 0,
  3845. message
  3846. )
  3847. );
  3848. }
  3849. }
  3850. const transformExpression = (node, context) => {
  3851. if (node.type === 5) {
  3852. node.content = processExpression(
  3853. node.content,
  3854. context
  3855. );
  3856. } else if (node.type === 1) {
  3857. const memo = findDir(node, "memo");
  3858. for (let i = 0; i < node.props.length; i++) {
  3859. const dir = node.props[i];
  3860. if (dir.type === 7 && dir.name !== "for") {
  3861. const exp = dir.exp;
  3862. const arg = dir.arg;
  3863. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  3864. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  3865. dir.exp = processExpression(
  3866. exp,
  3867. context,
  3868. // slot args must be processed as function params
  3869. dir.name === "slot"
  3870. );
  3871. }
  3872. if (arg && arg.type === 4 && !arg.isStatic) {
  3873. dir.arg = processExpression(arg, context);
  3874. }
  3875. }
  3876. }
  3877. }
  3878. };
  3879. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  3880. {
  3881. if (!!(process.env.NODE_ENV !== "production")) {
  3882. validateBrowserExpression(node, context, asParams, asRawStatements);
  3883. }
  3884. return node;
  3885. }
  3886. }
  3887. function stringifyExpression(exp) {
  3888. if (isString(exp)) {
  3889. return exp;
  3890. } else if (exp.type === 4) {
  3891. return exp.content;
  3892. } else {
  3893. return exp.children.map(stringifyExpression).join("");
  3894. }
  3895. }
  3896. const transformIf = createStructuralDirectiveTransform(
  3897. /^(?:if|else|else-if)$/,
  3898. (node, dir, context) => {
  3899. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  3900. const siblings = context.parent.children;
  3901. let i = siblings.indexOf(ifNode);
  3902. let key = 0;
  3903. while (i-- >= 0) {
  3904. const sibling = siblings[i];
  3905. if (sibling && sibling.type === 9) {
  3906. key += sibling.branches.length;
  3907. }
  3908. }
  3909. return () => {
  3910. if (isRoot) {
  3911. ifNode.codegenNode = createCodegenNodeForBranch(
  3912. branch,
  3913. key,
  3914. context
  3915. );
  3916. } else {
  3917. const parentCondition = getParentCondition(ifNode.codegenNode);
  3918. parentCondition.alternate = createCodegenNodeForBranch(
  3919. branch,
  3920. key + ifNode.branches.length - 1,
  3921. context
  3922. );
  3923. }
  3924. };
  3925. });
  3926. }
  3927. );
  3928. function processIf(node, dir, context, processCodegen) {
  3929. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  3930. const loc = dir.exp ? dir.exp.loc : node.loc;
  3931. context.onError(
  3932. createCompilerError(28, dir.loc)
  3933. );
  3934. dir.exp = createSimpleExpression(`true`, false, loc);
  3935. }
  3936. if (!!(process.env.NODE_ENV !== "production") && true && dir.exp) {
  3937. validateBrowserExpression(dir.exp, context);
  3938. }
  3939. if (dir.name === "if") {
  3940. const branch = createIfBranch(node, dir);
  3941. const ifNode = {
  3942. type: 9,
  3943. loc: cloneLoc(node.loc),
  3944. branches: [branch]
  3945. };
  3946. context.replaceNode(ifNode);
  3947. if (processCodegen) {
  3948. return processCodegen(ifNode, branch, true);
  3949. }
  3950. } else {
  3951. const siblings = context.parent.children;
  3952. const comments = [];
  3953. let i = siblings.indexOf(node);
  3954. while (i-- >= -1) {
  3955. const sibling = siblings[i];
  3956. if (sibling && sibling.type === 3) {
  3957. context.removeNode(sibling);
  3958. !!(process.env.NODE_ENV !== "production") && comments.unshift(sibling);
  3959. continue;
  3960. }
  3961. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  3962. context.removeNode(sibling);
  3963. continue;
  3964. }
  3965. if (sibling && sibling.type === 9) {
  3966. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  3967. context.onError(
  3968. createCompilerError(30, node.loc)
  3969. );
  3970. }
  3971. context.removeNode();
  3972. const branch = createIfBranch(node, dir);
  3973. if (!!(process.env.NODE_ENV !== "production") && comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  3974. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  3975. branch.children = [...comments, ...branch.children];
  3976. }
  3977. if (!!(process.env.NODE_ENV !== "production") || false) {
  3978. const key = branch.userKey;
  3979. if (key) {
  3980. sibling.branches.forEach(({ userKey }) => {
  3981. if (isSameKey(userKey, key)) {
  3982. context.onError(
  3983. createCompilerError(
  3984. 29,
  3985. branch.userKey.loc
  3986. )
  3987. );
  3988. }
  3989. });
  3990. }
  3991. }
  3992. sibling.branches.push(branch);
  3993. const onExit = processCodegen && processCodegen(sibling, branch, false);
  3994. traverseNode(branch, context);
  3995. if (onExit) onExit();
  3996. context.currentNode = null;
  3997. } else {
  3998. context.onError(
  3999. createCompilerError(30, node.loc)
  4000. );
  4001. }
  4002. break;
  4003. }
  4004. }
  4005. }
  4006. function createIfBranch(node, dir) {
  4007. const isTemplateIf = node.tagType === 3;
  4008. return {
  4009. type: 10,
  4010. loc: node.loc,
  4011. condition: dir.name === "else" ? void 0 : dir.exp,
  4012. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  4013. userKey: findProp(node, `key`),
  4014. isTemplateIf
  4015. };
  4016. }
  4017. function createCodegenNodeForBranch(branch, keyIndex, context) {
  4018. if (branch.condition) {
  4019. return createConditionalExpression(
  4020. branch.condition,
  4021. createChildrenCodegenNode(branch, keyIndex, context),
  4022. // make sure to pass in asBlock: true so that the comment node call
  4023. // closes the current block.
  4024. createCallExpression(context.helper(CREATE_COMMENT), [
  4025. !!(process.env.NODE_ENV !== "production") ? '"v-if"' : '""',
  4026. "true"
  4027. ])
  4028. );
  4029. } else {
  4030. return createChildrenCodegenNode(branch, keyIndex, context);
  4031. }
  4032. }
  4033. function createChildrenCodegenNode(branch, keyIndex, context) {
  4034. const { helper } = context;
  4035. const keyProperty = createObjectProperty(
  4036. `key`,
  4037. createSimpleExpression(
  4038. `${keyIndex}`,
  4039. false,
  4040. locStub,
  4041. 2
  4042. )
  4043. );
  4044. const { children } = branch;
  4045. const firstChild = children[0];
  4046. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  4047. if (needFragmentWrapper) {
  4048. if (children.length === 1 && firstChild.type === 11) {
  4049. const vnodeCall = firstChild.codegenNode;
  4050. injectProp(vnodeCall, keyProperty, context);
  4051. return vnodeCall;
  4052. } else {
  4053. let patchFlag = 64;
  4054. if (!!(process.env.NODE_ENV !== "production") && !branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  4055. patchFlag |= 2048;
  4056. }
  4057. return createVNodeCall(
  4058. context,
  4059. helper(FRAGMENT),
  4060. createObjectExpression([keyProperty]),
  4061. children,
  4062. patchFlag,
  4063. void 0,
  4064. void 0,
  4065. true,
  4066. false,
  4067. false,
  4068. branch.loc
  4069. );
  4070. }
  4071. } else {
  4072. const ret = firstChild.codegenNode;
  4073. const vnodeCall = getMemoedVNodeCall(ret);
  4074. if (vnodeCall.type === 13) {
  4075. convertToBlock(vnodeCall, context);
  4076. }
  4077. injectProp(vnodeCall, keyProperty, context);
  4078. return ret;
  4079. }
  4080. }
  4081. function isSameKey(a, b) {
  4082. if (!a || a.type !== b.type) {
  4083. return false;
  4084. }
  4085. if (a.type === 6) {
  4086. if (a.value.content !== b.value.content) {
  4087. return false;
  4088. }
  4089. } else {
  4090. const exp = a.exp;
  4091. const branchExp = b.exp;
  4092. if (exp.type !== branchExp.type) {
  4093. return false;
  4094. }
  4095. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  4096. return false;
  4097. }
  4098. }
  4099. return true;
  4100. }
  4101. function getParentCondition(node) {
  4102. while (true) {
  4103. if (node.type === 19) {
  4104. if (node.alternate.type === 19) {
  4105. node = node.alternate;
  4106. } else {
  4107. return node;
  4108. }
  4109. } else if (node.type === 20) {
  4110. node = node.value;
  4111. }
  4112. }
  4113. }
  4114. const transformBind = (dir, _node, context) => {
  4115. const { modifiers, loc } = dir;
  4116. const arg = dir.arg;
  4117. let { exp } = dir;
  4118. if (exp && exp.type === 4 && !exp.content.trim()) {
  4119. {
  4120. exp = void 0;
  4121. }
  4122. }
  4123. if (!exp) {
  4124. if (arg.type !== 4 || !arg.isStatic) {
  4125. context.onError(
  4126. createCompilerError(
  4127. 52,
  4128. arg.loc
  4129. )
  4130. );
  4131. return {
  4132. props: [
  4133. createObjectProperty(arg, createSimpleExpression("", true, loc))
  4134. ]
  4135. };
  4136. }
  4137. transformBindShorthand(dir);
  4138. exp = dir.exp;
  4139. }
  4140. if (arg.type !== 4) {
  4141. arg.children.unshift(`(`);
  4142. arg.children.push(`) || ""`);
  4143. } else if (!arg.isStatic) {
  4144. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  4145. }
  4146. if (modifiers.some((mod) => mod.content === "camel")) {
  4147. if (arg.type === 4) {
  4148. if (arg.isStatic) {
  4149. arg.content = camelize(arg.content);
  4150. } else {
  4151. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4152. }
  4153. } else {
  4154. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4155. arg.children.push(`)`);
  4156. }
  4157. }
  4158. if (!context.inSSR) {
  4159. if (modifiers.some((mod) => mod.content === "prop")) {
  4160. injectPrefix(arg, ".");
  4161. }
  4162. if (modifiers.some((mod) => mod.content === "attr")) {
  4163. injectPrefix(arg, "^");
  4164. }
  4165. }
  4166. return {
  4167. props: [createObjectProperty(arg, exp)]
  4168. };
  4169. };
  4170. const transformBindShorthand = (dir, context) => {
  4171. const arg = dir.arg;
  4172. const propName = camelize(arg.content);
  4173. dir.exp = createSimpleExpression(propName, false, arg.loc);
  4174. };
  4175. const injectPrefix = (arg, prefix) => {
  4176. if (arg.type === 4) {
  4177. if (arg.isStatic) {
  4178. arg.content = prefix + arg.content;
  4179. } else {
  4180. arg.content = `\`${prefix}\${${arg.content}}\``;
  4181. }
  4182. } else {
  4183. arg.children.unshift(`'${prefix}' + (`);
  4184. arg.children.push(`)`);
  4185. }
  4186. };
  4187. const transformFor = createStructuralDirectiveTransform(
  4188. "for",
  4189. (node, dir, context) => {
  4190. const { helper, removeHelper } = context;
  4191. return processFor(node, dir, context, (forNode) => {
  4192. const renderExp = createCallExpression(helper(RENDER_LIST), [
  4193. forNode.source
  4194. ]);
  4195. const isTemplate = isTemplateNode(node);
  4196. const memo = findDir(node, "memo");
  4197. const keyProp = findProp(node, `key`, false, true);
  4198. const isDirKey = keyProp && keyProp.type === 7;
  4199. if (isDirKey && !keyProp.exp) {
  4200. transformBindShorthand(keyProp);
  4201. }
  4202. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  4203. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  4204. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  4205. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  4206. forNode.codegenNode = createVNodeCall(
  4207. context,
  4208. helper(FRAGMENT),
  4209. void 0,
  4210. renderExp,
  4211. fragmentFlag,
  4212. void 0,
  4213. void 0,
  4214. true,
  4215. !isStableFragment,
  4216. false,
  4217. node.loc
  4218. );
  4219. return () => {
  4220. let childBlock;
  4221. const { children } = forNode;
  4222. if ((!!(process.env.NODE_ENV !== "production") || false) && isTemplate) {
  4223. node.children.some((c) => {
  4224. if (c.type === 1) {
  4225. const key = findProp(c, "key");
  4226. if (key) {
  4227. context.onError(
  4228. createCompilerError(
  4229. 33,
  4230. key.loc
  4231. )
  4232. );
  4233. return true;
  4234. }
  4235. }
  4236. });
  4237. }
  4238. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  4239. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  4240. if (slotOutlet) {
  4241. childBlock = slotOutlet.codegenNode;
  4242. if (isTemplate && keyProperty) {
  4243. injectProp(childBlock, keyProperty, context);
  4244. }
  4245. } else if (needFragmentWrapper) {
  4246. childBlock = createVNodeCall(
  4247. context,
  4248. helper(FRAGMENT),
  4249. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  4250. node.children,
  4251. 64,
  4252. void 0,
  4253. void 0,
  4254. true,
  4255. void 0,
  4256. false
  4257. );
  4258. } else {
  4259. childBlock = children[0].codegenNode;
  4260. if (isTemplate && keyProperty) {
  4261. injectProp(childBlock, keyProperty, context);
  4262. }
  4263. if (childBlock.isBlock !== !isStableFragment) {
  4264. if (childBlock.isBlock) {
  4265. removeHelper(OPEN_BLOCK);
  4266. removeHelper(
  4267. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  4268. );
  4269. } else {
  4270. removeHelper(
  4271. getVNodeHelper(context.inSSR, childBlock.isComponent)
  4272. );
  4273. }
  4274. }
  4275. childBlock.isBlock = !isStableFragment;
  4276. if (childBlock.isBlock) {
  4277. helper(OPEN_BLOCK);
  4278. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  4279. } else {
  4280. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  4281. }
  4282. }
  4283. if (memo) {
  4284. const loop = createFunctionExpression(
  4285. createForLoopParams(forNode.parseResult, [
  4286. createSimpleExpression(`_cached`)
  4287. ])
  4288. );
  4289. loop.body = createBlockStatement([
  4290. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  4291. createCompoundExpression([
  4292. `if (_cached`,
  4293. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  4294. ` && ${context.helperString(
  4295. IS_MEMO_SAME
  4296. )}(_cached, _memo)) return _cached`
  4297. ]),
  4298. createCompoundExpression([`const _item = `, childBlock]),
  4299. createSimpleExpression(`_item.memo = _memo`),
  4300. createSimpleExpression(`return _item`)
  4301. ]);
  4302. renderExp.arguments.push(
  4303. loop,
  4304. createSimpleExpression(`_cache`),
  4305. createSimpleExpression(String(context.cached.length))
  4306. );
  4307. context.cached.push(null);
  4308. } else {
  4309. renderExp.arguments.push(
  4310. createFunctionExpression(
  4311. createForLoopParams(forNode.parseResult),
  4312. childBlock,
  4313. true
  4314. )
  4315. );
  4316. }
  4317. };
  4318. });
  4319. }
  4320. );
  4321. function processFor(node, dir, context, processCodegen) {
  4322. if (!dir.exp) {
  4323. context.onError(
  4324. createCompilerError(31, dir.loc)
  4325. );
  4326. return;
  4327. }
  4328. const parseResult = dir.forParseResult;
  4329. if (!parseResult) {
  4330. context.onError(
  4331. createCompilerError(32, dir.loc)
  4332. );
  4333. return;
  4334. }
  4335. finalizeForParseResult(parseResult, context);
  4336. const { addIdentifiers, removeIdentifiers, scopes } = context;
  4337. const { source, value, key, index } = parseResult;
  4338. const forNode = {
  4339. type: 11,
  4340. loc: dir.loc,
  4341. source,
  4342. valueAlias: value,
  4343. keyAlias: key,
  4344. objectIndexAlias: index,
  4345. parseResult,
  4346. children: isTemplateNode(node) ? node.children : [node]
  4347. };
  4348. context.replaceNode(forNode);
  4349. scopes.vFor++;
  4350. const onExit = processCodegen && processCodegen(forNode);
  4351. return () => {
  4352. scopes.vFor--;
  4353. if (onExit) onExit();
  4354. };
  4355. }
  4356. function finalizeForParseResult(result, context) {
  4357. if (result.finalized) return;
  4358. if (!!(process.env.NODE_ENV !== "production") && true) {
  4359. validateBrowserExpression(result.source, context);
  4360. if (result.key) {
  4361. validateBrowserExpression(
  4362. result.key,
  4363. context,
  4364. true
  4365. );
  4366. }
  4367. if (result.index) {
  4368. validateBrowserExpression(
  4369. result.index,
  4370. context,
  4371. true
  4372. );
  4373. }
  4374. if (result.value) {
  4375. validateBrowserExpression(
  4376. result.value,
  4377. context,
  4378. true
  4379. );
  4380. }
  4381. }
  4382. result.finalized = true;
  4383. }
  4384. function createForLoopParams({ value, key, index }, memoArgs = []) {
  4385. return createParamsList([value, key, index, ...memoArgs]);
  4386. }
  4387. function createParamsList(args) {
  4388. let i = args.length;
  4389. while (i--) {
  4390. if (args[i]) break;
  4391. }
  4392. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  4393. }
  4394. const defaultFallback = createSimpleExpression(`undefined`, false);
  4395. const trackSlotScopes = (node, context) => {
  4396. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  4397. const vSlot = findDir(node, "slot");
  4398. if (vSlot) {
  4399. vSlot.exp;
  4400. context.scopes.vSlot++;
  4401. return () => {
  4402. context.scopes.vSlot--;
  4403. };
  4404. }
  4405. }
  4406. };
  4407. const trackVForSlotScopes = (node, context) => {
  4408. let vFor;
  4409. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  4410. const result = vFor.forParseResult;
  4411. if (result) {
  4412. finalizeForParseResult(result, context);
  4413. const { value, key, index } = result;
  4414. const { addIdentifiers, removeIdentifiers } = context;
  4415. value && addIdentifiers(value);
  4416. key && addIdentifiers(key);
  4417. index && addIdentifiers(index);
  4418. return () => {
  4419. value && removeIdentifiers(value);
  4420. key && removeIdentifiers(key);
  4421. index && removeIdentifiers(index);
  4422. };
  4423. }
  4424. }
  4425. };
  4426. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  4427. props,
  4428. children,
  4429. false,
  4430. true,
  4431. children.length ? children[0].loc : loc
  4432. );
  4433. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  4434. context.helper(WITH_CTX);
  4435. const { children, loc } = node;
  4436. const slotsProperties = [];
  4437. const dynamicSlots = [];
  4438. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  4439. const onComponentSlot = findDir(node, "slot", true);
  4440. if (onComponentSlot) {
  4441. const { arg, exp } = onComponentSlot;
  4442. if (arg && !isStaticExp(arg)) {
  4443. hasDynamicSlots = true;
  4444. }
  4445. slotsProperties.push(
  4446. createObjectProperty(
  4447. arg || createSimpleExpression("default", true),
  4448. buildSlotFn(exp, void 0, children, loc)
  4449. )
  4450. );
  4451. }
  4452. let hasTemplateSlots = false;
  4453. let hasNamedDefaultSlot = false;
  4454. const implicitDefaultChildren = [];
  4455. const seenSlotNames = /* @__PURE__ */ new Set();
  4456. let conditionalBranchIndex = 0;
  4457. for (let i = 0; i < children.length; i++) {
  4458. const slotElement = children[i];
  4459. let slotDir;
  4460. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  4461. if (slotElement.type !== 3) {
  4462. implicitDefaultChildren.push(slotElement);
  4463. }
  4464. continue;
  4465. }
  4466. if (onComponentSlot) {
  4467. context.onError(
  4468. createCompilerError(37, slotDir.loc)
  4469. );
  4470. break;
  4471. }
  4472. hasTemplateSlots = true;
  4473. const { children: slotChildren, loc: slotLoc } = slotElement;
  4474. const {
  4475. arg: slotName = createSimpleExpression(`default`, true),
  4476. exp: slotProps,
  4477. loc: dirLoc
  4478. } = slotDir;
  4479. let staticSlotName;
  4480. if (isStaticExp(slotName)) {
  4481. staticSlotName = slotName ? slotName.content : `default`;
  4482. } else {
  4483. hasDynamicSlots = true;
  4484. }
  4485. const vFor = findDir(slotElement, "for");
  4486. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  4487. let vIf;
  4488. let vElse;
  4489. if (vIf = findDir(slotElement, "if")) {
  4490. hasDynamicSlots = true;
  4491. dynamicSlots.push(
  4492. createConditionalExpression(
  4493. vIf.exp,
  4494. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  4495. defaultFallback
  4496. )
  4497. );
  4498. } else if (vElse = findDir(
  4499. slotElement,
  4500. /^else(?:-if)?$/,
  4501. true
  4502. /* allowEmpty */
  4503. )) {
  4504. let j = i;
  4505. let prev;
  4506. while (j--) {
  4507. prev = children[j];
  4508. if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
  4509. break;
  4510. }
  4511. }
  4512. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  4513. let conditional = dynamicSlots[dynamicSlots.length - 1];
  4514. while (conditional.alternate.type === 19) {
  4515. conditional = conditional.alternate;
  4516. }
  4517. conditional.alternate = vElse.exp ? createConditionalExpression(
  4518. vElse.exp,
  4519. buildDynamicSlot(
  4520. slotName,
  4521. slotFunction,
  4522. conditionalBranchIndex++
  4523. ),
  4524. defaultFallback
  4525. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  4526. } else {
  4527. context.onError(
  4528. createCompilerError(30, vElse.loc)
  4529. );
  4530. }
  4531. } else if (vFor) {
  4532. hasDynamicSlots = true;
  4533. const parseResult = vFor.forParseResult;
  4534. if (parseResult) {
  4535. finalizeForParseResult(parseResult, context);
  4536. dynamicSlots.push(
  4537. createCallExpression(context.helper(RENDER_LIST), [
  4538. parseResult.source,
  4539. createFunctionExpression(
  4540. createForLoopParams(parseResult),
  4541. buildDynamicSlot(slotName, slotFunction),
  4542. true
  4543. )
  4544. ])
  4545. );
  4546. } else {
  4547. context.onError(
  4548. createCompilerError(
  4549. 32,
  4550. vFor.loc
  4551. )
  4552. );
  4553. }
  4554. } else {
  4555. if (staticSlotName) {
  4556. if (seenSlotNames.has(staticSlotName)) {
  4557. context.onError(
  4558. createCompilerError(
  4559. 38,
  4560. dirLoc
  4561. )
  4562. );
  4563. continue;
  4564. }
  4565. seenSlotNames.add(staticSlotName);
  4566. if (staticSlotName === "default") {
  4567. hasNamedDefaultSlot = true;
  4568. }
  4569. }
  4570. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  4571. }
  4572. }
  4573. if (!onComponentSlot) {
  4574. const buildDefaultSlotProperty = (props, children2) => {
  4575. const fn = buildSlotFn(props, void 0, children2, loc);
  4576. if (context.compatConfig) {
  4577. fn.isNonScopedSlot = true;
  4578. }
  4579. return createObjectProperty(`default`, fn);
  4580. };
  4581. if (!hasTemplateSlots) {
  4582. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  4583. } else if (implicitDefaultChildren.length && // #3766
  4584. // with whitespace: 'preserve', whitespaces between slots will end up in
  4585. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  4586. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  4587. if (hasNamedDefaultSlot) {
  4588. context.onError(
  4589. createCompilerError(
  4590. 39,
  4591. implicitDefaultChildren[0].loc
  4592. )
  4593. );
  4594. } else {
  4595. slotsProperties.push(
  4596. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  4597. );
  4598. }
  4599. }
  4600. }
  4601. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  4602. let slots = createObjectExpression(
  4603. slotsProperties.concat(
  4604. createObjectProperty(
  4605. `_`,
  4606. // 2 = compiled but dynamic = can skip normalization, but must run diff
  4607. // 1 = compiled and static = can skip normalization AND diff as optimized
  4608. createSimpleExpression(
  4609. slotFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${slotFlagsText[slotFlag]} */` : ``),
  4610. false
  4611. )
  4612. )
  4613. ),
  4614. loc
  4615. );
  4616. if (dynamicSlots.length) {
  4617. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  4618. slots,
  4619. createArrayExpression(dynamicSlots)
  4620. ]);
  4621. }
  4622. return {
  4623. slots,
  4624. hasDynamicSlots
  4625. };
  4626. }
  4627. function buildDynamicSlot(name, fn, index) {
  4628. const props = [
  4629. createObjectProperty(`name`, name),
  4630. createObjectProperty(`fn`, fn)
  4631. ];
  4632. if (index != null) {
  4633. props.push(
  4634. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  4635. );
  4636. }
  4637. return createObjectExpression(props);
  4638. }
  4639. function hasForwardedSlots(children) {
  4640. for (let i = 0; i < children.length; i++) {
  4641. const child = children[i];
  4642. switch (child.type) {
  4643. case 1:
  4644. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  4645. return true;
  4646. }
  4647. break;
  4648. case 9:
  4649. if (hasForwardedSlots(child.branches)) return true;
  4650. break;
  4651. case 10:
  4652. case 11:
  4653. if (hasForwardedSlots(child.children)) return true;
  4654. break;
  4655. }
  4656. }
  4657. return false;
  4658. }
  4659. function isNonWhitespaceContent(node) {
  4660. if (node.type !== 2 && node.type !== 12)
  4661. return true;
  4662. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  4663. }
  4664. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  4665. const transformElement = (node, context) => {
  4666. return function postTransformElement() {
  4667. node = context.currentNode;
  4668. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  4669. return;
  4670. }
  4671. const { tag, props } = node;
  4672. const isComponent = node.tagType === 1;
  4673. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  4674. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  4675. let vnodeProps;
  4676. let vnodeChildren;
  4677. let patchFlag = 0;
  4678. let vnodeDynamicProps;
  4679. let dynamicPropNames;
  4680. let vnodeDirectives;
  4681. let shouldUseBlock = (
  4682. // dynamic component may resolve to plain elements
  4683. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  4684. // updates inside get proper isSVG flag at runtime. (#639, #643)
  4685. // This is technically web-specific, but splitting the logic out of core
  4686. // leads to too much unnecessary complexity.
  4687. (tag === "svg" || tag === "foreignObject" || tag === "math")
  4688. );
  4689. if (props.length > 0) {
  4690. const propsBuildResult = buildProps(
  4691. node,
  4692. context,
  4693. void 0,
  4694. isComponent,
  4695. isDynamicComponent
  4696. );
  4697. vnodeProps = propsBuildResult.props;
  4698. patchFlag = propsBuildResult.patchFlag;
  4699. dynamicPropNames = propsBuildResult.dynamicPropNames;
  4700. const directives = propsBuildResult.directives;
  4701. vnodeDirectives = directives && directives.length ? createArrayExpression(
  4702. directives.map((dir) => buildDirectiveArgs(dir, context))
  4703. ) : void 0;
  4704. if (propsBuildResult.shouldUseBlock) {
  4705. shouldUseBlock = true;
  4706. }
  4707. }
  4708. if (node.children.length > 0) {
  4709. if (vnodeTag === KEEP_ALIVE) {
  4710. shouldUseBlock = true;
  4711. patchFlag |= 1024;
  4712. if (!!(process.env.NODE_ENV !== "production") && node.children.length > 1) {
  4713. context.onError(
  4714. createCompilerError(46, {
  4715. start: node.children[0].loc.start,
  4716. end: node.children[node.children.length - 1].loc.end,
  4717. source: ""
  4718. })
  4719. );
  4720. }
  4721. }
  4722. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  4723. vnodeTag !== TELEPORT && // explained above.
  4724. vnodeTag !== KEEP_ALIVE;
  4725. if (shouldBuildAsSlots) {
  4726. const { slots, hasDynamicSlots } = buildSlots(node, context);
  4727. vnodeChildren = slots;
  4728. if (hasDynamicSlots) {
  4729. patchFlag |= 1024;
  4730. }
  4731. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  4732. const child = node.children[0];
  4733. const type = child.type;
  4734. const hasDynamicTextChild = type === 5 || type === 8;
  4735. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  4736. patchFlag |= 1;
  4737. }
  4738. if (hasDynamicTextChild || type === 2) {
  4739. vnodeChildren = child;
  4740. } else {
  4741. vnodeChildren = node.children;
  4742. }
  4743. } else {
  4744. vnodeChildren = node.children;
  4745. }
  4746. }
  4747. if (dynamicPropNames && dynamicPropNames.length) {
  4748. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  4749. }
  4750. node.codegenNode = createVNodeCall(
  4751. context,
  4752. vnodeTag,
  4753. vnodeProps,
  4754. vnodeChildren,
  4755. patchFlag === 0 ? void 0 : patchFlag,
  4756. vnodeDynamicProps,
  4757. vnodeDirectives,
  4758. !!shouldUseBlock,
  4759. false,
  4760. isComponent,
  4761. node.loc
  4762. );
  4763. };
  4764. };
  4765. function resolveComponentType(node, context, ssr = false) {
  4766. let { tag } = node;
  4767. const isExplicitDynamic = isComponentTag(tag);
  4768. const isProp = findProp(
  4769. node,
  4770. "is",
  4771. false,
  4772. true
  4773. /* allow empty */
  4774. );
  4775. if (isProp) {
  4776. if (isExplicitDynamic || isCompatEnabled(
  4777. "COMPILER_IS_ON_ELEMENT",
  4778. context
  4779. )) {
  4780. let exp;
  4781. if (isProp.type === 6) {
  4782. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  4783. } else {
  4784. exp = isProp.exp;
  4785. if (!exp) {
  4786. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  4787. }
  4788. }
  4789. if (exp) {
  4790. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  4791. exp
  4792. ]);
  4793. }
  4794. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  4795. tag = isProp.value.content.slice(4);
  4796. }
  4797. }
  4798. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  4799. if (builtIn) {
  4800. if (!ssr) context.helper(builtIn);
  4801. return builtIn;
  4802. }
  4803. context.helper(RESOLVE_COMPONENT);
  4804. context.components.add(tag);
  4805. return toValidAssetId(tag, `component`);
  4806. }
  4807. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  4808. const { tag, loc: elementLoc, children } = node;
  4809. let properties = [];
  4810. const mergeArgs = [];
  4811. const runtimeDirectives = [];
  4812. const hasChildren = children.length > 0;
  4813. let shouldUseBlock = false;
  4814. let patchFlag = 0;
  4815. let hasRef = false;
  4816. let hasClassBinding = false;
  4817. let hasStyleBinding = false;
  4818. let hasHydrationEventBinding = false;
  4819. let hasDynamicKeys = false;
  4820. let hasVnodeHook = false;
  4821. const dynamicPropNames = [];
  4822. const pushMergeArg = (arg) => {
  4823. if (properties.length) {
  4824. mergeArgs.push(
  4825. createObjectExpression(dedupeProperties(properties), elementLoc)
  4826. );
  4827. properties = [];
  4828. }
  4829. if (arg) mergeArgs.push(arg);
  4830. };
  4831. const pushRefVForMarker = () => {
  4832. if (context.scopes.vFor > 0) {
  4833. properties.push(
  4834. createObjectProperty(
  4835. createSimpleExpression("ref_for", true),
  4836. createSimpleExpression("true")
  4837. )
  4838. );
  4839. }
  4840. };
  4841. const analyzePatchFlag = ({ key, value }) => {
  4842. if (isStaticExp(key)) {
  4843. const name = key.content;
  4844. const isEventHandler = isOn(name);
  4845. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  4846. // dedicated fast path.
  4847. name.toLowerCase() !== "onclick" && // omit v-model handlers
  4848. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  4849. !isReservedProp(name)) {
  4850. hasHydrationEventBinding = true;
  4851. }
  4852. if (isEventHandler && isReservedProp(name)) {
  4853. hasVnodeHook = true;
  4854. }
  4855. if (isEventHandler && value.type === 14) {
  4856. value = value.arguments[0];
  4857. }
  4858. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  4859. return;
  4860. }
  4861. if (name === "ref") {
  4862. hasRef = true;
  4863. } else if (name === "class") {
  4864. hasClassBinding = true;
  4865. } else if (name === "style") {
  4866. hasStyleBinding = true;
  4867. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  4868. dynamicPropNames.push(name);
  4869. }
  4870. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  4871. dynamicPropNames.push(name);
  4872. }
  4873. } else {
  4874. hasDynamicKeys = true;
  4875. }
  4876. };
  4877. for (let i = 0; i < props.length; i++) {
  4878. const prop = props[i];
  4879. if (prop.type === 6) {
  4880. const { loc, name, nameLoc, value } = prop;
  4881. let isStatic = true;
  4882. if (name === "ref") {
  4883. hasRef = true;
  4884. pushRefVForMarker();
  4885. }
  4886. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  4887. "COMPILER_IS_ON_ELEMENT",
  4888. context
  4889. ))) {
  4890. continue;
  4891. }
  4892. properties.push(
  4893. createObjectProperty(
  4894. createSimpleExpression(name, true, nameLoc),
  4895. createSimpleExpression(
  4896. value ? value.content : "",
  4897. isStatic,
  4898. value ? value.loc : loc
  4899. )
  4900. )
  4901. );
  4902. } else {
  4903. const { name, arg, exp, loc, modifiers } = prop;
  4904. const isVBind = name === "bind";
  4905. const isVOn = name === "on";
  4906. if (name === "slot") {
  4907. if (!isComponent) {
  4908. context.onError(
  4909. createCompilerError(40, loc)
  4910. );
  4911. }
  4912. continue;
  4913. }
  4914. if (name === "once" || name === "memo") {
  4915. continue;
  4916. }
  4917. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  4918. "COMPILER_IS_ON_ELEMENT",
  4919. context
  4920. ))) {
  4921. continue;
  4922. }
  4923. if (isVOn && ssr) {
  4924. continue;
  4925. }
  4926. if (
  4927. // #938: elements with dynamic keys should be forced into blocks
  4928. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  4929. // before children
  4930. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  4931. ) {
  4932. shouldUseBlock = true;
  4933. }
  4934. if (isVBind && isStaticArgOf(arg, "ref")) {
  4935. pushRefVForMarker();
  4936. }
  4937. if (!arg && (isVBind || isVOn)) {
  4938. hasDynamicKeys = true;
  4939. if (exp) {
  4940. if (isVBind) {
  4941. {
  4942. pushMergeArg();
  4943. if (!!(process.env.NODE_ENV !== "production")) {
  4944. const hasOverridableKeys = mergeArgs.some((arg2) => {
  4945. if (arg2.type === 15) {
  4946. return arg2.properties.some(({ key }) => {
  4947. if (key.type !== 4 || !key.isStatic) {
  4948. return true;
  4949. }
  4950. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  4951. });
  4952. } else {
  4953. return true;
  4954. }
  4955. });
  4956. if (hasOverridableKeys) {
  4957. checkCompatEnabled(
  4958. "COMPILER_V_BIND_OBJECT_ORDER",
  4959. context,
  4960. loc
  4961. );
  4962. }
  4963. }
  4964. if (isCompatEnabled(
  4965. "COMPILER_V_BIND_OBJECT_ORDER",
  4966. context
  4967. )) {
  4968. mergeArgs.unshift(exp);
  4969. continue;
  4970. }
  4971. }
  4972. pushRefVForMarker();
  4973. pushMergeArg();
  4974. mergeArgs.push(exp);
  4975. } else {
  4976. pushMergeArg({
  4977. type: 14,
  4978. loc,
  4979. callee: context.helper(TO_HANDLERS),
  4980. arguments: isComponent ? [exp] : [exp, `true`]
  4981. });
  4982. }
  4983. } else {
  4984. context.onError(
  4985. createCompilerError(
  4986. isVBind ? 34 : 35,
  4987. loc
  4988. )
  4989. );
  4990. }
  4991. continue;
  4992. }
  4993. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  4994. patchFlag |= 32;
  4995. }
  4996. const directiveTransform = context.directiveTransforms[name];
  4997. if (directiveTransform) {
  4998. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  4999. !ssr && props2.forEach(analyzePatchFlag);
  5000. if (isVOn && arg && !isStaticExp(arg)) {
  5001. pushMergeArg(createObjectExpression(props2, elementLoc));
  5002. } else {
  5003. properties.push(...props2);
  5004. }
  5005. if (needRuntime) {
  5006. runtimeDirectives.push(prop);
  5007. if (isSymbol(needRuntime)) {
  5008. directiveImportMap.set(prop, needRuntime);
  5009. }
  5010. }
  5011. } else if (!isBuiltInDirective(name)) {
  5012. runtimeDirectives.push(prop);
  5013. if (hasChildren) {
  5014. shouldUseBlock = true;
  5015. }
  5016. }
  5017. }
  5018. }
  5019. let propsExpression = void 0;
  5020. if (mergeArgs.length) {
  5021. pushMergeArg();
  5022. if (mergeArgs.length > 1) {
  5023. propsExpression = createCallExpression(
  5024. context.helper(MERGE_PROPS),
  5025. mergeArgs,
  5026. elementLoc
  5027. );
  5028. } else {
  5029. propsExpression = mergeArgs[0];
  5030. }
  5031. } else if (properties.length) {
  5032. propsExpression = createObjectExpression(
  5033. dedupeProperties(properties),
  5034. elementLoc
  5035. );
  5036. }
  5037. if (hasDynamicKeys) {
  5038. patchFlag |= 16;
  5039. } else {
  5040. if (hasClassBinding && !isComponent) {
  5041. patchFlag |= 2;
  5042. }
  5043. if (hasStyleBinding && !isComponent) {
  5044. patchFlag |= 4;
  5045. }
  5046. if (dynamicPropNames.length) {
  5047. patchFlag |= 8;
  5048. }
  5049. if (hasHydrationEventBinding) {
  5050. patchFlag |= 32;
  5051. }
  5052. }
  5053. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  5054. patchFlag |= 512;
  5055. }
  5056. if (!context.inSSR && propsExpression) {
  5057. switch (propsExpression.type) {
  5058. case 15:
  5059. let classKeyIndex = -1;
  5060. let styleKeyIndex = -1;
  5061. let hasDynamicKey = false;
  5062. for (let i = 0; i < propsExpression.properties.length; i++) {
  5063. const key = propsExpression.properties[i].key;
  5064. if (isStaticExp(key)) {
  5065. if (key.content === "class") {
  5066. classKeyIndex = i;
  5067. } else if (key.content === "style") {
  5068. styleKeyIndex = i;
  5069. }
  5070. } else if (!key.isHandlerKey) {
  5071. hasDynamicKey = true;
  5072. }
  5073. }
  5074. const classProp = propsExpression.properties[classKeyIndex];
  5075. const styleProp = propsExpression.properties[styleKeyIndex];
  5076. if (!hasDynamicKey) {
  5077. if (classProp && !isStaticExp(classProp.value)) {
  5078. classProp.value = createCallExpression(
  5079. context.helper(NORMALIZE_CLASS),
  5080. [classProp.value]
  5081. );
  5082. }
  5083. if (styleProp && // the static style is compiled into an object,
  5084. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  5085. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  5086. // v-bind:style with static literal object
  5087. styleProp.value.type === 17)) {
  5088. styleProp.value = createCallExpression(
  5089. context.helper(NORMALIZE_STYLE),
  5090. [styleProp.value]
  5091. );
  5092. }
  5093. } else {
  5094. propsExpression = createCallExpression(
  5095. context.helper(NORMALIZE_PROPS),
  5096. [propsExpression]
  5097. );
  5098. }
  5099. break;
  5100. case 14:
  5101. break;
  5102. default:
  5103. propsExpression = createCallExpression(
  5104. context.helper(NORMALIZE_PROPS),
  5105. [
  5106. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  5107. propsExpression
  5108. ])
  5109. ]
  5110. );
  5111. break;
  5112. }
  5113. }
  5114. return {
  5115. props: propsExpression,
  5116. directives: runtimeDirectives,
  5117. patchFlag,
  5118. dynamicPropNames,
  5119. shouldUseBlock
  5120. };
  5121. }
  5122. function dedupeProperties(properties) {
  5123. const knownProps = /* @__PURE__ */ new Map();
  5124. const deduped = [];
  5125. for (let i = 0; i < properties.length; i++) {
  5126. const prop = properties[i];
  5127. if (prop.key.type === 8 || !prop.key.isStatic) {
  5128. deduped.push(prop);
  5129. continue;
  5130. }
  5131. const name = prop.key.content;
  5132. const existing = knownProps.get(name);
  5133. if (existing) {
  5134. if (name === "style" || name === "class" || isOn(name)) {
  5135. mergeAsArray(existing, prop);
  5136. }
  5137. } else {
  5138. knownProps.set(name, prop);
  5139. deduped.push(prop);
  5140. }
  5141. }
  5142. return deduped;
  5143. }
  5144. function mergeAsArray(existing, incoming) {
  5145. if (existing.value.type === 17) {
  5146. existing.value.elements.push(incoming.value);
  5147. } else {
  5148. existing.value = createArrayExpression(
  5149. [existing.value, incoming.value],
  5150. existing.loc
  5151. );
  5152. }
  5153. }
  5154. function buildDirectiveArgs(dir, context) {
  5155. const dirArgs = [];
  5156. const runtime = directiveImportMap.get(dir);
  5157. if (runtime) {
  5158. dirArgs.push(context.helperString(runtime));
  5159. } else {
  5160. {
  5161. context.helper(RESOLVE_DIRECTIVE);
  5162. context.directives.add(dir.name);
  5163. dirArgs.push(toValidAssetId(dir.name, `directive`));
  5164. }
  5165. }
  5166. const { loc } = dir;
  5167. if (dir.exp) dirArgs.push(dir.exp);
  5168. if (dir.arg) {
  5169. if (!dir.exp) {
  5170. dirArgs.push(`void 0`);
  5171. }
  5172. dirArgs.push(dir.arg);
  5173. }
  5174. if (Object.keys(dir.modifiers).length) {
  5175. if (!dir.arg) {
  5176. if (!dir.exp) {
  5177. dirArgs.push(`void 0`);
  5178. }
  5179. dirArgs.push(`void 0`);
  5180. }
  5181. const trueExpression = createSimpleExpression(`true`, false, loc);
  5182. dirArgs.push(
  5183. createObjectExpression(
  5184. dir.modifiers.map(
  5185. (modifier) => createObjectProperty(modifier, trueExpression)
  5186. ),
  5187. loc
  5188. )
  5189. );
  5190. }
  5191. return createArrayExpression(dirArgs, dir.loc);
  5192. }
  5193. function stringifyDynamicPropNames(props) {
  5194. let propsNamesString = `[`;
  5195. for (let i = 0, l = props.length; i < l; i++) {
  5196. propsNamesString += JSON.stringify(props[i]);
  5197. if (i < l - 1) propsNamesString += ", ";
  5198. }
  5199. return propsNamesString + `]`;
  5200. }
  5201. function isComponentTag(tag) {
  5202. return tag === "component" || tag === "Component";
  5203. }
  5204. const transformSlotOutlet = (node, context) => {
  5205. if (isSlotOutlet(node)) {
  5206. const { children, loc } = node;
  5207. const { slotName, slotProps } = processSlotOutlet(node, context);
  5208. const slotArgs = [
  5209. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  5210. slotName,
  5211. "{}",
  5212. "undefined",
  5213. "true"
  5214. ];
  5215. let expectedLen = 2;
  5216. if (slotProps) {
  5217. slotArgs[2] = slotProps;
  5218. expectedLen = 3;
  5219. }
  5220. if (children.length) {
  5221. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  5222. expectedLen = 4;
  5223. }
  5224. if (context.scopeId && !context.slotted) {
  5225. expectedLen = 5;
  5226. }
  5227. slotArgs.splice(expectedLen);
  5228. node.codegenNode = createCallExpression(
  5229. context.helper(RENDER_SLOT),
  5230. slotArgs,
  5231. loc
  5232. );
  5233. }
  5234. };
  5235. function processSlotOutlet(node, context) {
  5236. let slotName = `"default"`;
  5237. let slotProps = void 0;
  5238. const nonNameProps = [];
  5239. for (let i = 0; i < node.props.length; i++) {
  5240. const p = node.props[i];
  5241. if (p.type === 6) {
  5242. if (p.value) {
  5243. if (p.name === "name") {
  5244. slotName = JSON.stringify(p.value.content);
  5245. } else {
  5246. p.name = camelize(p.name);
  5247. nonNameProps.push(p);
  5248. }
  5249. }
  5250. } else {
  5251. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  5252. if (p.exp) {
  5253. slotName = p.exp;
  5254. } else if (p.arg && p.arg.type === 4) {
  5255. const name = camelize(p.arg.content);
  5256. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  5257. }
  5258. } else {
  5259. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  5260. p.arg.content = camelize(p.arg.content);
  5261. }
  5262. nonNameProps.push(p);
  5263. }
  5264. }
  5265. }
  5266. if (nonNameProps.length > 0) {
  5267. const { props, directives } = buildProps(
  5268. node,
  5269. context,
  5270. nonNameProps,
  5271. false,
  5272. false
  5273. );
  5274. slotProps = props;
  5275. if (directives.length) {
  5276. context.onError(
  5277. createCompilerError(
  5278. 36,
  5279. directives[0].loc
  5280. )
  5281. );
  5282. }
  5283. }
  5284. return {
  5285. slotName,
  5286. slotProps
  5287. };
  5288. }
  5289. const transformOn = (dir, node, context, augmentor) => {
  5290. const { loc, modifiers, arg } = dir;
  5291. if (!dir.exp && !modifiers.length) {
  5292. context.onError(createCompilerError(35, loc));
  5293. }
  5294. let eventName;
  5295. if (arg.type === 4) {
  5296. if (arg.isStatic) {
  5297. let rawName = arg.content;
  5298. if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) {
  5299. context.onError(createCompilerError(51, arg.loc));
  5300. }
  5301. if (rawName.startsWith("vue:")) {
  5302. rawName = `vnode-${rawName.slice(4)}`;
  5303. }
  5304. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  5305. // for non-element and vnode lifecycle event listeners, auto convert
  5306. // it to camelCase. See issue #2249
  5307. toHandlerKey(camelize(rawName))
  5308. ) : (
  5309. // preserve case for plain element listeners that have uppercase
  5310. // letters, as these may be custom elements' custom events
  5311. `on:${rawName}`
  5312. );
  5313. eventName = createSimpleExpression(eventString, true, arg.loc);
  5314. } else {
  5315. eventName = createCompoundExpression([
  5316. `${context.helperString(TO_HANDLER_KEY)}(`,
  5317. arg,
  5318. `)`
  5319. ]);
  5320. }
  5321. } else {
  5322. eventName = arg;
  5323. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  5324. eventName.children.push(`)`);
  5325. }
  5326. let exp = dir.exp;
  5327. if (exp && !exp.content.trim()) {
  5328. exp = void 0;
  5329. }
  5330. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  5331. if (exp) {
  5332. const isMemberExp = isMemberExpression(exp);
  5333. const isInlineStatement = !(isMemberExp || isFnExpression(exp));
  5334. const hasMultipleStatements = exp.content.includes(`;`);
  5335. if (!!(process.env.NODE_ENV !== "production") && true) {
  5336. validateBrowserExpression(
  5337. exp,
  5338. context,
  5339. false,
  5340. hasMultipleStatements
  5341. );
  5342. }
  5343. if (isInlineStatement || shouldCache && isMemberExp) {
  5344. exp = createCompoundExpression([
  5345. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  5346. exp,
  5347. hasMultipleStatements ? `}` : `)`
  5348. ]);
  5349. }
  5350. }
  5351. let ret = {
  5352. props: [
  5353. createObjectProperty(
  5354. eventName,
  5355. exp || createSimpleExpression(`() => {}`, false, loc)
  5356. )
  5357. ]
  5358. };
  5359. if (augmentor) {
  5360. ret = augmentor(ret);
  5361. }
  5362. if (shouldCache) {
  5363. ret.props[0].value = context.cache(ret.props[0].value);
  5364. }
  5365. ret.props.forEach((p) => p.key.isHandlerKey = true);
  5366. return ret;
  5367. };
  5368. const transformText = (node, context) => {
  5369. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  5370. return () => {
  5371. const children = node.children;
  5372. let currentContainer = void 0;
  5373. let hasText = false;
  5374. for (let i = 0; i < children.length; i++) {
  5375. const child = children[i];
  5376. if (isText$1(child)) {
  5377. hasText = true;
  5378. for (let j = i + 1; j < children.length; j++) {
  5379. const next = children[j];
  5380. if (isText$1(next)) {
  5381. if (!currentContainer) {
  5382. currentContainer = children[i] = createCompoundExpression(
  5383. [child],
  5384. child.loc
  5385. );
  5386. }
  5387. currentContainer.children.push(` + `, next);
  5388. children.splice(j, 1);
  5389. j--;
  5390. } else {
  5391. currentContainer = void 0;
  5392. break;
  5393. }
  5394. }
  5395. }
  5396. }
  5397. if (!hasText || // if this is a plain element with a single text child, leave it
  5398. // as-is since the runtime has dedicated fast path for this by directly
  5399. // setting textContent of the element.
  5400. // for component root it's always normalized anyway.
  5401. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  5402. // custom directives can potentially add DOM elements arbitrarily,
  5403. // we need to avoid setting textContent of the element at runtime
  5404. // to avoid accidentally overwriting the DOM elements added
  5405. // by the user through custom directives.
  5406. !node.props.find(
  5407. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  5408. ) && // in compat mode, <template> tags with no special directives
  5409. // will be rendered as a fragment so its children must be
  5410. // converted into vnodes.
  5411. !(node.tag === "template"))) {
  5412. return;
  5413. }
  5414. for (let i = 0; i < children.length; i++) {
  5415. const child = children[i];
  5416. if (isText$1(child) || child.type === 8) {
  5417. const callArgs = [];
  5418. if (child.type !== 2 || child.content !== " ") {
  5419. callArgs.push(child);
  5420. }
  5421. if (!context.ssr && getConstantType(child, context) === 0) {
  5422. callArgs.push(
  5423. 1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[1]} */` : ``)
  5424. );
  5425. }
  5426. children[i] = {
  5427. type: 12,
  5428. content: child,
  5429. loc: child.loc,
  5430. codegenNode: createCallExpression(
  5431. context.helper(CREATE_TEXT),
  5432. callArgs
  5433. )
  5434. };
  5435. }
  5436. }
  5437. };
  5438. }
  5439. };
  5440. const seen$1 = /* @__PURE__ */ new WeakSet();
  5441. const transformOnce = (node, context) => {
  5442. if (node.type === 1 && findDir(node, "once", true)) {
  5443. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  5444. return;
  5445. }
  5446. seen$1.add(node);
  5447. context.inVOnce = true;
  5448. context.helper(SET_BLOCK_TRACKING);
  5449. return () => {
  5450. context.inVOnce = false;
  5451. const cur = context.currentNode;
  5452. if (cur.codegenNode) {
  5453. cur.codegenNode = context.cache(
  5454. cur.codegenNode,
  5455. true,
  5456. true
  5457. );
  5458. }
  5459. };
  5460. }
  5461. };
  5462. const transformModel = (dir, node, context) => {
  5463. const { exp, arg } = dir;
  5464. if (!exp) {
  5465. context.onError(
  5466. createCompilerError(41, dir.loc)
  5467. );
  5468. return createTransformProps();
  5469. }
  5470. const rawExp = exp.loc.source.trim();
  5471. const expString = exp.type === 4 ? exp.content : rawExp;
  5472. const bindingType = context.bindingMetadata[rawExp];
  5473. if (bindingType === "props" || bindingType === "props-aliased") {
  5474. context.onError(createCompilerError(44, exp.loc));
  5475. return createTransformProps();
  5476. }
  5477. if (!expString.trim() || !isMemberExpression(exp) && true) {
  5478. context.onError(
  5479. createCompilerError(42, exp.loc)
  5480. );
  5481. return createTransformProps();
  5482. }
  5483. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  5484. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  5485. let assignmentExp;
  5486. const eventArg = context.isTS ? `($event: any)` : `$event`;
  5487. {
  5488. assignmentExp = createCompoundExpression([
  5489. `${eventArg} => ((`,
  5490. exp,
  5491. `) = $event)`
  5492. ]);
  5493. }
  5494. const props = [
  5495. // modelValue: foo
  5496. createObjectProperty(propName, dir.exp),
  5497. // "onUpdate:modelValue": $event => (foo = $event)
  5498. createObjectProperty(eventName, assignmentExp)
  5499. ];
  5500. if (dir.modifiers.length && node.tagType === 1) {
  5501. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  5502. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  5503. props.push(
  5504. createObjectProperty(
  5505. modifiersKey,
  5506. createSimpleExpression(
  5507. `{ ${modifiers} }`,
  5508. false,
  5509. dir.loc,
  5510. 2
  5511. )
  5512. )
  5513. );
  5514. }
  5515. return createTransformProps(props);
  5516. };
  5517. function createTransformProps(props = []) {
  5518. return { props };
  5519. }
  5520. const validDivisionCharRE = /[\w).+\-_$\]]/;
  5521. const transformFilter = (node, context) => {
  5522. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  5523. return;
  5524. }
  5525. if (node.type === 5) {
  5526. rewriteFilter(node.content, context);
  5527. } else if (node.type === 1) {
  5528. node.props.forEach((prop) => {
  5529. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  5530. rewriteFilter(prop.exp, context);
  5531. }
  5532. });
  5533. }
  5534. };
  5535. function rewriteFilter(node, context) {
  5536. if (node.type === 4) {
  5537. parseFilter(node, context);
  5538. } else {
  5539. for (let i = 0; i < node.children.length; i++) {
  5540. const child = node.children[i];
  5541. if (typeof child !== "object") continue;
  5542. if (child.type === 4) {
  5543. parseFilter(child, context);
  5544. } else if (child.type === 8) {
  5545. rewriteFilter(node, context);
  5546. } else if (child.type === 5) {
  5547. rewriteFilter(child.content, context);
  5548. }
  5549. }
  5550. }
  5551. }
  5552. function parseFilter(node, context) {
  5553. const exp = node.content;
  5554. let inSingle = false;
  5555. let inDouble = false;
  5556. let inTemplateString = false;
  5557. let inRegex = false;
  5558. let curly = 0;
  5559. let square = 0;
  5560. let paren = 0;
  5561. let lastFilterIndex = 0;
  5562. let c, prev, i, expression, filters = [];
  5563. for (i = 0; i < exp.length; i++) {
  5564. prev = c;
  5565. c = exp.charCodeAt(i);
  5566. if (inSingle) {
  5567. if (c === 39 && prev !== 92) inSingle = false;
  5568. } else if (inDouble) {
  5569. if (c === 34 && prev !== 92) inDouble = false;
  5570. } else if (inTemplateString) {
  5571. if (c === 96 && prev !== 92) inTemplateString = false;
  5572. } else if (inRegex) {
  5573. if (c === 47 && prev !== 92) inRegex = false;
  5574. } else if (c === 124 && // pipe
  5575. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  5576. if (expression === void 0) {
  5577. lastFilterIndex = i + 1;
  5578. expression = exp.slice(0, i).trim();
  5579. } else {
  5580. pushFilter();
  5581. }
  5582. } else {
  5583. switch (c) {
  5584. case 34:
  5585. inDouble = true;
  5586. break;
  5587. // "
  5588. case 39:
  5589. inSingle = true;
  5590. break;
  5591. // '
  5592. case 96:
  5593. inTemplateString = true;
  5594. break;
  5595. // `
  5596. case 40:
  5597. paren++;
  5598. break;
  5599. // (
  5600. case 41:
  5601. paren--;
  5602. break;
  5603. // )
  5604. case 91:
  5605. square++;
  5606. break;
  5607. // [
  5608. case 93:
  5609. square--;
  5610. break;
  5611. // ]
  5612. case 123:
  5613. curly++;
  5614. break;
  5615. // {
  5616. case 125:
  5617. curly--;
  5618. break;
  5619. }
  5620. if (c === 47) {
  5621. let j = i - 1;
  5622. let p;
  5623. for (; j >= 0; j--) {
  5624. p = exp.charAt(j);
  5625. if (p !== " ") break;
  5626. }
  5627. if (!p || !validDivisionCharRE.test(p)) {
  5628. inRegex = true;
  5629. }
  5630. }
  5631. }
  5632. }
  5633. if (expression === void 0) {
  5634. expression = exp.slice(0, i).trim();
  5635. } else if (lastFilterIndex !== 0) {
  5636. pushFilter();
  5637. }
  5638. function pushFilter() {
  5639. filters.push(exp.slice(lastFilterIndex, i).trim());
  5640. lastFilterIndex = i + 1;
  5641. }
  5642. if (filters.length) {
  5643. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  5644. "COMPILER_FILTERS",
  5645. context,
  5646. node.loc
  5647. );
  5648. for (i = 0; i < filters.length; i++) {
  5649. expression = wrapFilter(expression, filters[i], context);
  5650. }
  5651. node.content = expression;
  5652. node.ast = void 0;
  5653. }
  5654. }
  5655. function wrapFilter(exp, filter, context) {
  5656. context.helper(RESOLVE_FILTER);
  5657. const i = filter.indexOf("(");
  5658. if (i < 0) {
  5659. context.filters.add(filter);
  5660. return `${toValidAssetId(filter, "filter")}(${exp})`;
  5661. } else {
  5662. const name = filter.slice(0, i);
  5663. const args = filter.slice(i + 1);
  5664. context.filters.add(name);
  5665. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  5666. }
  5667. }
  5668. const seen = /* @__PURE__ */ new WeakSet();
  5669. const transformMemo = (node, context) => {
  5670. if (node.type === 1) {
  5671. const dir = findDir(node, "memo");
  5672. if (!dir || seen.has(node) || context.inSSR) {
  5673. return;
  5674. }
  5675. seen.add(node);
  5676. return () => {
  5677. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  5678. if (codegenNode && codegenNode.type === 13) {
  5679. if (node.tagType !== 1) {
  5680. convertToBlock(codegenNode, context);
  5681. }
  5682. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  5683. dir.exp,
  5684. createFunctionExpression(void 0, codegenNode),
  5685. `_cache`,
  5686. String(context.cached.length)
  5687. ]);
  5688. context.cached.push(null);
  5689. }
  5690. };
  5691. }
  5692. };
  5693. function getBaseTransformPreset(prefixIdentifiers) {
  5694. return [
  5695. [
  5696. transformOnce,
  5697. transformIf,
  5698. transformMemo,
  5699. transformFor,
  5700. ...[transformFilter] ,
  5701. ...!!(process.env.NODE_ENV !== "production") ? [transformExpression] : [],
  5702. transformSlotOutlet,
  5703. transformElement,
  5704. trackSlotScopes,
  5705. transformText
  5706. ],
  5707. {
  5708. on: transformOn,
  5709. bind: transformBind,
  5710. model: transformModel
  5711. }
  5712. ];
  5713. }
  5714. function baseCompile(source, options = {}) {
  5715. const onError = options.onError || defaultOnError;
  5716. const isModuleMode = options.mode === "module";
  5717. {
  5718. if (options.prefixIdentifiers === true) {
  5719. onError(createCompilerError(47));
  5720. } else if (isModuleMode) {
  5721. onError(createCompilerError(48));
  5722. }
  5723. }
  5724. const prefixIdentifiers = false;
  5725. if (options.cacheHandlers) {
  5726. onError(createCompilerError(49));
  5727. }
  5728. if (options.scopeId && !isModuleMode) {
  5729. onError(createCompilerError(50));
  5730. }
  5731. const resolvedOptions = extend({}, options, {
  5732. prefixIdentifiers
  5733. });
  5734. const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
  5735. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  5736. transform(
  5737. ast,
  5738. extend({}, resolvedOptions, {
  5739. nodeTransforms: [
  5740. ...nodeTransforms,
  5741. ...options.nodeTransforms || []
  5742. // user transforms
  5743. ],
  5744. directiveTransforms: extend(
  5745. {},
  5746. directiveTransforms,
  5747. options.directiveTransforms || {}
  5748. // user transforms
  5749. )
  5750. })
  5751. );
  5752. return generate(ast, resolvedOptions);
  5753. }
  5754. const BindingTypes = {
  5755. "DATA": "data",
  5756. "PROPS": "props",
  5757. "PROPS_ALIASED": "props-aliased",
  5758. "SETUP_LET": "setup-let",
  5759. "SETUP_CONST": "setup-const",
  5760. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  5761. "SETUP_MAYBE_REF": "setup-maybe-ref",
  5762. "SETUP_REF": "setup-ref",
  5763. "OPTIONS": "options",
  5764. "LITERAL_CONST": "literal-const"
  5765. };
  5766. const noopDirectiveTransform = () => ({ props: [] });
  5767. 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, traverseNode, unwrapTSNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };