compiler-core.cjs.prod.js 187 KB

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