compiler-core.cjs.prod.js 192 KB

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