compiler-dom.esm-browser.js 189 KB

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