Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compiler-dom.esm-browser.js 182KB

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