移动储能车V1版本
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

compiler-dom.esm-browser.js 181KB

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