compiler-dom.esm-browser.js 182 KB

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