compiler-core.cjs.prod.js 186 KB

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