Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compiler-dom.global.js 198KB

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