compiler-core.cjs.js 196 KB

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