652c9f55a78eb48c01054b54ed6b453089e50a1f75cfe18cb61480f55b2efaabe5a7e38586b50348c6cf8aed856e90a48898a887a09592fa10cc6f8716d732 193 KB

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