compiler-core.cjs.prod.js 193 KB

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