compiler-core.cjs.js 197 KB

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