compiler-dom.esm-browser.js 191 KB

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