compiler-dom.global.js 206 KB

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