compiler-dom.global.js 207 KB

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