compiler-core.cjs.js 191 KB

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