compiler-core.cjs.js 199 KB

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