compiler-dom.esm-browser.js 190 KB

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