compiler-core.cjs.prod.js 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690
  1. /**
  2. * @vue/compiler-core v3.5.13
  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 !grandparent;
  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.rawName
  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. if (toCache.length === children.length && node.type === 1) {
  3017. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
  3018. node.codegenNode.children = getCacheExpression(
  3019. createArrayExpression(node.codegenNode.children)
  3020. );
  3021. cachedAsArray = true;
  3022. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  3023. const slot = getSlotNode(node.codegenNode, "default");
  3024. if (slot) {
  3025. slot.returns = getCacheExpression(
  3026. createArrayExpression(slot.returns)
  3027. );
  3028. cachedAsArray = true;
  3029. }
  3030. } 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) {
  3031. const slotName = findDir(node, "slot", true);
  3032. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  3033. if (slot) {
  3034. slot.returns = getCacheExpression(
  3035. createArrayExpression(slot.returns)
  3036. );
  3037. cachedAsArray = true;
  3038. }
  3039. }
  3040. }
  3041. if (!cachedAsArray) {
  3042. for (const child of toCache) {
  3043. child.codegenNode = context.cache(child.codegenNode);
  3044. }
  3045. }
  3046. function getCacheExpression(value) {
  3047. const exp = context.cache(value);
  3048. if (inFor && context.hmr) {
  3049. exp.needArraySpread = true;
  3050. }
  3051. return exp;
  3052. }
  3053. function getSlotNode(node2, name) {
  3054. if (node2.children && !shared.isArray(node2.children) && node2.children.type === 15) {
  3055. const slot = node2.children.properties.find(
  3056. (p) => p.key === name || p.key.content === name
  3057. );
  3058. return slot && slot.value;
  3059. }
  3060. }
  3061. if (toCache.length && context.transformHoist) {
  3062. context.transformHoist(children, context, node);
  3063. }
  3064. }
  3065. function getConstantType(node, context) {
  3066. const { constantCache } = context;
  3067. switch (node.type) {
  3068. case 1:
  3069. if (node.tagType !== 0) {
  3070. return 0;
  3071. }
  3072. const cached = constantCache.get(node);
  3073. if (cached !== void 0) {
  3074. return cached;
  3075. }
  3076. const codegenNode = node.codegenNode;
  3077. if (codegenNode.type !== 13) {
  3078. return 0;
  3079. }
  3080. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  3081. return 0;
  3082. }
  3083. if (codegenNode.patchFlag === void 0) {
  3084. let returnType2 = 3;
  3085. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  3086. if (generatedPropsType === 0) {
  3087. constantCache.set(node, 0);
  3088. return 0;
  3089. }
  3090. if (generatedPropsType < returnType2) {
  3091. returnType2 = generatedPropsType;
  3092. }
  3093. for (let i = 0; i < node.children.length; i++) {
  3094. const childType = getConstantType(node.children[i], context);
  3095. if (childType === 0) {
  3096. constantCache.set(node, 0);
  3097. return 0;
  3098. }
  3099. if (childType < returnType2) {
  3100. returnType2 = childType;
  3101. }
  3102. }
  3103. if (returnType2 > 1) {
  3104. for (let i = 0; i < node.props.length; i++) {
  3105. const p = node.props[i];
  3106. if (p.type === 7 && p.name === "bind" && p.exp) {
  3107. const expType = getConstantType(p.exp, context);
  3108. if (expType === 0) {
  3109. constantCache.set(node, 0);
  3110. return 0;
  3111. }
  3112. if (expType < returnType2) {
  3113. returnType2 = expType;
  3114. }
  3115. }
  3116. }
  3117. }
  3118. if (codegenNode.isBlock) {
  3119. for (let i = 0; i < node.props.length; i++) {
  3120. const p = node.props[i];
  3121. if (p.type === 7) {
  3122. constantCache.set(node, 0);
  3123. return 0;
  3124. }
  3125. }
  3126. context.removeHelper(OPEN_BLOCK);
  3127. context.removeHelper(
  3128. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  3129. );
  3130. codegenNode.isBlock = false;
  3131. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  3132. }
  3133. constantCache.set(node, returnType2);
  3134. return returnType2;
  3135. } else {
  3136. constantCache.set(node, 0);
  3137. return 0;
  3138. }
  3139. case 2:
  3140. case 3:
  3141. return 3;
  3142. case 9:
  3143. case 11:
  3144. case 10:
  3145. return 0;
  3146. case 5:
  3147. case 12:
  3148. return getConstantType(node.content, context);
  3149. case 4:
  3150. return node.constType;
  3151. case 8:
  3152. let returnType = 3;
  3153. for (let i = 0; i < node.children.length; i++) {
  3154. const child = node.children[i];
  3155. if (shared.isString(child) || shared.isSymbol(child)) {
  3156. continue;
  3157. }
  3158. const childType = getConstantType(child, context);
  3159. if (childType === 0) {
  3160. return 0;
  3161. } else if (childType < returnType) {
  3162. returnType = childType;
  3163. }
  3164. }
  3165. return returnType;
  3166. case 20:
  3167. return 2;
  3168. default:
  3169. return 0;
  3170. }
  3171. }
  3172. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  3173. NORMALIZE_CLASS,
  3174. NORMALIZE_STYLE,
  3175. NORMALIZE_PROPS,
  3176. GUARD_REACTIVE_PROPS
  3177. ]);
  3178. function getConstantTypeOfHelperCall(value, context) {
  3179. if (value.type === 14 && !shared.isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  3180. const arg = value.arguments[0];
  3181. if (arg.type === 4) {
  3182. return getConstantType(arg, context);
  3183. } else if (arg.type === 14) {
  3184. return getConstantTypeOfHelperCall(arg, context);
  3185. }
  3186. }
  3187. return 0;
  3188. }
  3189. function getGeneratedPropsConstantType(node, context) {
  3190. let returnType = 3;
  3191. const props = getNodeProps(node);
  3192. if (props && props.type === 15) {
  3193. const { properties } = props;
  3194. for (let i = 0; i < properties.length; i++) {
  3195. const { key, value } = properties[i];
  3196. const keyType = getConstantType(key, context);
  3197. if (keyType === 0) {
  3198. return keyType;
  3199. }
  3200. if (keyType < returnType) {
  3201. returnType = keyType;
  3202. }
  3203. let valueType;
  3204. if (value.type === 4) {
  3205. valueType = getConstantType(value, context);
  3206. } else if (value.type === 14) {
  3207. valueType = getConstantTypeOfHelperCall(value, context);
  3208. } else {
  3209. valueType = 0;
  3210. }
  3211. if (valueType === 0) {
  3212. return valueType;
  3213. }
  3214. if (valueType < returnType) {
  3215. returnType = valueType;
  3216. }
  3217. }
  3218. }
  3219. return returnType;
  3220. }
  3221. function getNodeProps(node) {
  3222. const codegenNode = node.codegenNode;
  3223. if (codegenNode.type === 13) {
  3224. return codegenNode.props;
  3225. }
  3226. }
  3227. function createTransformContext(root, {
  3228. filename = "",
  3229. prefixIdentifiers = false,
  3230. hoistStatic = false,
  3231. hmr = false,
  3232. cacheHandlers = false,
  3233. nodeTransforms = [],
  3234. directiveTransforms = {},
  3235. transformHoist = null,
  3236. isBuiltInComponent = shared.NOOP,
  3237. isCustomElement = shared.NOOP,
  3238. expressionPlugins = [],
  3239. scopeId = null,
  3240. slotted = true,
  3241. ssr = false,
  3242. inSSR = false,
  3243. ssrCssVars = ``,
  3244. bindingMetadata = shared.EMPTY_OBJ,
  3245. inline = false,
  3246. isTS = false,
  3247. onError = defaultOnError,
  3248. onWarn = defaultOnWarn,
  3249. compatConfig
  3250. }) {
  3251. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  3252. const context = {
  3253. // options
  3254. filename,
  3255. selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
  3256. prefixIdentifiers,
  3257. hoistStatic,
  3258. hmr,
  3259. cacheHandlers,
  3260. nodeTransforms,
  3261. directiveTransforms,
  3262. transformHoist,
  3263. isBuiltInComponent,
  3264. isCustomElement,
  3265. expressionPlugins,
  3266. scopeId,
  3267. slotted,
  3268. ssr,
  3269. inSSR,
  3270. ssrCssVars,
  3271. bindingMetadata,
  3272. inline,
  3273. isTS,
  3274. onError,
  3275. onWarn,
  3276. compatConfig,
  3277. // state
  3278. root,
  3279. helpers: /* @__PURE__ */ new Map(),
  3280. components: /* @__PURE__ */ new Set(),
  3281. directives: /* @__PURE__ */ new Set(),
  3282. hoists: [],
  3283. imports: [],
  3284. cached: [],
  3285. constantCache: /* @__PURE__ */ new WeakMap(),
  3286. temps: 0,
  3287. identifiers: /* @__PURE__ */ Object.create(null),
  3288. scopes: {
  3289. vFor: 0,
  3290. vSlot: 0,
  3291. vPre: 0,
  3292. vOnce: 0
  3293. },
  3294. parent: null,
  3295. grandParent: null,
  3296. currentNode: root,
  3297. childIndex: 0,
  3298. inVOnce: false,
  3299. // methods
  3300. helper(name) {
  3301. const count = context.helpers.get(name) || 0;
  3302. context.helpers.set(name, count + 1);
  3303. return name;
  3304. },
  3305. removeHelper(name) {
  3306. const count = context.helpers.get(name);
  3307. if (count) {
  3308. const currentCount = count - 1;
  3309. if (!currentCount) {
  3310. context.helpers.delete(name);
  3311. } else {
  3312. context.helpers.set(name, currentCount);
  3313. }
  3314. }
  3315. },
  3316. helperString(name) {
  3317. return `_${helperNameMap[context.helper(name)]}`;
  3318. },
  3319. replaceNode(node) {
  3320. context.parent.children[context.childIndex] = context.currentNode = node;
  3321. },
  3322. removeNode(node) {
  3323. const list = context.parent.children;
  3324. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  3325. if (!node || node === context.currentNode) {
  3326. context.currentNode = null;
  3327. context.onNodeRemoved();
  3328. } else {
  3329. if (context.childIndex > removalIndex) {
  3330. context.childIndex--;
  3331. context.onNodeRemoved();
  3332. }
  3333. }
  3334. context.parent.children.splice(removalIndex, 1);
  3335. },
  3336. onNodeRemoved: shared.NOOP,
  3337. addIdentifiers(exp) {
  3338. {
  3339. if (shared.isString(exp)) {
  3340. addId(exp);
  3341. } else if (exp.identifiers) {
  3342. exp.identifiers.forEach(addId);
  3343. } else if (exp.type === 4) {
  3344. addId(exp.content);
  3345. }
  3346. }
  3347. },
  3348. removeIdentifiers(exp) {
  3349. {
  3350. if (shared.isString(exp)) {
  3351. removeId(exp);
  3352. } else if (exp.identifiers) {
  3353. exp.identifiers.forEach(removeId);
  3354. } else if (exp.type === 4) {
  3355. removeId(exp.content);
  3356. }
  3357. }
  3358. },
  3359. hoist(exp) {
  3360. if (shared.isString(exp)) exp = createSimpleExpression(exp);
  3361. context.hoists.push(exp);
  3362. const identifier = createSimpleExpression(
  3363. `_hoisted_${context.hoists.length}`,
  3364. false,
  3365. exp.loc,
  3366. 2
  3367. );
  3368. identifier.hoisted = exp;
  3369. return identifier;
  3370. },
  3371. cache(exp, isVNode = false, inVOnce = false) {
  3372. const cacheExp = createCacheExpression(
  3373. context.cached.length,
  3374. exp,
  3375. isVNode,
  3376. inVOnce
  3377. );
  3378. context.cached.push(cacheExp);
  3379. return cacheExp;
  3380. }
  3381. };
  3382. {
  3383. context.filters = /* @__PURE__ */ new Set();
  3384. }
  3385. function addId(id) {
  3386. const { identifiers } = context;
  3387. if (identifiers[id] === void 0) {
  3388. identifiers[id] = 0;
  3389. }
  3390. identifiers[id]++;
  3391. }
  3392. function removeId(id) {
  3393. context.identifiers[id]--;
  3394. }
  3395. return context;
  3396. }
  3397. function transform(root, options) {
  3398. const context = createTransformContext(root, options);
  3399. traverseNode(root, context);
  3400. if (options.hoistStatic) {
  3401. cacheStatic(root, context);
  3402. }
  3403. if (!options.ssr) {
  3404. createRootCodegen(root, context);
  3405. }
  3406. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  3407. root.components = [...context.components];
  3408. root.directives = [...context.directives];
  3409. root.imports = context.imports;
  3410. root.hoists = context.hoists;
  3411. root.temps = context.temps;
  3412. root.cached = context.cached;
  3413. root.transformed = true;
  3414. {
  3415. root.filters = [...context.filters];
  3416. }
  3417. }
  3418. function createRootCodegen(root, context) {
  3419. const { helper } = context;
  3420. const { children } = root;
  3421. if (children.length === 1) {
  3422. const child = children[0];
  3423. if (isSingleElementRoot(root, child) && child.codegenNode) {
  3424. const codegenNode = child.codegenNode;
  3425. if (codegenNode.type === 13) {
  3426. convertToBlock(codegenNode, context);
  3427. }
  3428. root.codegenNode = codegenNode;
  3429. } else {
  3430. root.codegenNode = child;
  3431. }
  3432. } else if (children.length > 1) {
  3433. let patchFlag = 64;
  3434. root.codegenNode = createVNodeCall(
  3435. context,
  3436. helper(FRAGMENT),
  3437. void 0,
  3438. root.children,
  3439. patchFlag,
  3440. void 0,
  3441. void 0,
  3442. true,
  3443. void 0,
  3444. false
  3445. );
  3446. } else ;
  3447. }
  3448. function traverseChildren(parent, context) {
  3449. let i = 0;
  3450. const nodeRemoved = () => {
  3451. i--;
  3452. };
  3453. for (; i < parent.children.length; i++) {
  3454. const child = parent.children[i];
  3455. if (shared.isString(child)) continue;
  3456. context.grandParent = context.parent;
  3457. context.parent = parent;
  3458. context.childIndex = i;
  3459. context.onNodeRemoved = nodeRemoved;
  3460. traverseNode(child, context);
  3461. }
  3462. }
  3463. function traverseNode(node, context) {
  3464. context.currentNode = node;
  3465. const { nodeTransforms } = context;
  3466. const exitFns = [];
  3467. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  3468. const onExit = nodeTransforms[i2](node, context);
  3469. if (onExit) {
  3470. if (shared.isArray(onExit)) {
  3471. exitFns.push(...onExit);
  3472. } else {
  3473. exitFns.push(onExit);
  3474. }
  3475. }
  3476. if (!context.currentNode) {
  3477. return;
  3478. } else {
  3479. node = context.currentNode;
  3480. }
  3481. }
  3482. switch (node.type) {
  3483. case 3:
  3484. if (!context.ssr) {
  3485. context.helper(CREATE_COMMENT);
  3486. }
  3487. break;
  3488. case 5:
  3489. if (!context.ssr) {
  3490. context.helper(TO_DISPLAY_STRING);
  3491. }
  3492. break;
  3493. // for container types, further traverse downwards
  3494. case 9:
  3495. for (let i2 = 0; i2 < node.branches.length; i2++) {
  3496. traverseNode(node.branches[i2], context);
  3497. }
  3498. break;
  3499. case 10:
  3500. case 11:
  3501. case 1:
  3502. case 0:
  3503. traverseChildren(node, context);
  3504. break;
  3505. }
  3506. context.currentNode = node;
  3507. let i = exitFns.length;
  3508. while (i--) {
  3509. exitFns[i]();
  3510. }
  3511. }
  3512. function createStructuralDirectiveTransform(name, fn) {
  3513. const matches = shared.isString(name) ? (n) => n === name : (n) => name.test(n);
  3514. return (node, context) => {
  3515. if (node.type === 1) {
  3516. const { props } = node;
  3517. if (node.tagType === 3 && props.some(isVSlot)) {
  3518. return;
  3519. }
  3520. const exitFns = [];
  3521. for (let i = 0; i < props.length; i++) {
  3522. const prop = props[i];
  3523. if (prop.type === 7 && matches(prop.name)) {
  3524. props.splice(i, 1);
  3525. i--;
  3526. const onExit = fn(node, prop, context);
  3527. if (onExit) exitFns.push(onExit);
  3528. }
  3529. }
  3530. return exitFns;
  3531. }
  3532. };
  3533. }
  3534. const PURE_ANNOTATION = `/*@__PURE__*/`;
  3535. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  3536. function createCodegenContext(ast, {
  3537. mode = "function",
  3538. prefixIdentifiers = mode === "module",
  3539. sourceMap = false,
  3540. filename = `template.vue.html`,
  3541. scopeId = null,
  3542. optimizeImports = false,
  3543. runtimeGlobalName = `Vue`,
  3544. runtimeModuleName = `vue`,
  3545. ssrRuntimeModuleName = "vue/server-renderer",
  3546. ssr = false,
  3547. isTS = false,
  3548. inSSR = false
  3549. }) {
  3550. const context = {
  3551. mode,
  3552. prefixIdentifiers,
  3553. sourceMap,
  3554. filename,
  3555. scopeId,
  3556. optimizeImports,
  3557. runtimeGlobalName,
  3558. runtimeModuleName,
  3559. ssrRuntimeModuleName,
  3560. ssr,
  3561. isTS,
  3562. inSSR,
  3563. source: ast.source,
  3564. code: ``,
  3565. column: 1,
  3566. line: 1,
  3567. offset: 0,
  3568. indentLevel: 0,
  3569. pure: false,
  3570. map: void 0,
  3571. helper(key) {
  3572. return `_${helperNameMap[key]}`;
  3573. },
  3574. push(code, newlineIndex = -2 /* None */, node) {
  3575. context.code += code;
  3576. if (context.map) {
  3577. if (node) {
  3578. let name;
  3579. if (node.type === 4 && !node.isStatic) {
  3580. const content = node.content.replace(/^_ctx\./, "");
  3581. if (content !== node.content && isSimpleIdentifier(content)) {
  3582. name = content;
  3583. }
  3584. }
  3585. addMapping(node.loc.start, name);
  3586. }
  3587. if (newlineIndex === -3 /* Unknown */) {
  3588. advancePositionWithMutation(context, code);
  3589. } else {
  3590. context.offset += code.length;
  3591. if (newlineIndex === -2 /* None */) {
  3592. context.column += code.length;
  3593. } else {
  3594. if (newlineIndex === -1 /* End */) {
  3595. newlineIndex = code.length - 1;
  3596. }
  3597. context.line++;
  3598. context.column = code.length - newlineIndex;
  3599. }
  3600. }
  3601. if (node && node.loc !== locStub) {
  3602. addMapping(node.loc.end);
  3603. }
  3604. }
  3605. },
  3606. indent() {
  3607. newline(++context.indentLevel);
  3608. },
  3609. deindent(withoutNewLine = false) {
  3610. if (withoutNewLine) {
  3611. --context.indentLevel;
  3612. } else {
  3613. newline(--context.indentLevel);
  3614. }
  3615. },
  3616. newline() {
  3617. newline(context.indentLevel);
  3618. }
  3619. };
  3620. function newline(n) {
  3621. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  3622. }
  3623. function addMapping(loc, name = null) {
  3624. const { _names, _mappings } = context.map;
  3625. if (name !== null && !_names.has(name)) _names.add(name);
  3626. _mappings.add({
  3627. originalLine: loc.line,
  3628. originalColumn: loc.column - 1,
  3629. // source-map column is 0 based
  3630. generatedLine: context.line,
  3631. generatedColumn: context.column - 1,
  3632. source: filename,
  3633. name
  3634. });
  3635. }
  3636. if (sourceMap) {
  3637. context.map = new sourceMapJs.SourceMapGenerator();
  3638. context.map.setSourceContent(filename, context.source);
  3639. context.map._sources.add(filename);
  3640. }
  3641. return context;
  3642. }
  3643. function generate(ast, options = {}) {
  3644. const context = createCodegenContext(ast, options);
  3645. if (options.onContextCreated) options.onContextCreated(context);
  3646. const {
  3647. mode,
  3648. push,
  3649. prefixIdentifiers,
  3650. indent,
  3651. deindent,
  3652. newline,
  3653. scopeId,
  3654. ssr
  3655. } = context;
  3656. const helpers = Array.from(ast.helpers);
  3657. const hasHelpers = helpers.length > 0;
  3658. const useWithBlock = !prefixIdentifiers && mode !== "module";
  3659. const genScopeId = scopeId != null && mode === "module";
  3660. const isSetupInlined = !!options.inline;
  3661. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  3662. if (mode === "module") {
  3663. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  3664. } else {
  3665. genFunctionPreamble(ast, preambleContext);
  3666. }
  3667. const functionName = ssr ? `ssrRender` : `render`;
  3668. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  3669. if (options.bindingMetadata && !options.inline) {
  3670. args.push("$props", "$setup", "$data", "$options");
  3671. }
  3672. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  3673. if (isSetupInlined) {
  3674. push(`(${signature}) => {`);
  3675. } else {
  3676. push(`function ${functionName}(${signature}) {`);
  3677. }
  3678. indent();
  3679. if (useWithBlock) {
  3680. push(`with (_ctx) {`);
  3681. indent();
  3682. if (hasHelpers) {
  3683. push(
  3684. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  3685. `,
  3686. -1 /* End */
  3687. );
  3688. newline();
  3689. }
  3690. }
  3691. if (ast.components.length) {
  3692. genAssets(ast.components, "component", context);
  3693. if (ast.directives.length || ast.temps > 0) {
  3694. newline();
  3695. }
  3696. }
  3697. if (ast.directives.length) {
  3698. genAssets(ast.directives, "directive", context);
  3699. if (ast.temps > 0) {
  3700. newline();
  3701. }
  3702. }
  3703. if (ast.filters && ast.filters.length) {
  3704. newline();
  3705. genAssets(ast.filters, "filter", context);
  3706. newline();
  3707. }
  3708. if (ast.temps > 0) {
  3709. push(`let `);
  3710. for (let i = 0; i < ast.temps; i++) {
  3711. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  3712. }
  3713. }
  3714. if (ast.components.length || ast.directives.length || ast.temps) {
  3715. push(`
  3716. `, 0 /* Start */);
  3717. newline();
  3718. }
  3719. if (!ssr) {
  3720. push(`return `);
  3721. }
  3722. if (ast.codegenNode) {
  3723. genNode(ast.codegenNode, context);
  3724. } else {
  3725. push(`null`);
  3726. }
  3727. if (useWithBlock) {
  3728. deindent();
  3729. push(`}`);
  3730. }
  3731. deindent();
  3732. push(`}`);
  3733. return {
  3734. ast,
  3735. code: context.code,
  3736. preamble: isSetupInlined ? preambleContext.code : ``,
  3737. map: context.map ? context.map.toJSON() : void 0
  3738. };
  3739. }
  3740. function genFunctionPreamble(ast, context) {
  3741. const {
  3742. ssr,
  3743. prefixIdentifiers,
  3744. push,
  3745. newline,
  3746. runtimeModuleName,
  3747. runtimeGlobalName,
  3748. ssrRuntimeModuleName
  3749. } = context;
  3750. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  3751. const helpers = Array.from(ast.helpers);
  3752. if (helpers.length > 0) {
  3753. if (prefixIdentifiers) {
  3754. push(
  3755. `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  3756. `,
  3757. -1 /* End */
  3758. );
  3759. } else {
  3760. push(`const _Vue = ${VueBinding}
  3761. `, -1 /* End */);
  3762. if (ast.hoists.length) {
  3763. const staticHelpers = [
  3764. CREATE_VNODE,
  3765. CREATE_ELEMENT_VNODE,
  3766. CREATE_COMMENT,
  3767. CREATE_TEXT,
  3768. CREATE_STATIC
  3769. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  3770. push(`const { ${staticHelpers} } = _Vue
  3771. `, -1 /* End */);
  3772. }
  3773. }
  3774. }
  3775. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  3776. push(
  3777. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  3778. `,
  3779. -1 /* End */
  3780. );
  3781. }
  3782. genHoists(ast.hoists, context);
  3783. newline();
  3784. push(`return `);
  3785. }
  3786. function genModulePreamble(ast, context, genScopeId, inline) {
  3787. const {
  3788. push,
  3789. newline,
  3790. optimizeImports,
  3791. runtimeModuleName,
  3792. ssrRuntimeModuleName
  3793. } = context;
  3794. if (ast.helpers.size) {
  3795. const helpers = Array.from(ast.helpers);
  3796. if (optimizeImports) {
  3797. push(
  3798. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  3799. `,
  3800. -1 /* End */
  3801. );
  3802. push(
  3803. `
  3804. // Binding optimization for webpack code-split
  3805. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  3806. `,
  3807. -1 /* End */
  3808. );
  3809. } else {
  3810. push(
  3811. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  3812. `,
  3813. -1 /* End */
  3814. );
  3815. }
  3816. }
  3817. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  3818. push(
  3819. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  3820. `,
  3821. -1 /* End */
  3822. );
  3823. }
  3824. if (ast.imports.length) {
  3825. genImports(ast.imports, context);
  3826. newline();
  3827. }
  3828. genHoists(ast.hoists, context);
  3829. newline();
  3830. if (!inline) {
  3831. push(`export `);
  3832. }
  3833. }
  3834. function genAssets(assets, type, { helper, push, newline, isTS }) {
  3835. const resolver = helper(
  3836. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  3837. );
  3838. for (let i = 0; i < assets.length; i++) {
  3839. let id = assets[i];
  3840. const maybeSelfReference = id.endsWith("__self");
  3841. if (maybeSelfReference) {
  3842. id = id.slice(0, -6);
  3843. }
  3844. push(
  3845. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  3846. );
  3847. if (i < assets.length - 1) {
  3848. newline();
  3849. }
  3850. }
  3851. }
  3852. function genHoists(hoists, context) {
  3853. if (!hoists.length) {
  3854. return;
  3855. }
  3856. context.pure = true;
  3857. const { push, newline } = context;
  3858. newline();
  3859. for (let i = 0; i < hoists.length; i++) {
  3860. const exp = hoists[i];
  3861. if (exp) {
  3862. push(`const _hoisted_${i + 1} = `);
  3863. genNode(exp, context);
  3864. newline();
  3865. }
  3866. }
  3867. context.pure = false;
  3868. }
  3869. function genImports(importsOptions, context) {
  3870. if (!importsOptions.length) {
  3871. return;
  3872. }
  3873. importsOptions.forEach((imports) => {
  3874. context.push(`import `);
  3875. genNode(imports.exp, context);
  3876. context.push(` from '${imports.path}'`);
  3877. context.newline();
  3878. });
  3879. }
  3880. function isText(n) {
  3881. return shared.isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  3882. }
  3883. function genNodeListAsArray(nodes, context) {
  3884. const multilines = nodes.length > 3 || nodes.some((n) => shared.isArray(n) || !isText(n));
  3885. context.push(`[`);
  3886. multilines && context.indent();
  3887. genNodeList(nodes, context, multilines);
  3888. multilines && context.deindent();
  3889. context.push(`]`);
  3890. }
  3891. function genNodeList(nodes, context, multilines = false, comma = true) {
  3892. const { push, newline } = context;
  3893. for (let i = 0; i < nodes.length; i++) {
  3894. const node = nodes[i];
  3895. if (shared.isString(node)) {
  3896. push(node, -3 /* Unknown */);
  3897. } else if (shared.isArray(node)) {
  3898. genNodeListAsArray(node, context);
  3899. } else {
  3900. genNode(node, context);
  3901. }
  3902. if (i < nodes.length - 1) {
  3903. if (multilines) {
  3904. comma && push(",");
  3905. newline();
  3906. } else {
  3907. comma && push(", ");
  3908. }
  3909. }
  3910. }
  3911. }
  3912. function genNode(node, context) {
  3913. if (shared.isString(node)) {
  3914. context.push(node, -3 /* Unknown */);
  3915. return;
  3916. }
  3917. if (shared.isSymbol(node)) {
  3918. context.push(context.helper(node));
  3919. return;
  3920. }
  3921. switch (node.type) {
  3922. case 1:
  3923. case 9:
  3924. case 11:
  3925. genNode(node.codegenNode, context);
  3926. break;
  3927. case 2:
  3928. genText(node, context);
  3929. break;
  3930. case 4:
  3931. genExpression(node, context);
  3932. break;
  3933. case 5:
  3934. genInterpolation(node, context);
  3935. break;
  3936. case 12:
  3937. genNode(node.codegenNode, context);
  3938. break;
  3939. case 8:
  3940. genCompoundExpression(node, context);
  3941. break;
  3942. case 3:
  3943. genComment(node, context);
  3944. break;
  3945. case 13:
  3946. genVNodeCall(node, context);
  3947. break;
  3948. case 14:
  3949. genCallExpression(node, context);
  3950. break;
  3951. case 15:
  3952. genObjectExpression(node, context);
  3953. break;
  3954. case 17:
  3955. genArrayExpression(node, context);
  3956. break;
  3957. case 18:
  3958. genFunctionExpression(node, context);
  3959. break;
  3960. case 19:
  3961. genConditionalExpression(node, context);
  3962. break;
  3963. case 20:
  3964. genCacheExpression(node, context);
  3965. break;
  3966. case 21:
  3967. genNodeList(node.body, context, true, false);
  3968. break;
  3969. // SSR only types
  3970. case 22:
  3971. genTemplateLiteral(node, context);
  3972. break;
  3973. case 23:
  3974. genIfStatement(node, context);
  3975. break;
  3976. case 24:
  3977. genAssignmentExpression(node, context);
  3978. break;
  3979. case 25:
  3980. genSequenceExpression(node, context);
  3981. break;
  3982. case 26:
  3983. genReturnStatement(node, context);
  3984. break;
  3985. }
  3986. }
  3987. function genText(node, context) {
  3988. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  3989. }
  3990. function genExpression(node, context) {
  3991. const { content, isStatic } = node;
  3992. context.push(
  3993. isStatic ? JSON.stringify(content) : content,
  3994. -3 /* Unknown */,
  3995. node
  3996. );
  3997. }
  3998. function genInterpolation(node, context) {
  3999. const { push, helper, pure } = context;
  4000. if (pure) push(PURE_ANNOTATION);
  4001. push(`${helper(TO_DISPLAY_STRING)}(`);
  4002. genNode(node.content, context);
  4003. push(`)`);
  4004. }
  4005. function genCompoundExpression(node, context) {
  4006. for (let i = 0; i < node.children.length; i++) {
  4007. const child = node.children[i];
  4008. if (shared.isString(child)) {
  4009. context.push(child, -3 /* Unknown */);
  4010. } else {
  4011. genNode(child, context);
  4012. }
  4013. }
  4014. }
  4015. function genExpressionAsPropertyKey(node, context) {
  4016. const { push } = context;
  4017. if (node.type === 8) {
  4018. push(`[`);
  4019. genCompoundExpression(node, context);
  4020. push(`]`);
  4021. } else if (node.isStatic) {
  4022. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  4023. push(text, -2 /* None */, node);
  4024. } else {
  4025. push(`[${node.content}]`, -3 /* Unknown */, node);
  4026. }
  4027. }
  4028. function genComment(node, context) {
  4029. const { push, helper, pure } = context;
  4030. if (pure) {
  4031. push(PURE_ANNOTATION);
  4032. }
  4033. push(
  4034. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  4035. -3 /* Unknown */,
  4036. node
  4037. );
  4038. }
  4039. function genVNodeCall(node, context) {
  4040. const { push, helper, pure } = context;
  4041. const {
  4042. tag,
  4043. props,
  4044. children,
  4045. patchFlag,
  4046. dynamicProps,
  4047. directives,
  4048. isBlock,
  4049. disableTracking,
  4050. isComponent
  4051. } = node;
  4052. let patchFlagString;
  4053. if (patchFlag) {
  4054. {
  4055. patchFlagString = String(patchFlag);
  4056. }
  4057. }
  4058. if (directives) {
  4059. push(helper(WITH_DIRECTIVES) + `(`);
  4060. }
  4061. if (isBlock) {
  4062. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  4063. }
  4064. if (pure) {
  4065. push(PURE_ANNOTATION);
  4066. }
  4067. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  4068. push(helper(callHelper) + `(`, -2 /* None */, node);
  4069. genNodeList(
  4070. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  4071. context
  4072. );
  4073. push(`)`);
  4074. if (isBlock) {
  4075. push(`)`);
  4076. }
  4077. if (directives) {
  4078. push(`, `);
  4079. genNode(directives, context);
  4080. push(`)`);
  4081. }
  4082. }
  4083. function genNullableArgs(args) {
  4084. let i = args.length;
  4085. while (i--) {
  4086. if (args[i] != null) break;
  4087. }
  4088. return args.slice(0, i + 1).map((arg) => arg || `null`);
  4089. }
  4090. function genCallExpression(node, context) {
  4091. const { push, helper, pure } = context;
  4092. const callee = shared.isString(node.callee) ? node.callee : helper(node.callee);
  4093. if (pure) {
  4094. push(PURE_ANNOTATION);
  4095. }
  4096. push(callee + `(`, -2 /* None */, node);
  4097. genNodeList(node.arguments, context);
  4098. push(`)`);
  4099. }
  4100. function genObjectExpression(node, context) {
  4101. const { push, indent, deindent, newline } = context;
  4102. const { properties } = node;
  4103. if (!properties.length) {
  4104. push(`{}`, -2 /* None */, node);
  4105. return;
  4106. }
  4107. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  4108. push(multilines ? `{` : `{ `);
  4109. multilines && indent();
  4110. for (let i = 0; i < properties.length; i++) {
  4111. const { key, value } = properties[i];
  4112. genExpressionAsPropertyKey(key, context);
  4113. push(`: `);
  4114. genNode(value, context);
  4115. if (i < properties.length - 1) {
  4116. push(`,`);
  4117. newline();
  4118. }
  4119. }
  4120. multilines && deindent();
  4121. push(multilines ? `}` : ` }`);
  4122. }
  4123. function genArrayExpression(node, context) {
  4124. genNodeListAsArray(node.elements, context);
  4125. }
  4126. function genFunctionExpression(node, context) {
  4127. const { push, indent, deindent } = context;
  4128. const { params, returns, body, newline, isSlot } = node;
  4129. if (isSlot) {
  4130. push(`_${helperNameMap[WITH_CTX]}(`);
  4131. }
  4132. push(`(`, -2 /* None */, node);
  4133. if (shared.isArray(params)) {
  4134. genNodeList(params, context);
  4135. } else if (params) {
  4136. genNode(params, context);
  4137. }
  4138. push(`) => `);
  4139. if (newline || body) {
  4140. push(`{`);
  4141. indent();
  4142. }
  4143. if (returns) {
  4144. if (newline) {
  4145. push(`return `);
  4146. }
  4147. if (shared.isArray(returns)) {
  4148. genNodeListAsArray(returns, context);
  4149. } else {
  4150. genNode(returns, context);
  4151. }
  4152. } else if (body) {
  4153. genNode(body, context);
  4154. }
  4155. if (newline || body) {
  4156. deindent();
  4157. push(`}`);
  4158. }
  4159. if (isSlot) {
  4160. if (node.isNonScopedSlot) {
  4161. push(`, undefined, true`);
  4162. }
  4163. push(`)`);
  4164. }
  4165. }
  4166. function genConditionalExpression(node, context) {
  4167. const { test, consequent, alternate, newline: needNewline } = node;
  4168. const { push, indent, deindent, newline } = context;
  4169. if (test.type === 4) {
  4170. const needsParens = !isSimpleIdentifier(test.content);
  4171. needsParens && push(`(`);
  4172. genExpression(test, context);
  4173. needsParens && push(`)`);
  4174. } else {
  4175. push(`(`);
  4176. genNode(test, context);
  4177. push(`)`);
  4178. }
  4179. needNewline && indent();
  4180. context.indentLevel++;
  4181. needNewline || push(` `);
  4182. push(`? `);
  4183. genNode(consequent, context);
  4184. context.indentLevel--;
  4185. needNewline && newline();
  4186. needNewline || push(` `);
  4187. push(`: `);
  4188. const isNested = alternate.type === 19;
  4189. if (!isNested) {
  4190. context.indentLevel++;
  4191. }
  4192. genNode(alternate, context);
  4193. if (!isNested) {
  4194. context.indentLevel--;
  4195. }
  4196. needNewline && deindent(
  4197. true
  4198. /* without newline */
  4199. );
  4200. }
  4201. function genCacheExpression(node, context) {
  4202. const { push, helper, indent, deindent, newline } = context;
  4203. const { needPauseTracking, needArraySpread } = node;
  4204. if (needArraySpread) {
  4205. push(`[...(`);
  4206. }
  4207. push(`_cache[${node.index}] || (`);
  4208. if (needPauseTracking) {
  4209. indent();
  4210. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  4211. if (node.inVOnce) push(`, true`);
  4212. push(`),`);
  4213. newline();
  4214. push(`(`);
  4215. }
  4216. push(`_cache[${node.index}] = `);
  4217. genNode(node.value, context);
  4218. if (needPauseTracking) {
  4219. push(`).cacheIndex = ${node.index},`);
  4220. newline();
  4221. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  4222. newline();
  4223. push(`_cache[${node.index}]`);
  4224. deindent();
  4225. }
  4226. push(`)`);
  4227. if (needArraySpread) {
  4228. push(`)]`);
  4229. }
  4230. }
  4231. function genTemplateLiteral(node, context) {
  4232. const { push, indent, deindent } = context;
  4233. push("`");
  4234. const l = node.elements.length;
  4235. const multilines = l > 3;
  4236. for (let i = 0; i < l; i++) {
  4237. const e = node.elements[i];
  4238. if (shared.isString(e)) {
  4239. push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
  4240. } else {
  4241. push("${");
  4242. if (multilines) indent();
  4243. genNode(e, context);
  4244. if (multilines) deindent();
  4245. push("}");
  4246. }
  4247. }
  4248. push("`");
  4249. }
  4250. function genIfStatement(node, context) {
  4251. const { push, indent, deindent } = context;
  4252. const { test, consequent, alternate } = node;
  4253. push(`if (`);
  4254. genNode(test, context);
  4255. push(`) {`);
  4256. indent();
  4257. genNode(consequent, context);
  4258. deindent();
  4259. push(`}`);
  4260. if (alternate) {
  4261. push(` else `);
  4262. if (alternate.type === 23) {
  4263. genIfStatement(alternate, context);
  4264. } else {
  4265. push(`{`);
  4266. indent();
  4267. genNode(alternate, context);
  4268. deindent();
  4269. push(`}`);
  4270. }
  4271. }
  4272. }
  4273. function genAssignmentExpression(node, context) {
  4274. genNode(node.left, context);
  4275. context.push(` = `);
  4276. genNode(node.right, context);
  4277. }
  4278. function genSequenceExpression(node, context) {
  4279. context.push(`(`);
  4280. genNodeList(node.expressions, context);
  4281. context.push(`)`);
  4282. }
  4283. function genReturnStatement({ returns }, context) {
  4284. context.push(`return `);
  4285. if (shared.isArray(returns)) {
  4286. genNodeListAsArray(returns, context);
  4287. } else {
  4288. genNode(returns, context);
  4289. }
  4290. }
  4291. const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
  4292. const transformExpression = (node, context) => {
  4293. if (node.type === 5) {
  4294. node.content = processExpression(
  4295. node.content,
  4296. context
  4297. );
  4298. } else if (node.type === 1) {
  4299. const memo = findDir(node, "memo");
  4300. for (let i = 0; i < node.props.length; i++) {
  4301. const dir = node.props[i];
  4302. if (dir.type === 7 && dir.name !== "for") {
  4303. const exp = dir.exp;
  4304. const arg = dir.arg;
  4305. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  4306. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  4307. dir.exp = processExpression(
  4308. exp,
  4309. context,
  4310. // slot args must be processed as function params
  4311. dir.name === "slot"
  4312. );
  4313. }
  4314. if (arg && arg.type === 4 && !arg.isStatic) {
  4315. dir.arg = processExpression(arg, context);
  4316. }
  4317. }
  4318. }
  4319. }
  4320. };
  4321. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  4322. if (!context.prefixIdentifiers || !node.content.trim()) {
  4323. return node;
  4324. }
  4325. const { inline, bindingMetadata } = context;
  4326. const rewriteIdentifier = (raw, parent, id) => {
  4327. const type = shared.hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  4328. if (inline) {
  4329. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  4330. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  4331. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  4332. const isNewExpression = parent && isInNewExpression(parentStack);
  4333. const wrapWithUnref = (raw2) => {
  4334. const wrapped = `${context.helperString(UNREF)}(${raw2})`;
  4335. return isNewExpression ? `(${wrapped})` : wrapped;
  4336. };
  4337. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  4338. return raw;
  4339. } else if (type === "setup-ref") {
  4340. return `${raw}.value`;
  4341. } else if (type === "setup-maybe-ref") {
  4342. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
  4343. } else if (type === "setup-let") {
  4344. if (isAssignmentLVal) {
  4345. const { right: rVal, operator } = parent;
  4346. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  4347. const rExpString = stringifyExpression(
  4348. processExpression(
  4349. createSimpleExpression(rExp, false),
  4350. context,
  4351. false,
  4352. false,
  4353. knownIds
  4354. )
  4355. );
  4356. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  4357. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  4358. } else if (isUpdateArg) {
  4359. id.start = parent.start;
  4360. id.end = parent.end;
  4361. const { prefix: isPrefix, operator } = parent;
  4362. const prefix = isPrefix ? operator : ``;
  4363. const postfix = isPrefix ? `` : operator;
  4364. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  4365. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  4366. } else if (isDestructureAssignment) {
  4367. return raw;
  4368. } else {
  4369. return wrapWithUnref(raw);
  4370. }
  4371. } else if (type === "props") {
  4372. return shared.genPropsAccessExp(raw);
  4373. } else if (type === "props-aliased") {
  4374. return shared.genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  4375. }
  4376. } else {
  4377. if (type && type.startsWith("setup") || type === "literal-const") {
  4378. return `$setup.${raw}`;
  4379. } else if (type === "props-aliased") {
  4380. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  4381. } else if (type) {
  4382. return `$${type}.${raw}`;
  4383. }
  4384. }
  4385. return `_ctx.${raw}`;
  4386. };
  4387. const rawExp = node.content;
  4388. let ast = node.ast;
  4389. if (ast === false) {
  4390. return node;
  4391. }
  4392. if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
  4393. const isScopeVarReference = context.identifiers[rawExp];
  4394. const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
  4395. const isLiteral = isLiteralWhitelisted(rawExp);
  4396. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  4397. if (isConst(bindingMetadata[rawExp])) {
  4398. node.constType = 1;
  4399. }
  4400. node.content = rewriteIdentifier(rawExp);
  4401. } else if (!isScopeVarReference) {
  4402. if (isLiteral) {
  4403. node.constType = 3;
  4404. } else {
  4405. node.constType = 2;
  4406. }
  4407. }
  4408. return node;
  4409. }
  4410. if (!ast) {
  4411. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  4412. try {
  4413. ast = parser.parseExpression(source, {
  4414. sourceType: "module",
  4415. plugins: context.expressionPlugins
  4416. });
  4417. } catch (e) {
  4418. context.onError(
  4419. createCompilerError(
  4420. 45,
  4421. node.loc,
  4422. void 0,
  4423. e.message
  4424. )
  4425. );
  4426. return node;
  4427. }
  4428. }
  4429. const ids = [];
  4430. const parentStack = [];
  4431. const knownIds = Object.create(context.identifiers);
  4432. walkIdentifiers(
  4433. ast,
  4434. (node2, parent, _, isReferenced, isLocal) => {
  4435. if (isStaticPropertyKey(node2, parent)) {
  4436. return;
  4437. }
  4438. if (node2.name.startsWith("_filter_")) {
  4439. return;
  4440. }
  4441. const needPrefix = isReferenced && canPrefix(node2);
  4442. if (needPrefix && !isLocal) {
  4443. if (isStaticProperty(parent) && parent.shorthand) {
  4444. node2.prefix = `${node2.name}: `;
  4445. }
  4446. node2.name = rewriteIdentifier(node2.name, parent, node2);
  4447. ids.push(node2);
  4448. } else {
  4449. if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
  4450. node2.isConstant = true;
  4451. }
  4452. ids.push(node2);
  4453. }
  4454. },
  4455. true,
  4456. // invoke on ALL identifiers
  4457. parentStack,
  4458. knownIds
  4459. );
  4460. const children = [];
  4461. ids.sort((a, b) => a.start - b.start);
  4462. ids.forEach((id, i) => {
  4463. const start = id.start - 1;
  4464. const end = id.end - 1;
  4465. const last = ids[i - 1];
  4466. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  4467. if (leadingText.length || id.prefix) {
  4468. children.push(leadingText + (id.prefix || ``));
  4469. }
  4470. const source = rawExp.slice(start, end);
  4471. children.push(
  4472. createSimpleExpression(
  4473. id.name,
  4474. false,
  4475. {
  4476. start: advancePositionWithClone(node.loc.start, source, start),
  4477. end: advancePositionWithClone(node.loc.start, source, end),
  4478. source
  4479. },
  4480. id.isConstant ? 3 : 0
  4481. )
  4482. );
  4483. if (i === ids.length - 1 && end < rawExp.length) {
  4484. children.push(rawExp.slice(end));
  4485. }
  4486. });
  4487. let ret;
  4488. if (children.length) {
  4489. ret = createCompoundExpression(children, node.loc);
  4490. ret.ast = ast;
  4491. } else {
  4492. ret = node;
  4493. ret.constType = 3;
  4494. }
  4495. ret.identifiers = Object.keys(knownIds);
  4496. return ret;
  4497. }
  4498. function canPrefix(id) {
  4499. if (shared.isGloballyAllowed(id.name)) {
  4500. return false;
  4501. }
  4502. if (id.name === "require") {
  4503. return false;
  4504. }
  4505. return true;
  4506. }
  4507. function stringifyExpression(exp) {
  4508. if (shared.isString(exp)) {
  4509. return exp;
  4510. } else if (exp.type === 4) {
  4511. return exp.content;
  4512. } else {
  4513. return exp.children.map(stringifyExpression).join("");
  4514. }
  4515. }
  4516. function isConst(type) {
  4517. return type === "setup-const" || type === "literal-const";
  4518. }
  4519. const transformIf = createStructuralDirectiveTransform(
  4520. /^(if|else|else-if)$/,
  4521. (node, dir, context) => {
  4522. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  4523. const siblings = context.parent.children;
  4524. let i = siblings.indexOf(ifNode);
  4525. let key = 0;
  4526. while (i-- >= 0) {
  4527. const sibling = siblings[i];
  4528. if (sibling && sibling.type === 9) {
  4529. key += sibling.branches.length;
  4530. }
  4531. }
  4532. return () => {
  4533. if (isRoot) {
  4534. ifNode.codegenNode = createCodegenNodeForBranch(
  4535. branch,
  4536. key,
  4537. context
  4538. );
  4539. } else {
  4540. const parentCondition = getParentCondition(ifNode.codegenNode);
  4541. parentCondition.alternate = createCodegenNodeForBranch(
  4542. branch,
  4543. key + ifNode.branches.length - 1,
  4544. context
  4545. );
  4546. }
  4547. };
  4548. });
  4549. }
  4550. );
  4551. function processIf(node, dir, context, processCodegen) {
  4552. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  4553. const loc = dir.exp ? dir.exp.loc : node.loc;
  4554. context.onError(
  4555. createCompilerError(28, dir.loc)
  4556. );
  4557. dir.exp = createSimpleExpression(`true`, false, loc);
  4558. }
  4559. if (context.prefixIdentifiers && dir.exp) {
  4560. dir.exp = processExpression(dir.exp, context);
  4561. }
  4562. if (dir.name === "if") {
  4563. const branch = createIfBranch(node, dir);
  4564. const ifNode = {
  4565. type: 9,
  4566. loc: cloneLoc(node.loc),
  4567. branches: [branch]
  4568. };
  4569. context.replaceNode(ifNode);
  4570. if (processCodegen) {
  4571. return processCodegen(ifNode, branch, true);
  4572. }
  4573. } else {
  4574. const siblings = context.parent.children;
  4575. let i = siblings.indexOf(node);
  4576. while (i-- >= -1) {
  4577. const sibling = siblings[i];
  4578. if (sibling && sibling.type === 3) {
  4579. context.removeNode(sibling);
  4580. continue;
  4581. }
  4582. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  4583. context.removeNode(sibling);
  4584. continue;
  4585. }
  4586. if (sibling && sibling.type === 9) {
  4587. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  4588. context.onError(
  4589. createCompilerError(30, node.loc)
  4590. );
  4591. }
  4592. context.removeNode();
  4593. const branch = createIfBranch(node, dir);
  4594. {
  4595. const key = branch.userKey;
  4596. if (key) {
  4597. sibling.branches.forEach(({ userKey }) => {
  4598. if (isSameKey(userKey, key)) {
  4599. context.onError(
  4600. createCompilerError(
  4601. 29,
  4602. branch.userKey.loc
  4603. )
  4604. );
  4605. }
  4606. });
  4607. }
  4608. }
  4609. sibling.branches.push(branch);
  4610. const onExit = processCodegen && processCodegen(sibling, branch, false);
  4611. traverseNode(branch, context);
  4612. if (onExit) onExit();
  4613. context.currentNode = null;
  4614. } else {
  4615. context.onError(
  4616. createCompilerError(30, node.loc)
  4617. );
  4618. }
  4619. break;
  4620. }
  4621. }
  4622. }
  4623. function createIfBranch(node, dir) {
  4624. const isTemplateIf = node.tagType === 3;
  4625. return {
  4626. type: 10,
  4627. loc: node.loc,
  4628. condition: dir.name === "else" ? void 0 : dir.exp,
  4629. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  4630. userKey: findProp(node, `key`),
  4631. isTemplateIf
  4632. };
  4633. }
  4634. function createCodegenNodeForBranch(branch, keyIndex, context) {
  4635. if (branch.condition) {
  4636. return createConditionalExpression(
  4637. branch.condition,
  4638. createChildrenCodegenNode(branch, keyIndex, context),
  4639. // make sure to pass in asBlock: true so that the comment node call
  4640. // closes the current block.
  4641. createCallExpression(context.helper(CREATE_COMMENT), [
  4642. '""',
  4643. "true"
  4644. ])
  4645. );
  4646. } else {
  4647. return createChildrenCodegenNode(branch, keyIndex, context);
  4648. }
  4649. }
  4650. function createChildrenCodegenNode(branch, keyIndex, context) {
  4651. const { helper } = context;
  4652. const keyProperty = createObjectProperty(
  4653. `key`,
  4654. createSimpleExpression(
  4655. `${keyIndex}`,
  4656. false,
  4657. locStub,
  4658. 2
  4659. )
  4660. );
  4661. const { children } = branch;
  4662. const firstChild = children[0];
  4663. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  4664. if (needFragmentWrapper) {
  4665. if (children.length === 1 && firstChild.type === 11) {
  4666. const vnodeCall = firstChild.codegenNode;
  4667. injectProp(vnodeCall, keyProperty, context);
  4668. return vnodeCall;
  4669. } else {
  4670. let patchFlag = 64;
  4671. return createVNodeCall(
  4672. context,
  4673. helper(FRAGMENT),
  4674. createObjectExpression([keyProperty]),
  4675. children,
  4676. patchFlag,
  4677. void 0,
  4678. void 0,
  4679. true,
  4680. false,
  4681. false,
  4682. branch.loc
  4683. );
  4684. }
  4685. } else {
  4686. const ret = firstChild.codegenNode;
  4687. const vnodeCall = getMemoedVNodeCall(ret);
  4688. if (vnodeCall.type === 13) {
  4689. convertToBlock(vnodeCall, context);
  4690. }
  4691. injectProp(vnodeCall, keyProperty, context);
  4692. return ret;
  4693. }
  4694. }
  4695. function isSameKey(a, b) {
  4696. if (!a || a.type !== b.type) {
  4697. return false;
  4698. }
  4699. if (a.type === 6) {
  4700. if (a.value.content !== b.value.content) {
  4701. return false;
  4702. }
  4703. } else {
  4704. const exp = a.exp;
  4705. const branchExp = b.exp;
  4706. if (exp.type !== branchExp.type) {
  4707. return false;
  4708. }
  4709. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  4710. return false;
  4711. }
  4712. }
  4713. return true;
  4714. }
  4715. function getParentCondition(node) {
  4716. while (true) {
  4717. if (node.type === 19) {
  4718. if (node.alternate.type === 19) {
  4719. node = node.alternate;
  4720. } else {
  4721. return node;
  4722. }
  4723. } else if (node.type === 20) {
  4724. node = node.value;
  4725. }
  4726. }
  4727. }
  4728. const transformBind = (dir, _node, context) => {
  4729. const { modifiers, loc } = dir;
  4730. const arg = dir.arg;
  4731. let { exp } = dir;
  4732. if (exp && exp.type === 4 && !exp.content.trim()) {
  4733. {
  4734. context.onError(
  4735. createCompilerError(34, loc)
  4736. );
  4737. return {
  4738. props: [
  4739. createObjectProperty(arg, createSimpleExpression("", true, loc))
  4740. ]
  4741. };
  4742. }
  4743. }
  4744. if (!exp) {
  4745. if (arg.type !== 4 || !arg.isStatic) {
  4746. context.onError(
  4747. createCompilerError(
  4748. 52,
  4749. arg.loc
  4750. )
  4751. );
  4752. return {
  4753. props: [
  4754. createObjectProperty(arg, createSimpleExpression("", true, loc))
  4755. ]
  4756. };
  4757. }
  4758. transformBindShorthand(dir, context);
  4759. exp = dir.exp;
  4760. }
  4761. if (arg.type !== 4) {
  4762. arg.children.unshift(`(`);
  4763. arg.children.push(`) || ""`);
  4764. } else if (!arg.isStatic) {
  4765. arg.content = `${arg.content} || ""`;
  4766. }
  4767. if (modifiers.some((mod) => mod.content === "camel")) {
  4768. if (arg.type === 4) {
  4769. if (arg.isStatic) {
  4770. arg.content = shared.camelize(arg.content);
  4771. } else {
  4772. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4773. }
  4774. } else {
  4775. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4776. arg.children.push(`)`);
  4777. }
  4778. }
  4779. if (!context.inSSR) {
  4780. if (modifiers.some((mod) => mod.content === "prop")) {
  4781. injectPrefix(arg, ".");
  4782. }
  4783. if (modifiers.some((mod) => mod.content === "attr")) {
  4784. injectPrefix(arg, "^");
  4785. }
  4786. }
  4787. return {
  4788. props: [createObjectProperty(arg, exp)]
  4789. };
  4790. };
  4791. const transformBindShorthand = (dir, context) => {
  4792. const arg = dir.arg;
  4793. const propName = shared.camelize(arg.content);
  4794. dir.exp = createSimpleExpression(propName, false, arg.loc);
  4795. {
  4796. dir.exp = processExpression(dir.exp, context);
  4797. }
  4798. };
  4799. const injectPrefix = (arg, prefix) => {
  4800. if (arg.type === 4) {
  4801. if (arg.isStatic) {
  4802. arg.content = prefix + arg.content;
  4803. } else {
  4804. arg.content = `\`${prefix}\${${arg.content}}\``;
  4805. }
  4806. } else {
  4807. arg.children.unshift(`'${prefix}' + (`);
  4808. arg.children.push(`)`);
  4809. }
  4810. };
  4811. const transformFor = createStructuralDirectiveTransform(
  4812. "for",
  4813. (node, dir, context) => {
  4814. const { helper, removeHelper } = context;
  4815. return processFor(node, dir, context, (forNode) => {
  4816. const renderExp = createCallExpression(helper(RENDER_LIST), [
  4817. forNode.source
  4818. ]);
  4819. const isTemplate = isTemplateNode(node);
  4820. const memo = findDir(node, "memo");
  4821. const keyProp = findProp(node, `key`, false, true);
  4822. const isDirKey = keyProp && keyProp.type === 7;
  4823. if (isDirKey && !keyProp.exp) {
  4824. transformBindShorthand(keyProp, context);
  4825. }
  4826. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  4827. if (memo && keyExp && isDirKey) {
  4828. {
  4829. keyProp.exp = keyExp = processExpression(
  4830. keyExp,
  4831. context
  4832. );
  4833. }
  4834. }
  4835. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  4836. if (isTemplate) {
  4837. if (memo) {
  4838. memo.exp = processExpression(
  4839. memo.exp,
  4840. context
  4841. );
  4842. }
  4843. if (keyProperty && keyProp.type !== 6) {
  4844. keyProperty.value = processExpression(
  4845. keyProperty.value,
  4846. context
  4847. );
  4848. }
  4849. }
  4850. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  4851. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  4852. forNode.codegenNode = createVNodeCall(
  4853. context,
  4854. helper(FRAGMENT),
  4855. void 0,
  4856. renderExp,
  4857. fragmentFlag,
  4858. void 0,
  4859. void 0,
  4860. true,
  4861. !isStableFragment,
  4862. false,
  4863. node.loc
  4864. );
  4865. return () => {
  4866. let childBlock;
  4867. const { children } = forNode;
  4868. if (isTemplate) {
  4869. node.children.some((c) => {
  4870. if (c.type === 1) {
  4871. const key = findProp(c, "key");
  4872. if (key) {
  4873. context.onError(
  4874. createCompilerError(
  4875. 33,
  4876. key.loc
  4877. )
  4878. );
  4879. return true;
  4880. }
  4881. }
  4882. });
  4883. }
  4884. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  4885. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  4886. if (slotOutlet) {
  4887. childBlock = slotOutlet.codegenNode;
  4888. if (isTemplate && keyProperty) {
  4889. injectProp(childBlock, keyProperty, context);
  4890. }
  4891. } else if (needFragmentWrapper) {
  4892. childBlock = createVNodeCall(
  4893. context,
  4894. helper(FRAGMENT),
  4895. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  4896. node.children,
  4897. 64,
  4898. void 0,
  4899. void 0,
  4900. true,
  4901. void 0,
  4902. false
  4903. );
  4904. } else {
  4905. childBlock = children[0].codegenNode;
  4906. if (isTemplate && keyProperty) {
  4907. injectProp(childBlock, keyProperty, context);
  4908. }
  4909. if (childBlock.isBlock !== !isStableFragment) {
  4910. if (childBlock.isBlock) {
  4911. removeHelper(OPEN_BLOCK);
  4912. removeHelper(
  4913. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  4914. );
  4915. } else {
  4916. removeHelper(
  4917. getVNodeHelper(context.inSSR, childBlock.isComponent)
  4918. );
  4919. }
  4920. }
  4921. childBlock.isBlock = !isStableFragment;
  4922. if (childBlock.isBlock) {
  4923. helper(OPEN_BLOCK);
  4924. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  4925. } else {
  4926. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  4927. }
  4928. }
  4929. if (memo) {
  4930. const loop = createFunctionExpression(
  4931. createForLoopParams(forNode.parseResult, [
  4932. createSimpleExpression(`_cached`)
  4933. ])
  4934. );
  4935. loop.body = createBlockStatement([
  4936. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  4937. createCompoundExpression([
  4938. `if (_cached`,
  4939. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  4940. ` && ${context.helperString(
  4941. IS_MEMO_SAME
  4942. )}(_cached, _memo)) return _cached`
  4943. ]),
  4944. createCompoundExpression([`const _item = `, childBlock]),
  4945. createSimpleExpression(`_item.memo = _memo`),
  4946. createSimpleExpression(`return _item`)
  4947. ]);
  4948. renderExp.arguments.push(
  4949. loop,
  4950. createSimpleExpression(`_cache`),
  4951. createSimpleExpression(String(context.cached.length))
  4952. );
  4953. context.cached.push(null);
  4954. } else {
  4955. renderExp.arguments.push(
  4956. createFunctionExpression(
  4957. createForLoopParams(forNode.parseResult),
  4958. childBlock,
  4959. true
  4960. )
  4961. );
  4962. }
  4963. };
  4964. });
  4965. }
  4966. );
  4967. function processFor(node, dir, context, processCodegen) {
  4968. if (!dir.exp) {
  4969. context.onError(
  4970. createCompilerError(31, dir.loc)
  4971. );
  4972. return;
  4973. }
  4974. const parseResult = dir.forParseResult;
  4975. if (!parseResult) {
  4976. context.onError(
  4977. createCompilerError(32, dir.loc)
  4978. );
  4979. return;
  4980. }
  4981. finalizeForParseResult(parseResult, context);
  4982. const { addIdentifiers, removeIdentifiers, scopes } = context;
  4983. const { source, value, key, index } = parseResult;
  4984. const forNode = {
  4985. type: 11,
  4986. loc: dir.loc,
  4987. source,
  4988. valueAlias: value,
  4989. keyAlias: key,
  4990. objectIndexAlias: index,
  4991. parseResult,
  4992. children: isTemplateNode(node) ? node.children : [node]
  4993. };
  4994. context.replaceNode(forNode);
  4995. scopes.vFor++;
  4996. if (context.prefixIdentifiers) {
  4997. value && addIdentifiers(value);
  4998. key && addIdentifiers(key);
  4999. index && addIdentifiers(index);
  5000. }
  5001. const onExit = processCodegen && processCodegen(forNode);
  5002. return () => {
  5003. scopes.vFor--;
  5004. if (context.prefixIdentifiers) {
  5005. value && removeIdentifiers(value);
  5006. key && removeIdentifiers(key);
  5007. index && removeIdentifiers(index);
  5008. }
  5009. if (onExit) onExit();
  5010. };
  5011. }
  5012. function finalizeForParseResult(result, context) {
  5013. if (result.finalized) return;
  5014. if (context.prefixIdentifiers) {
  5015. result.source = processExpression(
  5016. result.source,
  5017. context
  5018. );
  5019. if (result.key) {
  5020. result.key = processExpression(
  5021. result.key,
  5022. context,
  5023. true
  5024. );
  5025. }
  5026. if (result.index) {
  5027. result.index = processExpression(
  5028. result.index,
  5029. context,
  5030. true
  5031. );
  5032. }
  5033. if (result.value) {
  5034. result.value = processExpression(
  5035. result.value,
  5036. context,
  5037. true
  5038. );
  5039. }
  5040. }
  5041. result.finalized = true;
  5042. }
  5043. function createForLoopParams({ value, key, index }, memoArgs = []) {
  5044. return createParamsList([value, key, index, ...memoArgs]);
  5045. }
  5046. function createParamsList(args) {
  5047. let i = args.length;
  5048. while (i--) {
  5049. if (args[i]) break;
  5050. }
  5051. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  5052. }
  5053. const defaultFallback = createSimpleExpression(`undefined`, false);
  5054. const trackSlotScopes = (node, context) => {
  5055. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  5056. const vSlot = findDir(node, "slot");
  5057. if (vSlot) {
  5058. const slotProps = vSlot.exp;
  5059. if (context.prefixIdentifiers) {
  5060. slotProps && context.addIdentifiers(slotProps);
  5061. }
  5062. context.scopes.vSlot++;
  5063. return () => {
  5064. if (context.prefixIdentifiers) {
  5065. slotProps && context.removeIdentifiers(slotProps);
  5066. }
  5067. context.scopes.vSlot--;
  5068. };
  5069. }
  5070. }
  5071. };
  5072. const trackVForSlotScopes = (node, context) => {
  5073. let vFor;
  5074. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  5075. const result = vFor.forParseResult;
  5076. if (result) {
  5077. finalizeForParseResult(result, context);
  5078. const { value, key, index } = result;
  5079. const { addIdentifiers, removeIdentifiers } = context;
  5080. value && addIdentifiers(value);
  5081. key && addIdentifiers(key);
  5082. index && addIdentifiers(index);
  5083. return () => {
  5084. value && removeIdentifiers(value);
  5085. key && removeIdentifiers(key);
  5086. index && removeIdentifiers(index);
  5087. };
  5088. }
  5089. }
  5090. };
  5091. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  5092. props,
  5093. children,
  5094. false,
  5095. true,
  5096. children.length ? children[0].loc : loc
  5097. );
  5098. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  5099. context.helper(WITH_CTX);
  5100. const { children, loc } = node;
  5101. const slotsProperties = [];
  5102. const dynamicSlots = [];
  5103. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  5104. if (!context.ssr && context.prefixIdentifiers) {
  5105. hasDynamicSlots = hasScopeRef(node, context.identifiers);
  5106. }
  5107. const onComponentSlot = findDir(node, "slot", true);
  5108. if (onComponentSlot) {
  5109. const { arg, exp } = onComponentSlot;
  5110. if (arg && !isStaticExp(arg)) {
  5111. hasDynamicSlots = true;
  5112. }
  5113. slotsProperties.push(
  5114. createObjectProperty(
  5115. arg || createSimpleExpression("default", true),
  5116. buildSlotFn(exp, void 0, children, loc)
  5117. )
  5118. );
  5119. }
  5120. let hasTemplateSlots = false;
  5121. let hasNamedDefaultSlot = false;
  5122. const implicitDefaultChildren = [];
  5123. const seenSlotNames = /* @__PURE__ */ new Set();
  5124. let conditionalBranchIndex = 0;
  5125. for (let i = 0; i < children.length; i++) {
  5126. const slotElement = children[i];
  5127. let slotDir;
  5128. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  5129. if (slotElement.type !== 3) {
  5130. implicitDefaultChildren.push(slotElement);
  5131. }
  5132. continue;
  5133. }
  5134. if (onComponentSlot) {
  5135. context.onError(
  5136. createCompilerError(37, slotDir.loc)
  5137. );
  5138. break;
  5139. }
  5140. hasTemplateSlots = true;
  5141. const { children: slotChildren, loc: slotLoc } = slotElement;
  5142. const {
  5143. arg: slotName = createSimpleExpression(`default`, true),
  5144. exp: slotProps,
  5145. loc: dirLoc
  5146. } = slotDir;
  5147. let staticSlotName;
  5148. if (isStaticExp(slotName)) {
  5149. staticSlotName = slotName ? slotName.content : `default`;
  5150. } else {
  5151. hasDynamicSlots = true;
  5152. }
  5153. const vFor = findDir(slotElement, "for");
  5154. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  5155. let vIf;
  5156. let vElse;
  5157. if (vIf = findDir(slotElement, "if")) {
  5158. hasDynamicSlots = true;
  5159. dynamicSlots.push(
  5160. createConditionalExpression(
  5161. vIf.exp,
  5162. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  5163. defaultFallback
  5164. )
  5165. );
  5166. } else if (vElse = findDir(
  5167. slotElement,
  5168. /^else(-if)?$/,
  5169. true
  5170. /* allowEmpty */
  5171. )) {
  5172. let j = i;
  5173. let prev;
  5174. while (j--) {
  5175. prev = children[j];
  5176. if (prev.type !== 3) {
  5177. break;
  5178. }
  5179. }
  5180. if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
  5181. let conditional = dynamicSlots[dynamicSlots.length - 1];
  5182. while (conditional.alternate.type === 19) {
  5183. conditional = conditional.alternate;
  5184. }
  5185. conditional.alternate = vElse.exp ? createConditionalExpression(
  5186. vElse.exp,
  5187. buildDynamicSlot(
  5188. slotName,
  5189. slotFunction,
  5190. conditionalBranchIndex++
  5191. ),
  5192. defaultFallback
  5193. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  5194. } else {
  5195. context.onError(
  5196. createCompilerError(30, vElse.loc)
  5197. );
  5198. }
  5199. } else if (vFor) {
  5200. hasDynamicSlots = true;
  5201. const parseResult = vFor.forParseResult;
  5202. if (parseResult) {
  5203. finalizeForParseResult(parseResult, context);
  5204. dynamicSlots.push(
  5205. createCallExpression(context.helper(RENDER_LIST), [
  5206. parseResult.source,
  5207. createFunctionExpression(
  5208. createForLoopParams(parseResult),
  5209. buildDynamicSlot(slotName, slotFunction),
  5210. true
  5211. )
  5212. ])
  5213. );
  5214. } else {
  5215. context.onError(
  5216. createCompilerError(
  5217. 32,
  5218. vFor.loc
  5219. )
  5220. );
  5221. }
  5222. } else {
  5223. if (staticSlotName) {
  5224. if (seenSlotNames.has(staticSlotName)) {
  5225. context.onError(
  5226. createCompilerError(
  5227. 38,
  5228. dirLoc
  5229. )
  5230. );
  5231. continue;
  5232. }
  5233. seenSlotNames.add(staticSlotName);
  5234. if (staticSlotName === "default") {
  5235. hasNamedDefaultSlot = true;
  5236. }
  5237. }
  5238. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  5239. }
  5240. }
  5241. if (!onComponentSlot) {
  5242. const buildDefaultSlotProperty = (props, children2) => {
  5243. const fn = buildSlotFn(props, void 0, children2, loc);
  5244. if (context.compatConfig) {
  5245. fn.isNonScopedSlot = true;
  5246. }
  5247. return createObjectProperty(`default`, fn);
  5248. };
  5249. if (!hasTemplateSlots) {
  5250. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  5251. } else if (implicitDefaultChildren.length && // #3766
  5252. // with whitespace: 'preserve', whitespaces between slots will end up in
  5253. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  5254. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  5255. if (hasNamedDefaultSlot) {
  5256. context.onError(
  5257. createCompilerError(
  5258. 39,
  5259. implicitDefaultChildren[0].loc
  5260. )
  5261. );
  5262. } else {
  5263. slotsProperties.push(
  5264. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  5265. );
  5266. }
  5267. }
  5268. }
  5269. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  5270. let slots = createObjectExpression(
  5271. slotsProperties.concat(
  5272. createObjectProperty(
  5273. `_`,
  5274. // 2 = compiled but dynamic = can skip normalization, but must run diff
  5275. // 1 = compiled and static = can skip normalization AND diff as optimized
  5276. createSimpleExpression(
  5277. slotFlag + (``),
  5278. false
  5279. )
  5280. )
  5281. ),
  5282. loc
  5283. );
  5284. if (dynamicSlots.length) {
  5285. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  5286. slots,
  5287. createArrayExpression(dynamicSlots)
  5288. ]);
  5289. }
  5290. return {
  5291. slots,
  5292. hasDynamicSlots
  5293. };
  5294. }
  5295. function buildDynamicSlot(name, fn, index) {
  5296. const props = [
  5297. createObjectProperty(`name`, name),
  5298. createObjectProperty(`fn`, fn)
  5299. ];
  5300. if (index != null) {
  5301. props.push(
  5302. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  5303. );
  5304. }
  5305. return createObjectExpression(props);
  5306. }
  5307. function hasForwardedSlots(children) {
  5308. for (let i = 0; i < children.length; i++) {
  5309. const child = children[i];
  5310. switch (child.type) {
  5311. case 1:
  5312. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  5313. return true;
  5314. }
  5315. break;
  5316. case 9:
  5317. if (hasForwardedSlots(child.branches)) return true;
  5318. break;
  5319. case 10:
  5320. case 11:
  5321. if (hasForwardedSlots(child.children)) return true;
  5322. break;
  5323. }
  5324. }
  5325. return false;
  5326. }
  5327. function isNonWhitespaceContent(node) {
  5328. if (node.type !== 2 && node.type !== 12)
  5329. return true;
  5330. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  5331. }
  5332. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  5333. const transformElement = (node, context) => {
  5334. return function postTransformElement() {
  5335. node = context.currentNode;
  5336. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  5337. return;
  5338. }
  5339. const { tag, props } = node;
  5340. const isComponent = node.tagType === 1;
  5341. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  5342. const isDynamicComponent = shared.isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  5343. let vnodeProps;
  5344. let vnodeChildren;
  5345. let patchFlag = 0;
  5346. let vnodeDynamicProps;
  5347. let dynamicPropNames;
  5348. let vnodeDirectives;
  5349. let shouldUseBlock = (
  5350. // dynamic component may resolve to plain elements
  5351. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  5352. // updates inside get proper isSVG flag at runtime. (#639, #643)
  5353. // This is technically web-specific, but splitting the logic out of core
  5354. // leads to too much unnecessary complexity.
  5355. (tag === "svg" || tag === "foreignObject" || tag === "math")
  5356. );
  5357. if (props.length > 0) {
  5358. const propsBuildResult = buildProps(
  5359. node,
  5360. context,
  5361. void 0,
  5362. isComponent,
  5363. isDynamicComponent
  5364. );
  5365. vnodeProps = propsBuildResult.props;
  5366. patchFlag = propsBuildResult.patchFlag;
  5367. dynamicPropNames = propsBuildResult.dynamicPropNames;
  5368. const directives = propsBuildResult.directives;
  5369. vnodeDirectives = directives && directives.length ? createArrayExpression(
  5370. directives.map((dir) => buildDirectiveArgs(dir, context))
  5371. ) : void 0;
  5372. if (propsBuildResult.shouldUseBlock) {
  5373. shouldUseBlock = true;
  5374. }
  5375. }
  5376. if (node.children.length > 0) {
  5377. if (vnodeTag === KEEP_ALIVE) {
  5378. shouldUseBlock = true;
  5379. patchFlag |= 1024;
  5380. }
  5381. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  5382. vnodeTag !== TELEPORT && // explained above.
  5383. vnodeTag !== KEEP_ALIVE;
  5384. if (shouldBuildAsSlots) {
  5385. const { slots, hasDynamicSlots } = buildSlots(node, context);
  5386. vnodeChildren = slots;
  5387. if (hasDynamicSlots) {
  5388. patchFlag |= 1024;
  5389. }
  5390. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  5391. const child = node.children[0];
  5392. const type = child.type;
  5393. const hasDynamicTextChild = type === 5 || type === 8;
  5394. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  5395. patchFlag |= 1;
  5396. }
  5397. if (hasDynamicTextChild || type === 2) {
  5398. vnodeChildren = child;
  5399. } else {
  5400. vnodeChildren = node.children;
  5401. }
  5402. } else {
  5403. vnodeChildren = node.children;
  5404. }
  5405. }
  5406. if (dynamicPropNames && dynamicPropNames.length) {
  5407. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  5408. }
  5409. node.codegenNode = createVNodeCall(
  5410. context,
  5411. vnodeTag,
  5412. vnodeProps,
  5413. vnodeChildren,
  5414. patchFlag === 0 ? void 0 : patchFlag,
  5415. vnodeDynamicProps,
  5416. vnodeDirectives,
  5417. !!shouldUseBlock,
  5418. false,
  5419. isComponent,
  5420. node.loc
  5421. );
  5422. };
  5423. };
  5424. function resolveComponentType(node, context, ssr = false) {
  5425. let { tag } = node;
  5426. const isExplicitDynamic = isComponentTag(tag);
  5427. const isProp = findProp(
  5428. node,
  5429. "is",
  5430. false,
  5431. true
  5432. /* allow empty */
  5433. );
  5434. if (isProp) {
  5435. if (isExplicitDynamic || isCompatEnabled(
  5436. "COMPILER_IS_ON_ELEMENT",
  5437. context
  5438. )) {
  5439. let exp;
  5440. if (isProp.type === 6) {
  5441. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  5442. } else {
  5443. exp = isProp.exp;
  5444. if (!exp) {
  5445. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  5446. {
  5447. exp = isProp.exp = processExpression(exp, context);
  5448. }
  5449. }
  5450. }
  5451. if (exp) {
  5452. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  5453. exp
  5454. ]);
  5455. }
  5456. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  5457. tag = isProp.value.content.slice(4);
  5458. }
  5459. }
  5460. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  5461. if (builtIn) {
  5462. if (!ssr) context.helper(builtIn);
  5463. return builtIn;
  5464. }
  5465. {
  5466. const fromSetup = resolveSetupReference(tag, context);
  5467. if (fromSetup) {
  5468. return fromSetup;
  5469. }
  5470. const dotIndex = tag.indexOf(".");
  5471. if (dotIndex > 0) {
  5472. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  5473. if (ns) {
  5474. return ns + tag.slice(dotIndex);
  5475. }
  5476. }
  5477. }
  5478. if (context.selfName && shared.capitalize(shared.camelize(tag)) === context.selfName) {
  5479. context.helper(RESOLVE_COMPONENT);
  5480. context.components.add(tag + `__self`);
  5481. return toValidAssetId(tag, `component`);
  5482. }
  5483. context.helper(RESOLVE_COMPONENT);
  5484. context.components.add(tag);
  5485. return toValidAssetId(tag, `component`);
  5486. }
  5487. function resolveSetupReference(name, context) {
  5488. const bindings = context.bindingMetadata;
  5489. if (!bindings || bindings.__isScriptSetup === false) {
  5490. return;
  5491. }
  5492. const camelName = shared.camelize(name);
  5493. const PascalName = shared.capitalize(camelName);
  5494. const checkType = (type) => {
  5495. if (bindings[name] === type) {
  5496. return name;
  5497. }
  5498. if (bindings[camelName] === type) {
  5499. return camelName;
  5500. }
  5501. if (bindings[PascalName] === type) {
  5502. return PascalName;
  5503. }
  5504. };
  5505. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  5506. if (fromConst) {
  5507. return context.inline ? (
  5508. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  5509. fromConst
  5510. ) : `$setup[${JSON.stringify(fromConst)}]`;
  5511. }
  5512. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  5513. if (fromMaybeRef) {
  5514. return context.inline ? (
  5515. // setup scope bindings that may be refs need to be unrefed
  5516. `${context.helperString(UNREF)}(${fromMaybeRef})`
  5517. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  5518. }
  5519. const fromProps = checkType("props");
  5520. if (fromProps) {
  5521. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  5522. }
  5523. }
  5524. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  5525. const { tag, loc: elementLoc, children } = node;
  5526. let properties = [];
  5527. const mergeArgs = [];
  5528. const runtimeDirectives = [];
  5529. const hasChildren = children.length > 0;
  5530. let shouldUseBlock = false;
  5531. let patchFlag = 0;
  5532. let hasRef = false;
  5533. let hasClassBinding = false;
  5534. let hasStyleBinding = false;
  5535. let hasHydrationEventBinding = false;
  5536. let hasDynamicKeys = false;
  5537. let hasVnodeHook = false;
  5538. const dynamicPropNames = [];
  5539. const pushMergeArg = (arg) => {
  5540. if (properties.length) {
  5541. mergeArgs.push(
  5542. createObjectExpression(dedupeProperties(properties), elementLoc)
  5543. );
  5544. properties = [];
  5545. }
  5546. if (arg) mergeArgs.push(arg);
  5547. };
  5548. const pushRefVForMarker = () => {
  5549. if (context.scopes.vFor > 0) {
  5550. properties.push(
  5551. createObjectProperty(
  5552. createSimpleExpression("ref_for", true),
  5553. createSimpleExpression("true")
  5554. )
  5555. );
  5556. }
  5557. };
  5558. const analyzePatchFlag = ({ key, value }) => {
  5559. if (isStaticExp(key)) {
  5560. const name = key.content;
  5561. const isEventHandler = shared.isOn(name);
  5562. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  5563. // dedicated fast path.
  5564. name.toLowerCase() !== "onclick" && // omit v-model handlers
  5565. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  5566. !shared.isReservedProp(name)) {
  5567. hasHydrationEventBinding = true;
  5568. }
  5569. if (isEventHandler && shared.isReservedProp(name)) {
  5570. hasVnodeHook = true;
  5571. }
  5572. if (isEventHandler && value.type === 14) {
  5573. value = value.arguments[0];
  5574. }
  5575. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  5576. return;
  5577. }
  5578. if (name === "ref") {
  5579. hasRef = true;
  5580. } else if (name === "class") {
  5581. hasClassBinding = true;
  5582. } else if (name === "style") {
  5583. hasStyleBinding = true;
  5584. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  5585. dynamicPropNames.push(name);
  5586. }
  5587. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  5588. dynamicPropNames.push(name);
  5589. }
  5590. } else {
  5591. hasDynamicKeys = true;
  5592. }
  5593. };
  5594. for (let i = 0; i < props.length; i++) {
  5595. const prop = props[i];
  5596. if (prop.type === 6) {
  5597. const { loc, name, nameLoc, value } = prop;
  5598. let isStatic = true;
  5599. if (name === "ref") {
  5600. hasRef = true;
  5601. pushRefVForMarker();
  5602. if (value && context.inline) {
  5603. const binding = context.bindingMetadata[value.content];
  5604. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  5605. isStatic = false;
  5606. properties.push(
  5607. createObjectProperty(
  5608. createSimpleExpression("ref_key", true),
  5609. createSimpleExpression(value.content, true, value.loc)
  5610. )
  5611. );
  5612. }
  5613. }
  5614. }
  5615. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  5616. "COMPILER_IS_ON_ELEMENT",
  5617. context
  5618. ))) {
  5619. continue;
  5620. }
  5621. properties.push(
  5622. createObjectProperty(
  5623. createSimpleExpression(name, true, nameLoc),
  5624. createSimpleExpression(
  5625. value ? value.content : "",
  5626. isStatic,
  5627. value ? value.loc : loc
  5628. )
  5629. )
  5630. );
  5631. } else {
  5632. const { name, arg, exp, loc, modifiers } = prop;
  5633. const isVBind = name === "bind";
  5634. const isVOn = name === "on";
  5635. if (name === "slot") {
  5636. if (!isComponent) {
  5637. context.onError(
  5638. createCompilerError(40, loc)
  5639. );
  5640. }
  5641. continue;
  5642. }
  5643. if (name === "once" || name === "memo") {
  5644. continue;
  5645. }
  5646. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  5647. "COMPILER_IS_ON_ELEMENT",
  5648. context
  5649. ))) {
  5650. continue;
  5651. }
  5652. if (isVOn && ssr) {
  5653. continue;
  5654. }
  5655. if (
  5656. // #938: elements with dynamic keys should be forced into blocks
  5657. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  5658. // before children
  5659. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  5660. ) {
  5661. shouldUseBlock = true;
  5662. }
  5663. if (isVBind && isStaticArgOf(arg, "ref")) {
  5664. pushRefVForMarker();
  5665. }
  5666. if (!arg && (isVBind || isVOn)) {
  5667. hasDynamicKeys = true;
  5668. if (exp) {
  5669. if (isVBind) {
  5670. pushRefVForMarker();
  5671. pushMergeArg();
  5672. {
  5673. if (isCompatEnabled(
  5674. "COMPILER_V_BIND_OBJECT_ORDER",
  5675. context
  5676. )) {
  5677. mergeArgs.unshift(exp);
  5678. continue;
  5679. }
  5680. }
  5681. mergeArgs.push(exp);
  5682. } else {
  5683. pushMergeArg({
  5684. type: 14,
  5685. loc,
  5686. callee: context.helper(TO_HANDLERS),
  5687. arguments: isComponent ? [exp] : [exp, `true`]
  5688. });
  5689. }
  5690. } else {
  5691. context.onError(
  5692. createCompilerError(
  5693. isVBind ? 34 : 35,
  5694. loc
  5695. )
  5696. );
  5697. }
  5698. continue;
  5699. }
  5700. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  5701. patchFlag |= 32;
  5702. }
  5703. const directiveTransform = context.directiveTransforms[name];
  5704. if (directiveTransform) {
  5705. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  5706. !ssr && props2.forEach(analyzePatchFlag);
  5707. if (isVOn && arg && !isStaticExp(arg)) {
  5708. pushMergeArg(createObjectExpression(props2, elementLoc));
  5709. } else {
  5710. properties.push(...props2);
  5711. }
  5712. if (needRuntime) {
  5713. runtimeDirectives.push(prop);
  5714. if (shared.isSymbol(needRuntime)) {
  5715. directiveImportMap.set(prop, needRuntime);
  5716. }
  5717. }
  5718. } else if (!shared.isBuiltInDirective(name)) {
  5719. runtimeDirectives.push(prop);
  5720. if (hasChildren) {
  5721. shouldUseBlock = true;
  5722. }
  5723. }
  5724. }
  5725. }
  5726. let propsExpression = void 0;
  5727. if (mergeArgs.length) {
  5728. pushMergeArg();
  5729. if (mergeArgs.length > 1) {
  5730. propsExpression = createCallExpression(
  5731. context.helper(MERGE_PROPS),
  5732. mergeArgs,
  5733. elementLoc
  5734. );
  5735. } else {
  5736. propsExpression = mergeArgs[0];
  5737. }
  5738. } else if (properties.length) {
  5739. propsExpression = createObjectExpression(
  5740. dedupeProperties(properties),
  5741. elementLoc
  5742. );
  5743. }
  5744. if (hasDynamicKeys) {
  5745. patchFlag |= 16;
  5746. } else {
  5747. if (hasClassBinding && !isComponent) {
  5748. patchFlag |= 2;
  5749. }
  5750. if (hasStyleBinding && !isComponent) {
  5751. patchFlag |= 4;
  5752. }
  5753. if (dynamicPropNames.length) {
  5754. patchFlag |= 8;
  5755. }
  5756. if (hasHydrationEventBinding) {
  5757. patchFlag |= 32;
  5758. }
  5759. }
  5760. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  5761. patchFlag |= 512;
  5762. }
  5763. if (!context.inSSR && propsExpression) {
  5764. switch (propsExpression.type) {
  5765. case 15:
  5766. let classKeyIndex = -1;
  5767. let styleKeyIndex = -1;
  5768. let hasDynamicKey = false;
  5769. for (let i = 0; i < propsExpression.properties.length; i++) {
  5770. const key = propsExpression.properties[i].key;
  5771. if (isStaticExp(key)) {
  5772. if (key.content === "class") {
  5773. classKeyIndex = i;
  5774. } else if (key.content === "style") {
  5775. styleKeyIndex = i;
  5776. }
  5777. } else if (!key.isHandlerKey) {
  5778. hasDynamicKey = true;
  5779. }
  5780. }
  5781. const classProp = propsExpression.properties[classKeyIndex];
  5782. const styleProp = propsExpression.properties[styleKeyIndex];
  5783. if (!hasDynamicKey) {
  5784. if (classProp && !isStaticExp(classProp.value)) {
  5785. classProp.value = createCallExpression(
  5786. context.helper(NORMALIZE_CLASS),
  5787. [classProp.value]
  5788. );
  5789. }
  5790. if (styleProp && // the static style is compiled into an object,
  5791. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  5792. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  5793. // v-bind:style with static literal object
  5794. styleProp.value.type === 17)) {
  5795. styleProp.value = createCallExpression(
  5796. context.helper(NORMALIZE_STYLE),
  5797. [styleProp.value]
  5798. );
  5799. }
  5800. } else {
  5801. propsExpression = createCallExpression(
  5802. context.helper(NORMALIZE_PROPS),
  5803. [propsExpression]
  5804. );
  5805. }
  5806. break;
  5807. case 14:
  5808. break;
  5809. default:
  5810. propsExpression = createCallExpression(
  5811. context.helper(NORMALIZE_PROPS),
  5812. [
  5813. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  5814. propsExpression
  5815. ])
  5816. ]
  5817. );
  5818. break;
  5819. }
  5820. }
  5821. return {
  5822. props: propsExpression,
  5823. directives: runtimeDirectives,
  5824. patchFlag,
  5825. dynamicPropNames,
  5826. shouldUseBlock
  5827. };
  5828. }
  5829. function dedupeProperties(properties) {
  5830. const knownProps = /* @__PURE__ */ new Map();
  5831. const deduped = [];
  5832. for (let i = 0; i < properties.length; i++) {
  5833. const prop = properties[i];
  5834. if (prop.key.type === 8 || !prop.key.isStatic) {
  5835. deduped.push(prop);
  5836. continue;
  5837. }
  5838. const name = prop.key.content;
  5839. const existing = knownProps.get(name);
  5840. if (existing) {
  5841. if (name === "style" || name === "class" || shared.isOn(name)) {
  5842. mergeAsArray(existing, prop);
  5843. }
  5844. } else {
  5845. knownProps.set(name, prop);
  5846. deduped.push(prop);
  5847. }
  5848. }
  5849. return deduped;
  5850. }
  5851. function mergeAsArray(existing, incoming) {
  5852. if (existing.value.type === 17) {
  5853. existing.value.elements.push(incoming.value);
  5854. } else {
  5855. existing.value = createArrayExpression(
  5856. [existing.value, incoming.value],
  5857. existing.loc
  5858. );
  5859. }
  5860. }
  5861. function buildDirectiveArgs(dir, context) {
  5862. const dirArgs = [];
  5863. const runtime = directiveImportMap.get(dir);
  5864. if (runtime) {
  5865. dirArgs.push(context.helperString(runtime));
  5866. } else {
  5867. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  5868. if (fromSetup) {
  5869. dirArgs.push(fromSetup);
  5870. } else {
  5871. context.helper(RESOLVE_DIRECTIVE);
  5872. context.directives.add(dir.name);
  5873. dirArgs.push(toValidAssetId(dir.name, `directive`));
  5874. }
  5875. }
  5876. const { loc } = dir;
  5877. if (dir.exp) dirArgs.push(dir.exp);
  5878. if (dir.arg) {
  5879. if (!dir.exp) {
  5880. dirArgs.push(`void 0`);
  5881. }
  5882. dirArgs.push(dir.arg);
  5883. }
  5884. if (Object.keys(dir.modifiers).length) {
  5885. if (!dir.arg) {
  5886. if (!dir.exp) {
  5887. dirArgs.push(`void 0`);
  5888. }
  5889. dirArgs.push(`void 0`);
  5890. }
  5891. const trueExpression = createSimpleExpression(`true`, false, loc);
  5892. dirArgs.push(
  5893. createObjectExpression(
  5894. dir.modifiers.map(
  5895. (modifier) => createObjectProperty(modifier, trueExpression)
  5896. ),
  5897. loc
  5898. )
  5899. );
  5900. }
  5901. return createArrayExpression(dirArgs, dir.loc);
  5902. }
  5903. function stringifyDynamicPropNames(props) {
  5904. let propsNamesString = `[`;
  5905. for (let i = 0, l = props.length; i < l; i++) {
  5906. propsNamesString += JSON.stringify(props[i]);
  5907. if (i < l - 1) propsNamesString += ", ";
  5908. }
  5909. return propsNamesString + `]`;
  5910. }
  5911. function isComponentTag(tag) {
  5912. return tag === "component" || tag === "Component";
  5913. }
  5914. const transformSlotOutlet = (node, context) => {
  5915. if (isSlotOutlet(node)) {
  5916. const { children, loc } = node;
  5917. const { slotName, slotProps } = processSlotOutlet(node, context);
  5918. const slotArgs = [
  5919. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  5920. slotName,
  5921. "{}",
  5922. "undefined",
  5923. "true"
  5924. ];
  5925. let expectedLen = 2;
  5926. if (slotProps) {
  5927. slotArgs[2] = slotProps;
  5928. expectedLen = 3;
  5929. }
  5930. if (children.length) {
  5931. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  5932. expectedLen = 4;
  5933. }
  5934. if (context.scopeId && !context.slotted) {
  5935. expectedLen = 5;
  5936. }
  5937. slotArgs.splice(expectedLen);
  5938. node.codegenNode = createCallExpression(
  5939. context.helper(RENDER_SLOT),
  5940. slotArgs,
  5941. loc
  5942. );
  5943. }
  5944. };
  5945. function processSlotOutlet(node, context) {
  5946. let slotName = `"default"`;
  5947. let slotProps = void 0;
  5948. const nonNameProps = [];
  5949. for (let i = 0; i < node.props.length; i++) {
  5950. const p = node.props[i];
  5951. if (p.type === 6) {
  5952. if (p.value) {
  5953. if (p.name === "name") {
  5954. slotName = JSON.stringify(p.value.content);
  5955. } else {
  5956. p.name = shared.camelize(p.name);
  5957. nonNameProps.push(p);
  5958. }
  5959. }
  5960. } else {
  5961. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  5962. if (p.exp) {
  5963. slotName = p.exp;
  5964. } else if (p.arg && p.arg.type === 4) {
  5965. const name = shared.camelize(p.arg.content);
  5966. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  5967. {
  5968. slotName = p.exp = processExpression(p.exp, context);
  5969. }
  5970. }
  5971. } else {
  5972. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  5973. p.arg.content = shared.camelize(p.arg.content);
  5974. }
  5975. nonNameProps.push(p);
  5976. }
  5977. }
  5978. }
  5979. if (nonNameProps.length > 0) {
  5980. const { props, directives } = buildProps(
  5981. node,
  5982. context,
  5983. nonNameProps,
  5984. false,
  5985. false
  5986. );
  5987. slotProps = props;
  5988. if (directives.length) {
  5989. context.onError(
  5990. createCompilerError(
  5991. 36,
  5992. directives[0].loc
  5993. )
  5994. );
  5995. }
  5996. }
  5997. return {
  5998. slotName,
  5999. slotProps
  6000. };
  6001. }
  6002. const transformOn = (dir, node, context, augmentor) => {
  6003. const { loc, modifiers, arg } = dir;
  6004. if (!dir.exp && !modifiers.length) {
  6005. context.onError(createCompilerError(35, loc));
  6006. }
  6007. let eventName;
  6008. if (arg.type === 4) {
  6009. if (arg.isStatic) {
  6010. let rawName = arg.content;
  6011. if (rawName.startsWith("vue:")) {
  6012. rawName = `vnode-${rawName.slice(4)}`;
  6013. }
  6014. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  6015. // for non-element and vnode lifecycle event listeners, auto convert
  6016. // it to camelCase. See issue #2249
  6017. shared.toHandlerKey(shared.camelize(rawName))
  6018. ) : (
  6019. // preserve case for plain element listeners that have uppercase
  6020. // letters, as these may be custom elements' custom events
  6021. `on:${rawName}`
  6022. );
  6023. eventName = createSimpleExpression(eventString, true, arg.loc);
  6024. } else {
  6025. eventName = createCompoundExpression([
  6026. `${context.helperString(TO_HANDLER_KEY)}(`,
  6027. arg,
  6028. `)`
  6029. ]);
  6030. }
  6031. } else {
  6032. eventName = arg;
  6033. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  6034. eventName.children.push(`)`);
  6035. }
  6036. let exp = dir.exp;
  6037. if (exp && !exp.content.trim()) {
  6038. exp = void 0;
  6039. }
  6040. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  6041. if (exp) {
  6042. const isMemberExp = isMemberExpression(exp, context);
  6043. const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
  6044. const hasMultipleStatements = exp.content.includes(`;`);
  6045. if (context.prefixIdentifiers) {
  6046. isInlineStatement && context.addIdentifiers(`$event`);
  6047. exp = dir.exp = processExpression(
  6048. exp,
  6049. context,
  6050. false,
  6051. hasMultipleStatements
  6052. );
  6053. isInlineStatement && context.removeIdentifiers(`$event`);
  6054. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  6055. !context.inVOnce && // runtime constants don't need to be cached
  6056. // (this is analyzed by compileScript in SFC <script setup>)
  6057. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  6058. // we need to use the original function to preserve arity,
  6059. // e.g. <transition> relies on checking cb.length to determine
  6060. // transition end handling. Inline function is ok since its arity
  6061. // is preserved even when cached.
  6062. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  6063. // it must be passed fresh to avoid stale values.
  6064. !hasScopeRef(exp, context.identifiers);
  6065. if (shouldCache && isMemberExp) {
  6066. if (exp.type === 4) {
  6067. exp.content = `${exp.content} && ${exp.content}(...args)`;
  6068. } else {
  6069. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  6070. }
  6071. }
  6072. }
  6073. if (isInlineStatement || shouldCache && isMemberExp) {
  6074. exp = createCompoundExpression([
  6075. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  6076. //@ts-ignore
  6077. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  6078. exp,
  6079. hasMultipleStatements ? `}` : `)`
  6080. ]);
  6081. }
  6082. }
  6083. let ret = {
  6084. props: [
  6085. createObjectProperty(
  6086. eventName,
  6087. exp || createSimpleExpression(`() => {}`, false, loc)
  6088. )
  6089. ]
  6090. };
  6091. if (augmentor) {
  6092. ret = augmentor(ret);
  6093. }
  6094. if (shouldCache) {
  6095. ret.props[0].value = context.cache(ret.props[0].value);
  6096. }
  6097. ret.props.forEach((p) => p.key.isHandlerKey = true);
  6098. return ret;
  6099. };
  6100. const transformText = (node, context) => {
  6101. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  6102. return () => {
  6103. const children = node.children;
  6104. let currentContainer = void 0;
  6105. let hasText = false;
  6106. for (let i = 0; i < children.length; i++) {
  6107. const child = children[i];
  6108. if (isText$1(child)) {
  6109. hasText = true;
  6110. for (let j = i + 1; j < children.length; j++) {
  6111. const next = children[j];
  6112. if (isText$1(next)) {
  6113. if (!currentContainer) {
  6114. currentContainer = children[i] = createCompoundExpression(
  6115. [child],
  6116. child.loc
  6117. );
  6118. }
  6119. currentContainer.children.push(` + `, next);
  6120. children.splice(j, 1);
  6121. j--;
  6122. } else {
  6123. currentContainer = void 0;
  6124. break;
  6125. }
  6126. }
  6127. }
  6128. }
  6129. if (!hasText || // if this is a plain element with a single text child, leave it
  6130. // as-is since the runtime has dedicated fast path for this by directly
  6131. // setting textContent of the element.
  6132. // for component root it's always normalized anyway.
  6133. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  6134. // custom directives can potentially add DOM elements arbitrarily,
  6135. // we need to avoid setting textContent of the element at runtime
  6136. // to avoid accidentally overwriting the DOM elements added
  6137. // by the user through custom directives.
  6138. !node.props.find(
  6139. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  6140. ) && // in compat mode, <template> tags with no special directives
  6141. // will be rendered as a fragment so its children must be
  6142. // converted into vnodes.
  6143. !(node.tag === "template"))) {
  6144. return;
  6145. }
  6146. for (let i = 0; i < children.length; i++) {
  6147. const child = children[i];
  6148. if (isText$1(child) || child.type === 8) {
  6149. const callArgs = [];
  6150. if (child.type !== 2 || child.content !== " ") {
  6151. callArgs.push(child);
  6152. }
  6153. if (!context.ssr && getConstantType(child, context) === 0) {
  6154. callArgs.push(
  6155. 1 + (``)
  6156. );
  6157. }
  6158. children[i] = {
  6159. type: 12,
  6160. content: child,
  6161. loc: child.loc,
  6162. codegenNode: createCallExpression(
  6163. context.helper(CREATE_TEXT),
  6164. callArgs
  6165. )
  6166. };
  6167. }
  6168. }
  6169. };
  6170. }
  6171. };
  6172. const seen$1 = /* @__PURE__ */ new WeakSet();
  6173. const transformOnce = (node, context) => {
  6174. if (node.type === 1 && findDir(node, "once", true)) {
  6175. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  6176. return;
  6177. }
  6178. seen$1.add(node);
  6179. context.inVOnce = true;
  6180. context.helper(SET_BLOCK_TRACKING);
  6181. return () => {
  6182. context.inVOnce = false;
  6183. const cur = context.currentNode;
  6184. if (cur.codegenNode) {
  6185. cur.codegenNode = context.cache(
  6186. cur.codegenNode,
  6187. true,
  6188. true
  6189. );
  6190. }
  6191. };
  6192. }
  6193. };
  6194. const transformModel = (dir, node, context) => {
  6195. const { exp, arg } = dir;
  6196. if (!exp) {
  6197. context.onError(
  6198. createCompilerError(41, dir.loc)
  6199. );
  6200. return createTransformProps();
  6201. }
  6202. const rawExp = exp.loc.source.trim();
  6203. const expString = exp.type === 4 ? exp.content : rawExp;
  6204. const bindingType = context.bindingMetadata[rawExp];
  6205. if (bindingType === "props" || bindingType === "props-aliased") {
  6206. context.onError(createCompilerError(44, exp.loc));
  6207. return createTransformProps();
  6208. }
  6209. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  6210. if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
  6211. context.onError(
  6212. createCompilerError(42, exp.loc)
  6213. );
  6214. return createTransformProps();
  6215. }
  6216. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  6217. context.onError(
  6218. createCompilerError(43, exp.loc)
  6219. );
  6220. return createTransformProps();
  6221. }
  6222. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  6223. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${shared.camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  6224. let assignmentExp;
  6225. const eventArg = context.isTS ? `($event: any)` : `$event`;
  6226. if (maybeRef) {
  6227. if (bindingType === "setup-ref") {
  6228. assignmentExp = createCompoundExpression([
  6229. `${eventArg} => ((`,
  6230. createSimpleExpression(rawExp, false, exp.loc),
  6231. `).value = $event)`
  6232. ]);
  6233. } else {
  6234. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  6235. assignmentExp = createCompoundExpression([
  6236. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  6237. createSimpleExpression(rawExp, false, exp.loc),
  6238. `).value = $event : ${altAssignment})`
  6239. ]);
  6240. }
  6241. } else {
  6242. assignmentExp = createCompoundExpression([
  6243. `${eventArg} => ((`,
  6244. exp,
  6245. `) = $event)`
  6246. ]);
  6247. }
  6248. const props = [
  6249. // modelValue: foo
  6250. createObjectProperty(propName, dir.exp),
  6251. // "onUpdate:modelValue": $event => (foo = $event)
  6252. createObjectProperty(eventName, assignmentExp)
  6253. ];
  6254. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  6255. props[1].value = context.cache(props[1].value);
  6256. }
  6257. if (dir.modifiers.length && node.tagType === 1) {
  6258. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  6259. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  6260. props.push(
  6261. createObjectProperty(
  6262. modifiersKey,
  6263. createSimpleExpression(
  6264. `{ ${modifiers} }`,
  6265. false,
  6266. dir.loc,
  6267. 2
  6268. )
  6269. )
  6270. );
  6271. }
  6272. return createTransformProps(props);
  6273. };
  6274. function createTransformProps(props = []) {
  6275. return { props };
  6276. }
  6277. const validDivisionCharRE = /[\w).+\-_$\]]/;
  6278. const transformFilter = (node, context) => {
  6279. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  6280. return;
  6281. }
  6282. if (node.type === 5) {
  6283. rewriteFilter(node.content, context);
  6284. } else if (node.type === 1) {
  6285. node.props.forEach((prop) => {
  6286. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  6287. rewriteFilter(prop.exp, context);
  6288. }
  6289. });
  6290. }
  6291. };
  6292. function rewriteFilter(node, context) {
  6293. if (node.type === 4) {
  6294. parseFilter(node, context);
  6295. } else {
  6296. for (let i = 0; i < node.children.length; i++) {
  6297. const child = node.children[i];
  6298. if (typeof child !== "object") continue;
  6299. if (child.type === 4) {
  6300. parseFilter(child, context);
  6301. } else if (child.type === 8) {
  6302. rewriteFilter(node, context);
  6303. } else if (child.type === 5) {
  6304. rewriteFilter(child.content, context);
  6305. }
  6306. }
  6307. }
  6308. }
  6309. function parseFilter(node, context) {
  6310. const exp = node.content;
  6311. let inSingle = false;
  6312. let inDouble = false;
  6313. let inTemplateString = false;
  6314. let inRegex = false;
  6315. let curly = 0;
  6316. let square = 0;
  6317. let paren = 0;
  6318. let lastFilterIndex = 0;
  6319. let c, prev, i, expression, filters = [];
  6320. for (i = 0; i < exp.length; i++) {
  6321. prev = c;
  6322. c = exp.charCodeAt(i);
  6323. if (inSingle) {
  6324. if (c === 39 && prev !== 92) inSingle = false;
  6325. } else if (inDouble) {
  6326. if (c === 34 && prev !== 92) inDouble = false;
  6327. } else if (inTemplateString) {
  6328. if (c === 96 && prev !== 92) inTemplateString = false;
  6329. } else if (inRegex) {
  6330. if (c === 47 && prev !== 92) inRegex = false;
  6331. } else if (c === 124 && // pipe
  6332. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  6333. if (expression === void 0) {
  6334. lastFilterIndex = i + 1;
  6335. expression = exp.slice(0, i).trim();
  6336. } else {
  6337. pushFilter();
  6338. }
  6339. } else {
  6340. switch (c) {
  6341. case 34:
  6342. inDouble = true;
  6343. break;
  6344. // "
  6345. case 39:
  6346. inSingle = true;
  6347. break;
  6348. // '
  6349. case 96:
  6350. inTemplateString = true;
  6351. break;
  6352. // `
  6353. case 40:
  6354. paren++;
  6355. break;
  6356. // (
  6357. case 41:
  6358. paren--;
  6359. break;
  6360. // )
  6361. case 91:
  6362. square++;
  6363. break;
  6364. // [
  6365. case 93:
  6366. square--;
  6367. break;
  6368. // ]
  6369. case 123:
  6370. curly++;
  6371. break;
  6372. // {
  6373. case 125:
  6374. curly--;
  6375. break;
  6376. }
  6377. if (c === 47) {
  6378. let j = i - 1;
  6379. let p;
  6380. for (; j >= 0; j--) {
  6381. p = exp.charAt(j);
  6382. if (p !== " ") break;
  6383. }
  6384. if (!p || !validDivisionCharRE.test(p)) {
  6385. inRegex = true;
  6386. }
  6387. }
  6388. }
  6389. }
  6390. if (expression === void 0) {
  6391. expression = exp.slice(0, i).trim();
  6392. } else if (lastFilterIndex !== 0) {
  6393. pushFilter();
  6394. }
  6395. function pushFilter() {
  6396. filters.push(exp.slice(lastFilterIndex, i).trim());
  6397. lastFilterIndex = i + 1;
  6398. }
  6399. if (filters.length) {
  6400. for (i = 0; i < filters.length; i++) {
  6401. expression = wrapFilter(expression, filters[i], context);
  6402. }
  6403. node.content = expression;
  6404. node.ast = void 0;
  6405. }
  6406. }
  6407. function wrapFilter(exp, filter, context) {
  6408. context.helper(RESOLVE_FILTER);
  6409. const i = filter.indexOf("(");
  6410. if (i < 0) {
  6411. context.filters.add(filter);
  6412. return `${toValidAssetId(filter, "filter")}(${exp})`;
  6413. } else {
  6414. const name = filter.slice(0, i);
  6415. const args = filter.slice(i + 1);
  6416. context.filters.add(name);
  6417. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  6418. }
  6419. }
  6420. const seen = /* @__PURE__ */ new WeakSet();
  6421. const transformMemo = (node, context) => {
  6422. if (node.type === 1) {
  6423. const dir = findDir(node, "memo");
  6424. if (!dir || seen.has(node)) {
  6425. return;
  6426. }
  6427. seen.add(node);
  6428. return () => {
  6429. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  6430. if (codegenNode && codegenNode.type === 13) {
  6431. if (node.tagType !== 1) {
  6432. convertToBlock(codegenNode, context);
  6433. }
  6434. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  6435. dir.exp,
  6436. createFunctionExpression(void 0, codegenNode),
  6437. `_cache`,
  6438. String(context.cached.length)
  6439. ]);
  6440. context.cached.push(null);
  6441. }
  6442. };
  6443. }
  6444. };
  6445. function getBaseTransformPreset(prefixIdentifiers) {
  6446. return [
  6447. [
  6448. transformOnce,
  6449. transformIf,
  6450. transformMemo,
  6451. transformFor,
  6452. ...[transformFilter] ,
  6453. ...prefixIdentifiers ? [
  6454. // order is important
  6455. trackVForSlotScopes,
  6456. transformExpression
  6457. ] : [],
  6458. transformSlotOutlet,
  6459. transformElement,
  6460. trackSlotScopes,
  6461. transformText
  6462. ],
  6463. {
  6464. on: transformOn,
  6465. bind: transformBind,
  6466. model: transformModel
  6467. }
  6468. ];
  6469. }
  6470. function baseCompile(source, options = {}) {
  6471. const onError = options.onError || defaultOnError;
  6472. const isModuleMode = options.mode === "module";
  6473. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  6474. if (!prefixIdentifiers && options.cacheHandlers) {
  6475. onError(createCompilerError(49));
  6476. }
  6477. if (options.scopeId && !isModuleMode) {
  6478. onError(createCompilerError(50));
  6479. }
  6480. const resolvedOptions = shared.extend({}, options, {
  6481. prefixIdentifiers
  6482. });
  6483. const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
  6484. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  6485. if (options.isTS) {
  6486. const { expressionPlugins } = options;
  6487. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  6488. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  6489. }
  6490. }
  6491. transform(
  6492. ast,
  6493. shared.extend({}, resolvedOptions, {
  6494. nodeTransforms: [
  6495. ...nodeTransforms,
  6496. ...options.nodeTransforms || []
  6497. // user transforms
  6498. ],
  6499. directiveTransforms: shared.extend(
  6500. {},
  6501. directiveTransforms,
  6502. options.directiveTransforms || {}
  6503. // user transforms
  6504. )
  6505. })
  6506. );
  6507. return generate(ast, resolvedOptions);
  6508. }
  6509. const BindingTypes = {
  6510. "DATA": "data",
  6511. "PROPS": "props",
  6512. "PROPS_ALIASED": "props-aliased",
  6513. "SETUP_LET": "setup-let",
  6514. "SETUP_CONST": "setup-const",
  6515. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  6516. "SETUP_MAYBE_REF": "setup-maybe-ref",
  6517. "SETUP_REF": "setup-ref",
  6518. "OPTIONS": "options",
  6519. "LITERAL_CONST": "literal-const"
  6520. };
  6521. const noopDirectiveTransform = () => ({ props: [] });
  6522. exports.generateCodeFrame = shared.generateCodeFrame;
  6523. exports.BASE_TRANSITION = BASE_TRANSITION;
  6524. exports.BindingTypes = BindingTypes;
  6525. exports.CAMELIZE = CAMELIZE;
  6526. exports.CAPITALIZE = CAPITALIZE;
  6527. exports.CREATE_BLOCK = CREATE_BLOCK;
  6528. exports.CREATE_COMMENT = CREATE_COMMENT;
  6529. exports.CREATE_ELEMENT_BLOCK = CREATE_ELEMENT_BLOCK;
  6530. exports.CREATE_ELEMENT_VNODE = CREATE_ELEMENT_VNODE;
  6531. exports.CREATE_SLOTS = CREATE_SLOTS;
  6532. exports.CREATE_STATIC = CREATE_STATIC;
  6533. exports.CREATE_TEXT = CREATE_TEXT;
  6534. exports.CREATE_VNODE = CREATE_VNODE;
  6535. exports.CompilerDeprecationTypes = CompilerDeprecationTypes;
  6536. exports.ConstantTypes = ConstantTypes;
  6537. exports.ElementTypes = ElementTypes;
  6538. exports.ErrorCodes = ErrorCodes;
  6539. exports.FRAGMENT = FRAGMENT;
  6540. exports.GUARD_REACTIVE_PROPS = GUARD_REACTIVE_PROPS;
  6541. exports.IS_MEMO_SAME = IS_MEMO_SAME;
  6542. exports.IS_REF = IS_REF;
  6543. exports.KEEP_ALIVE = KEEP_ALIVE;
  6544. exports.MERGE_PROPS = MERGE_PROPS;
  6545. exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
  6546. exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
  6547. exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
  6548. exports.Namespaces = Namespaces;
  6549. exports.NodeTypes = NodeTypes;
  6550. exports.OPEN_BLOCK = OPEN_BLOCK;
  6551. exports.POP_SCOPE_ID = POP_SCOPE_ID;
  6552. exports.PUSH_SCOPE_ID = PUSH_SCOPE_ID;
  6553. exports.RENDER_LIST = RENDER_LIST;
  6554. exports.RENDER_SLOT = RENDER_SLOT;
  6555. exports.RESOLVE_COMPONENT = RESOLVE_COMPONENT;
  6556. exports.RESOLVE_DIRECTIVE = RESOLVE_DIRECTIVE;
  6557. exports.RESOLVE_DYNAMIC_COMPONENT = RESOLVE_DYNAMIC_COMPONENT;
  6558. exports.RESOLVE_FILTER = RESOLVE_FILTER;
  6559. exports.SET_BLOCK_TRACKING = SET_BLOCK_TRACKING;
  6560. exports.SUSPENSE = SUSPENSE;
  6561. exports.TELEPORT = TELEPORT;
  6562. exports.TO_DISPLAY_STRING = TO_DISPLAY_STRING;
  6563. exports.TO_HANDLERS = TO_HANDLERS;
  6564. exports.TO_HANDLER_KEY = TO_HANDLER_KEY;
  6565. exports.TS_NODE_TYPES = TS_NODE_TYPES;
  6566. exports.UNREF = UNREF;
  6567. exports.WITH_CTX = WITH_CTX;
  6568. exports.WITH_DIRECTIVES = WITH_DIRECTIVES;
  6569. exports.WITH_MEMO = WITH_MEMO;
  6570. exports.advancePositionWithClone = advancePositionWithClone;
  6571. exports.advancePositionWithMutation = advancePositionWithMutation;
  6572. exports.assert = assert;
  6573. exports.baseCompile = baseCompile;
  6574. exports.baseParse = baseParse;
  6575. exports.buildDirectiveArgs = buildDirectiveArgs;
  6576. exports.buildProps = buildProps;
  6577. exports.buildSlots = buildSlots;
  6578. exports.checkCompatEnabled = checkCompatEnabled;
  6579. exports.convertToBlock = convertToBlock;
  6580. exports.createArrayExpression = createArrayExpression;
  6581. exports.createAssignmentExpression = createAssignmentExpression;
  6582. exports.createBlockStatement = createBlockStatement;
  6583. exports.createCacheExpression = createCacheExpression;
  6584. exports.createCallExpression = createCallExpression;
  6585. exports.createCompilerError = createCompilerError;
  6586. exports.createCompoundExpression = createCompoundExpression;
  6587. exports.createConditionalExpression = createConditionalExpression;
  6588. exports.createForLoopParams = createForLoopParams;
  6589. exports.createFunctionExpression = createFunctionExpression;
  6590. exports.createIfStatement = createIfStatement;
  6591. exports.createInterpolation = createInterpolation;
  6592. exports.createObjectExpression = createObjectExpression;
  6593. exports.createObjectProperty = createObjectProperty;
  6594. exports.createReturnStatement = createReturnStatement;
  6595. exports.createRoot = createRoot;
  6596. exports.createSequenceExpression = createSequenceExpression;
  6597. exports.createSimpleExpression = createSimpleExpression;
  6598. exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
  6599. exports.createTemplateLiteral = createTemplateLiteral;
  6600. exports.createTransformContext = createTransformContext;
  6601. exports.createVNodeCall = createVNodeCall;
  6602. exports.errorMessages = errorMessages;
  6603. exports.extractIdentifiers = extractIdentifiers;
  6604. exports.findDir = findDir;
  6605. exports.findProp = findProp;
  6606. exports.forAliasRE = forAliasRE;
  6607. exports.generate = generate;
  6608. exports.getBaseTransformPreset = getBaseTransformPreset;
  6609. exports.getConstantType = getConstantType;
  6610. exports.getMemoedVNodeCall = getMemoedVNodeCall;
  6611. exports.getVNodeBlockHelper = getVNodeBlockHelper;
  6612. exports.getVNodeHelper = getVNodeHelper;
  6613. exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
  6614. exports.hasScopeRef = hasScopeRef;
  6615. exports.helperNameMap = helperNameMap;
  6616. exports.injectProp = injectProp;
  6617. exports.isCoreComponent = isCoreComponent;
  6618. exports.isFnExpression = isFnExpression;
  6619. exports.isFnExpressionBrowser = isFnExpressionBrowser;
  6620. exports.isFnExpressionNode = isFnExpressionNode;
  6621. exports.isFunctionType = isFunctionType;
  6622. exports.isInDestructureAssignment = isInDestructureAssignment;
  6623. exports.isInNewExpression = isInNewExpression;
  6624. exports.isMemberExpression = isMemberExpression;
  6625. exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
  6626. exports.isMemberExpressionNode = isMemberExpressionNode;
  6627. exports.isReferencedIdentifier = isReferencedIdentifier;
  6628. exports.isSimpleIdentifier = isSimpleIdentifier;
  6629. exports.isSlotOutlet = isSlotOutlet;
  6630. exports.isStaticArgOf = isStaticArgOf;
  6631. exports.isStaticExp = isStaticExp;
  6632. exports.isStaticProperty = isStaticProperty;
  6633. exports.isStaticPropertyKey = isStaticPropertyKey;
  6634. exports.isTemplateNode = isTemplateNode;
  6635. exports.isText = isText$1;
  6636. exports.isVSlot = isVSlot;
  6637. exports.locStub = locStub;
  6638. exports.noopDirectiveTransform = noopDirectiveTransform;
  6639. exports.processExpression = processExpression;
  6640. exports.processFor = processFor;
  6641. exports.processIf = processIf;
  6642. exports.processSlotOutlet = processSlotOutlet;
  6643. exports.registerRuntimeHelpers = registerRuntimeHelpers;
  6644. exports.resolveComponentType = resolveComponentType;
  6645. exports.stringifyExpression = stringifyExpression;
  6646. exports.toValidAssetId = toValidAssetId;
  6647. exports.trackSlotScopes = trackSlotScopes;
  6648. exports.trackVForSlotScopes = trackVForSlotScopes;
  6649. exports.transform = transform;
  6650. exports.transformBind = transformBind;
  6651. exports.transformElement = transformElement;
  6652. exports.transformExpression = transformExpression;
  6653. exports.transformModel = transformModel;
  6654. exports.transformOn = transformOn;
  6655. exports.traverseNode = traverseNode;
  6656. exports.unwrapTSNode = unwrapTSNode;
  6657. exports.walkBlockDeclarations = walkBlockDeclarations;
  6658. exports.walkFunctionParams = walkFunctionParams;
  6659. exports.walkIdentifiers = walkIdentifiers;
  6660. exports.warnDeprecation = warnDeprecation;