compiler-dom.global.js 209 KB

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