compiler-core.cjs.prod.js 196 KB

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