compiler-dom.global.js 206 KB

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