compiler-dom.global.js 207 KB

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