compiler-dom.esm-browser.js 182 KB

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