compiler-dom.esm-browser.js 189 KB

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