compiler-dom.esm-browser.js 193 KB

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