compiler-dom.esm-browser.js 181 KB

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