compiler-core.cjs.js 197 KB

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