compiler-dom.esm-browser.js 189 KB

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