compiler-core.cjs.js 200 KB

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