compiler-dom.global.js 198 KB

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