compiler-core.esm-bundler.js 169 KB

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