compiler-core.esm-bundler.js 171 KB

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