9cd4e68c78476c954ae2a024bb744ee71d8acc42635639eaef6328c6a15f6aa4cec46e1076d727ffb935bc837d16ae5a1c896a57fdf2ed85a4c88e88002036 198 KB

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