123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675 |
- /**
- * @vue/compiler-core v3.5.12
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
- * @license MIT
- **/
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- var shared = require('@vue/shared');
- var decode_js = require('entities/lib/decode.js');
- var parser = require('@babel/parser');
- var estreeWalker = require('estree-walker');
- var sourceMapJs = require('source-map-js');
- const FRAGMENT = Symbol(``);
- const TELEPORT = Symbol(``);
- const SUSPENSE = Symbol(``);
- const KEEP_ALIVE = Symbol(``);
- const BASE_TRANSITION = Symbol(
- ``
- );
- const OPEN_BLOCK = Symbol(``);
- const CREATE_BLOCK = Symbol(``);
- const CREATE_ELEMENT_BLOCK = Symbol(
- ``
- );
- const CREATE_VNODE = Symbol(``);
- const CREATE_ELEMENT_VNODE = Symbol(
- ``
- );
- const CREATE_COMMENT = Symbol(
- ``
- );
- const CREATE_TEXT = Symbol(
- ``
- );
- const CREATE_STATIC = Symbol(
- ``
- );
- const RESOLVE_COMPONENT = Symbol(
- ``
- );
- const RESOLVE_DYNAMIC_COMPONENT = Symbol(
- ``
- );
- const RESOLVE_DIRECTIVE = Symbol(
- ``
- );
- const RESOLVE_FILTER = Symbol(
- ``
- );
- const WITH_DIRECTIVES = Symbol(
- ``
- );
- const RENDER_LIST = Symbol(``);
- const RENDER_SLOT = Symbol(``);
- const CREATE_SLOTS = Symbol(``);
- const TO_DISPLAY_STRING = Symbol(
- ``
- );
- const MERGE_PROPS = Symbol(``);
- const NORMALIZE_CLASS = Symbol(
- ``
- );
- const NORMALIZE_STYLE = Symbol(
- ``
- );
- const NORMALIZE_PROPS = Symbol(
- ``
- );
- const GUARD_REACTIVE_PROPS = Symbol(
- ``
- );
- const TO_HANDLERS = Symbol(``);
- const CAMELIZE = Symbol(``);
- const CAPITALIZE = Symbol(``);
- const TO_HANDLER_KEY = Symbol(
- ``
- );
- const SET_BLOCK_TRACKING = Symbol(
- ``
- );
- const PUSH_SCOPE_ID = Symbol(``);
- const POP_SCOPE_ID = Symbol(``);
- const WITH_CTX = Symbol(``);
- const UNREF = Symbol(``);
- const IS_REF = Symbol(``);
- const WITH_MEMO = Symbol(``);
- const IS_MEMO_SAME = Symbol(``);
- const helperNameMap = {
- [FRAGMENT]: `Fragment`,
- [TELEPORT]: `Teleport`,
- [SUSPENSE]: `Suspense`,
- [KEEP_ALIVE]: `KeepAlive`,
- [BASE_TRANSITION]: `BaseTransition`,
- [OPEN_BLOCK]: `openBlock`,
- [CREATE_BLOCK]: `createBlock`,
- [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
- [CREATE_VNODE]: `createVNode`,
- [CREATE_ELEMENT_VNODE]: `createElementVNode`,
- [CREATE_COMMENT]: `createCommentVNode`,
- [CREATE_TEXT]: `createTextVNode`,
- [CREATE_STATIC]: `createStaticVNode`,
- [RESOLVE_COMPONENT]: `resolveComponent`,
- [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
- [RESOLVE_DIRECTIVE]: `resolveDirective`,
- [RESOLVE_FILTER]: `resolveFilter`,
- [WITH_DIRECTIVES]: `withDirectives`,
- [RENDER_LIST]: `renderList`,
- [RENDER_SLOT]: `renderSlot`,
- [CREATE_SLOTS]: `createSlots`,
- [TO_DISPLAY_STRING]: `toDisplayString`,
- [MERGE_PROPS]: `mergeProps`,
- [NORMALIZE_CLASS]: `normalizeClass`,
- [NORMALIZE_STYLE]: `normalizeStyle`,
- [NORMALIZE_PROPS]: `normalizeProps`,
- [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
- [TO_HANDLERS]: `toHandlers`,
- [CAMELIZE]: `camelize`,
- [CAPITALIZE]: `capitalize`,
- [TO_HANDLER_KEY]: `toHandlerKey`,
- [SET_BLOCK_TRACKING]: `setBlockTracking`,
- [PUSH_SCOPE_ID]: `pushScopeId`,
- [POP_SCOPE_ID]: `popScopeId`,
- [WITH_CTX]: `withCtx`,
- [UNREF]: `unref`,
- [IS_REF]: `isRef`,
- [WITH_MEMO]: `withMemo`,
- [IS_MEMO_SAME]: `isMemoSame`
- };
- function registerRuntimeHelpers(helpers) {
- Object.getOwnPropertySymbols(helpers).forEach((s) => {
- helperNameMap[s] = helpers[s];
- });
- }
- const Namespaces = {
- "HTML": 0,
- "0": "HTML",
- "SVG": 1,
- "1": "SVG",
- "MATH_ML": 2,
- "2": "MATH_ML"
- };
- const NodeTypes = {
- "ROOT": 0,
- "0": "ROOT",
- "ELEMENT": 1,
- "1": "ELEMENT",
- "TEXT": 2,
- "2": "TEXT",
- "COMMENT": 3,
- "3": "COMMENT",
- "SIMPLE_EXPRESSION": 4,
- "4": "SIMPLE_EXPRESSION",
- "INTERPOLATION": 5,
- "5": "INTERPOLATION",
- "ATTRIBUTE": 6,
- "6": "ATTRIBUTE",
- "DIRECTIVE": 7,
- "7": "DIRECTIVE",
- "COMPOUND_EXPRESSION": 8,
- "8": "COMPOUND_EXPRESSION",
- "IF": 9,
- "9": "IF",
- "IF_BRANCH": 10,
- "10": "IF_BRANCH",
- "FOR": 11,
- "11": "FOR",
- "TEXT_CALL": 12,
- "12": "TEXT_CALL",
- "VNODE_CALL": 13,
- "13": "VNODE_CALL",
- "JS_CALL_EXPRESSION": 14,
- "14": "JS_CALL_EXPRESSION",
- "JS_OBJECT_EXPRESSION": 15,
- "15": "JS_OBJECT_EXPRESSION",
- "JS_PROPERTY": 16,
- "16": "JS_PROPERTY",
- "JS_ARRAY_EXPRESSION": 17,
- "17": "JS_ARRAY_EXPRESSION",
- "JS_FUNCTION_EXPRESSION": 18,
- "18": "JS_FUNCTION_EXPRESSION",
- "JS_CONDITIONAL_EXPRESSION": 19,
- "19": "JS_CONDITIONAL_EXPRESSION",
- "JS_CACHE_EXPRESSION": 20,
- "20": "JS_CACHE_EXPRESSION",
- "JS_BLOCK_STATEMENT": 21,
- "21": "JS_BLOCK_STATEMENT",
- "JS_TEMPLATE_LITERAL": 22,
- "22": "JS_TEMPLATE_LITERAL",
- "JS_IF_STATEMENT": 23,
- "23": "JS_IF_STATEMENT",
- "JS_ASSIGNMENT_EXPRESSION": 24,
- "24": "JS_ASSIGNMENT_EXPRESSION",
- "JS_SEQUENCE_EXPRESSION": 25,
- "25": "JS_SEQUENCE_EXPRESSION",
- "JS_RETURN_STATEMENT": 26,
- "26": "JS_RETURN_STATEMENT"
- };
- const ElementTypes = {
- "ELEMENT": 0,
- "0": "ELEMENT",
- "COMPONENT": 1,
- "1": "COMPONENT",
- "SLOT": 2,
- "2": "SLOT",
- "TEMPLATE": 3,
- "3": "TEMPLATE"
- };
- const ConstantTypes = {
- "NOT_CONSTANT": 0,
- "0": "NOT_CONSTANT",
- "CAN_SKIP_PATCH": 1,
- "1": "CAN_SKIP_PATCH",
- "CAN_CACHE": 2,
- "2": "CAN_CACHE",
- "CAN_STRINGIFY": 3,
- "3": "CAN_STRINGIFY"
- };
- const locStub = {
- start: { line: 1, column: 1, offset: 0 },
- end: { line: 1, column: 1, offset: 0 },
- source: ""
- };
- function createRoot(children, source = "") {
- return {
- type: 0,
- source,
- children,
- helpers: /* @__PURE__ */ new Set(),
- components: [],
- directives: [],
- hoists: [],
- imports: [],
- cached: [],
- temps: 0,
- codegenNode: void 0,
- loc: locStub
- };
- }
- function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
- if (context) {
- if (isBlock) {
- context.helper(OPEN_BLOCK);
- context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
- } else {
- context.helper(getVNodeHelper(context.inSSR, isComponent));
- }
- if (directives) {
- context.helper(WITH_DIRECTIVES);
- }
- }
- return {
- type: 13,
- tag,
- props,
- children,
- patchFlag,
- dynamicProps,
- directives,
- isBlock,
- disableTracking,
- isComponent,
- loc
- };
- }
- function createArrayExpression(elements, loc = locStub) {
- return {
- type: 17,
- loc,
- elements
- };
- }
- function createObjectExpression(properties, loc = locStub) {
- return {
- type: 15,
- loc,
- properties
- };
- }
- function createObjectProperty(key, value) {
- return {
- type: 16,
- loc: locStub,
- key: shared.isString(key) ? createSimpleExpression(key, true) : key,
- value
- };
- }
- function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
- return {
- type: 4,
- loc,
- content,
- isStatic,
- constType: isStatic ? 3 : constType
- };
- }
- function createInterpolation(content, loc) {
- return {
- type: 5,
- loc,
- content: shared.isString(content) ? createSimpleExpression(content, false, loc) : content
- };
- }
- function createCompoundExpression(children, loc = locStub) {
- return {
- type: 8,
- loc,
- children
- };
- }
- function createCallExpression(callee, args = [], loc = locStub) {
- return {
- type: 14,
- loc,
- callee,
- arguments: args
- };
- }
- function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
- return {
- type: 18,
- params,
- returns,
- newline,
- isSlot,
- loc
- };
- }
- function createConditionalExpression(test, consequent, alternate, newline = true) {
- return {
- type: 19,
- test,
- consequent,
- alternate,
- newline,
- loc: locStub
- };
- }
- function createCacheExpression(index, value, needPauseTracking = false) {
- return {
- type: 20,
- index,
- value,
- needPauseTracking,
- needArraySpread: false,
- loc: locStub
- };
- }
- function createBlockStatement(body) {
- return {
- type: 21,
- body,
- loc: locStub
- };
- }
- function createTemplateLiteral(elements) {
- return {
- type: 22,
- elements,
- loc: locStub
- };
- }
- function createIfStatement(test, consequent, alternate) {
- return {
- type: 23,
- test,
- consequent,
- alternate,
- loc: locStub
- };
- }
- function createAssignmentExpression(left, right) {
- return {
- type: 24,
- left,
- right,
- loc: locStub
- };
- }
- function createSequenceExpression(expressions) {
- return {
- type: 25,
- expressions,
- loc: locStub
- };
- }
- function createReturnStatement(returns) {
- return {
- type: 26,
- returns,
- loc: locStub
- };
- }
- function getVNodeHelper(ssr, isComponent) {
- return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
- }
- function getVNodeBlockHelper(ssr, isComponent) {
- return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
- }
- function convertToBlock(node, { helper, removeHelper, inSSR }) {
- if (!node.isBlock) {
- node.isBlock = true;
- removeHelper(getVNodeHelper(inSSR, node.isComponent));
- helper(OPEN_BLOCK);
- helper(getVNodeBlockHelper(inSSR, node.isComponent));
- }
- }
- const defaultDelimitersOpen = new Uint8Array([123, 123]);
- const defaultDelimitersClose = new Uint8Array([125, 125]);
- function isTagStartChar(c) {
- return c >= 97 && c <= 122 || c >= 65 && c <= 90;
- }
- function isWhitespace(c) {
- return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
- }
- function isEndOfTagSection(c) {
- return c === 47 || c === 62 || isWhitespace(c);
- }
- function toCharCodes(str) {
- const ret = new Uint8Array(str.length);
- for (let i = 0; i < str.length; i++) {
- ret[i] = str.charCodeAt(i);
- }
- return ret;
- }
- const Sequences = {
- Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
- // CDATA[
- CdataEnd: new Uint8Array([93, 93, 62]),
- // ]]>
- CommentEnd: new Uint8Array([45, 45, 62]),
- // `-->`
- ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
- // `<\/script`
- StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
- // `</style`
- TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
- // `</title`
- TextareaEnd: new Uint8Array([
- 60,
- 47,
- 116,
- 101,
- 120,
- 116,
- 97,
- 114,
- 101,
- 97
- ])
- // `</textarea
- };
- class Tokenizer {
- constructor(stack, cbs) {
- this.stack = stack;
- this.cbs = cbs;
- /** The current state the tokenizer is in. */
- this.state = 1;
- /** The read buffer. */
- this.buffer = "";
- /** The beginning of the section that is currently being read. */
- this.sectionStart = 0;
- /** The index within the buffer that we are currently looking at. */
- this.index = 0;
- /** The start of the last entity. */
- this.entityStart = 0;
- /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
- this.baseState = 1;
- /** For special parsing behavior inside of script and style tags. */
- this.inRCDATA = false;
- /** For disabling RCDATA tags handling */
- this.inXML = false;
- /** For disabling interpolation parsing in v-pre */
- this.inVPre = false;
- /** Record newline positions for fast line / column calculation */
- this.newlines = [];
- this.mode = 0;
- this.delimiterOpen = defaultDelimitersOpen;
- this.delimiterClose = defaultDelimitersClose;
- this.delimiterIndex = -1;
- this.currentSequence = void 0;
- this.sequenceIndex = 0;
- {
- this.entityDecoder = new decode_js.EntityDecoder(
- decode_js.htmlDecodeTree,
- (cp, consumed) => this.emitCodePoint(cp, consumed)
- );
- }
- }
- get inSFCRoot() {
- return this.mode === 2 && this.stack.length === 0;
- }
- reset() {
- this.state = 1;
- this.mode = 0;
- this.buffer = "";
- this.sectionStart = 0;
- this.index = 0;
- this.baseState = 1;
- this.inRCDATA = false;
- this.currentSequence = void 0;
- this.newlines.length = 0;
- this.delimiterOpen = defaultDelimitersOpen;
- this.delimiterClose = defaultDelimitersClose;
- }
- /**
- * Generate Position object with line / column information using recorded
- * newline positions. We know the index is always going to be an already
- * processed index, so all the newlines up to this index should have been
- * recorded.
- */
- getPos(index) {
- let line = 1;
- let column = index + 1;
- for (let i = this.newlines.length - 1; i >= 0; i--) {
- const newlineIndex = this.newlines[i];
- if (index > newlineIndex) {
- line = i + 2;
- column = index - newlineIndex;
- break;
- }
- }
- return {
- column,
- line,
- offset: index
- };
- }
- peek() {
- return this.buffer.charCodeAt(this.index + 1);
- }
- stateText(c) {
- if (c === 60) {
- if (this.index > this.sectionStart) {
- this.cbs.ontext(this.sectionStart, this.index);
- }
- this.state = 5;
- this.sectionStart = this.index;
- } else if (c === 38) {
- this.startEntity();
- } else if (!this.inVPre && c === this.delimiterOpen[0]) {
- this.state = 2;
- this.delimiterIndex = 0;
- this.stateInterpolationOpen(c);
- }
- }
- stateInterpolationOpen(c) {
- if (c === this.delimiterOpen[this.delimiterIndex]) {
- if (this.delimiterIndex === this.delimiterOpen.length - 1) {
- const start = this.index + 1 - this.delimiterOpen.length;
- if (start > this.sectionStart) {
- this.cbs.ontext(this.sectionStart, start);
- }
- this.state = 3;
- this.sectionStart = start;
- } else {
- this.delimiterIndex++;
- }
- } else if (this.inRCDATA) {
- this.state = 32;
- this.stateInRCDATA(c);
- } else {
- this.state = 1;
- this.stateText(c);
- }
- }
- stateInterpolation(c) {
- if (c === this.delimiterClose[0]) {
- this.state = 4;
- this.delimiterIndex = 0;
- this.stateInterpolationClose(c);
- }
- }
- stateInterpolationClose(c) {
- if (c === this.delimiterClose[this.delimiterIndex]) {
- if (this.delimiterIndex === this.delimiterClose.length - 1) {
- this.cbs.oninterpolation(this.sectionStart, this.index + 1);
- if (this.inRCDATA) {
- this.state = 32;
- } else {
- this.state = 1;
- }
- this.sectionStart = this.index + 1;
- } else {
- this.delimiterIndex++;
- }
- } else {
- this.state = 3;
- this.stateInterpolation(c);
- }
- }
- stateSpecialStartSequence(c) {
- const isEnd = this.sequenceIndex === this.currentSequence.length;
- const isMatch = isEnd ? (
- // If we are at the end of the sequence, make sure the tag name has ended
- isEndOfTagSection(c)
- ) : (
- // Otherwise, do a case-insensitive comparison
- (c | 32) === this.currentSequence[this.sequenceIndex]
- );
- if (!isMatch) {
- this.inRCDATA = false;
- } else if (!isEnd) {
- this.sequenceIndex++;
- return;
- }
- this.sequenceIndex = 0;
- this.state = 6;
- this.stateInTagName(c);
- }
- /** Look for an end tag. For <title> and <textarea>, also decode entities. */
- stateInRCDATA(c) {
- if (this.sequenceIndex === this.currentSequence.length) {
- if (c === 62 || isWhitespace(c)) {
- const endOfText = this.index - this.currentSequence.length;
- if (this.sectionStart < endOfText) {
- const actualIndex = this.index;
- this.index = endOfText;
- this.cbs.ontext(this.sectionStart, endOfText);
- this.index = actualIndex;
- }
- this.sectionStart = endOfText + 2;
- this.stateInClosingTagName(c);
- this.inRCDATA = false;
- return;
- }
- this.sequenceIndex = 0;
- }
- if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
- this.sequenceIndex += 1;
- } else if (this.sequenceIndex === 0) {
- if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
- if (c === 38) {
- this.startEntity();
- } else if (!this.inVPre && c === this.delimiterOpen[0]) {
- this.state = 2;
- this.delimiterIndex = 0;
- this.stateInterpolationOpen(c);
- }
- } else if (this.fastForwardTo(60)) {
- this.sequenceIndex = 1;
- }
- } else {
- this.sequenceIndex = Number(c === 60);
- }
- }
- stateCDATASequence(c) {
- if (c === Sequences.Cdata[this.sequenceIndex]) {
- if (++this.sequenceIndex === Sequences.Cdata.length) {
- this.state = 28;
- this.currentSequence = Sequences.CdataEnd;
- this.sequenceIndex = 0;
- this.sectionStart = this.index + 1;
- }
- } else {
- this.sequenceIndex = 0;
- this.state = 23;
- this.stateInDeclaration(c);
- }
- }
- /**
- * When we wait for one specific character, we can speed things up
- * by skipping through the buffer until we find it.
- *
- * @returns Whether the character was found.
- */
- fastForwardTo(c) {
- while (++this.index < this.buffer.length) {
- const cc = this.buffer.charCodeAt(this.index);
- if (cc === 10) {
- this.newlines.push(this.index);
- }
- if (cc === c) {
- return true;
- }
- }
- this.index = this.buffer.length - 1;
- return false;
- }
- /**
- * Comments and CDATA end with `-->` and `]]>`.
- *
- * Their common qualities are:
- * - Their end sequences have a distinct character they start with.
- * - That character is then repeated, so we have to check multiple repeats.
- * - All characters but the start character of the sequence can be skipped.
- */
- stateInCommentLike(c) {
- if (c === this.currentSequence[this.sequenceIndex]) {
- if (++this.sequenceIndex === this.currentSequence.length) {
- if (this.currentSequence === Sequences.CdataEnd) {
- this.cbs.oncdata(this.sectionStart, this.index - 2);
- } else {
- this.cbs.oncomment(this.sectionStart, this.index - 2);
- }
- this.sequenceIndex = 0;
- this.sectionStart = this.index + 1;
- this.state = 1;
- }
- } else if (this.sequenceIndex === 0) {
- if (this.fastForwardTo(this.currentSequence[0])) {
- this.sequenceIndex = 1;
- }
- } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
- this.sequenceIndex = 0;
- }
- }
- startSpecial(sequence, offset) {
- this.enterRCDATA(sequence, offset);
- this.state = 31;
- }
- enterRCDATA(sequence, offset) {
- this.inRCDATA = true;
- this.currentSequence = sequence;
- this.sequenceIndex = offset;
- }
- stateBeforeTagName(c) {
- if (c === 33) {
- this.state = 22;
- this.sectionStart = this.index + 1;
- } else if (c === 63) {
- this.state = 24;
- this.sectionStart = this.index + 1;
- } else if (isTagStartChar(c)) {
- this.sectionStart = this.index;
- if (this.mode === 0) {
- this.state = 6;
- } else if (this.inSFCRoot) {
- this.state = 34;
- } else if (!this.inXML) {
- if (c === 116) {
- this.state = 30;
- } else {
- this.state = c === 115 ? 29 : 6;
- }
- } else {
- this.state = 6;
- }
- } else if (c === 47) {
- this.state = 8;
- } else {
- this.state = 1;
- this.stateText(c);
- }
- }
- stateInTagName(c) {
- if (isEndOfTagSection(c)) {
- this.handleTagName(c);
- }
- }
- stateInSFCRootTagName(c) {
- if (isEndOfTagSection(c)) {
- const tag = this.buffer.slice(this.sectionStart, this.index);
- if (tag !== "template") {
- this.enterRCDATA(toCharCodes(`</` + tag), 0);
- }
- this.handleTagName(c);
- }
- }
- handleTagName(c) {
- this.cbs.onopentagname(this.sectionStart, this.index);
- this.sectionStart = -1;
- this.state = 11;
- this.stateBeforeAttrName(c);
- }
- stateBeforeClosingTagName(c) {
- if (isWhitespace(c)) ; else if (c === 62) {
- {
- this.cbs.onerr(14, this.index);
- }
- this.state = 1;
- this.sectionStart = this.index + 1;
- } else {
- this.state = isTagStartChar(c) ? 9 : 27;
- this.sectionStart = this.index;
- }
- }
- stateInClosingTagName(c) {
- if (c === 62 || isWhitespace(c)) {
- this.cbs.onclosetag(this.sectionStart, this.index);
- this.sectionStart = -1;
- this.state = 10;
- this.stateAfterClosingTagName(c);
- }
- }
- stateAfterClosingTagName(c) {
- if (c === 62) {
- this.state = 1;
- this.sectionStart = this.index + 1;
- }
- }
- stateBeforeAttrName(c) {
- if (c === 62) {
- this.cbs.onopentagend(this.index);
- if (this.inRCDATA) {
- this.state = 32;
- } else {
- this.state = 1;
- }
- this.sectionStart = this.index + 1;
- } else if (c === 47) {
- this.state = 7;
- if (this.peek() !== 62) {
- this.cbs.onerr(22, this.index);
- }
- } else if (c === 60 && this.peek() === 47) {
- this.cbs.onopentagend(this.index);
- this.state = 5;
- this.sectionStart = this.index;
- } else if (!isWhitespace(c)) {
- if (c === 61) {
- this.cbs.onerr(
- 19,
- this.index
- );
- }
- this.handleAttrStart(c);
- }
- }
- handleAttrStart(c) {
- if (c === 118 && this.peek() === 45) {
- this.state = 13;
- this.sectionStart = this.index;
- } else if (c === 46 || c === 58 || c === 64 || c === 35) {
- this.cbs.ondirname(this.index, this.index + 1);
- this.state = 14;
- this.sectionStart = this.index + 1;
- } else {
- this.state = 12;
- this.sectionStart = this.index;
- }
- }
- stateInSelfClosingTag(c) {
- if (c === 62) {
- this.cbs.onselfclosingtag(this.index);
- this.state = 1;
- this.sectionStart = this.index + 1;
- this.inRCDATA = false;
- } else if (!isWhitespace(c)) {
- this.state = 11;
- this.stateBeforeAttrName(c);
- }
- }
- stateInAttrName(c) {
- if (c === 61 || isEndOfTagSection(c)) {
- this.cbs.onattribname(this.sectionStart, this.index);
- this.handleAttrNameEnd(c);
- } else if (c === 34 || c === 39 || c === 60) {
- this.cbs.onerr(
- 17,
- this.index
- );
- }
- }
- stateInDirName(c) {
- if (c === 61 || isEndOfTagSection(c)) {
- this.cbs.ondirname(this.sectionStart, this.index);
- this.handleAttrNameEnd(c);
- } else if (c === 58) {
- this.cbs.ondirname(this.sectionStart, this.index);
- this.state = 14;
- this.sectionStart = this.index + 1;
- } else if (c === 46) {
- this.cbs.ondirname(this.sectionStart, this.index);
- this.state = 16;
- this.sectionStart = this.index + 1;
- }
- }
- stateInDirArg(c) {
- if (c === 61 || isEndOfTagSection(c)) {
- this.cbs.ondirarg(this.sectionStart, this.index);
- this.handleAttrNameEnd(c);
- } else if (c === 91) {
- this.state = 15;
- } else if (c === 46) {
- this.cbs.ondirarg(this.sectionStart, this.index);
- this.state = 16;
- this.sectionStart = this.index + 1;
- }
- }
- stateInDynamicDirArg(c) {
- if (c === 93) {
- this.state = 14;
- } else if (c === 61 || isEndOfTagSection(c)) {
- this.cbs.ondirarg(this.sectionStart, this.index + 1);
- this.handleAttrNameEnd(c);
- {
- this.cbs.onerr(
- 27,
- this.index
- );
- }
- }
- }
- stateInDirModifier(c) {
- if (c === 61 || isEndOfTagSection(c)) {
- this.cbs.ondirmodifier(this.sectionStart, this.index);
- this.handleAttrNameEnd(c);
- } else if (c === 46) {
- this.cbs.ondirmodifier(this.sectionStart, this.index);
- this.sectionStart = this.index + 1;
- }
- }
- handleAttrNameEnd(c) {
- this.sectionStart = this.index;
- this.state = 17;
- this.cbs.onattribnameend(this.index);
- this.stateAfterAttrName(c);
- }
- stateAfterAttrName(c) {
- if (c === 61) {
- this.state = 18;
- } else if (c === 47 || c === 62) {
- this.cbs.onattribend(0, this.sectionStart);
- this.sectionStart = -1;
- this.state = 11;
- this.stateBeforeAttrName(c);
- } else if (!isWhitespace(c)) {
- this.cbs.onattribend(0, this.sectionStart);
- this.handleAttrStart(c);
- }
- }
- stateBeforeAttrValue(c) {
- if (c === 34) {
- this.state = 19;
- this.sectionStart = this.index + 1;
- } else if (c === 39) {
- this.state = 20;
- this.sectionStart = this.index + 1;
- } else if (!isWhitespace(c)) {
- this.sectionStart = this.index;
- this.state = 21;
- this.stateInAttrValueNoQuotes(c);
- }
- }
- handleInAttrValue(c, quote) {
- if (c === quote || false) {
- this.cbs.onattribdata(this.sectionStart, this.index);
- this.sectionStart = -1;
- this.cbs.onattribend(
- quote === 34 ? 3 : 2,
- this.index + 1
- );
- this.state = 11;
- } else if (c === 38) {
- this.startEntity();
- }
- }
- stateInAttrValueDoubleQuotes(c) {
- this.handleInAttrValue(c, 34);
- }
- stateInAttrValueSingleQuotes(c) {
- this.handleInAttrValue(c, 39);
- }
- stateInAttrValueNoQuotes(c) {
- if (isWhitespace(c) || c === 62) {
- this.cbs.onattribdata(this.sectionStart, this.index);
- this.sectionStart = -1;
- this.cbs.onattribend(1, this.index);
- this.state = 11;
- this.stateBeforeAttrName(c);
- } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
- this.cbs.onerr(
- 18,
- this.index
- );
- } else if (c === 38) {
- this.startEntity();
- }
- }
- stateBeforeDeclaration(c) {
- if (c === 91) {
- this.state = 26;
- this.sequenceIndex = 0;
- } else {
- this.state = c === 45 ? 25 : 23;
- }
- }
- stateInDeclaration(c) {
- if (c === 62 || this.fastForwardTo(62)) {
- this.state = 1;
- this.sectionStart = this.index + 1;
- }
- }
- stateInProcessingInstruction(c) {
- if (c === 62 || this.fastForwardTo(62)) {
- this.cbs.onprocessinginstruction(this.sectionStart, this.index);
- this.state = 1;
- this.sectionStart = this.index + 1;
- }
- }
- stateBeforeComment(c) {
- if (c === 45) {
- this.state = 28;
- this.currentSequence = Sequences.CommentEnd;
- this.sequenceIndex = 2;
- this.sectionStart = this.index + 1;
- } else {
- this.state = 23;
- }
- }
- stateInSpecialComment(c) {
- if (c === 62 || this.fastForwardTo(62)) {
- this.cbs.oncomment(this.sectionStart, this.index);
- this.state = 1;
- this.sectionStart = this.index + 1;
- }
- }
- stateBeforeSpecialS(c) {
- if (c === Sequences.ScriptEnd[3]) {
- this.startSpecial(Sequences.ScriptEnd, 4);
- } else if (c === Sequences.StyleEnd[3]) {
- this.startSpecial(Sequences.StyleEnd, 4);
- } else {
- this.state = 6;
- this.stateInTagName(c);
- }
- }
- stateBeforeSpecialT(c) {
- if (c === Sequences.TitleEnd[3]) {
- this.startSpecial(Sequences.TitleEnd, 4);
- } else if (c === Sequences.TextareaEnd[3]) {
- this.startSpecial(Sequences.TextareaEnd, 4);
- } else {
- this.state = 6;
- this.stateInTagName(c);
- }
- }
- startEntity() {
- {
- this.baseState = this.state;
- this.state = 33;
- this.entityStart = this.index;
- this.entityDecoder.startEntity(
- this.baseState === 1 || this.baseState === 32 ? decode_js.DecodingMode.Legacy : decode_js.DecodingMode.Attribute
- );
- }
- }
- stateInEntity() {
- {
- const length = this.entityDecoder.write(this.buffer, this.index);
- if (length >= 0) {
- this.state = this.baseState;
- if (length === 0) {
- this.index = this.entityStart;
- }
- } else {
- this.index = this.buffer.length - 1;
- }
- }
- }
- /**
- * Iterates through the buffer, calling the function corresponding to the current state.
- *
- * States that are more likely to be hit are higher up, as a performance improvement.
- */
- parse(input) {
- this.buffer = input;
- while (this.index < this.buffer.length) {
- const c = this.buffer.charCodeAt(this.index);
- if (c === 10) {
- this.newlines.push(this.index);
- }
- switch (this.state) {
- case 1: {
- this.stateText(c);
- break;
- }
- case 2: {
- this.stateInterpolationOpen(c);
- break;
- }
- case 3: {
- this.stateInterpolation(c);
- break;
- }
- case 4: {
- this.stateInterpolationClose(c);
- break;
- }
- case 31: {
- this.stateSpecialStartSequence(c);
- break;
- }
- case 32: {
- this.stateInRCDATA(c);
- break;
- }
- case 26: {
- this.stateCDATASequence(c);
- break;
- }
- case 19: {
- this.stateInAttrValueDoubleQuotes(c);
- break;
- }
- case 12: {
- this.stateInAttrName(c);
- break;
- }
- case 13: {
- this.stateInDirName(c);
- break;
- }
- case 14: {
- this.stateInDirArg(c);
- break;
- }
- case 15: {
- this.stateInDynamicDirArg(c);
- break;
- }
- case 16: {
- this.stateInDirModifier(c);
- break;
- }
- case 28: {
- this.stateInCommentLike(c);
- break;
- }
- case 27: {
- this.stateInSpecialComment(c);
- break;
- }
- case 11: {
- this.stateBeforeAttrName(c);
- break;
- }
- case 6: {
- this.stateInTagName(c);
- break;
- }
- case 34: {
- this.stateInSFCRootTagName(c);
- break;
- }
- case 9: {
- this.stateInClosingTagName(c);
- break;
- }
- case 5: {
- this.stateBeforeTagName(c);
- break;
- }
- case 17: {
- this.stateAfterAttrName(c);
- break;
- }
- case 20: {
- this.stateInAttrValueSingleQuotes(c);
- break;
- }
- case 18: {
- this.stateBeforeAttrValue(c);
- break;
- }
- case 8: {
- this.stateBeforeClosingTagName(c);
- break;
- }
- case 10: {
- this.stateAfterClosingTagName(c);
- break;
- }
- case 29: {
- this.stateBeforeSpecialS(c);
- break;
- }
- case 30: {
- this.stateBeforeSpecialT(c);
- break;
- }
- case 21: {
- this.stateInAttrValueNoQuotes(c);
- break;
- }
- case 7: {
- this.stateInSelfClosingTag(c);
- break;
- }
- case 23: {
- this.stateInDeclaration(c);
- break;
- }
- case 22: {
- this.stateBeforeDeclaration(c);
- break;
- }
- case 25: {
- this.stateBeforeComment(c);
- break;
- }
- case 24: {
- this.stateInProcessingInstruction(c);
- break;
- }
- case 33: {
- this.stateInEntity();
- break;
- }
- }
- this.index++;
- }
- this.cleanup();
- this.finish();
- }
- /**
- * Remove data that has already been consumed from the buffer.
- */
- cleanup() {
- if (this.sectionStart !== this.index) {
- if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
- this.cbs.ontext(this.sectionStart, this.index);
- this.sectionStart = this.index;
- } else if (this.state === 19 || this.state === 20 || this.state === 21) {
- this.cbs.onattribdata(this.sectionStart, this.index);
- this.sectionStart = this.index;
- }
- }
- }
- finish() {
- if (this.state === 33) {
- this.entityDecoder.end();
- this.state = this.baseState;
- }
- this.handleTrailingData();
- this.cbs.onend();
- }
- /** Handle any trailing data. */
- handleTrailingData() {
- const endIndex = this.buffer.length;
- if (this.sectionStart >= endIndex) {
- return;
- }
- if (this.state === 28) {
- if (this.currentSequence === Sequences.CdataEnd) {
- this.cbs.oncdata(this.sectionStart, endIndex);
- } else {
- this.cbs.oncomment(this.sectionStart, endIndex);
- }
- } 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 {
- this.cbs.ontext(this.sectionStart, endIndex);
- }
- }
- emitCodePoint(cp, consumed) {
- {
- if (this.baseState !== 1 && this.baseState !== 32) {
- if (this.sectionStart < this.entityStart) {
- this.cbs.onattribdata(this.sectionStart, this.entityStart);
- }
- this.sectionStart = this.entityStart + consumed;
- this.index = this.sectionStart - 1;
- this.cbs.onattribentity(
- decode_js.fromCodePoint(cp),
- this.entityStart,
- this.sectionStart
- );
- } else {
- if (this.sectionStart < this.entityStart) {
- this.cbs.ontext(this.sectionStart, this.entityStart);
- }
- this.sectionStart = this.entityStart + consumed;
- this.index = this.sectionStart - 1;
- this.cbs.ontextentity(
- decode_js.fromCodePoint(cp),
- this.entityStart,
- this.sectionStart
- );
- }
- }
- }
- }
- const CompilerDeprecationTypes = {
- "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
- "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
- "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
- "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
- "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
- "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
- "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
- "COMPILER_FILTERS": "COMPILER_FILTERS"
- };
- const deprecationData = {
- ["COMPILER_IS_ON_ELEMENT"]: {
- 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:".`,
- link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
- },
- ["COMPILER_V_BIND_SYNC"]: {
- 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}\`.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
- },
- ["COMPILER_V_BIND_OBJECT_ORDER"]: {
- 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.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
- },
- ["COMPILER_V_ON_NATIVE"]: {
- message: `.native modifier for v-on has been removed as is no longer necessary.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
- },
- ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
- 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.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
- },
- ["COMPILER_NATIVE_TEMPLATE"]: {
- message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
- },
- ["COMPILER_INLINE_TEMPLATE"]: {
- message: `"inline-template" has been removed in Vue 3.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
- },
- ["COMPILER_FILTERS"]: {
- 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.`,
- link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
- }
- };
- function getCompatValue(key, { compatConfig }) {
- const value = compatConfig && compatConfig[key];
- if (key === "MODE") {
- return value || 3;
- } else {
- return value;
- }
- }
- function isCompatEnabled(key, context) {
- const mode = getCompatValue("MODE", context);
- const value = getCompatValue(key, context);
- return mode === 3 ? value === true : value !== false;
- }
- function checkCompatEnabled(key, context, loc, ...args) {
- const enabled = isCompatEnabled(key, context);
- return enabled;
- }
- function warnDeprecation(key, context, loc, ...args) {
- const val = getCompatValue(key, context);
- if (val === "suppress-warning") {
- return;
- }
- const { message, link } = deprecationData[key];
- const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
- Details: ${link}` : ``}`;
- const err = new SyntaxError(msg);
- err.code = key;
- if (loc) err.loc = loc;
- context.onWarn(err);
- }
- function defaultOnError(error) {
- throw error;
- }
- function defaultOnWarn(msg) {
- }
- function createCompilerError(code, loc, messages, additionalMessage) {
- const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
- const error = new SyntaxError(String(msg));
- error.code = code;
- error.loc = loc;
- return error;
- }
- const ErrorCodes = {
- "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
- "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
- "CDATA_IN_HTML_CONTENT": 1,
- "1": "CDATA_IN_HTML_CONTENT",
- "DUPLICATE_ATTRIBUTE": 2,
- "2": "DUPLICATE_ATTRIBUTE",
- "END_TAG_WITH_ATTRIBUTES": 3,
- "3": "END_TAG_WITH_ATTRIBUTES",
- "END_TAG_WITH_TRAILING_SOLIDUS": 4,
- "4": "END_TAG_WITH_TRAILING_SOLIDUS",
- "EOF_BEFORE_TAG_NAME": 5,
- "5": "EOF_BEFORE_TAG_NAME",
- "EOF_IN_CDATA": 6,
- "6": "EOF_IN_CDATA",
- "EOF_IN_COMMENT": 7,
- "7": "EOF_IN_COMMENT",
- "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
- "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
- "EOF_IN_TAG": 9,
- "9": "EOF_IN_TAG",
- "INCORRECTLY_CLOSED_COMMENT": 10,
- "10": "INCORRECTLY_CLOSED_COMMENT",
- "INCORRECTLY_OPENED_COMMENT": 11,
- "11": "INCORRECTLY_OPENED_COMMENT",
- "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
- "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
- "MISSING_ATTRIBUTE_VALUE": 13,
- "13": "MISSING_ATTRIBUTE_VALUE",
- "MISSING_END_TAG_NAME": 14,
- "14": "MISSING_END_TAG_NAME",
- "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
- "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
- "NESTED_COMMENT": 16,
- "16": "NESTED_COMMENT",
- "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
- "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
- "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
- "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
- "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
- "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
- "UNEXPECTED_NULL_CHARACTER": 20,
- "20": "UNEXPECTED_NULL_CHARACTER",
- "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
- "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
- "UNEXPECTED_SOLIDUS_IN_TAG": 22,
- "22": "UNEXPECTED_SOLIDUS_IN_TAG",
- "X_INVALID_END_TAG": 23,
- "23": "X_INVALID_END_TAG",
- "X_MISSING_END_TAG": 24,
- "24": "X_MISSING_END_TAG",
- "X_MISSING_INTERPOLATION_END": 25,
- "25": "X_MISSING_INTERPOLATION_END",
- "X_MISSING_DIRECTIVE_NAME": 26,
- "26": "X_MISSING_DIRECTIVE_NAME",
- "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
- "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
- "X_V_IF_NO_EXPRESSION": 28,
- "28": "X_V_IF_NO_EXPRESSION",
- "X_V_IF_SAME_KEY": 29,
- "29": "X_V_IF_SAME_KEY",
- "X_V_ELSE_NO_ADJACENT_IF": 30,
- "30": "X_V_ELSE_NO_ADJACENT_IF",
- "X_V_FOR_NO_EXPRESSION": 31,
- "31": "X_V_FOR_NO_EXPRESSION",
- "X_V_FOR_MALFORMED_EXPRESSION": 32,
- "32": "X_V_FOR_MALFORMED_EXPRESSION",
- "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
- "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
- "X_V_BIND_NO_EXPRESSION": 34,
- "34": "X_V_BIND_NO_EXPRESSION",
- "X_V_ON_NO_EXPRESSION": 35,
- "35": "X_V_ON_NO_EXPRESSION",
- "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
- "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
- "X_V_SLOT_MIXED_SLOT_USAGE": 37,
- "37": "X_V_SLOT_MIXED_SLOT_USAGE",
- "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
- "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
- "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
- "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
- "X_V_SLOT_MISPLACED": 40,
- "40": "X_V_SLOT_MISPLACED",
- "X_V_MODEL_NO_EXPRESSION": 41,
- "41": "X_V_MODEL_NO_EXPRESSION",
- "X_V_MODEL_MALFORMED_EXPRESSION": 42,
- "42": "X_V_MODEL_MALFORMED_EXPRESSION",
- "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
- "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
- "X_V_MODEL_ON_PROPS": 44,
- "44": "X_V_MODEL_ON_PROPS",
- "X_INVALID_EXPRESSION": 45,
- "45": "X_INVALID_EXPRESSION",
- "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
- "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
- "X_PREFIX_ID_NOT_SUPPORTED": 47,
- "47": "X_PREFIX_ID_NOT_SUPPORTED",
- "X_MODULE_MODE_NOT_SUPPORTED": 48,
- "48": "X_MODULE_MODE_NOT_SUPPORTED",
- "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
- "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
- "X_SCOPE_ID_NOT_SUPPORTED": 50,
- "50": "X_SCOPE_ID_NOT_SUPPORTED",
- "X_VNODE_HOOKS": 51,
- "51": "X_VNODE_HOOKS",
- "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
- "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
- "__EXTEND_POINT__": 53,
- "53": "__EXTEND_POINT__"
- };
- const errorMessages = {
- // parse errors
- [0]: "Illegal comment.",
- [1]: "CDATA section is allowed only in XML context.",
- [2]: "Duplicate attribute.",
- [3]: "End tag cannot have attributes.",
- [4]: "Illegal '/' in tags.",
- [5]: "Unexpected EOF in tag.",
- [6]: "Unexpected EOF in CDATA section.",
- [7]: "Unexpected EOF in comment.",
- [8]: "Unexpected EOF in script.",
- [9]: "Unexpected EOF in tag.",
- [10]: "Incorrectly closed comment.",
- [11]: "Incorrectly opened comment.",
- [12]: "Illegal tag name. Use '<' to print '<'.",
- [13]: "Attribute value was expected.",
- [14]: "End tag name was expected.",
- [15]: "Whitespace was expected.",
- [16]: "Unexpected '<!--' in comment.",
- [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
- [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
- [19]: "Attribute name cannot start with '='.",
- [21]: "'<?' is allowed only in XML context.",
- [20]: `Unexpected null character.`,
- [22]: "Illegal '/' in tags.",
- // Vue-specific parse errors
- [23]: "Invalid end tag.",
- [24]: "Element is missing end tag.",
- [25]: "Interpolation end sign was not found.",
- [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
- [26]: "Legal directive name was expected.",
- // transform errors
- [28]: `v-if/v-else-if is missing expression.`,
- [29]: `v-if/else branches must use unique keys.`,
- [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
- [31]: `v-for is missing expression.`,
- [32]: `v-for has invalid expression.`,
- [33]: `<template v-for> key should be placed on the <template> tag.`,
- [34]: `v-bind is missing expression.`,
- [52]: `v-bind with same-name shorthand only allows static argument.`,
- [35]: `v-on is missing expression.`,
- [36]: `Unexpected custom directive on <slot> outlet.`,
- [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.`,
- [38]: `Duplicate slot names found. `,
- [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
- [40]: `v-slot can only be used on components or <template> tags.`,
- [41]: `v-model is missing expression.`,
- [42]: `v-model value must be a valid JavaScript member expression.`,
- [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
- [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
- Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
- [45]: `Error parsing JavaScript expression: `,
- [46]: `<KeepAlive> expects exactly one child component.`,
- [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.`,
- // generic errors
- [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
- [48]: `ES module mode is not supported in this build of compiler.`,
- [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
- [50]: `"scopeId" option is only supported in module mode.`,
- // just to fulfill types
- [53]: ``
- };
- function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
- const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
- estreeWalker.walk(root, {
- enter(node, parent) {
- parent && parentStack.push(parent);
- if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
- return this.skip();
- }
- if (node.type === "Identifier") {
- const isLocal = !!knownIds[node.name];
- const isRefed = isReferencedIdentifier(node, parent, parentStack);
- if (includeAll || isRefed && !isLocal) {
- onIdentifier(node, parent, parentStack, isRefed, isLocal);
- }
- } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
- (parent == null ? void 0 : parent.type) === "ObjectPattern") {
- node.inPattern = true;
- } else if (isFunctionType(node)) {
- if (node.scopeIds) {
- node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
- } else {
- walkFunctionParams(
- node,
- (id) => markScopeIdentifier(node, id, knownIds)
- );
- }
- } else if (node.type === "BlockStatement") {
- if (node.scopeIds) {
- node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
- } else {
- walkBlockDeclarations(
- node,
- (id) => markScopeIdentifier(node, id, knownIds)
- );
- }
- } else if (node.type === "CatchClause" && node.param) {
- for (const id of extractIdentifiers(node.param)) {
- markScopeIdentifier(node, id, knownIds);
- }
- } else if (isForStatement(node)) {
- walkForStatement(
- node,
- false,
- (id) => markScopeIdentifier(node, id, knownIds)
- );
- }
- },
- leave(node, parent) {
- parent && parentStack.pop();
- if (node !== rootExp && node.scopeIds) {
- for (const id of node.scopeIds) {
- knownIds[id]--;
- if (knownIds[id] === 0) {
- delete knownIds[id];
- }
- }
- }
- }
- });
- }
- function isReferencedIdentifier(id, parent, parentStack) {
- if (!parent) {
- return true;
- }
- if (id.name === "arguments") {
- return false;
- }
- if (isReferenced(id, parent)) {
- return true;
- }
- switch (parent.type) {
- case "AssignmentExpression":
- case "AssignmentPattern":
- return true;
- case "ObjectPattern":
- case "ArrayPattern":
- return isInDestructureAssignment(parent, parentStack);
- }
- return false;
- }
- function isInDestructureAssignment(parent, parentStack) {
- if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
- let i = parentStack.length;
- while (i--) {
- const p = parentStack[i];
- if (p.type === "AssignmentExpression") {
- return true;
- } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
- break;
- }
- }
- }
- return false;
- }
- function isInNewExpression(parentStack) {
- let i = parentStack.length;
- while (i--) {
- const p = parentStack[i];
- if (p.type === "NewExpression") {
- return true;
- } else if (p.type !== "MemberExpression") {
- break;
- }
- }
- return false;
- }
- function walkFunctionParams(node, onIdent) {
- for (const p of node.params) {
- for (const id of extractIdentifiers(p)) {
- onIdent(id);
- }
- }
- }
- function walkBlockDeclarations(block, onIdent) {
- for (const stmt of block.body) {
- if (stmt.type === "VariableDeclaration") {
- if (stmt.declare) continue;
- for (const decl of stmt.declarations) {
- for (const id of extractIdentifiers(decl.id)) {
- onIdent(id);
- }
- }
- } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
- if (stmt.declare || !stmt.id) continue;
- onIdent(stmt.id);
- } else if (isForStatement(stmt)) {
- walkForStatement(stmt, true, onIdent);
- }
- }
- }
- function isForStatement(stmt) {
- return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
- }
- function walkForStatement(stmt, isVar, onIdent) {
- const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
- if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
- for (const decl of variable.declarations) {
- for (const id of extractIdentifiers(decl.id)) {
- onIdent(id);
- }
- }
- }
- }
- function extractIdentifiers(param, nodes = []) {
- switch (param.type) {
- case "Identifier":
- nodes.push(param);
- break;
- case "MemberExpression":
- let object = param;
- while (object.type === "MemberExpression") {
- object = object.object;
- }
- nodes.push(object);
- break;
- case "ObjectPattern":
- for (const prop of param.properties) {
- if (prop.type === "RestElement") {
- extractIdentifiers(prop.argument, nodes);
- } else {
- extractIdentifiers(prop.value, nodes);
- }
- }
- break;
- case "ArrayPattern":
- param.elements.forEach((element) => {
- if (element) extractIdentifiers(element, nodes);
- });
- break;
- case "RestElement":
- extractIdentifiers(param.argument, nodes);
- break;
- case "AssignmentPattern":
- extractIdentifiers(param.left, nodes);
- break;
- }
- return nodes;
- }
- function markKnownIds(name, knownIds) {
- if (name in knownIds) {
- knownIds[name]++;
- } else {
- knownIds[name] = 1;
- }
- }
- function markScopeIdentifier(node, child, knownIds) {
- const { name } = child;
- if (node.scopeIds && node.scopeIds.has(name)) {
- return;
- }
- markKnownIds(name, knownIds);
- (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
- }
- const isFunctionType = (node) => {
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
- };
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
- const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
- function isReferenced(node, parent, grandparent) {
- switch (parent.type) {
- // yes: PARENT[NODE]
- // yes: NODE.child
- // no: parent.NODE
- case "MemberExpression":
- case "OptionalMemberExpression":
- if (parent.property === node) {
- return !!parent.computed;
- }
- return parent.object === node;
- case "JSXMemberExpression":
- return parent.object === node;
- // no: let NODE = init;
- // yes: let id = NODE;
- case "VariableDeclarator":
- return parent.init === node;
- // yes: () => NODE
- // no: (NODE) => {}
- case "ArrowFunctionExpression":
- return parent.body === node;
- // no: class { #NODE; }
- // no: class { get #NODE() {} }
- // no: class { #NODE() {} }
- // no: class { fn() { return this.#NODE; } }
- case "PrivateName":
- return false;
- // no: class { NODE() {} }
- // yes: class { [NODE]() {} }
- // no: class { foo(NODE) {} }
- case "ClassMethod":
- case "ClassPrivateMethod":
- case "ObjectMethod":
- if (parent.key === node) {
- return !!parent.computed;
- }
- return false;
- // yes: { [NODE]: "" }
- // no: { NODE: "" }
- // depends: { NODE }
- // depends: { key: NODE }
- case "ObjectProperty":
- if (parent.key === node) {
- return !!parent.computed;
- }
- return !grandparent;
- // no: class { NODE = value; }
- // yes: class { [NODE] = value; }
- // yes: class { key = NODE; }
- case "ClassProperty":
- if (parent.key === node) {
- return !!parent.computed;
- }
- return true;
- case "ClassPrivateProperty":
- return parent.key !== node;
- // no: class NODE {}
- // yes: class Foo extends NODE {}
- case "ClassDeclaration":
- case "ClassExpression":
- return parent.superClass === node;
- // yes: left = NODE;
- // no: NODE = right;
- case "AssignmentExpression":
- return parent.right === node;
- // no: [NODE = foo] = [];
- // yes: [foo = NODE] = [];
- case "AssignmentPattern":
- return parent.right === node;
- // no: NODE: for (;;) {}
- case "LabeledStatement":
- return false;
- // no: try {} catch (NODE) {}
- case "CatchClause":
- return false;
- // no: function foo(...NODE) {}
- case "RestElement":
- return false;
- case "BreakStatement":
- case "ContinueStatement":
- return false;
- // no: function NODE() {}
- // no: function foo(NODE) {}
- case "FunctionDeclaration":
- case "FunctionExpression":
- return false;
- // no: export NODE from "foo";
- // no: export * as NODE from "foo";
- case "ExportNamespaceSpecifier":
- case "ExportDefaultSpecifier":
- return false;
- // no: export { foo as NODE };
- // yes: export { NODE as foo };
- // no: export { NODE as foo } from "foo";
- case "ExportSpecifier":
- return parent.local === node;
- // no: import NODE from "foo";
- // no: import * as NODE from "foo";
- // no: import { NODE as foo } from "foo";
- // no: import { foo as NODE } from "foo";
- // no: import NODE from "bar";
- case "ImportDefaultSpecifier":
- case "ImportNamespaceSpecifier":
- case "ImportSpecifier":
- return false;
- // no: import "foo" assert { NODE: "json" }
- case "ImportAttribute":
- return false;
- // no: <div NODE="foo" />
- case "JSXAttribute":
- return false;
- // no: [NODE] = [];
- // no: ({ NODE }) = [];
- case "ObjectPattern":
- case "ArrayPattern":
- return false;
- // no: new.NODE
- // no: NODE.target
- case "MetaProperty":
- return false;
- // yes: type X = { someProperty: NODE }
- // no: type X = { NODE: OtherType }
- case "ObjectTypeProperty":
- return parent.key !== node;
- // yes: enum X { Foo = NODE }
- // no: enum X { NODE }
- case "TSEnumMember":
- return parent.id !== node;
- // yes: { [NODE]: value }
- // no: { NODE: value }
- case "TSPropertySignature":
- if (parent.key === node) {
- return !!parent.computed;
- }
- return true;
- }
- return true;
- }
- const TS_NODE_TYPES = [
- "TSAsExpression",
- // foo as number
- "TSTypeAssertion",
- // (<number>foo)
- "TSNonNullExpression",
- // foo!
- "TSInstantiationExpression",
- // foo<string>
- "TSSatisfiesExpression"
- // foo satisfies T
- ];
- function unwrapTSNode(node) {
- if (TS_NODE_TYPES.includes(node.type)) {
- return unwrapTSNode(node.expression);
- } else {
- return node;
- }
- }
- const isStaticExp = (p) => p.type === 4 && p.isStatic;
- function isCoreComponent(tag) {
- switch (tag) {
- case "Teleport":
- case "teleport":
- return TELEPORT;
- case "Suspense":
- case "suspense":
- return SUSPENSE;
- case "KeepAlive":
- case "keep-alive":
- return KEEP_ALIVE;
- case "BaseTransition":
- case "base-transition":
- return BASE_TRANSITION;
- }
- }
- const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
- const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
- const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
- const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
- const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
- const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
- const isMemberExpressionBrowser = (exp) => {
- const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
- let state = 0 /* inMemberExp */;
- let stateStack = [];
- let currentOpenBracketCount = 0;
- let currentOpenParensCount = 0;
- let currentStringType = null;
- for (let i = 0; i < path.length; i++) {
- const char = path.charAt(i);
- switch (state) {
- case 0 /* inMemberExp */:
- if (char === "[") {
- stateStack.push(state);
- state = 1 /* inBrackets */;
- currentOpenBracketCount++;
- } else if (char === "(") {
- stateStack.push(state);
- state = 2 /* inParens */;
- currentOpenParensCount++;
- } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
- return false;
- }
- break;
- case 1 /* inBrackets */:
- if (char === `'` || char === `"` || char === "`") {
- stateStack.push(state);
- state = 3 /* inString */;
- currentStringType = char;
- } else if (char === `[`) {
- currentOpenBracketCount++;
- } else if (char === `]`) {
- if (!--currentOpenBracketCount) {
- state = stateStack.pop();
- }
- }
- break;
- case 2 /* inParens */:
- if (char === `'` || char === `"` || char === "`") {
- stateStack.push(state);
- state = 3 /* inString */;
- currentStringType = char;
- } else if (char === `(`) {
- currentOpenParensCount++;
- } else if (char === `)`) {
- if (i === path.length - 1) {
- return false;
- }
- if (!--currentOpenParensCount) {
- state = stateStack.pop();
- }
- }
- break;
- case 3 /* inString */:
- if (char === currentStringType) {
- state = stateStack.pop();
- currentStringType = null;
- }
- break;
- }
- }
- return !currentOpenBracketCount && !currentOpenParensCount;
- };
- const isMemberExpressionNode = (exp, context) => {
- try {
- let ret = exp.ast || parser.parseExpression(getExpSource(exp), {
- plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
- });
- ret = unwrapTSNode(ret);
- return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
- } catch (e) {
- return false;
- }
- };
- const isMemberExpression = isMemberExpressionNode;
- const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
- const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
- const isFnExpressionNode = (exp, context) => {
- try {
- let ret = exp.ast || parser.parseExpression(getExpSource(exp), {
- plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
- });
- if (ret.type === "Program") {
- ret = ret.body[0];
- if (ret.type === "ExpressionStatement") {
- ret = ret.expression;
- }
- }
- ret = unwrapTSNode(ret);
- return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
- } catch (e) {
- return false;
- }
- };
- const isFnExpression = isFnExpressionNode;
- function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
- return advancePositionWithMutation(
- {
- offset: pos.offset,
- line: pos.line,
- column: pos.column
- },
- source,
- numberOfCharacters
- );
- }
- function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
- let linesCount = 0;
- let lastNewLinePos = -1;
- for (let i = 0; i < numberOfCharacters; i++) {
- if (source.charCodeAt(i) === 10) {
- linesCount++;
- lastNewLinePos = i;
- }
- }
- pos.offset += numberOfCharacters;
- pos.line += linesCount;
- pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
- return pos;
- }
- function assert(condition, msg) {
- if (!condition) {
- throw new Error(msg || `unexpected compiler condition`);
- }
- }
- function findDir(node, name, allowEmpty = false) {
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 7 && (allowEmpty || p.exp) && (shared.isString(name) ? p.name === name : name.test(p.name))) {
- return p;
- }
- }
- }
- function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 6) {
- if (dynamicOnly) continue;
- if (p.name === name && (p.value || allowEmpty)) {
- return p;
- }
- } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
- return p;
- }
- }
- }
- function isStaticArgOf(arg, name) {
- return !!(arg && isStaticExp(arg) && arg.content === name);
- }
- function hasDynamicKeyVBind(node) {
- return node.props.some(
- (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
- p.arg.type !== 4 || // v-bind:[_ctx.foo]
- !p.arg.isStatic)
- // v-bind:[foo]
- );
- }
- function isText$1(node) {
- return node.type === 5 || node.type === 2;
- }
- function isVSlot(p) {
- return p.type === 7 && p.name === "slot";
- }
- function isTemplateNode(node) {
- return node.type === 1 && node.tagType === 3;
- }
- function isSlotOutlet(node) {
- return node.type === 1 && node.tagType === 2;
- }
- const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
- function getUnnormalizedProps(props, callPath = []) {
- if (props && !shared.isString(props) && props.type === 14) {
- const callee = props.callee;
- if (!shared.isString(callee) && propsHelperSet.has(callee)) {
- return getUnnormalizedProps(
- props.arguments[0],
- callPath.concat(props)
- );
- }
- }
- return [props, callPath];
- }
- function injectProp(node, prop, context) {
- let propsWithInjection;
- let props = node.type === 13 ? node.props : node.arguments[2];
- let callPath = [];
- let parentCall;
- if (props && !shared.isString(props) && props.type === 14) {
- const ret = getUnnormalizedProps(props);
- props = ret[0];
- callPath = ret[1];
- parentCall = callPath[callPath.length - 1];
- }
- if (props == null || shared.isString(props)) {
- propsWithInjection = createObjectExpression([prop]);
- } else if (props.type === 14) {
- const first = props.arguments[0];
- if (!shared.isString(first) && first.type === 15) {
- if (!hasProp(prop, first)) {
- first.properties.unshift(prop);
- }
- } else {
- if (props.callee === TO_HANDLERS) {
- propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
- createObjectExpression([prop]),
- props
- ]);
- } else {
- props.arguments.unshift(createObjectExpression([prop]));
- }
- }
- !propsWithInjection && (propsWithInjection = props);
- } else if (props.type === 15) {
- if (!hasProp(prop, props)) {
- props.properties.unshift(prop);
- }
- propsWithInjection = props;
- } else {
- propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
- createObjectExpression([prop]),
- props
- ]);
- if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
- parentCall = callPath[callPath.length - 2];
- }
- }
- if (node.type === 13) {
- if (parentCall) {
- parentCall.arguments[0] = propsWithInjection;
- } else {
- node.props = propsWithInjection;
- }
- } else {
- if (parentCall) {
- parentCall.arguments[0] = propsWithInjection;
- } else {
- node.arguments[2] = propsWithInjection;
- }
- }
- }
- function hasProp(prop, props) {
- let result = false;
- if (prop.key.type === 4) {
- const propKeyName = prop.key.content;
- result = props.properties.some(
- (p) => p.key.type === 4 && p.key.content === propKeyName
- );
- }
- return result;
- }
- function toValidAssetId(name, type) {
- return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
- return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
- })}`;
- }
- function hasScopeRef(node, ids) {
- if (!node || Object.keys(ids).length === 0) {
- return false;
- }
- switch (node.type) {
- case 1:
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
- return true;
- }
- }
- return node.children.some((c) => hasScopeRef(c, ids));
- case 11:
- if (hasScopeRef(node.source, ids)) {
- return true;
- }
- return node.children.some((c) => hasScopeRef(c, ids));
- case 9:
- return node.branches.some((b) => hasScopeRef(b, ids));
- case 10:
- if (hasScopeRef(node.condition, ids)) {
- return true;
- }
- return node.children.some((c) => hasScopeRef(c, ids));
- case 4:
- return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
- case 8:
- return node.children.some((c) => shared.isObject(c) && hasScopeRef(c, ids));
- case 5:
- case 12:
- return hasScopeRef(node.content, ids);
- case 2:
- case 3:
- case 20:
- return false;
- default:
- return false;
- }
- }
- function getMemoedVNodeCall(node) {
- if (node.type === 14 && node.callee === WITH_MEMO) {
- return node.arguments[1].returns;
- } else {
- return node;
- }
- }
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
- const defaultParserOptions = {
- parseMode: "base",
- ns: 0,
- delimiters: [`{{`, `}}`],
- getNamespace: () => 0,
- isVoidTag: shared.NO,
- isPreTag: shared.NO,
- isIgnoreNewlineTag: shared.NO,
- isCustomElement: shared.NO,
- onError: defaultOnError,
- onWarn: defaultOnWarn,
- comments: false,
- prefixIdentifiers: false
- };
- let currentOptions = defaultParserOptions;
- let currentRoot = null;
- let currentInput = "";
- let currentOpenTag = null;
- let currentProp = null;
- let currentAttrValue = "";
- let currentAttrStartIndex = -1;
- let currentAttrEndIndex = -1;
- let inPre = 0;
- let inVPre = false;
- let currentVPreBoundary = null;
- const stack = [];
- const tokenizer = new Tokenizer(stack, {
- onerr: emitError,
- ontext(start, end) {
- onText(getSlice(start, end), start, end);
- },
- ontextentity(char, start, end) {
- onText(char, start, end);
- },
- oninterpolation(start, end) {
- if (inVPre) {
- return onText(getSlice(start, end), start, end);
- }
- let innerStart = start + tokenizer.delimiterOpen.length;
- let innerEnd = end - tokenizer.delimiterClose.length;
- while (isWhitespace(currentInput.charCodeAt(innerStart))) {
- innerStart++;
- }
- while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
- innerEnd--;
- }
- let exp = getSlice(innerStart, innerEnd);
- if (exp.includes("&")) {
- {
- exp = decode_js.decodeHTML(exp);
- }
- }
- addNode({
- type: 5,
- content: createExp(exp, false, getLoc(innerStart, innerEnd)),
- loc: getLoc(start, end)
- });
- },
- onopentagname(start, end) {
- const name = getSlice(start, end);
- currentOpenTag = {
- type: 1,
- tag: name,
- ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
- tagType: 0,
- // will be refined on tag close
- props: [],
- children: [],
- loc: getLoc(start - 1, end),
- codegenNode: void 0
- };
- },
- onopentagend(end) {
- endOpenTag(end);
- },
- onclosetag(start, end) {
- const name = getSlice(start, end);
- if (!currentOptions.isVoidTag(name)) {
- let found = false;
- for (let i = 0; i < stack.length; i++) {
- const e = stack[i];
- if (e.tag.toLowerCase() === name.toLowerCase()) {
- found = true;
- if (i > 0) {
- emitError(24, stack[0].loc.start.offset);
- }
- for (let j = 0; j <= i; j++) {
- const el = stack.shift();
- onCloseTag(el, end, j < i);
- }
- break;
- }
- }
- if (!found) {
- emitError(23, backTrack(start, 60));
- }
- }
- },
- onselfclosingtag(end) {
- const name = currentOpenTag.tag;
- currentOpenTag.isSelfClosing = true;
- endOpenTag(end);
- if (stack[0] && stack[0].tag === name) {
- onCloseTag(stack.shift(), end);
- }
- },
- onattribname(start, end) {
- currentProp = {
- type: 6,
- name: getSlice(start, end),
- nameLoc: getLoc(start, end),
- value: void 0,
- loc: getLoc(start)
- };
- },
- ondirname(start, end) {
- const raw = getSlice(start, end);
- const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
- if (!inVPre && name === "") {
- emitError(26, start);
- }
- if (inVPre || name === "") {
- currentProp = {
- type: 6,
- name: raw,
- nameLoc: getLoc(start, end),
- value: void 0,
- loc: getLoc(start)
- };
- } else {
- currentProp = {
- type: 7,
- name,
- rawName: raw,
- exp: void 0,
- arg: void 0,
- modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
- loc: getLoc(start)
- };
- if (name === "pre") {
- inVPre = tokenizer.inVPre = true;
- currentVPreBoundary = currentOpenTag;
- const props = currentOpenTag.props;
- for (let i = 0; i < props.length; i++) {
- if (props[i].type === 7) {
- props[i] = dirToAttr(props[i]);
- }
- }
- }
- }
- },
- ondirarg(start, end) {
- if (start === end) return;
- const arg = getSlice(start, end);
- if (inVPre) {
- currentProp.name += arg;
- setLocEnd(currentProp.nameLoc, end);
- } else {
- const isStatic = arg[0] !== `[`;
- currentProp.arg = createExp(
- isStatic ? arg : arg.slice(1, -1),
- isStatic,
- getLoc(start, end),
- isStatic ? 3 : 0
- );
- }
- },
- ondirmodifier(start, end) {
- const mod = getSlice(start, end);
- if (inVPre) {
- currentProp.name += "." + mod;
- setLocEnd(currentProp.nameLoc, end);
- } else if (currentProp.name === "slot") {
- const arg = currentProp.arg;
- if (arg) {
- arg.content += "." + mod;
- setLocEnd(arg.loc, end);
- }
- } else {
- const exp = createSimpleExpression(mod, true, getLoc(start, end));
- currentProp.modifiers.push(exp);
- }
- },
- onattribdata(start, end) {
- currentAttrValue += getSlice(start, end);
- if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
- currentAttrEndIndex = end;
- },
- onattribentity(char, start, end) {
- currentAttrValue += char;
- if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
- currentAttrEndIndex = end;
- },
- onattribnameend(end) {
- const start = currentProp.loc.start.offset;
- const name = getSlice(start, end);
- if (currentProp.type === 7) {
- currentProp.rawName = name;
- }
- if (currentOpenTag.props.some(
- (p) => (p.type === 7 ? p.rawName : p.name) === name
- )) {
- emitError(2, start);
- }
- },
- onattribend(quote, end) {
- if (currentOpenTag && currentProp) {
- setLocEnd(currentProp.loc, end);
- if (quote !== 0) {
- if (currentProp.type === 6) {
- if (currentProp.name === "class") {
- currentAttrValue = condense(currentAttrValue).trim();
- }
- if (quote === 1 && !currentAttrValue) {
- emitError(13, end);
- }
- currentProp.value = {
- type: 2,
- content: currentAttrValue,
- loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
- };
- if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
- tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
- }
- } else {
- let expParseMode = 0 /* Normal */;
- {
- if (currentProp.name === "for") {
- expParseMode = 3 /* Skip */;
- } else if (currentProp.name === "slot") {
- expParseMode = 1 /* Params */;
- } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
- expParseMode = 2 /* Statements */;
- }
- }
- currentProp.exp = createExp(
- currentAttrValue,
- false,
- getLoc(currentAttrStartIndex, currentAttrEndIndex),
- 0,
- expParseMode
- );
- if (currentProp.name === "for") {
- currentProp.forParseResult = parseForExpression(currentProp.exp);
- }
- let syncIndex = -1;
- if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
- (mod) => mod.content === "sync"
- )) > -1 && checkCompatEnabled(
- "COMPILER_V_BIND_SYNC",
- currentOptions,
- currentProp.loc,
- currentProp.rawName
- )) {
- currentProp.name = "model";
- currentProp.modifiers.splice(syncIndex, 1);
- }
- }
- }
- if (currentProp.type !== 7 || currentProp.name !== "pre") {
- currentOpenTag.props.push(currentProp);
- }
- }
- currentAttrValue = "";
- currentAttrStartIndex = currentAttrEndIndex = -1;
- },
- oncomment(start, end) {
- if (currentOptions.comments) {
- addNode({
- type: 3,
- content: getSlice(start, end),
- loc: getLoc(start - 4, end + 3)
- });
- }
- },
- onend() {
- const end = currentInput.length;
- if (tokenizer.state !== 1) {
- switch (tokenizer.state) {
- case 5:
- case 8:
- emitError(5, end);
- break;
- case 3:
- case 4:
- emitError(
- 25,
- tokenizer.sectionStart
- );
- break;
- case 28:
- if (tokenizer.currentSequence === Sequences.CdataEnd) {
- emitError(6, end);
- } else {
- emitError(7, end);
- }
- break;
- case 6:
- case 7:
- case 9:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- // "
- case 20:
- // '
- case 21:
- emitError(9, end);
- break;
- }
- }
- for (let index = 0; index < stack.length; index++) {
- onCloseTag(stack[index], end - 1);
- emitError(24, stack[index].loc.start.offset);
- }
- },
- oncdata(start, end) {
- if (stack[0].ns !== 0) {
- onText(getSlice(start, end), start, end);
- } else {
- emitError(1, start - 9);
- }
- },
- onprocessinginstruction(start) {
- if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
- emitError(
- 21,
- start - 1
- );
- }
- }
- });
- const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
- const stripParensRE = /^\(|\)$/g;
- function parseForExpression(input) {
- const loc = input.loc;
- const exp = input.content;
- const inMatch = exp.match(forAliasRE);
- if (!inMatch) return;
- const [, LHS, RHS] = inMatch;
- const createAliasExpression = (content, offset, asParam = false) => {
- const start = loc.start.offset + offset;
- const end = start + content.length;
- return createExp(
- content,
- false,
- getLoc(start, end),
- 0,
- asParam ? 1 /* Params */ : 0 /* Normal */
- );
- };
- const result = {
- source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
- value: void 0,
- key: void 0,
- index: void 0,
- finalized: false
- };
- let valueContent = LHS.trim().replace(stripParensRE, "").trim();
- const trimmedOffset = LHS.indexOf(valueContent);
- const iteratorMatch = valueContent.match(forIteratorRE);
- if (iteratorMatch) {
- valueContent = valueContent.replace(forIteratorRE, "").trim();
- const keyContent = iteratorMatch[1].trim();
- let keyOffset;
- if (keyContent) {
- keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
- result.key = createAliasExpression(keyContent, keyOffset, true);
- }
- if (iteratorMatch[2]) {
- const indexContent = iteratorMatch[2].trim();
- if (indexContent) {
- result.index = createAliasExpression(
- indexContent,
- exp.indexOf(
- indexContent,
- result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
- ),
- true
- );
- }
- }
- }
- if (valueContent) {
- result.value = createAliasExpression(valueContent, trimmedOffset, true);
- }
- return result;
- }
- function getSlice(start, end) {
- return currentInput.slice(start, end);
- }
- function endOpenTag(end) {
- if (tokenizer.inSFCRoot) {
- currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
- }
- addNode(currentOpenTag);
- const { tag, ns } = currentOpenTag;
- if (ns === 0 && currentOptions.isPreTag(tag)) {
- inPre++;
- }
- if (currentOptions.isVoidTag(tag)) {
- onCloseTag(currentOpenTag, end);
- } else {
- stack.unshift(currentOpenTag);
- if (ns === 1 || ns === 2) {
- tokenizer.inXML = true;
- }
- }
- currentOpenTag = null;
- }
- function onText(content, start, end) {
- const parent = stack[0] || currentRoot;
- const lastNode = parent.children[parent.children.length - 1];
- if (lastNode && lastNode.type === 2) {
- lastNode.content += content;
- setLocEnd(lastNode.loc, end);
- } else {
- parent.children.push({
- type: 2,
- content,
- loc: getLoc(start, end)
- });
- }
- }
- function onCloseTag(el, end, isImplied = false) {
- if (isImplied) {
- setLocEnd(el.loc, backTrack(end, 60));
- } else {
- setLocEnd(el.loc, lookAhead(end, 62) + 1);
- }
- if (tokenizer.inSFCRoot) {
- if (el.children.length) {
- el.innerLoc.end = shared.extend({}, el.children[el.children.length - 1].loc.end);
- } else {
- el.innerLoc.end = shared.extend({}, el.innerLoc.start);
- }
- el.innerLoc.source = getSlice(
- el.innerLoc.start.offset,
- el.innerLoc.end.offset
- );
- }
- const { tag, ns, children } = el;
- if (!inVPre) {
- if (tag === "slot") {
- el.tagType = 2;
- } else if (isFragmentTemplate(el)) {
- el.tagType = 3;
- } else if (isComponent(el)) {
- el.tagType = 1;
- }
- }
- if (!tokenizer.inRCDATA) {
- el.children = condenseWhitespace(children);
- }
- if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
- const first = children[0];
- if (first && first.type === 2) {
- first.content = first.content.replace(/^\r?\n/, "");
- }
- }
- if (ns === 0 && currentOptions.isPreTag(tag)) {
- inPre--;
- }
- if (currentVPreBoundary === el) {
- inVPre = tokenizer.inVPre = false;
- currentVPreBoundary = null;
- }
- if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
- tokenizer.inXML = false;
- }
- {
- const props = el.props;
- if (!tokenizer.inSFCRoot && isCompatEnabled(
- "COMPILER_NATIVE_TEMPLATE",
- currentOptions
- ) && el.tag === "template" && !isFragmentTemplate(el)) {
- const parent = stack[0] || currentRoot;
- const index = parent.children.indexOf(el);
- parent.children.splice(index, 1, ...el.children);
- }
- const inlineTemplateProp = props.find(
- (p) => p.type === 6 && p.name === "inline-template"
- );
- if (inlineTemplateProp && checkCompatEnabled(
- "COMPILER_INLINE_TEMPLATE",
- currentOptions,
- inlineTemplateProp.loc
- ) && el.children.length) {
- inlineTemplateProp.value = {
- type: 2,
- content: getSlice(
- el.children[0].loc.start.offset,
- el.children[el.children.length - 1].loc.end.offset
- ),
- loc: inlineTemplateProp.loc
- };
- }
- }
- }
- function lookAhead(index, c) {
- let i = index;
- while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
- return i;
- }
- function backTrack(index, c) {
- let i = index;
- while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
- return i;
- }
- const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
- function isFragmentTemplate({ tag, props }) {
- if (tag === "template") {
- for (let i = 0; i < props.length; i++) {
- if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
- return true;
- }
- }
- }
- return false;
- }
- function isComponent({ tag, props }) {
- if (currentOptions.isCustomElement(tag)) {
- return false;
- }
- if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
- return true;
- }
- for (let i = 0; i < props.length; i++) {
- const p = props[i];
- if (p.type === 6) {
- if (p.name === "is" && p.value) {
- if (p.value.content.startsWith("vue:")) {
- return true;
- } else if (checkCompatEnabled(
- "COMPILER_IS_ON_ELEMENT",
- currentOptions,
- p.loc
- )) {
- return true;
- }
- }
- } else if (// :is on plain element - only treat as component in compat mode
- p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
- "COMPILER_IS_ON_ELEMENT",
- currentOptions,
- p.loc
- )) {
- return true;
- }
- }
- return false;
- }
- function isUpperCase(c) {
- return c > 64 && c < 91;
- }
- const windowsNewlineRE = /\r\n/g;
- function condenseWhitespace(nodes, tag) {
- const shouldCondense = currentOptions.whitespace !== "preserve";
- let removedWhitespace = false;
- for (let i = 0; i < nodes.length; i++) {
- const node = nodes[i];
- if (node.type === 2) {
- if (!inPre) {
- if (isAllWhitespace(node.content)) {
- const prev = nodes[i - 1] && nodes[i - 1].type;
- const next = nodes[i + 1] && nodes[i + 1].type;
- if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
- removedWhitespace = true;
- nodes[i] = null;
- } else {
- node.content = " ";
- }
- } else if (shouldCondense) {
- node.content = condense(node.content);
- }
- } else {
- node.content = node.content.replace(windowsNewlineRE, "\n");
- }
- }
- }
- return removedWhitespace ? nodes.filter(Boolean) : nodes;
- }
- function isAllWhitespace(str) {
- for (let i = 0; i < str.length; i++) {
- if (!isWhitespace(str.charCodeAt(i))) {
- return false;
- }
- }
- return true;
- }
- function hasNewlineChar(str) {
- for (let i = 0; i < str.length; i++) {
- const c = str.charCodeAt(i);
- if (c === 10 || c === 13) {
- return true;
- }
- }
- return false;
- }
- function condense(str) {
- let ret = "";
- let prevCharIsWhitespace = false;
- for (let i = 0; i < str.length; i++) {
- if (isWhitespace(str.charCodeAt(i))) {
- if (!prevCharIsWhitespace) {
- ret += " ";
- prevCharIsWhitespace = true;
- }
- } else {
- ret += str[i];
- prevCharIsWhitespace = false;
- }
- }
- return ret;
- }
- function addNode(node) {
- (stack[0] || currentRoot).children.push(node);
- }
- function getLoc(start, end) {
- return {
- start: tokenizer.getPos(start),
- // @ts-expect-error allow late attachment
- end: end == null ? end : tokenizer.getPos(end),
- // @ts-expect-error allow late attachment
- source: end == null ? end : getSlice(start, end)
- };
- }
- function cloneLoc(loc) {
- return getLoc(loc.start.offset, loc.end.offset);
- }
- function setLocEnd(loc, end) {
- loc.end = tokenizer.getPos(end);
- loc.source = getSlice(loc.start.offset, end);
- }
- function dirToAttr(dir) {
- const attr = {
- type: 6,
- name: dir.rawName,
- nameLoc: getLoc(
- dir.loc.start.offset,
- dir.loc.start.offset + dir.rawName.length
- ),
- value: void 0,
- loc: dir.loc
- };
- if (dir.exp) {
- const loc = dir.exp.loc;
- if (loc.end.offset < dir.loc.end.offset) {
- loc.start.offset--;
- loc.start.column--;
- loc.end.offset++;
- loc.end.column++;
- }
- attr.value = {
- type: 2,
- content: dir.exp.content,
- loc
- };
- }
- return attr;
- }
- function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
- const exp = createSimpleExpression(content, isStatic, loc, constType);
- if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
- if (isSimpleIdentifier(content)) {
- exp.ast = null;
- return exp;
- }
- try {
- const plugins = currentOptions.expressionPlugins;
- const options = {
- plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
- };
- if (parseMode === 2 /* Statements */) {
- exp.ast = parser.parse(` ${content} `, options).program;
- } else if (parseMode === 1 /* Params */) {
- exp.ast = parser.parseExpression(`(${content})=>{}`, options);
- } else {
- exp.ast = parser.parseExpression(`(${content})`, options);
- }
- } catch (e) {
- exp.ast = false;
- emitError(45, loc.start.offset, e.message);
- }
- }
- return exp;
- }
- function emitError(code, index, message) {
- currentOptions.onError(
- createCompilerError(code, getLoc(index, index), void 0, message)
- );
- }
- function reset() {
- tokenizer.reset();
- currentOpenTag = null;
- currentProp = null;
- currentAttrValue = "";
- currentAttrStartIndex = -1;
- currentAttrEndIndex = -1;
- stack.length = 0;
- }
- function baseParse(input, options) {
- reset();
- currentInput = input;
- currentOptions = shared.extend({}, defaultParserOptions);
- if (options) {
- let key;
- for (key in options) {
- if (options[key] != null) {
- currentOptions[key] = options[key];
- }
- }
- }
- tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
- tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
- const delimiters = options && options.delimiters;
- if (delimiters) {
- tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
- tokenizer.delimiterClose = toCharCodes(delimiters[1]);
- }
- const root = currentRoot = createRoot([], input);
- tokenizer.parse(currentInput);
- root.loc = getLoc(0, input.length);
- root.children = condenseWhitespace(root.children);
- currentRoot = null;
- return root;
- }
- function cacheStatic(root, context) {
- walk(
- root,
- void 0,
- context,
- // Root node is unfortunately non-hoistable due to potential parent
- // fallthrough attributes.
- isSingleElementRoot(root, root.children[0])
- );
- }
- function isSingleElementRoot(root, child) {
- const { children } = root;
- return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
- }
- function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
- const { children } = node;
- const toCache = [];
- for (let i = 0; i < children.length; i++) {
- const child = children[i];
- if (child.type === 1 && child.tagType === 0) {
- const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
- if (constantType > 0) {
- if (constantType >= 2) {
- child.codegenNode.patchFlag = -1;
- toCache.push(child);
- continue;
- }
- } else {
- const codegenNode = child.codegenNode;
- if (codegenNode.type === 13) {
- const flag = codegenNode.patchFlag;
- if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
- const props = getNodeProps(child);
- if (props) {
- codegenNode.props = context.hoist(props);
- }
- }
- if (codegenNode.dynamicProps) {
- codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
- }
- }
- }
- } else if (child.type === 12) {
- const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
- if (constantType >= 2) {
- toCache.push(child);
- continue;
- }
- }
- if (child.type === 1) {
- const isComponent = child.tagType === 1;
- if (isComponent) {
- context.scopes.vSlot++;
- }
- walk(child, node, context, false, inFor);
- if (isComponent) {
- context.scopes.vSlot--;
- }
- } else if (child.type === 11) {
- walk(child, node, context, child.children.length === 1, true);
- } else if (child.type === 9) {
- for (let i2 = 0; i2 < child.branches.length; i2++) {
- walk(
- child.branches[i2],
- node,
- context,
- child.branches[i2].children.length === 1,
- inFor
- );
- }
- }
- }
- let cachedAsArray = false;
- if (toCache.length === children.length && node.type === 1) {
- if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
- node.codegenNode.children = getCacheExpression(
- createArrayExpression(node.codegenNode.children)
- );
- cachedAsArray = true;
- } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
- const slot = getSlotNode(node.codegenNode, "default");
- if (slot) {
- slot.returns = getCacheExpression(
- createArrayExpression(slot.returns)
- );
- cachedAsArray = true;
- }
- } 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) {
- const slotName = findDir(node, "slot", true);
- const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
- if (slot) {
- slot.returns = getCacheExpression(
- createArrayExpression(slot.returns)
- );
- cachedAsArray = true;
- }
- }
- }
- if (!cachedAsArray) {
- for (const child of toCache) {
- child.codegenNode = context.cache(child.codegenNode);
- }
- }
- function getCacheExpression(value) {
- const exp = context.cache(value);
- if (inFor && context.hmr) {
- exp.needArraySpread = true;
- }
- return exp;
- }
- function getSlotNode(node2, name) {
- if (node2.children && !shared.isArray(node2.children) && node2.children.type === 15) {
- const slot = node2.children.properties.find(
- (p) => p.key === name || p.key.content === name
- );
- return slot && slot.value;
- }
- }
- if (toCache.length && context.transformHoist) {
- context.transformHoist(children, context, node);
- }
- }
- function getConstantType(node, context) {
- const { constantCache } = context;
- switch (node.type) {
- case 1:
- if (node.tagType !== 0) {
- return 0;
- }
- const cached = constantCache.get(node);
- if (cached !== void 0) {
- return cached;
- }
- const codegenNode = node.codegenNode;
- if (codegenNode.type !== 13) {
- return 0;
- }
- if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
- return 0;
- }
- if (codegenNode.patchFlag === void 0) {
- let returnType2 = 3;
- const generatedPropsType = getGeneratedPropsConstantType(node, context);
- if (generatedPropsType === 0) {
- constantCache.set(node, 0);
- return 0;
- }
- if (generatedPropsType < returnType2) {
- returnType2 = generatedPropsType;
- }
- for (let i = 0; i < node.children.length; i++) {
- const childType = getConstantType(node.children[i], context);
- if (childType === 0) {
- constantCache.set(node, 0);
- return 0;
- }
- if (childType < returnType2) {
- returnType2 = childType;
- }
- }
- if (returnType2 > 1) {
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 7 && p.name === "bind" && p.exp) {
- const expType = getConstantType(p.exp, context);
- if (expType === 0) {
- constantCache.set(node, 0);
- return 0;
- }
- if (expType < returnType2) {
- returnType2 = expType;
- }
- }
- }
- }
- if (codegenNode.isBlock) {
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 7) {
- constantCache.set(node, 0);
- return 0;
- }
- }
- context.removeHelper(OPEN_BLOCK);
- context.removeHelper(
- getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
- );
- codegenNode.isBlock = false;
- context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
- }
- constantCache.set(node, returnType2);
- return returnType2;
- } else {
- constantCache.set(node, 0);
- return 0;
- }
- case 2:
- case 3:
- return 3;
- case 9:
- case 11:
- case 10:
- return 0;
- case 5:
- case 12:
- return getConstantType(node.content, context);
- case 4:
- return node.constType;
- case 8:
- let returnType = 3;
- for (let i = 0; i < node.children.length; i++) {
- const child = node.children[i];
- if (shared.isString(child) || shared.isSymbol(child)) {
- continue;
- }
- const childType = getConstantType(child, context);
- if (childType === 0) {
- return 0;
- } else if (childType < returnType) {
- returnType = childType;
- }
- }
- return returnType;
- case 20:
- return 2;
- default:
- return 0;
- }
- }
- const allowHoistedHelperSet = /* @__PURE__ */ new Set([
- NORMALIZE_CLASS,
- NORMALIZE_STYLE,
- NORMALIZE_PROPS,
- GUARD_REACTIVE_PROPS
- ]);
- function getConstantTypeOfHelperCall(value, context) {
- if (value.type === 14 && !shared.isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
- const arg = value.arguments[0];
- if (arg.type === 4) {
- return getConstantType(arg, context);
- } else if (arg.type === 14) {
- return getConstantTypeOfHelperCall(arg, context);
- }
- }
- return 0;
- }
- function getGeneratedPropsConstantType(node, context) {
- let returnType = 3;
- const props = getNodeProps(node);
- if (props && props.type === 15) {
- const { properties } = props;
- for (let i = 0; i < properties.length; i++) {
- const { key, value } = properties[i];
- const keyType = getConstantType(key, context);
- if (keyType === 0) {
- return keyType;
- }
- if (keyType < returnType) {
- returnType = keyType;
- }
- let valueType;
- if (value.type === 4) {
- valueType = getConstantType(value, context);
- } else if (value.type === 14) {
- valueType = getConstantTypeOfHelperCall(value, context);
- } else {
- valueType = 0;
- }
- if (valueType === 0) {
- return valueType;
- }
- if (valueType < returnType) {
- returnType = valueType;
- }
- }
- }
- return returnType;
- }
- function getNodeProps(node) {
- const codegenNode = node.codegenNode;
- if (codegenNode.type === 13) {
- return codegenNode.props;
- }
- }
- function createTransformContext(root, {
- filename = "",
- prefixIdentifiers = false,
- hoistStatic = false,
- hmr = false,
- cacheHandlers = false,
- nodeTransforms = [],
- directiveTransforms = {},
- transformHoist = null,
- isBuiltInComponent = shared.NOOP,
- isCustomElement = shared.NOOP,
- expressionPlugins = [],
- scopeId = null,
- slotted = true,
- ssr = false,
- inSSR = false,
- ssrCssVars = ``,
- bindingMetadata = shared.EMPTY_OBJ,
- inline = false,
- isTS = false,
- onError = defaultOnError,
- onWarn = defaultOnWarn,
- compatConfig
- }) {
- const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
- const context = {
- // options
- filename,
- selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
- prefixIdentifiers,
- hoistStatic,
- hmr,
- cacheHandlers,
- nodeTransforms,
- directiveTransforms,
- transformHoist,
- isBuiltInComponent,
- isCustomElement,
- expressionPlugins,
- scopeId,
- slotted,
- ssr,
- inSSR,
- ssrCssVars,
- bindingMetadata,
- inline,
- isTS,
- onError,
- onWarn,
- compatConfig,
- // state
- root,
- helpers: /* @__PURE__ */ new Map(),
- components: /* @__PURE__ */ new Set(),
- directives: /* @__PURE__ */ new Set(),
- hoists: [],
- imports: [],
- cached: [],
- constantCache: /* @__PURE__ */ new WeakMap(),
- temps: 0,
- identifiers: /* @__PURE__ */ Object.create(null),
- scopes: {
- vFor: 0,
- vSlot: 0,
- vPre: 0,
- vOnce: 0
- },
- parent: null,
- grandParent: null,
- currentNode: root,
- childIndex: 0,
- inVOnce: false,
- // methods
- helper(name) {
- const count = context.helpers.get(name) || 0;
- context.helpers.set(name, count + 1);
- return name;
- },
- removeHelper(name) {
- const count = context.helpers.get(name);
- if (count) {
- const currentCount = count - 1;
- if (!currentCount) {
- context.helpers.delete(name);
- } else {
- context.helpers.set(name, currentCount);
- }
- }
- },
- helperString(name) {
- return `_${helperNameMap[context.helper(name)]}`;
- },
- replaceNode(node) {
- context.parent.children[context.childIndex] = context.currentNode = node;
- },
- removeNode(node) {
- const list = context.parent.children;
- const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
- if (!node || node === context.currentNode) {
- context.currentNode = null;
- context.onNodeRemoved();
- } else {
- if (context.childIndex > removalIndex) {
- context.childIndex--;
- context.onNodeRemoved();
- }
- }
- context.parent.children.splice(removalIndex, 1);
- },
- onNodeRemoved: shared.NOOP,
- addIdentifiers(exp) {
- {
- if (shared.isString(exp)) {
- addId(exp);
- } else if (exp.identifiers) {
- exp.identifiers.forEach(addId);
- } else if (exp.type === 4) {
- addId(exp.content);
- }
- }
- },
- removeIdentifiers(exp) {
- {
- if (shared.isString(exp)) {
- removeId(exp);
- } else if (exp.identifiers) {
- exp.identifiers.forEach(removeId);
- } else if (exp.type === 4) {
- removeId(exp.content);
- }
- }
- },
- hoist(exp) {
- if (shared.isString(exp)) exp = createSimpleExpression(exp);
- context.hoists.push(exp);
- const identifier = createSimpleExpression(
- `_hoisted_${context.hoists.length}`,
- false,
- exp.loc,
- 2
- );
- identifier.hoisted = exp;
- return identifier;
- },
- cache(exp, isVNode = false) {
- const cacheExp = createCacheExpression(
- context.cached.length,
- exp,
- isVNode
- );
- context.cached.push(cacheExp);
- return cacheExp;
- }
- };
- {
- context.filters = /* @__PURE__ */ new Set();
- }
- function addId(id) {
- const { identifiers } = context;
- if (identifiers[id] === void 0) {
- identifiers[id] = 0;
- }
- identifiers[id]++;
- }
- function removeId(id) {
- context.identifiers[id]--;
- }
- return context;
- }
- function transform(root, options) {
- const context = createTransformContext(root, options);
- traverseNode(root, context);
- if (options.hoistStatic) {
- cacheStatic(root, context);
- }
- if (!options.ssr) {
- createRootCodegen(root, context);
- }
- root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
- root.components = [...context.components];
- root.directives = [...context.directives];
- root.imports = context.imports;
- root.hoists = context.hoists;
- root.temps = context.temps;
- root.cached = context.cached;
- root.transformed = true;
- {
- root.filters = [...context.filters];
- }
- }
- function createRootCodegen(root, context) {
- const { helper } = context;
- const { children } = root;
- if (children.length === 1) {
- const child = children[0];
- if (isSingleElementRoot(root, child) && child.codegenNode) {
- const codegenNode = child.codegenNode;
- if (codegenNode.type === 13) {
- convertToBlock(codegenNode, context);
- }
- root.codegenNode = codegenNode;
- } else {
- root.codegenNode = child;
- }
- } else if (children.length > 1) {
- let patchFlag = 64;
- root.codegenNode = createVNodeCall(
- context,
- helper(FRAGMENT),
- void 0,
- root.children,
- patchFlag,
- void 0,
- void 0,
- true,
- void 0,
- false
- );
- } else ;
- }
- function traverseChildren(parent, context) {
- let i = 0;
- const nodeRemoved = () => {
- i--;
- };
- for (; i < parent.children.length; i++) {
- const child = parent.children[i];
- if (shared.isString(child)) continue;
- context.grandParent = context.parent;
- context.parent = parent;
- context.childIndex = i;
- context.onNodeRemoved = nodeRemoved;
- traverseNode(child, context);
- }
- }
- function traverseNode(node, context) {
- context.currentNode = node;
- const { nodeTransforms } = context;
- const exitFns = [];
- for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
- const onExit = nodeTransforms[i2](node, context);
- if (onExit) {
- if (shared.isArray(onExit)) {
- exitFns.push(...onExit);
- } else {
- exitFns.push(onExit);
- }
- }
- if (!context.currentNode) {
- return;
- } else {
- node = context.currentNode;
- }
- }
- switch (node.type) {
- case 3:
- if (!context.ssr) {
- context.helper(CREATE_COMMENT);
- }
- break;
- case 5:
- if (!context.ssr) {
- context.helper(TO_DISPLAY_STRING);
- }
- break;
- // for container types, further traverse downwards
- case 9:
- for (let i2 = 0; i2 < node.branches.length; i2++) {
- traverseNode(node.branches[i2], context);
- }
- break;
- case 10:
- case 11:
- case 1:
- case 0:
- traverseChildren(node, context);
- break;
- }
- context.currentNode = node;
- let i = exitFns.length;
- while (i--) {
- exitFns[i]();
- }
- }
- function createStructuralDirectiveTransform(name, fn) {
- const matches = shared.isString(name) ? (n) => n === name : (n) => name.test(n);
- return (node, context) => {
- if (node.type === 1) {
- const { props } = node;
- if (node.tagType === 3 && props.some(isVSlot)) {
- return;
- }
- const exitFns = [];
- for (let i = 0; i < props.length; i++) {
- const prop = props[i];
- if (prop.type === 7 && matches(prop.name)) {
- props.splice(i, 1);
- i--;
- const onExit = fn(node, prop, context);
- if (onExit) exitFns.push(onExit);
- }
- }
- return exitFns;
- }
- };
- }
- const PURE_ANNOTATION = `/*@__PURE__*/`;
- const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
- function createCodegenContext(ast, {
- mode = "function",
- prefixIdentifiers = mode === "module",
- sourceMap = false,
- filename = `template.vue.html`,
- scopeId = null,
- optimizeImports = false,
- runtimeGlobalName = `Vue`,
- runtimeModuleName = `vue`,
- ssrRuntimeModuleName = "vue/server-renderer",
- ssr = false,
- isTS = false,
- inSSR = false
- }) {
- const context = {
- mode,
- prefixIdentifiers,
- sourceMap,
- filename,
- scopeId,
- optimizeImports,
- runtimeGlobalName,
- runtimeModuleName,
- ssrRuntimeModuleName,
- ssr,
- isTS,
- inSSR,
- source: ast.source,
- code: ``,
- column: 1,
- line: 1,
- offset: 0,
- indentLevel: 0,
- pure: false,
- map: void 0,
- helper(key) {
- return `_${helperNameMap[key]}`;
- },
- push(code, newlineIndex = -2 /* None */, node) {
- context.code += code;
- if (context.map) {
- if (node) {
- let name;
- if (node.type === 4 && !node.isStatic) {
- const content = node.content.replace(/^_ctx\./, "");
- if (content !== node.content && isSimpleIdentifier(content)) {
- name = content;
- }
- }
- addMapping(node.loc.start, name);
- }
- if (newlineIndex === -3 /* Unknown */) {
- advancePositionWithMutation(context, code);
- } else {
- context.offset += code.length;
- if (newlineIndex === -2 /* None */) {
- context.column += code.length;
- } else {
- if (newlineIndex === -1 /* End */) {
- newlineIndex = code.length - 1;
- }
- context.line++;
- context.column = code.length - newlineIndex;
- }
- }
- if (node && node.loc !== locStub) {
- addMapping(node.loc.end);
- }
- }
- },
- indent() {
- newline(++context.indentLevel);
- },
- deindent(withoutNewLine = false) {
- if (withoutNewLine) {
- --context.indentLevel;
- } else {
- newline(--context.indentLevel);
- }
- },
- newline() {
- newline(context.indentLevel);
- }
- };
- function newline(n) {
- context.push("\n" + ` `.repeat(n), 0 /* Start */);
- }
- function addMapping(loc, name = null) {
- const { _names, _mappings } = context.map;
- if (name !== null && !_names.has(name)) _names.add(name);
- _mappings.add({
- originalLine: loc.line,
- originalColumn: loc.column - 1,
- // source-map column is 0 based
- generatedLine: context.line,
- generatedColumn: context.column - 1,
- source: filename,
- name
- });
- }
- if (sourceMap) {
- context.map = new sourceMapJs.SourceMapGenerator();
- context.map.setSourceContent(filename, context.source);
- context.map._sources.add(filename);
- }
- return context;
- }
- function generate(ast, options = {}) {
- const context = createCodegenContext(ast, options);
- if (options.onContextCreated) options.onContextCreated(context);
- const {
- mode,
- push,
- prefixIdentifiers,
- indent,
- deindent,
- newline,
- scopeId,
- ssr
- } = context;
- const helpers = Array.from(ast.helpers);
- const hasHelpers = helpers.length > 0;
- const useWithBlock = !prefixIdentifiers && mode !== "module";
- const genScopeId = scopeId != null && mode === "module";
- const isSetupInlined = !!options.inline;
- const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
- if (mode === "module") {
- genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
- } else {
- genFunctionPreamble(ast, preambleContext);
- }
- const functionName = ssr ? `ssrRender` : `render`;
- const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
- if (options.bindingMetadata && !options.inline) {
- args.push("$props", "$setup", "$data", "$options");
- }
- const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
- if (isSetupInlined) {
- push(`(${signature}) => {`);
- } else {
- push(`function ${functionName}(${signature}) {`);
- }
- indent();
- if (useWithBlock) {
- push(`with (_ctx) {`);
- indent();
- if (hasHelpers) {
- push(
- `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
- `,
- -1 /* End */
- );
- newline();
- }
- }
- if (ast.components.length) {
- genAssets(ast.components, "component", context);
- if (ast.directives.length || ast.temps > 0) {
- newline();
- }
- }
- if (ast.directives.length) {
- genAssets(ast.directives, "directive", context);
- if (ast.temps > 0) {
- newline();
- }
- }
- if (ast.filters && ast.filters.length) {
- newline();
- genAssets(ast.filters, "filter", context);
- newline();
- }
- if (ast.temps > 0) {
- push(`let `);
- for (let i = 0; i < ast.temps; i++) {
- push(`${i > 0 ? `, ` : ``}_temp${i}`);
- }
- }
- if (ast.components.length || ast.directives.length || ast.temps) {
- push(`
- `, 0 /* Start */);
- newline();
- }
- if (!ssr) {
- push(`return `);
- }
- if (ast.codegenNode) {
- genNode(ast.codegenNode, context);
- } else {
- push(`null`);
- }
- if (useWithBlock) {
- deindent();
- push(`}`);
- }
- deindent();
- push(`}`);
- return {
- ast,
- code: context.code,
- preamble: isSetupInlined ? preambleContext.code : ``,
- map: context.map ? context.map.toJSON() : void 0
- };
- }
- function genFunctionPreamble(ast, context) {
- const {
- ssr,
- prefixIdentifiers,
- push,
- newline,
- runtimeModuleName,
- runtimeGlobalName,
- ssrRuntimeModuleName
- } = context;
- const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
- const helpers = Array.from(ast.helpers);
- if (helpers.length > 0) {
- if (prefixIdentifiers) {
- push(
- `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
- `,
- -1 /* End */
- );
- } else {
- push(`const _Vue = ${VueBinding}
- `, -1 /* End */);
- if (ast.hoists.length) {
- const staticHelpers = [
- CREATE_VNODE,
- CREATE_ELEMENT_VNODE,
- CREATE_COMMENT,
- CREATE_TEXT,
- CREATE_STATIC
- ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
- push(`const { ${staticHelpers} } = _Vue
- `, -1 /* End */);
- }
- }
- }
- if (ast.ssrHelpers && ast.ssrHelpers.length) {
- push(
- `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
- `,
- -1 /* End */
- );
- }
- genHoists(ast.hoists, context);
- newline();
- push(`return `);
- }
- function genModulePreamble(ast, context, genScopeId, inline) {
- const {
- push,
- newline,
- optimizeImports,
- runtimeModuleName,
- ssrRuntimeModuleName
- } = context;
- if (ast.helpers.size) {
- const helpers = Array.from(ast.helpers);
- if (optimizeImports) {
- push(
- `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
- `,
- -1 /* End */
- );
- push(
- `
- // Binding optimization for webpack code-split
- const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
- `,
- -1 /* End */
- );
- } else {
- push(
- `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
- `,
- -1 /* End */
- );
- }
- }
- if (ast.ssrHelpers && ast.ssrHelpers.length) {
- push(
- `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
- `,
- -1 /* End */
- );
- }
- if (ast.imports.length) {
- genImports(ast.imports, context);
- newline();
- }
- genHoists(ast.hoists, context);
- newline();
- if (!inline) {
- push(`export `);
- }
- }
- function genAssets(assets, type, { helper, push, newline, isTS }) {
- const resolver = helper(
- type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
- );
- for (let i = 0; i < assets.length; i++) {
- let id = assets[i];
- const maybeSelfReference = id.endsWith("__self");
- if (maybeSelfReference) {
- id = id.slice(0, -6);
- }
- push(
- `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
- );
- if (i < assets.length - 1) {
- newline();
- }
- }
- }
- function genHoists(hoists, context) {
- if (!hoists.length) {
- return;
- }
- context.pure = true;
- const { push, newline } = context;
- newline();
- for (let i = 0; i < hoists.length; i++) {
- const exp = hoists[i];
- if (exp) {
- push(`const _hoisted_${i + 1} = `);
- genNode(exp, context);
- newline();
- }
- }
- context.pure = false;
- }
- function genImports(importsOptions, context) {
- if (!importsOptions.length) {
- return;
- }
- importsOptions.forEach((imports) => {
- context.push(`import `);
- genNode(imports.exp, context);
- context.push(` from '${imports.path}'`);
- context.newline();
- });
- }
- function isText(n) {
- return shared.isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
- }
- function genNodeListAsArray(nodes, context) {
- const multilines = nodes.length > 3 || nodes.some((n) => shared.isArray(n) || !isText(n));
- context.push(`[`);
- multilines && context.indent();
- genNodeList(nodes, context, multilines);
- multilines && context.deindent();
- context.push(`]`);
- }
- function genNodeList(nodes, context, multilines = false, comma = true) {
- const { push, newline } = context;
- for (let i = 0; i < nodes.length; i++) {
- const node = nodes[i];
- if (shared.isString(node)) {
- push(node, -3 /* Unknown */);
- } else if (shared.isArray(node)) {
- genNodeListAsArray(node, context);
- } else {
- genNode(node, context);
- }
- if (i < nodes.length - 1) {
- if (multilines) {
- comma && push(",");
- newline();
- } else {
- comma && push(", ");
- }
- }
- }
- }
- function genNode(node, context) {
- if (shared.isString(node)) {
- context.push(node, -3 /* Unknown */);
- return;
- }
- if (shared.isSymbol(node)) {
- context.push(context.helper(node));
- return;
- }
- switch (node.type) {
- case 1:
- case 9:
- case 11:
- genNode(node.codegenNode, context);
- break;
- case 2:
- genText(node, context);
- break;
- case 4:
- genExpression(node, context);
- break;
- case 5:
- genInterpolation(node, context);
- break;
- case 12:
- genNode(node.codegenNode, context);
- break;
- case 8:
- genCompoundExpression(node, context);
- break;
- case 3:
- genComment(node, context);
- break;
- case 13:
- genVNodeCall(node, context);
- break;
- case 14:
- genCallExpression(node, context);
- break;
- case 15:
- genObjectExpression(node, context);
- break;
- case 17:
- genArrayExpression(node, context);
- break;
- case 18:
- genFunctionExpression(node, context);
- break;
- case 19:
- genConditionalExpression(node, context);
- break;
- case 20:
- genCacheExpression(node, context);
- break;
- case 21:
- genNodeList(node.body, context, true, false);
- break;
- // SSR only types
- case 22:
- genTemplateLiteral(node, context);
- break;
- case 23:
- genIfStatement(node, context);
- break;
- case 24:
- genAssignmentExpression(node, context);
- break;
- case 25:
- genSequenceExpression(node, context);
- break;
- case 26:
- genReturnStatement(node, context);
- break;
- }
- }
- function genText(node, context) {
- context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
- }
- function genExpression(node, context) {
- const { content, isStatic } = node;
- context.push(
- isStatic ? JSON.stringify(content) : content,
- -3 /* Unknown */,
- node
- );
- }
- function genInterpolation(node, context) {
- const { push, helper, pure } = context;
- if (pure) push(PURE_ANNOTATION);
- push(`${helper(TO_DISPLAY_STRING)}(`);
- genNode(node.content, context);
- push(`)`);
- }
- function genCompoundExpression(node, context) {
- for (let i = 0; i < node.children.length; i++) {
- const child = node.children[i];
- if (shared.isString(child)) {
- context.push(child, -3 /* Unknown */);
- } else {
- genNode(child, context);
- }
- }
- }
- function genExpressionAsPropertyKey(node, context) {
- const { push } = context;
- if (node.type === 8) {
- push(`[`);
- genCompoundExpression(node, context);
- push(`]`);
- } else if (node.isStatic) {
- const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
- push(text, -2 /* None */, node);
- } else {
- push(`[${node.content}]`, -3 /* Unknown */, node);
- }
- }
- function genComment(node, context) {
- const { push, helper, pure } = context;
- if (pure) {
- push(PURE_ANNOTATION);
- }
- push(
- `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
- -3 /* Unknown */,
- node
- );
- }
- function genVNodeCall(node, context) {
- const { push, helper, pure } = context;
- const {
- tag,
- props,
- children,
- patchFlag,
- dynamicProps,
- directives,
- isBlock,
- disableTracking,
- isComponent
- } = node;
- let patchFlagString;
- if (patchFlag) {
- {
- patchFlagString = String(patchFlag);
- }
- }
- if (directives) {
- push(helper(WITH_DIRECTIVES) + `(`);
- }
- if (isBlock) {
- push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
- }
- if (pure) {
- push(PURE_ANNOTATION);
- }
- const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
- push(helper(callHelper) + `(`, -2 /* None */, node);
- genNodeList(
- genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
- context
- );
- push(`)`);
- if (isBlock) {
- push(`)`);
- }
- if (directives) {
- push(`, `);
- genNode(directives, context);
- push(`)`);
- }
- }
- function genNullableArgs(args) {
- let i = args.length;
- while (i--) {
- if (args[i] != null) break;
- }
- return args.slice(0, i + 1).map((arg) => arg || `null`);
- }
- function genCallExpression(node, context) {
- const { push, helper, pure } = context;
- const callee = shared.isString(node.callee) ? node.callee : helper(node.callee);
- if (pure) {
- push(PURE_ANNOTATION);
- }
- push(callee + `(`, -2 /* None */, node);
- genNodeList(node.arguments, context);
- push(`)`);
- }
- function genObjectExpression(node, context) {
- const { push, indent, deindent, newline } = context;
- const { properties } = node;
- if (!properties.length) {
- push(`{}`, -2 /* None */, node);
- return;
- }
- const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
- push(multilines ? `{` : `{ `);
- multilines && indent();
- for (let i = 0; i < properties.length; i++) {
- const { key, value } = properties[i];
- genExpressionAsPropertyKey(key, context);
- push(`: `);
- genNode(value, context);
- if (i < properties.length - 1) {
- push(`,`);
- newline();
- }
- }
- multilines && deindent();
- push(multilines ? `}` : ` }`);
- }
- function genArrayExpression(node, context) {
- genNodeListAsArray(node.elements, context);
- }
- function genFunctionExpression(node, context) {
- const { push, indent, deindent } = context;
- const { params, returns, body, newline, isSlot } = node;
- if (isSlot) {
- push(`_${helperNameMap[WITH_CTX]}(`);
- }
- push(`(`, -2 /* None */, node);
- if (shared.isArray(params)) {
- genNodeList(params, context);
- } else if (params) {
- genNode(params, context);
- }
- push(`) => `);
- if (newline || body) {
- push(`{`);
- indent();
- }
- if (returns) {
- if (newline) {
- push(`return `);
- }
- if (shared.isArray(returns)) {
- genNodeListAsArray(returns, context);
- } else {
- genNode(returns, context);
- }
- } else if (body) {
- genNode(body, context);
- }
- if (newline || body) {
- deindent();
- push(`}`);
- }
- if (isSlot) {
- if (node.isNonScopedSlot) {
- push(`, undefined, true`);
- }
- push(`)`);
- }
- }
- function genConditionalExpression(node, context) {
- const { test, consequent, alternate, newline: needNewline } = node;
- const { push, indent, deindent, newline } = context;
- if (test.type === 4) {
- const needsParens = !isSimpleIdentifier(test.content);
- needsParens && push(`(`);
- genExpression(test, context);
- needsParens && push(`)`);
- } else {
- push(`(`);
- genNode(test, context);
- push(`)`);
- }
- needNewline && indent();
- context.indentLevel++;
- needNewline || push(` `);
- push(`? `);
- genNode(consequent, context);
- context.indentLevel--;
- needNewline && newline();
- needNewline || push(` `);
- push(`: `);
- const isNested = alternate.type === 19;
- if (!isNested) {
- context.indentLevel++;
- }
- genNode(alternate, context);
- if (!isNested) {
- context.indentLevel--;
- }
- needNewline && deindent(
- true
- /* without newline */
- );
- }
- function genCacheExpression(node, context) {
- const { push, helper, indent, deindent, newline } = context;
- const { needPauseTracking, needArraySpread } = node;
- if (needArraySpread) {
- push(`[...(`);
- }
- push(`_cache[${node.index}] || (`);
- if (needPauseTracking) {
- indent();
- push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
- newline();
- push(`(`);
- }
- push(`_cache[${node.index}] = `);
- genNode(node.value, context);
- if (needPauseTracking) {
- push(`).cacheIndex = ${node.index},`);
- newline();
- push(`${helper(SET_BLOCK_TRACKING)}(1),`);
- newline();
- push(`_cache[${node.index}]`);
- deindent();
- }
- push(`)`);
- if (needArraySpread) {
- push(`)]`);
- }
- }
- function genTemplateLiteral(node, context) {
- const { push, indent, deindent } = context;
- push("`");
- const l = node.elements.length;
- const multilines = l > 3;
- for (let i = 0; i < l; i++) {
- const e = node.elements[i];
- if (shared.isString(e)) {
- push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
- } else {
- push("${");
- if (multilines) indent();
- genNode(e, context);
- if (multilines) deindent();
- push("}");
- }
- }
- push("`");
- }
- function genIfStatement(node, context) {
- const { push, indent, deindent } = context;
- const { test, consequent, alternate } = node;
- push(`if (`);
- genNode(test, context);
- push(`) {`);
- indent();
- genNode(consequent, context);
- deindent();
- push(`}`);
- if (alternate) {
- push(` else `);
- if (alternate.type === 23) {
- genIfStatement(alternate, context);
- } else {
- push(`{`);
- indent();
- genNode(alternate, context);
- deindent();
- push(`}`);
- }
- }
- }
- function genAssignmentExpression(node, context) {
- genNode(node.left, context);
- context.push(` = `);
- genNode(node.right, context);
- }
- function genSequenceExpression(node, context) {
- context.push(`(`);
- genNodeList(node.expressions, context);
- context.push(`)`);
- }
- function genReturnStatement({ returns }, context) {
- context.push(`return `);
- if (shared.isArray(returns)) {
- genNodeListAsArray(returns, context);
- } else {
- genNode(returns, context);
- }
- }
- const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
- const transformExpression = (node, context) => {
- if (node.type === 5) {
- node.content = processExpression(
- node.content,
- context
- );
- } else if (node.type === 1) {
- for (let i = 0; i < node.props.length; i++) {
- const dir = node.props[i];
- if (dir.type === 7 && dir.name !== "for") {
- const exp = dir.exp;
- const arg = dir.arg;
- if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
- dir.exp = processExpression(
- exp,
- context,
- // slot args must be processed as function params
- dir.name === "slot"
- );
- }
- if (arg && arg.type === 4 && !arg.isStatic) {
- dir.arg = processExpression(arg, context);
- }
- }
- }
- }
- };
- function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
- if (!context.prefixIdentifiers || !node.content.trim()) {
- return node;
- }
- const { inline, bindingMetadata } = context;
- const rewriteIdentifier = (raw, parent, id) => {
- const type = shared.hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
- if (inline) {
- const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
- const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
- const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
- const isNewExpression = parent && isInNewExpression(parentStack);
- const wrapWithUnref = (raw2) => {
- const wrapped = `${context.helperString(UNREF)}(${raw2})`;
- return isNewExpression ? `(${wrapped})` : wrapped;
- };
- if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
- return raw;
- } else if (type === "setup-ref") {
- return `${raw}.value`;
- } else if (type === "setup-maybe-ref") {
- return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
- } else if (type === "setup-let") {
- if (isAssignmentLVal) {
- const { right: rVal, operator } = parent;
- const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
- const rExpString = stringifyExpression(
- processExpression(
- createSimpleExpression(rExp, false),
- context,
- false,
- false,
- knownIds
- )
- );
- return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
- ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
- } else if (isUpdateArg) {
- id.start = parent.start;
- id.end = parent.end;
- const { prefix: isPrefix, operator } = parent;
- const prefix = isPrefix ? operator : ``;
- const postfix = isPrefix ? `` : operator;
- return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
- ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
- } else if (isDestructureAssignment) {
- return raw;
- } else {
- return wrapWithUnref(raw);
- }
- } else if (type === "props") {
- return shared.genPropsAccessExp(raw);
- } else if (type === "props-aliased") {
- return shared.genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
- }
- } else {
- if (type && type.startsWith("setup") || type === "literal-const") {
- return `$setup.${raw}`;
- } else if (type === "props-aliased") {
- return `$props['${bindingMetadata.__propsAliases[raw]}']`;
- } else if (type) {
- return `$${type}.${raw}`;
- }
- }
- return `_ctx.${raw}`;
- };
- const rawExp = node.content;
- let ast = node.ast;
- if (ast === false) {
- return node;
- }
- if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
- const isScopeVarReference = context.identifiers[rawExp];
- const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
- const isLiteral = isLiteralWhitelisted(rawExp);
- if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
- if (isConst(bindingMetadata[rawExp])) {
- node.constType = 1;
- }
- node.content = rewriteIdentifier(rawExp);
- } else if (!isScopeVarReference) {
- if (isLiteral) {
- node.constType = 3;
- } else {
- node.constType = 2;
- }
- }
- return node;
- }
- if (!ast) {
- const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
- try {
- ast = parser.parseExpression(source, {
- sourceType: "module",
- plugins: context.expressionPlugins
- });
- } catch (e) {
- context.onError(
- createCompilerError(
- 45,
- node.loc,
- void 0,
- e.message
- )
- );
- return node;
- }
- }
- const ids = [];
- const parentStack = [];
- const knownIds = Object.create(context.identifiers);
- walkIdentifiers(
- ast,
- (node2, parent, _, isReferenced, isLocal) => {
- if (isStaticPropertyKey(node2, parent)) {
- return;
- }
- if (node2.name.startsWith("_filter_")) {
- return;
- }
- const needPrefix = isReferenced && canPrefix(node2);
- if (needPrefix && !isLocal) {
- if (isStaticProperty(parent) && parent.shorthand) {
- node2.prefix = `${node2.name}: `;
- }
- node2.name = rewriteIdentifier(node2.name, parent, node2);
- ids.push(node2);
- } else {
- if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
- node2.isConstant = true;
- }
- ids.push(node2);
- }
- },
- true,
- // invoke on ALL identifiers
- parentStack,
- knownIds
- );
- const children = [];
- ids.sort((a, b) => a.start - b.start);
- ids.forEach((id, i) => {
- const start = id.start - 1;
- const end = id.end - 1;
- const last = ids[i - 1];
- const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
- if (leadingText.length || id.prefix) {
- children.push(leadingText + (id.prefix || ``));
- }
- const source = rawExp.slice(start, end);
- children.push(
- createSimpleExpression(
- id.name,
- false,
- {
- start: advancePositionWithClone(node.loc.start, source, start),
- end: advancePositionWithClone(node.loc.start, source, end),
- source
- },
- id.isConstant ? 3 : 0
- )
- );
- if (i === ids.length - 1 && end < rawExp.length) {
- children.push(rawExp.slice(end));
- }
- });
- let ret;
- if (children.length) {
- ret = createCompoundExpression(children, node.loc);
- ret.ast = ast;
- } else {
- ret = node;
- ret.constType = 3;
- }
- ret.identifiers = Object.keys(knownIds);
- return ret;
- }
- function canPrefix(id) {
- if (shared.isGloballyAllowed(id.name)) {
- return false;
- }
- if (id.name === "require") {
- return false;
- }
- return true;
- }
- function stringifyExpression(exp) {
- if (shared.isString(exp)) {
- return exp;
- } else if (exp.type === 4) {
- return exp.content;
- } else {
- return exp.children.map(stringifyExpression).join("");
- }
- }
- function isConst(type) {
- return type === "setup-const" || type === "literal-const";
- }
- const transformIf = createStructuralDirectiveTransform(
- /^(if|else|else-if)$/,
- (node, dir, context) => {
- return processIf(node, dir, context, (ifNode, branch, isRoot) => {
- const siblings = context.parent.children;
- let i = siblings.indexOf(ifNode);
- let key = 0;
- while (i-- >= 0) {
- const sibling = siblings[i];
- if (sibling && sibling.type === 9) {
- key += sibling.branches.length;
- }
- }
- return () => {
- if (isRoot) {
- ifNode.codegenNode = createCodegenNodeForBranch(
- branch,
- key,
- context
- );
- } else {
- const parentCondition = getParentCondition(ifNode.codegenNode);
- parentCondition.alternate = createCodegenNodeForBranch(
- branch,
- key + ifNode.branches.length - 1,
- context
- );
- }
- };
- });
- }
- );
- function processIf(node, dir, context, processCodegen) {
- if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
- const loc = dir.exp ? dir.exp.loc : node.loc;
- context.onError(
- createCompilerError(28, dir.loc)
- );
- dir.exp = createSimpleExpression(`true`, false, loc);
- }
- if (context.prefixIdentifiers && dir.exp) {
- dir.exp = processExpression(dir.exp, context);
- }
- if (dir.name === "if") {
- const branch = createIfBranch(node, dir);
- const ifNode = {
- type: 9,
- loc: cloneLoc(node.loc),
- branches: [branch]
- };
- context.replaceNode(ifNode);
- if (processCodegen) {
- return processCodegen(ifNode, branch, true);
- }
- } else {
- const siblings = context.parent.children;
- let i = siblings.indexOf(node);
- while (i-- >= -1) {
- const sibling = siblings[i];
- if (sibling && sibling.type === 3) {
- context.removeNode(sibling);
- continue;
- }
- if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
- context.removeNode(sibling);
- continue;
- }
- if (sibling && sibling.type === 9) {
- if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
- context.onError(
- createCompilerError(30, node.loc)
- );
- }
- context.removeNode();
- const branch = createIfBranch(node, dir);
- {
- const key = branch.userKey;
- if (key) {
- sibling.branches.forEach(({ userKey }) => {
- if (isSameKey(userKey, key)) {
- context.onError(
- createCompilerError(
- 29,
- branch.userKey.loc
- )
- );
- }
- });
- }
- }
- sibling.branches.push(branch);
- const onExit = processCodegen && processCodegen(sibling, branch, false);
- traverseNode(branch, context);
- if (onExit) onExit();
- context.currentNode = null;
- } else {
- context.onError(
- createCompilerError(30, node.loc)
- );
- }
- break;
- }
- }
- }
- function createIfBranch(node, dir) {
- const isTemplateIf = node.tagType === 3;
- return {
- type: 10,
- loc: node.loc,
- condition: dir.name === "else" ? void 0 : dir.exp,
- children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
- userKey: findProp(node, `key`),
- isTemplateIf
- };
- }
- function createCodegenNodeForBranch(branch, keyIndex, context) {
- if (branch.condition) {
- return createConditionalExpression(
- branch.condition,
- createChildrenCodegenNode(branch, keyIndex, context),
- // make sure to pass in asBlock: true so that the comment node call
- // closes the current block.
- createCallExpression(context.helper(CREATE_COMMENT), [
- '""',
- "true"
- ])
- );
- } else {
- return createChildrenCodegenNode(branch, keyIndex, context);
- }
- }
- function createChildrenCodegenNode(branch, keyIndex, context) {
- const { helper } = context;
- const keyProperty = createObjectProperty(
- `key`,
- createSimpleExpression(
- `${keyIndex}`,
- false,
- locStub,
- 2
- )
- );
- const { children } = branch;
- const firstChild = children[0];
- const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
- if (needFragmentWrapper) {
- if (children.length === 1 && firstChild.type === 11) {
- const vnodeCall = firstChild.codegenNode;
- injectProp(vnodeCall, keyProperty, context);
- return vnodeCall;
- } else {
- let patchFlag = 64;
- return createVNodeCall(
- context,
- helper(FRAGMENT),
- createObjectExpression([keyProperty]),
- children,
- patchFlag,
- void 0,
- void 0,
- true,
- false,
- false,
- branch.loc
- );
- }
- } else {
- const ret = firstChild.codegenNode;
- const vnodeCall = getMemoedVNodeCall(ret);
- if (vnodeCall.type === 13) {
- convertToBlock(vnodeCall, context);
- }
- injectProp(vnodeCall, keyProperty, context);
- return ret;
- }
- }
- function isSameKey(a, b) {
- if (!a || a.type !== b.type) {
- return false;
- }
- if (a.type === 6) {
- if (a.value.content !== b.value.content) {
- return false;
- }
- } else {
- const exp = a.exp;
- const branchExp = b.exp;
- if (exp.type !== branchExp.type) {
- return false;
- }
- if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
- return false;
- }
- }
- return true;
- }
- function getParentCondition(node) {
- while (true) {
- if (node.type === 19) {
- if (node.alternate.type === 19) {
- node = node.alternate;
- } else {
- return node;
- }
- } else if (node.type === 20) {
- node = node.value;
- }
- }
- }
- const transformBind = (dir, _node, context) => {
- const { modifiers, loc } = dir;
- const arg = dir.arg;
- let { exp } = dir;
- if (exp && exp.type === 4 && !exp.content.trim()) {
- {
- context.onError(
- createCompilerError(34, loc)
- );
- return {
- props: [
- createObjectProperty(arg, createSimpleExpression("", true, loc))
- ]
- };
- }
- }
- if (!exp) {
- if (arg.type !== 4 || !arg.isStatic) {
- context.onError(
- createCompilerError(
- 52,
- arg.loc
- )
- );
- return {
- props: [
- createObjectProperty(arg, createSimpleExpression("", true, loc))
- ]
- };
- }
- transformBindShorthand(dir, context);
- exp = dir.exp;
- }
- if (arg.type !== 4) {
- arg.children.unshift(`(`);
- arg.children.push(`) || ""`);
- } else if (!arg.isStatic) {
- arg.content = `${arg.content} || ""`;
- }
- if (modifiers.some((mod) => mod.content === "camel")) {
- if (arg.type === 4) {
- if (arg.isStatic) {
- arg.content = shared.camelize(arg.content);
- } else {
- arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
- }
- } else {
- arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
- arg.children.push(`)`);
- }
- }
- if (!context.inSSR) {
- if (modifiers.some((mod) => mod.content === "prop")) {
- injectPrefix(arg, ".");
- }
- if (modifiers.some((mod) => mod.content === "attr")) {
- injectPrefix(arg, "^");
- }
- }
- return {
- props: [createObjectProperty(arg, exp)]
- };
- };
- const transformBindShorthand = (dir, context) => {
- const arg = dir.arg;
- const propName = shared.camelize(arg.content);
- dir.exp = createSimpleExpression(propName, false, arg.loc);
- {
- dir.exp = processExpression(dir.exp, context);
- }
- };
- const injectPrefix = (arg, prefix) => {
- if (arg.type === 4) {
- if (arg.isStatic) {
- arg.content = prefix + arg.content;
- } else {
- arg.content = `\`${prefix}\${${arg.content}}\``;
- }
- } else {
- arg.children.unshift(`'${prefix}' + (`);
- arg.children.push(`)`);
- }
- };
- const transformFor = createStructuralDirectiveTransform(
- "for",
- (node, dir, context) => {
- const { helper, removeHelper } = context;
- return processFor(node, dir, context, (forNode) => {
- const renderExp = createCallExpression(helper(RENDER_LIST), [
- forNode.source
- ]);
- const isTemplate = isTemplateNode(node);
- const memo = findDir(node, "memo");
- const keyProp = findProp(node, `key`, false, true);
- if (keyProp && keyProp.type === 7 && !keyProp.exp) {
- transformBindShorthand(keyProp, context);
- }
- const keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
- const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
- if (isTemplate) {
- if (memo) {
- memo.exp = processExpression(
- memo.exp,
- context
- );
- }
- if (keyProperty && keyProp.type !== 6) {
- keyProperty.value = processExpression(
- keyProperty.value,
- context
- );
- }
- }
- const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
- const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
- forNode.codegenNode = createVNodeCall(
- context,
- helper(FRAGMENT),
- void 0,
- renderExp,
- fragmentFlag,
- void 0,
- void 0,
- true,
- !isStableFragment,
- false,
- node.loc
- );
- return () => {
- let childBlock;
- const { children } = forNode;
- if (isTemplate) {
- node.children.some((c) => {
- if (c.type === 1) {
- const key = findProp(c, "key");
- if (key) {
- context.onError(
- createCompilerError(
- 33,
- key.loc
- )
- );
- return true;
- }
- }
- });
- }
- const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
- const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
- if (slotOutlet) {
- childBlock = slotOutlet.codegenNode;
- if (isTemplate && keyProperty) {
- injectProp(childBlock, keyProperty, context);
- }
- } else if (needFragmentWrapper) {
- childBlock = createVNodeCall(
- context,
- helper(FRAGMENT),
- keyProperty ? createObjectExpression([keyProperty]) : void 0,
- node.children,
- 64,
- void 0,
- void 0,
- true,
- void 0,
- false
- );
- } else {
- childBlock = children[0].codegenNode;
- if (isTemplate && keyProperty) {
- injectProp(childBlock, keyProperty, context);
- }
- if (childBlock.isBlock !== !isStableFragment) {
- if (childBlock.isBlock) {
- removeHelper(OPEN_BLOCK);
- removeHelper(
- getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
- );
- } else {
- removeHelper(
- getVNodeHelper(context.inSSR, childBlock.isComponent)
- );
- }
- }
- childBlock.isBlock = !isStableFragment;
- if (childBlock.isBlock) {
- helper(OPEN_BLOCK);
- helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
- } else {
- helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
- }
- }
- if (memo) {
- const loop = createFunctionExpression(
- createForLoopParams(forNode.parseResult, [
- createSimpleExpression(`_cached`)
- ])
- );
- loop.body = createBlockStatement([
- createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
- createCompoundExpression([
- `if (_cached`,
- ...keyExp ? [` && _cached.key === `, keyExp] : [],
- ` && ${context.helperString(
- IS_MEMO_SAME
- )}(_cached, _memo)) return _cached`
- ]),
- createCompoundExpression([`const _item = `, childBlock]),
- createSimpleExpression(`_item.memo = _memo`),
- createSimpleExpression(`return _item`)
- ]);
- renderExp.arguments.push(
- loop,
- createSimpleExpression(`_cache`),
- createSimpleExpression(String(context.cached.length))
- );
- context.cached.push(null);
- } else {
- renderExp.arguments.push(
- createFunctionExpression(
- createForLoopParams(forNode.parseResult),
- childBlock,
- true
- )
- );
- }
- };
- });
- }
- );
- function processFor(node, dir, context, processCodegen) {
- if (!dir.exp) {
- context.onError(
- createCompilerError(31, dir.loc)
- );
- return;
- }
- const parseResult = dir.forParseResult;
- if (!parseResult) {
- context.onError(
- createCompilerError(32, dir.loc)
- );
- return;
- }
- finalizeForParseResult(parseResult, context);
- const { addIdentifiers, removeIdentifiers, scopes } = context;
- const { source, value, key, index } = parseResult;
- const forNode = {
- type: 11,
- loc: dir.loc,
- source,
- valueAlias: value,
- keyAlias: key,
- objectIndexAlias: index,
- parseResult,
- children: isTemplateNode(node) ? node.children : [node]
- };
- context.replaceNode(forNode);
- scopes.vFor++;
- if (context.prefixIdentifiers) {
- value && addIdentifiers(value);
- key && addIdentifiers(key);
- index && addIdentifiers(index);
- }
- const onExit = processCodegen && processCodegen(forNode);
- return () => {
- scopes.vFor--;
- if (context.prefixIdentifiers) {
- value && removeIdentifiers(value);
- key && removeIdentifiers(key);
- index && removeIdentifiers(index);
- }
- if (onExit) onExit();
- };
- }
- function finalizeForParseResult(result, context) {
- if (result.finalized) return;
- if (context.prefixIdentifiers) {
- result.source = processExpression(
- result.source,
- context
- );
- if (result.key) {
- result.key = processExpression(
- result.key,
- context,
- true
- );
- }
- if (result.index) {
- result.index = processExpression(
- result.index,
- context,
- true
- );
- }
- if (result.value) {
- result.value = processExpression(
- result.value,
- context,
- true
- );
- }
- }
- result.finalized = true;
- }
- function createForLoopParams({ value, key, index }, memoArgs = []) {
- return createParamsList([value, key, index, ...memoArgs]);
- }
- function createParamsList(args) {
- let i = args.length;
- while (i--) {
- if (args[i]) break;
- }
- return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
- }
- const defaultFallback = createSimpleExpression(`undefined`, false);
- const trackSlotScopes = (node, context) => {
- if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
- const vSlot = findDir(node, "slot");
- if (vSlot) {
- const slotProps = vSlot.exp;
- if (context.prefixIdentifiers) {
- slotProps && context.addIdentifiers(slotProps);
- }
- context.scopes.vSlot++;
- return () => {
- if (context.prefixIdentifiers) {
- slotProps && context.removeIdentifiers(slotProps);
- }
- context.scopes.vSlot--;
- };
- }
- }
- };
- const trackVForSlotScopes = (node, context) => {
- let vFor;
- if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
- const result = vFor.forParseResult;
- if (result) {
- finalizeForParseResult(result, context);
- const { value, key, index } = result;
- const { addIdentifiers, removeIdentifiers } = context;
- value && addIdentifiers(value);
- key && addIdentifiers(key);
- index && addIdentifiers(index);
- return () => {
- value && removeIdentifiers(value);
- key && removeIdentifiers(key);
- index && removeIdentifiers(index);
- };
- }
- }
- };
- const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
- props,
- children,
- false,
- true,
- children.length ? children[0].loc : loc
- );
- function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
- context.helper(WITH_CTX);
- const { children, loc } = node;
- const slotsProperties = [];
- const dynamicSlots = [];
- let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
- if (!context.ssr && context.prefixIdentifiers) {
- hasDynamicSlots = hasScopeRef(node, context.identifiers);
- }
- const onComponentSlot = findDir(node, "slot", true);
- if (onComponentSlot) {
- const { arg, exp } = onComponentSlot;
- if (arg && !isStaticExp(arg)) {
- hasDynamicSlots = true;
- }
- slotsProperties.push(
- createObjectProperty(
- arg || createSimpleExpression("default", true),
- buildSlotFn(exp, void 0, children, loc)
- )
- );
- }
- let hasTemplateSlots = false;
- let hasNamedDefaultSlot = false;
- const implicitDefaultChildren = [];
- const seenSlotNames = /* @__PURE__ */ new Set();
- let conditionalBranchIndex = 0;
- for (let i = 0; i < children.length; i++) {
- const slotElement = children[i];
- let slotDir;
- if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
- if (slotElement.type !== 3) {
- implicitDefaultChildren.push(slotElement);
- }
- continue;
- }
- if (onComponentSlot) {
- context.onError(
- createCompilerError(37, slotDir.loc)
- );
- break;
- }
- hasTemplateSlots = true;
- const { children: slotChildren, loc: slotLoc } = slotElement;
- const {
- arg: slotName = createSimpleExpression(`default`, true),
- exp: slotProps,
- loc: dirLoc
- } = slotDir;
- let staticSlotName;
- if (isStaticExp(slotName)) {
- staticSlotName = slotName ? slotName.content : `default`;
- } else {
- hasDynamicSlots = true;
- }
- const vFor = findDir(slotElement, "for");
- const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
- let vIf;
- let vElse;
- if (vIf = findDir(slotElement, "if")) {
- hasDynamicSlots = true;
- dynamicSlots.push(
- createConditionalExpression(
- vIf.exp,
- buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
- defaultFallback
- )
- );
- } else if (vElse = findDir(
- slotElement,
- /^else(-if)?$/,
- true
- /* allowEmpty */
- )) {
- let j = i;
- let prev;
- while (j--) {
- prev = children[j];
- if (prev.type !== 3) {
- break;
- }
- }
- if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
- let conditional = dynamicSlots[dynamicSlots.length - 1];
- while (conditional.alternate.type === 19) {
- conditional = conditional.alternate;
- }
- conditional.alternate = vElse.exp ? createConditionalExpression(
- vElse.exp,
- buildDynamicSlot(
- slotName,
- slotFunction,
- conditionalBranchIndex++
- ),
- defaultFallback
- ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
- } else {
- context.onError(
- createCompilerError(30, vElse.loc)
- );
- }
- } else if (vFor) {
- hasDynamicSlots = true;
- const parseResult = vFor.forParseResult;
- if (parseResult) {
- finalizeForParseResult(parseResult, context);
- dynamicSlots.push(
- createCallExpression(context.helper(RENDER_LIST), [
- parseResult.source,
- createFunctionExpression(
- createForLoopParams(parseResult),
- buildDynamicSlot(slotName, slotFunction),
- true
- )
- ])
- );
- } else {
- context.onError(
- createCompilerError(
- 32,
- vFor.loc
- )
- );
- }
- } else {
- if (staticSlotName) {
- if (seenSlotNames.has(staticSlotName)) {
- context.onError(
- createCompilerError(
- 38,
- dirLoc
- )
- );
- continue;
- }
- seenSlotNames.add(staticSlotName);
- if (staticSlotName === "default") {
- hasNamedDefaultSlot = true;
- }
- }
- slotsProperties.push(createObjectProperty(slotName, slotFunction));
- }
- }
- if (!onComponentSlot) {
- const buildDefaultSlotProperty = (props, children2) => {
- const fn = buildSlotFn(props, void 0, children2, loc);
- if (context.compatConfig) {
- fn.isNonScopedSlot = true;
- }
- return createObjectProperty(`default`, fn);
- };
- if (!hasTemplateSlots) {
- slotsProperties.push(buildDefaultSlotProperty(void 0, children));
- } else if (implicitDefaultChildren.length && // #3766
- // with whitespace: 'preserve', whitespaces between slots will end up in
- // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
- implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
- if (hasNamedDefaultSlot) {
- context.onError(
- createCompilerError(
- 39,
- implicitDefaultChildren[0].loc
- )
- );
- } else {
- slotsProperties.push(
- buildDefaultSlotProperty(void 0, implicitDefaultChildren)
- );
- }
- }
- }
- const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
- let slots = createObjectExpression(
- slotsProperties.concat(
- createObjectProperty(
- `_`,
- // 2 = compiled but dynamic = can skip normalization, but must run diff
- // 1 = compiled and static = can skip normalization AND diff as optimized
- createSimpleExpression(
- slotFlag + (``),
- false
- )
- )
- ),
- loc
- );
- if (dynamicSlots.length) {
- slots = createCallExpression(context.helper(CREATE_SLOTS), [
- slots,
- createArrayExpression(dynamicSlots)
- ]);
- }
- return {
- slots,
- hasDynamicSlots
- };
- }
- function buildDynamicSlot(name, fn, index) {
- const props = [
- createObjectProperty(`name`, name),
- createObjectProperty(`fn`, fn)
- ];
- if (index != null) {
- props.push(
- createObjectProperty(`key`, createSimpleExpression(String(index), true))
- );
- }
- return createObjectExpression(props);
- }
- function hasForwardedSlots(children) {
- for (let i = 0; i < children.length; i++) {
- const child = children[i];
- switch (child.type) {
- case 1:
- if (child.tagType === 2 || hasForwardedSlots(child.children)) {
- return true;
- }
- break;
- case 9:
- if (hasForwardedSlots(child.branches)) return true;
- break;
- case 10:
- case 11:
- if (hasForwardedSlots(child.children)) return true;
- break;
- }
- }
- return false;
- }
- function isNonWhitespaceContent(node) {
- if (node.type !== 2 && node.type !== 12)
- return true;
- return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
- }
- const directiveImportMap = /* @__PURE__ */ new WeakMap();
- const transformElement = (node, context) => {
- return function postTransformElement() {
- node = context.currentNode;
- if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
- return;
- }
- const { tag, props } = node;
- const isComponent = node.tagType === 1;
- let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
- const isDynamicComponent = shared.isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
- let vnodeProps;
- let vnodeChildren;
- let patchFlag = 0;
- let vnodeDynamicProps;
- let dynamicPropNames;
- let vnodeDirectives;
- let shouldUseBlock = (
- // dynamic component may resolve to plain elements
- isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
- // updates inside get proper isSVG flag at runtime. (#639, #643)
- // This is technically web-specific, but splitting the logic out of core
- // leads to too much unnecessary complexity.
- (tag === "svg" || tag === "foreignObject" || tag === "math")
- );
- if (props.length > 0) {
- const propsBuildResult = buildProps(
- node,
- context,
- void 0,
- isComponent,
- isDynamicComponent
- );
- vnodeProps = propsBuildResult.props;
- patchFlag = propsBuildResult.patchFlag;
- dynamicPropNames = propsBuildResult.dynamicPropNames;
- const directives = propsBuildResult.directives;
- vnodeDirectives = directives && directives.length ? createArrayExpression(
- directives.map((dir) => buildDirectiveArgs(dir, context))
- ) : void 0;
- if (propsBuildResult.shouldUseBlock) {
- shouldUseBlock = true;
- }
- }
- if (node.children.length > 0) {
- if (vnodeTag === KEEP_ALIVE) {
- shouldUseBlock = true;
- patchFlag |= 1024;
- }
- const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
- vnodeTag !== TELEPORT && // explained above.
- vnodeTag !== KEEP_ALIVE;
- if (shouldBuildAsSlots) {
- const { slots, hasDynamicSlots } = buildSlots(node, context);
- vnodeChildren = slots;
- if (hasDynamicSlots) {
- patchFlag |= 1024;
- }
- } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
- const child = node.children[0];
- const type = child.type;
- const hasDynamicTextChild = type === 5 || type === 8;
- if (hasDynamicTextChild && getConstantType(child, context) === 0) {
- patchFlag |= 1;
- }
- if (hasDynamicTextChild || type === 2) {
- vnodeChildren = child;
- } else {
- vnodeChildren = node.children;
- }
- } else {
- vnodeChildren = node.children;
- }
- }
- if (dynamicPropNames && dynamicPropNames.length) {
- vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
- }
- node.codegenNode = createVNodeCall(
- context,
- vnodeTag,
- vnodeProps,
- vnodeChildren,
- patchFlag === 0 ? void 0 : patchFlag,
- vnodeDynamicProps,
- vnodeDirectives,
- !!shouldUseBlock,
- false,
- isComponent,
- node.loc
- );
- };
- };
- function resolveComponentType(node, context, ssr = false) {
- let { tag } = node;
- const isExplicitDynamic = isComponentTag(tag);
- const isProp = findProp(
- node,
- "is",
- false,
- true
- /* allow empty */
- );
- if (isProp) {
- if (isExplicitDynamic || isCompatEnabled(
- "COMPILER_IS_ON_ELEMENT",
- context
- )) {
- let exp;
- if (isProp.type === 6) {
- exp = isProp.value && createSimpleExpression(isProp.value.content, true);
- } else {
- exp = isProp.exp;
- if (!exp) {
- exp = createSimpleExpression(`is`, false, isProp.arg.loc);
- {
- exp = isProp.exp = processExpression(exp, context);
- }
- }
- }
- if (exp) {
- return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
- exp
- ]);
- }
- } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
- tag = isProp.value.content.slice(4);
- }
- }
- const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
- if (builtIn) {
- if (!ssr) context.helper(builtIn);
- return builtIn;
- }
- {
- const fromSetup = resolveSetupReference(tag, context);
- if (fromSetup) {
- return fromSetup;
- }
- const dotIndex = tag.indexOf(".");
- if (dotIndex > 0) {
- const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
- if (ns) {
- return ns + tag.slice(dotIndex);
- }
- }
- }
- if (context.selfName && shared.capitalize(shared.camelize(tag)) === context.selfName) {
- context.helper(RESOLVE_COMPONENT);
- context.components.add(tag + `__self`);
- return toValidAssetId(tag, `component`);
- }
- context.helper(RESOLVE_COMPONENT);
- context.components.add(tag);
- return toValidAssetId(tag, `component`);
- }
- function resolveSetupReference(name, context) {
- const bindings = context.bindingMetadata;
- if (!bindings || bindings.__isScriptSetup === false) {
- return;
- }
- const camelName = shared.camelize(name);
- const PascalName = shared.capitalize(camelName);
- const checkType = (type) => {
- if (bindings[name] === type) {
- return name;
- }
- if (bindings[camelName] === type) {
- return camelName;
- }
- if (bindings[PascalName] === type) {
- return PascalName;
- }
- };
- const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
- if (fromConst) {
- return context.inline ? (
- // in inline mode, const setup bindings (e.g. imports) can be used as-is
- fromConst
- ) : `$setup[${JSON.stringify(fromConst)}]`;
- }
- const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
- if (fromMaybeRef) {
- return context.inline ? (
- // setup scope bindings that may be refs need to be unrefed
- `${context.helperString(UNREF)}(${fromMaybeRef})`
- ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
- }
- const fromProps = checkType("props");
- if (fromProps) {
- return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
- }
- }
- function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
- const { tag, loc: elementLoc, children } = node;
- let properties = [];
- const mergeArgs = [];
- const runtimeDirectives = [];
- const hasChildren = children.length > 0;
- let shouldUseBlock = false;
- let patchFlag = 0;
- let hasRef = false;
- let hasClassBinding = false;
- let hasStyleBinding = false;
- let hasHydrationEventBinding = false;
- let hasDynamicKeys = false;
- let hasVnodeHook = false;
- const dynamicPropNames = [];
- const pushMergeArg = (arg) => {
- if (properties.length) {
- mergeArgs.push(
- createObjectExpression(dedupeProperties(properties), elementLoc)
- );
- properties = [];
- }
- if (arg) mergeArgs.push(arg);
- };
- const pushRefVForMarker = () => {
- if (context.scopes.vFor > 0) {
- properties.push(
- createObjectProperty(
- createSimpleExpression("ref_for", true),
- createSimpleExpression("true")
- )
- );
- }
- };
- const analyzePatchFlag = ({ key, value }) => {
- if (isStaticExp(key)) {
- const name = key.content;
- const isEventHandler = shared.isOn(name);
- if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
- // dedicated fast path.
- name.toLowerCase() !== "onclick" && // omit v-model handlers
- name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
- !shared.isReservedProp(name)) {
- hasHydrationEventBinding = true;
- }
- if (isEventHandler && shared.isReservedProp(name)) {
- hasVnodeHook = true;
- }
- if (isEventHandler && value.type === 14) {
- value = value.arguments[0];
- }
- if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
- return;
- }
- if (name === "ref") {
- hasRef = true;
- } else if (name === "class") {
- hasClassBinding = true;
- } else if (name === "style") {
- hasStyleBinding = true;
- } else if (name !== "key" && !dynamicPropNames.includes(name)) {
- dynamicPropNames.push(name);
- }
- if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
- dynamicPropNames.push(name);
- }
- } else {
- hasDynamicKeys = true;
- }
- };
- for (let i = 0; i < props.length; i++) {
- const prop = props[i];
- if (prop.type === 6) {
- const { loc, name, nameLoc, value } = prop;
- let isStatic = true;
- if (name === "ref") {
- hasRef = true;
- pushRefVForMarker();
- if (value && context.inline) {
- const binding = context.bindingMetadata[value.content];
- if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
- isStatic = false;
- properties.push(
- createObjectProperty(
- createSimpleExpression("ref_key", true),
- createSimpleExpression(value.content, true, value.loc)
- )
- );
- }
- }
- }
- if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
- "COMPILER_IS_ON_ELEMENT",
- context
- ))) {
- continue;
- }
- properties.push(
- createObjectProperty(
- createSimpleExpression(name, true, nameLoc),
- createSimpleExpression(
- value ? value.content : "",
- isStatic,
- value ? value.loc : loc
- )
- )
- );
- } else {
- const { name, arg, exp, loc, modifiers } = prop;
- const isVBind = name === "bind";
- const isVOn = name === "on";
- if (name === "slot") {
- if (!isComponent) {
- context.onError(
- createCompilerError(40, loc)
- );
- }
- continue;
- }
- if (name === "once" || name === "memo") {
- continue;
- }
- if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
- "COMPILER_IS_ON_ELEMENT",
- context
- ))) {
- continue;
- }
- if (isVOn && ssr) {
- continue;
- }
- if (
- // #938: elements with dynamic keys should be forced into blocks
- isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
- // before children
- isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
- ) {
- shouldUseBlock = true;
- }
- if (isVBind && isStaticArgOf(arg, "ref")) {
- pushRefVForMarker();
- }
- if (!arg && (isVBind || isVOn)) {
- hasDynamicKeys = true;
- if (exp) {
- if (isVBind) {
- pushRefVForMarker();
- pushMergeArg();
- {
- if (isCompatEnabled(
- "COMPILER_V_BIND_OBJECT_ORDER",
- context
- )) {
- mergeArgs.unshift(exp);
- continue;
- }
- }
- mergeArgs.push(exp);
- } else {
- pushMergeArg({
- type: 14,
- loc,
- callee: context.helper(TO_HANDLERS),
- arguments: isComponent ? [exp] : [exp, `true`]
- });
- }
- } else {
- context.onError(
- createCompilerError(
- isVBind ? 34 : 35,
- loc
- )
- );
- }
- continue;
- }
- if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
- patchFlag |= 32;
- }
- const directiveTransform = context.directiveTransforms[name];
- if (directiveTransform) {
- const { props: props2, needRuntime } = directiveTransform(prop, node, context);
- !ssr && props2.forEach(analyzePatchFlag);
- if (isVOn && arg && !isStaticExp(arg)) {
- pushMergeArg(createObjectExpression(props2, elementLoc));
- } else {
- properties.push(...props2);
- }
- if (needRuntime) {
- runtimeDirectives.push(prop);
- if (shared.isSymbol(needRuntime)) {
- directiveImportMap.set(prop, needRuntime);
- }
- }
- } else if (!shared.isBuiltInDirective(name)) {
- runtimeDirectives.push(prop);
- if (hasChildren) {
- shouldUseBlock = true;
- }
- }
- }
- }
- let propsExpression = void 0;
- if (mergeArgs.length) {
- pushMergeArg();
- if (mergeArgs.length > 1) {
- propsExpression = createCallExpression(
- context.helper(MERGE_PROPS),
- mergeArgs,
- elementLoc
- );
- } else {
- propsExpression = mergeArgs[0];
- }
- } else if (properties.length) {
- propsExpression = createObjectExpression(
- dedupeProperties(properties),
- elementLoc
- );
- }
- if (hasDynamicKeys) {
- patchFlag |= 16;
- } else {
- if (hasClassBinding && !isComponent) {
- patchFlag |= 2;
- }
- if (hasStyleBinding && !isComponent) {
- patchFlag |= 4;
- }
- if (dynamicPropNames.length) {
- patchFlag |= 8;
- }
- if (hasHydrationEventBinding) {
- patchFlag |= 32;
- }
- }
- if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
- patchFlag |= 512;
- }
- if (!context.inSSR && propsExpression) {
- switch (propsExpression.type) {
- case 15:
- let classKeyIndex = -1;
- let styleKeyIndex = -1;
- let hasDynamicKey = false;
- for (let i = 0; i < propsExpression.properties.length; i++) {
- const key = propsExpression.properties[i].key;
- if (isStaticExp(key)) {
- if (key.content === "class") {
- classKeyIndex = i;
- } else if (key.content === "style") {
- styleKeyIndex = i;
- }
- } else if (!key.isHandlerKey) {
- hasDynamicKey = true;
- }
- }
- const classProp = propsExpression.properties[classKeyIndex];
- const styleProp = propsExpression.properties[styleKeyIndex];
- if (!hasDynamicKey) {
- if (classProp && !isStaticExp(classProp.value)) {
- classProp.value = createCallExpression(
- context.helper(NORMALIZE_CLASS),
- [classProp.value]
- );
- }
- if (styleProp && // the static style is compiled into an object,
- // so use `hasStyleBinding` to ensure that it is a dynamic style binding
- (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
- // v-bind:style with static literal object
- styleProp.value.type === 17)) {
- styleProp.value = createCallExpression(
- context.helper(NORMALIZE_STYLE),
- [styleProp.value]
- );
- }
- } else {
- propsExpression = createCallExpression(
- context.helper(NORMALIZE_PROPS),
- [propsExpression]
- );
- }
- break;
- case 14:
- break;
- default:
- propsExpression = createCallExpression(
- context.helper(NORMALIZE_PROPS),
- [
- createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
- propsExpression
- ])
- ]
- );
- break;
- }
- }
- return {
- props: propsExpression,
- directives: runtimeDirectives,
- patchFlag,
- dynamicPropNames,
- shouldUseBlock
- };
- }
- function dedupeProperties(properties) {
- const knownProps = /* @__PURE__ */ new Map();
- const deduped = [];
- for (let i = 0; i < properties.length; i++) {
- const prop = properties[i];
- if (prop.key.type === 8 || !prop.key.isStatic) {
- deduped.push(prop);
- continue;
- }
- const name = prop.key.content;
- const existing = knownProps.get(name);
- if (existing) {
- if (name === "style" || name === "class" || shared.isOn(name)) {
- mergeAsArray(existing, prop);
- }
- } else {
- knownProps.set(name, prop);
- deduped.push(prop);
- }
- }
- return deduped;
- }
- function mergeAsArray(existing, incoming) {
- if (existing.value.type === 17) {
- existing.value.elements.push(incoming.value);
- } else {
- existing.value = createArrayExpression(
- [existing.value, incoming.value],
- existing.loc
- );
- }
- }
- function buildDirectiveArgs(dir, context) {
- const dirArgs = [];
- const runtime = directiveImportMap.get(dir);
- if (runtime) {
- dirArgs.push(context.helperString(runtime));
- } else {
- const fromSetup = resolveSetupReference("v-" + dir.name, context);
- if (fromSetup) {
- dirArgs.push(fromSetup);
- } else {
- context.helper(RESOLVE_DIRECTIVE);
- context.directives.add(dir.name);
- dirArgs.push(toValidAssetId(dir.name, `directive`));
- }
- }
- const { loc } = dir;
- if (dir.exp) dirArgs.push(dir.exp);
- if (dir.arg) {
- if (!dir.exp) {
- dirArgs.push(`void 0`);
- }
- dirArgs.push(dir.arg);
- }
- if (Object.keys(dir.modifiers).length) {
- if (!dir.arg) {
- if (!dir.exp) {
- dirArgs.push(`void 0`);
- }
- dirArgs.push(`void 0`);
- }
- const trueExpression = createSimpleExpression(`true`, false, loc);
- dirArgs.push(
- createObjectExpression(
- dir.modifiers.map(
- (modifier) => createObjectProperty(modifier, trueExpression)
- ),
- loc
- )
- );
- }
- return createArrayExpression(dirArgs, dir.loc);
- }
- function stringifyDynamicPropNames(props) {
- let propsNamesString = `[`;
- for (let i = 0, l = props.length; i < l; i++) {
- propsNamesString += JSON.stringify(props[i]);
- if (i < l - 1) propsNamesString += ", ";
- }
- return propsNamesString + `]`;
- }
- function isComponentTag(tag) {
- return tag === "component" || tag === "Component";
- }
- const transformSlotOutlet = (node, context) => {
- if (isSlotOutlet(node)) {
- const { children, loc } = node;
- const { slotName, slotProps } = processSlotOutlet(node, context);
- const slotArgs = [
- context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
- slotName,
- "{}",
- "undefined",
- "true"
- ];
- let expectedLen = 2;
- if (slotProps) {
- slotArgs[2] = slotProps;
- expectedLen = 3;
- }
- if (children.length) {
- slotArgs[3] = createFunctionExpression([], children, false, false, loc);
- expectedLen = 4;
- }
- if (context.scopeId && !context.slotted) {
- expectedLen = 5;
- }
- slotArgs.splice(expectedLen);
- node.codegenNode = createCallExpression(
- context.helper(RENDER_SLOT),
- slotArgs,
- loc
- );
- }
- };
- function processSlotOutlet(node, context) {
- let slotName = `"default"`;
- let slotProps = void 0;
- const nonNameProps = [];
- for (let i = 0; i < node.props.length; i++) {
- const p = node.props[i];
- if (p.type === 6) {
- if (p.value) {
- if (p.name === "name") {
- slotName = JSON.stringify(p.value.content);
- } else {
- p.name = shared.camelize(p.name);
- nonNameProps.push(p);
- }
- }
- } else {
- if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
- if (p.exp) {
- slotName = p.exp;
- } else if (p.arg && p.arg.type === 4) {
- const name = shared.camelize(p.arg.content);
- slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
- {
- slotName = p.exp = processExpression(p.exp, context);
- }
- }
- } else {
- if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
- p.arg.content = shared.camelize(p.arg.content);
- }
- nonNameProps.push(p);
- }
- }
- }
- if (nonNameProps.length > 0) {
- const { props, directives } = buildProps(
- node,
- context,
- nonNameProps,
- false,
- false
- );
- slotProps = props;
- if (directives.length) {
- context.onError(
- createCompilerError(
- 36,
- directives[0].loc
- )
- );
- }
- }
- return {
- slotName,
- slotProps
- };
- }
- const transformOn = (dir, node, context, augmentor) => {
- const { loc, modifiers, arg } = dir;
- if (!dir.exp && !modifiers.length) {
- context.onError(createCompilerError(35, loc));
- }
- let eventName;
- if (arg.type === 4) {
- if (arg.isStatic) {
- let rawName = arg.content;
- if (rawName.startsWith("vue:")) {
- rawName = `vnode-${rawName.slice(4)}`;
- }
- const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
- // for non-element and vnode lifecycle event listeners, auto convert
- // it to camelCase. See issue #2249
- shared.toHandlerKey(shared.camelize(rawName))
- ) : (
- // preserve case for plain element listeners that have uppercase
- // letters, as these may be custom elements' custom events
- `on:${rawName}`
- );
- eventName = createSimpleExpression(eventString, true, arg.loc);
- } else {
- eventName = createCompoundExpression([
- `${context.helperString(TO_HANDLER_KEY)}(`,
- arg,
- `)`
- ]);
- }
- } else {
- eventName = arg;
- eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
- eventName.children.push(`)`);
- }
- let exp = dir.exp;
- if (exp && !exp.content.trim()) {
- exp = void 0;
- }
- let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
- if (exp) {
- const isMemberExp = isMemberExpression(exp, context);
- const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
- const hasMultipleStatements = exp.content.includes(`;`);
- if (context.prefixIdentifiers) {
- isInlineStatement && context.addIdentifiers(`$event`);
- exp = dir.exp = processExpression(
- exp,
- context,
- false,
- hasMultipleStatements
- );
- isInlineStatement && context.removeIdentifiers(`$event`);
- shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
- !context.inVOnce && // runtime constants don't need to be cached
- // (this is analyzed by compileScript in SFC <script setup>)
- !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
- // we need to use the original function to preserve arity,
- // e.g. <transition> relies on checking cb.length to determine
- // transition end handling. Inline function is ok since its arity
- // is preserved even when cached.
- !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
- // it must be passed fresh to avoid stale values.
- !hasScopeRef(exp, context.identifiers);
- if (shouldCache && isMemberExp) {
- if (exp.type === 4) {
- exp.content = `${exp.content} && ${exp.content}(...args)`;
- } else {
- exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
- }
- }
- }
- if (isInlineStatement || shouldCache && isMemberExp) {
- exp = createCompoundExpression([
- `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
- //@ts-ignore
- ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
- exp,
- hasMultipleStatements ? `}` : `)`
- ]);
- }
- }
- let ret = {
- props: [
- createObjectProperty(
- eventName,
- exp || createSimpleExpression(`() => {}`, false, loc)
- )
- ]
- };
- if (augmentor) {
- ret = augmentor(ret);
- }
- if (shouldCache) {
- ret.props[0].value = context.cache(ret.props[0].value);
- }
- ret.props.forEach((p) => p.key.isHandlerKey = true);
- return ret;
- };
- const transformText = (node, context) => {
- if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
- return () => {
- const children = node.children;
- let currentContainer = void 0;
- let hasText = false;
- for (let i = 0; i < children.length; i++) {
- const child = children[i];
- if (isText$1(child)) {
- hasText = true;
- for (let j = i + 1; j < children.length; j++) {
- const next = children[j];
- if (isText$1(next)) {
- if (!currentContainer) {
- currentContainer = children[i] = createCompoundExpression(
- [child],
- child.loc
- );
- }
- currentContainer.children.push(` + `, next);
- children.splice(j, 1);
- j--;
- } else {
- currentContainer = void 0;
- break;
- }
- }
- }
- }
- if (!hasText || // if this is a plain element with a single text child, leave it
- // as-is since the runtime has dedicated fast path for this by directly
- // setting textContent of the element.
- // for component root it's always normalized anyway.
- children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
- // custom directives can potentially add DOM elements arbitrarily,
- // we need to avoid setting textContent of the element at runtime
- // to avoid accidentally overwriting the DOM elements added
- // by the user through custom directives.
- !node.props.find(
- (p) => p.type === 7 && !context.directiveTransforms[p.name]
- ) && // in compat mode, <template> tags with no special directives
- // will be rendered as a fragment so its children must be
- // converted into vnodes.
- !(node.tag === "template"))) {
- return;
- }
- for (let i = 0; i < children.length; i++) {
- const child = children[i];
- if (isText$1(child) || child.type === 8) {
- const callArgs = [];
- if (child.type !== 2 || child.content !== " ") {
- callArgs.push(child);
- }
- if (!context.ssr && getConstantType(child, context) === 0) {
- callArgs.push(
- 1 + (``)
- );
- }
- children[i] = {
- type: 12,
- content: child,
- loc: child.loc,
- codegenNode: createCallExpression(
- context.helper(CREATE_TEXT),
- callArgs
- )
- };
- }
- }
- };
- }
- };
- const seen$1 = /* @__PURE__ */ new WeakSet();
- const transformOnce = (node, context) => {
- if (node.type === 1 && findDir(node, "once", true)) {
- if (seen$1.has(node) || context.inVOnce || context.inSSR) {
- return;
- }
- seen$1.add(node);
- context.inVOnce = true;
- context.helper(SET_BLOCK_TRACKING);
- return () => {
- context.inVOnce = false;
- const cur = context.currentNode;
- if (cur.codegenNode) {
- cur.codegenNode = context.cache(
- cur.codegenNode,
- true
- /* isVNode */
- );
- }
- };
- }
- };
- const transformModel = (dir, node, context) => {
- const { exp, arg } = dir;
- if (!exp) {
- context.onError(
- createCompilerError(41, dir.loc)
- );
- return createTransformProps();
- }
- const rawExp = exp.loc.source.trim();
- const expString = exp.type === 4 ? exp.content : rawExp;
- const bindingType = context.bindingMetadata[rawExp];
- if (bindingType === "props" || bindingType === "props-aliased") {
- context.onError(createCompilerError(44, exp.loc));
- return createTransformProps();
- }
- const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
- if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
- context.onError(
- createCompilerError(42, exp.loc)
- );
- return createTransformProps();
- }
- if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
- context.onError(
- createCompilerError(43, exp.loc)
- );
- return createTransformProps();
- }
- const propName = arg ? arg : createSimpleExpression("modelValue", true);
- const eventName = arg ? isStaticExp(arg) ? `onUpdate:${shared.camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
- let assignmentExp;
- const eventArg = context.isTS ? `($event: any)` : `$event`;
- if (maybeRef) {
- if (bindingType === "setup-ref") {
- assignmentExp = createCompoundExpression([
- `${eventArg} => ((`,
- createSimpleExpression(rawExp, false, exp.loc),
- `).value = $event)`
- ]);
- } else {
- const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
- assignmentExp = createCompoundExpression([
- `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
- createSimpleExpression(rawExp, false, exp.loc),
- `).value = $event : ${altAssignment})`
- ]);
- }
- } else {
- assignmentExp = createCompoundExpression([
- `${eventArg} => ((`,
- exp,
- `) = $event)`
- ]);
- }
- const props = [
- // modelValue: foo
- createObjectProperty(propName, dir.exp),
- // "onUpdate:modelValue": $event => (foo = $event)
- createObjectProperty(eventName, assignmentExp)
- ];
- if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
- props[1].value = context.cache(props[1].value);
- }
- if (dir.modifiers.length && node.tagType === 1) {
- const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
- const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
- props.push(
- createObjectProperty(
- modifiersKey,
- createSimpleExpression(
- `{ ${modifiers} }`,
- false,
- dir.loc,
- 2
- )
- )
- );
- }
- return createTransformProps(props);
- };
- function createTransformProps(props = []) {
- return { props };
- }
- const validDivisionCharRE = /[\w).+\-_$\]]/;
- const transformFilter = (node, context) => {
- if (!isCompatEnabled("COMPILER_FILTERS", context)) {
- return;
- }
- if (node.type === 5) {
- rewriteFilter(node.content, context);
- } else if (node.type === 1) {
- node.props.forEach((prop) => {
- if (prop.type === 7 && prop.name !== "for" && prop.exp) {
- rewriteFilter(prop.exp, context);
- }
- });
- }
- };
- function rewriteFilter(node, context) {
- if (node.type === 4) {
- parseFilter(node, context);
- } else {
- for (let i = 0; i < node.children.length; i++) {
- const child = node.children[i];
- if (typeof child !== "object") continue;
- if (child.type === 4) {
- parseFilter(child, context);
- } else if (child.type === 8) {
- rewriteFilter(node, context);
- } else if (child.type === 5) {
- rewriteFilter(child.content, context);
- }
- }
- }
- }
- function parseFilter(node, context) {
- const exp = node.content;
- let inSingle = false;
- let inDouble = false;
- let inTemplateString = false;
- let inRegex = false;
- let curly = 0;
- let square = 0;
- let paren = 0;
- let lastFilterIndex = 0;
- let c, prev, i, expression, filters = [];
- for (i = 0; i < exp.length; i++) {
- prev = c;
- c = exp.charCodeAt(i);
- if (inSingle) {
- if (c === 39 && prev !== 92) inSingle = false;
- } else if (inDouble) {
- if (c === 34 && prev !== 92) inDouble = false;
- } else if (inTemplateString) {
- if (c === 96 && prev !== 92) inTemplateString = false;
- } else if (inRegex) {
- if (c === 47 && prev !== 92) inRegex = false;
- } else if (c === 124 && // pipe
- exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
- if (expression === void 0) {
- lastFilterIndex = i + 1;
- expression = exp.slice(0, i).trim();
- } else {
- pushFilter();
- }
- } else {
- switch (c) {
- case 34:
- inDouble = true;
- break;
- // "
- case 39:
- inSingle = true;
- break;
- // '
- case 96:
- inTemplateString = true;
- break;
- // `
- case 40:
- paren++;
- break;
- // (
- case 41:
- paren--;
- break;
- // )
- case 91:
- square++;
- break;
- // [
- case 93:
- square--;
- break;
- // ]
- case 123:
- curly++;
- break;
- // {
- case 125:
- curly--;
- break;
- }
- if (c === 47) {
- let j = i - 1;
- let p;
- for (; j >= 0; j--) {
- p = exp.charAt(j);
- if (p !== " ") break;
- }
- if (!p || !validDivisionCharRE.test(p)) {
- inRegex = true;
- }
- }
- }
- }
- if (expression === void 0) {
- expression = exp.slice(0, i).trim();
- } else if (lastFilterIndex !== 0) {
- pushFilter();
- }
- function pushFilter() {
- filters.push(exp.slice(lastFilterIndex, i).trim());
- lastFilterIndex = i + 1;
- }
- if (filters.length) {
- for (i = 0; i < filters.length; i++) {
- expression = wrapFilter(expression, filters[i], context);
- }
- node.content = expression;
- node.ast = void 0;
- }
- }
- function wrapFilter(exp, filter, context) {
- context.helper(RESOLVE_FILTER);
- const i = filter.indexOf("(");
- if (i < 0) {
- context.filters.add(filter);
- return `${toValidAssetId(filter, "filter")}(${exp})`;
- } else {
- const name = filter.slice(0, i);
- const args = filter.slice(i + 1);
- context.filters.add(name);
- return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
- }
- }
- const seen = /* @__PURE__ */ new WeakSet();
- const transformMemo = (node, context) => {
- if (node.type === 1) {
- const dir = findDir(node, "memo");
- if (!dir || seen.has(node)) {
- return;
- }
- seen.add(node);
- return () => {
- const codegenNode = node.codegenNode || context.currentNode.codegenNode;
- if (codegenNode && codegenNode.type === 13) {
- if (node.tagType !== 1) {
- convertToBlock(codegenNode, context);
- }
- node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
- dir.exp,
- createFunctionExpression(void 0, codegenNode),
- `_cache`,
- String(context.cached.length)
- ]);
- context.cached.push(null);
- }
- };
- }
- };
- function getBaseTransformPreset(prefixIdentifiers) {
- return [
- [
- transformOnce,
- transformIf,
- transformMemo,
- transformFor,
- ...[transformFilter] ,
- ...prefixIdentifiers ? [
- // order is important
- trackVForSlotScopes,
- transformExpression
- ] : [],
- transformSlotOutlet,
- transformElement,
- trackSlotScopes,
- transformText
- ],
- {
- on: transformOn,
- bind: transformBind,
- model: transformModel
- }
- ];
- }
- function baseCompile(source, options = {}) {
- const onError = options.onError || defaultOnError;
- const isModuleMode = options.mode === "module";
- const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
- if (!prefixIdentifiers && options.cacheHandlers) {
- onError(createCompilerError(49));
- }
- if (options.scopeId && !isModuleMode) {
- onError(createCompilerError(50));
- }
- const resolvedOptions = shared.extend({}, options, {
- prefixIdentifiers
- });
- const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
- const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
- if (options.isTS) {
- const { expressionPlugins } = options;
- if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
- options.expressionPlugins = [...expressionPlugins || [], "typescript"];
- }
- }
- transform(
- ast,
- shared.extend({}, resolvedOptions, {
- nodeTransforms: [
- ...nodeTransforms,
- ...options.nodeTransforms || []
- // user transforms
- ],
- directiveTransforms: shared.extend(
- {},
- directiveTransforms,
- options.directiveTransforms || {}
- // user transforms
- )
- })
- );
- return generate(ast, resolvedOptions);
- }
- const BindingTypes = {
- "DATA": "data",
- "PROPS": "props",
- "PROPS_ALIASED": "props-aliased",
- "SETUP_LET": "setup-let",
- "SETUP_CONST": "setup-const",
- "SETUP_REACTIVE_CONST": "setup-reactive-const",
- "SETUP_MAYBE_REF": "setup-maybe-ref",
- "SETUP_REF": "setup-ref",
- "OPTIONS": "options",
- "LITERAL_CONST": "literal-const"
- };
- const noopDirectiveTransform = () => ({ props: [] });
- exports.generateCodeFrame = shared.generateCodeFrame;
- exports.BASE_TRANSITION = BASE_TRANSITION;
- exports.BindingTypes = BindingTypes;
- exports.CAMELIZE = CAMELIZE;
- exports.CAPITALIZE = CAPITALIZE;
- exports.CREATE_BLOCK = CREATE_BLOCK;
- exports.CREATE_COMMENT = CREATE_COMMENT;
- exports.CREATE_ELEMENT_BLOCK = CREATE_ELEMENT_BLOCK;
- exports.CREATE_ELEMENT_VNODE = CREATE_ELEMENT_VNODE;
- exports.CREATE_SLOTS = CREATE_SLOTS;
- exports.CREATE_STATIC = CREATE_STATIC;
- exports.CREATE_TEXT = CREATE_TEXT;
- exports.CREATE_VNODE = CREATE_VNODE;
- exports.CompilerDeprecationTypes = CompilerDeprecationTypes;
- exports.ConstantTypes = ConstantTypes;
- exports.ElementTypes = ElementTypes;
- exports.ErrorCodes = ErrorCodes;
- exports.FRAGMENT = FRAGMENT;
- exports.GUARD_REACTIVE_PROPS = GUARD_REACTIVE_PROPS;
- exports.IS_MEMO_SAME = IS_MEMO_SAME;
- exports.IS_REF = IS_REF;
- exports.KEEP_ALIVE = KEEP_ALIVE;
- exports.MERGE_PROPS = MERGE_PROPS;
- exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
- exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
- exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
- exports.Namespaces = Namespaces;
- exports.NodeTypes = NodeTypes;
- exports.OPEN_BLOCK = OPEN_BLOCK;
- exports.POP_SCOPE_ID = POP_SCOPE_ID;
- exports.PUSH_SCOPE_ID = PUSH_SCOPE_ID;
- exports.RENDER_LIST = RENDER_LIST;
- exports.RENDER_SLOT = RENDER_SLOT;
- exports.RESOLVE_COMPONENT = RESOLVE_COMPONENT;
- exports.RESOLVE_DIRECTIVE = RESOLVE_DIRECTIVE;
- exports.RESOLVE_DYNAMIC_COMPONENT = RESOLVE_DYNAMIC_COMPONENT;
- exports.RESOLVE_FILTER = RESOLVE_FILTER;
- exports.SET_BLOCK_TRACKING = SET_BLOCK_TRACKING;
- exports.SUSPENSE = SUSPENSE;
- exports.TELEPORT = TELEPORT;
- exports.TO_DISPLAY_STRING = TO_DISPLAY_STRING;
- exports.TO_HANDLERS = TO_HANDLERS;
- exports.TO_HANDLER_KEY = TO_HANDLER_KEY;
- exports.TS_NODE_TYPES = TS_NODE_TYPES;
- exports.UNREF = UNREF;
- exports.WITH_CTX = WITH_CTX;
- exports.WITH_DIRECTIVES = WITH_DIRECTIVES;
- exports.WITH_MEMO = WITH_MEMO;
- exports.advancePositionWithClone = advancePositionWithClone;
- exports.advancePositionWithMutation = advancePositionWithMutation;
- exports.assert = assert;
- exports.baseCompile = baseCompile;
- exports.baseParse = baseParse;
- exports.buildDirectiveArgs = buildDirectiveArgs;
- exports.buildProps = buildProps;
- exports.buildSlots = buildSlots;
- exports.checkCompatEnabled = checkCompatEnabled;
- exports.convertToBlock = convertToBlock;
- exports.createArrayExpression = createArrayExpression;
- exports.createAssignmentExpression = createAssignmentExpression;
- exports.createBlockStatement = createBlockStatement;
- exports.createCacheExpression = createCacheExpression;
- exports.createCallExpression = createCallExpression;
- exports.createCompilerError = createCompilerError;
- exports.createCompoundExpression = createCompoundExpression;
- exports.createConditionalExpression = createConditionalExpression;
- exports.createForLoopParams = createForLoopParams;
- exports.createFunctionExpression = createFunctionExpression;
- exports.createIfStatement = createIfStatement;
- exports.createInterpolation = createInterpolation;
- exports.createObjectExpression = createObjectExpression;
- exports.createObjectProperty = createObjectProperty;
- exports.createReturnStatement = createReturnStatement;
- exports.createRoot = createRoot;
- exports.createSequenceExpression = createSequenceExpression;
- exports.createSimpleExpression = createSimpleExpression;
- exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
- exports.createTemplateLiteral = createTemplateLiteral;
- exports.createTransformContext = createTransformContext;
- exports.createVNodeCall = createVNodeCall;
- exports.errorMessages = errorMessages;
- exports.extractIdentifiers = extractIdentifiers;
- exports.findDir = findDir;
- exports.findProp = findProp;
- exports.forAliasRE = forAliasRE;
- exports.generate = generate;
- exports.getBaseTransformPreset = getBaseTransformPreset;
- exports.getConstantType = getConstantType;
- exports.getMemoedVNodeCall = getMemoedVNodeCall;
- exports.getVNodeBlockHelper = getVNodeBlockHelper;
- exports.getVNodeHelper = getVNodeHelper;
- exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
- exports.hasScopeRef = hasScopeRef;
- exports.helperNameMap = helperNameMap;
- exports.injectProp = injectProp;
- exports.isCoreComponent = isCoreComponent;
- exports.isFnExpression = isFnExpression;
- exports.isFnExpressionBrowser = isFnExpressionBrowser;
- exports.isFnExpressionNode = isFnExpressionNode;
- exports.isFunctionType = isFunctionType;
- exports.isInDestructureAssignment = isInDestructureAssignment;
- exports.isInNewExpression = isInNewExpression;
- exports.isMemberExpression = isMemberExpression;
- exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
- exports.isMemberExpressionNode = isMemberExpressionNode;
- exports.isReferencedIdentifier = isReferencedIdentifier;
- exports.isSimpleIdentifier = isSimpleIdentifier;
- exports.isSlotOutlet = isSlotOutlet;
- exports.isStaticArgOf = isStaticArgOf;
- exports.isStaticExp = isStaticExp;
- exports.isStaticProperty = isStaticProperty;
- exports.isStaticPropertyKey = isStaticPropertyKey;
- exports.isTemplateNode = isTemplateNode;
- exports.isText = isText$1;
- exports.isVSlot = isVSlot;
- exports.locStub = locStub;
- exports.noopDirectiveTransform = noopDirectiveTransform;
- exports.processExpression = processExpression;
- exports.processFor = processFor;
- exports.processIf = processIf;
- exports.processSlotOutlet = processSlotOutlet;
- exports.registerRuntimeHelpers = registerRuntimeHelpers;
- exports.resolveComponentType = resolveComponentType;
- exports.stringifyExpression = stringifyExpression;
- exports.toValidAssetId = toValidAssetId;
- exports.trackSlotScopes = trackSlotScopes;
- exports.trackVForSlotScopes = trackVForSlotScopes;
- exports.transform = transform;
- exports.transformBind = transformBind;
- exports.transformElement = transformElement;
- exports.transformExpression = transformExpression;
- exports.transformModel = transformModel;
- exports.transformOn = transformOn;
- exports.traverseNode = traverseNode;
- exports.unwrapTSNode = unwrapTSNode;
- exports.walkBlockDeclarations = walkBlockDeclarations;
- exports.walkFunctionParams = walkFunctionParams;
- exports.walkIdentifiers = walkIdentifiers;
- exports.warnDeprecation = warnDeprecation;
|