compiler-core.esm-bundler.js 171 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836
  1. /**
  2. * @vue/compiler-core v3.5.30
  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].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. temps: 0,
  3041. identifiers: /* @__PURE__ */ Object.create(null),
  3042. scopes: {
  3043. vFor: 0,
  3044. vSlot: 0,
  3045. vPre: 0,
  3046. vOnce: 0
  3047. },
  3048. parent: null,
  3049. grandParent: null,
  3050. currentNode: root,
  3051. childIndex: 0,
  3052. inVOnce: false,
  3053. // methods
  3054. helper(name) {
  3055. const count = context.helpers.get(name) || 0;
  3056. context.helpers.set(name, count + 1);
  3057. return name;
  3058. },
  3059. removeHelper(name) {
  3060. const count = context.helpers.get(name);
  3061. if (count) {
  3062. const currentCount = count - 1;
  3063. if (!currentCount) {
  3064. context.helpers.delete(name);
  3065. } else {
  3066. context.helpers.set(name, currentCount);
  3067. }
  3068. }
  3069. },
  3070. helperString(name) {
  3071. return `_${helperNameMap[context.helper(name)]}`;
  3072. },
  3073. replaceNode(node) {
  3074. if (!!(process.env.NODE_ENV !== "production")) {
  3075. if (!context.currentNode) {
  3076. throw new Error(`Node being replaced is already removed.`);
  3077. }
  3078. if (!context.parent) {
  3079. throw new Error(`Cannot replace root node.`);
  3080. }
  3081. }
  3082. context.parent.children[context.childIndex] = context.currentNode = node;
  3083. },
  3084. removeNode(node) {
  3085. if (!!(process.env.NODE_ENV !== "production") && !context.parent) {
  3086. throw new Error(`Cannot remove root node.`);
  3087. }
  3088. const list = context.parent.children;
  3089. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  3090. if (!!(process.env.NODE_ENV !== "production") && removalIndex < 0) {
  3091. throw new Error(`node being removed is not a child of current parent`);
  3092. }
  3093. if (!node || node === context.currentNode) {
  3094. context.currentNode = null;
  3095. context.onNodeRemoved();
  3096. } else {
  3097. if (context.childIndex > removalIndex) {
  3098. context.childIndex--;
  3099. context.onNodeRemoved();
  3100. }
  3101. }
  3102. context.parent.children.splice(removalIndex, 1);
  3103. },
  3104. onNodeRemoved: NOOP,
  3105. addIdentifiers(exp) {
  3106. },
  3107. removeIdentifiers(exp) {
  3108. },
  3109. hoist(exp) {
  3110. if (isString(exp)) exp = createSimpleExpression(exp);
  3111. context.hoists.push(exp);
  3112. const identifier = createSimpleExpression(
  3113. `_hoisted_${context.hoists.length}`,
  3114. false,
  3115. exp.loc,
  3116. 2
  3117. );
  3118. identifier.hoisted = exp;
  3119. return identifier;
  3120. },
  3121. cache(exp, isVNode = false, inVOnce = false) {
  3122. const cacheExp = createCacheExpression(
  3123. context.cached.length,
  3124. exp,
  3125. isVNode,
  3126. inVOnce
  3127. );
  3128. context.cached.push(cacheExp);
  3129. return cacheExp;
  3130. }
  3131. };
  3132. {
  3133. context.filters = /* @__PURE__ */ new Set();
  3134. }
  3135. return context;
  3136. }
  3137. function transform(root, options) {
  3138. const context = createTransformContext(root, options);
  3139. traverseNode(root, context);
  3140. if (options.hoistStatic) {
  3141. cacheStatic(root, context);
  3142. }
  3143. if (!options.ssr) {
  3144. createRootCodegen(root, context);
  3145. }
  3146. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  3147. root.components = [...context.components];
  3148. root.directives = [...context.directives];
  3149. root.imports = context.imports;
  3150. root.hoists = context.hoists;
  3151. root.temps = context.temps;
  3152. root.cached = context.cached;
  3153. root.transformed = true;
  3154. {
  3155. root.filters = [...context.filters];
  3156. }
  3157. }
  3158. function createRootCodegen(root, context) {
  3159. const { helper } = context;
  3160. const { children } = root;
  3161. if (children.length === 1) {
  3162. const singleElementRootChild = getSingleElementRoot(root);
  3163. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  3164. const codegenNode = singleElementRootChild.codegenNode;
  3165. if (codegenNode.type === 13) {
  3166. convertToBlock(codegenNode, context);
  3167. }
  3168. root.codegenNode = codegenNode;
  3169. } else {
  3170. root.codegenNode = children[0];
  3171. }
  3172. } else if (children.length > 1) {
  3173. let patchFlag = 64;
  3174. if (!!(process.env.NODE_ENV !== "production") && children.filter((c) => c.type !== 3).length === 1) {
  3175. patchFlag |= 2048;
  3176. }
  3177. root.codegenNode = createVNodeCall(
  3178. context,
  3179. helper(FRAGMENT),
  3180. void 0,
  3181. root.children,
  3182. patchFlag,
  3183. void 0,
  3184. void 0,
  3185. true,
  3186. void 0,
  3187. false
  3188. );
  3189. } else ;
  3190. }
  3191. function traverseChildren(parent, context) {
  3192. let i = 0;
  3193. const nodeRemoved = () => {
  3194. i--;
  3195. };
  3196. for (; i < parent.children.length; i++) {
  3197. const child = parent.children[i];
  3198. if (isString(child)) continue;
  3199. context.grandParent = context.parent;
  3200. context.parent = parent;
  3201. context.childIndex = i;
  3202. context.onNodeRemoved = nodeRemoved;
  3203. traverseNode(child, context);
  3204. }
  3205. }
  3206. function traverseNode(node, context) {
  3207. context.currentNode = node;
  3208. const { nodeTransforms } = context;
  3209. const exitFns = [];
  3210. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  3211. const onExit = nodeTransforms[i2](node, context);
  3212. if (onExit) {
  3213. if (isArray(onExit)) {
  3214. exitFns.push(...onExit);
  3215. } else {
  3216. exitFns.push(onExit);
  3217. }
  3218. }
  3219. if (!context.currentNode) {
  3220. return;
  3221. } else {
  3222. node = context.currentNode;
  3223. }
  3224. }
  3225. switch (node.type) {
  3226. case 3:
  3227. if (!context.ssr) {
  3228. context.helper(CREATE_COMMENT);
  3229. }
  3230. break;
  3231. case 5:
  3232. if (!context.ssr) {
  3233. context.helper(TO_DISPLAY_STRING);
  3234. }
  3235. break;
  3236. // for container types, further traverse downwards
  3237. case 9:
  3238. for (let i2 = 0; i2 < node.branches.length; i2++) {
  3239. traverseNode(node.branches[i2], context);
  3240. }
  3241. break;
  3242. case 10:
  3243. case 11:
  3244. case 1:
  3245. case 0:
  3246. traverseChildren(node, context);
  3247. break;
  3248. }
  3249. context.currentNode = node;
  3250. let i = exitFns.length;
  3251. while (i--) {
  3252. exitFns[i]();
  3253. }
  3254. }
  3255. function createStructuralDirectiveTransform(name, fn) {
  3256. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  3257. return (node, context) => {
  3258. if (node.type === 1) {
  3259. const { props } = node;
  3260. if (node.tagType === 3 && props.some(isVSlot)) {
  3261. return;
  3262. }
  3263. const exitFns = [];
  3264. for (let i = 0; i < props.length; i++) {
  3265. const prop = props[i];
  3266. if (prop.type === 7 && matches(prop.name)) {
  3267. props.splice(i, 1);
  3268. i--;
  3269. const onExit = fn(node, prop, context);
  3270. if (onExit) exitFns.push(onExit);
  3271. }
  3272. }
  3273. return exitFns;
  3274. }
  3275. };
  3276. }
  3277. const PURE_ANNOTATION = `/*@__PURE__*/`;
  3278. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  3279. function createCodegenContext(ast, {
  3280. mode = "function",
  3281. prefixIdentifiers = mode === "module",
  3282. sourceMap = false,
  3283. filename = `template.vue.html`,
  3284. scopeId = null,
  3285. optimizeImports = false,
  3286. runtimeGlobalName = `Vue`,
  3287. runtimeModuleName = `vue`,
  3288. ssrRuntimeModuleName = "vue/server-renderer",
  3289. ssr = false,
  3290. isTS = false,
  3291. inSSR = false
  3292. }) {
  3293. const context = {
  3294. mode,
  3295. prefixIdentifiers,
  3296. sourceMap,
  3297. filename,
  3298. scopeId,
  3299. optimizeImports,
  3300. runtimeGlobalName,
  3301. runtimeModuleName,
  3302. ssrRuntimeModuleName,
  3303. ssr,
  3304. isTS,
  3305. inSSR,
  3306. source: ast.source,
  3307. code: ``,
  3308. column: 1,
  3309. line: 1,
  3310. offset: 0,
  3311. indentLevel: 0,
  3312. pure: false,
  3313. map: void 0,
  3314. helper(key) {
  3315. return `_${helperNameMap[key]}`;
  3316. },
  3317. push(code, newlineIndex = -2 /* None */, node) {
  3318. context.code += code;
  3319. },
  3320. indent() {
  3321. newline(++context.indentLevel);
  3322. },
  3323. deindent(withoutNewLine = false) {
  3324. if (withoutNewLine) {
  3325. --context.indentLevel;
  3326. } else {
  3327. newline(--context.indentLevel);
  3328. }
  3329. },
  3330. newline() {
  3331. newline(context.indentLevel);
  3332. }
  3333. };
  3334. function newline(n) {
  3335. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  3336. }
  3337. return context;
  3338. }
  3339. function generate(ast, options = {}) {
  3340. const context = createCodegenContext(ast, options);
  3341. if (options.onContextCreated) options.onContextCreated(context);
  3342. const {
  3343. mode,
  3344. push,
  3345. prefixIdentifiers,
  3346. indent,
  3347. deindent,
  3348. newline,
  3349. scopeId,
  3350. ssr
  3351. } = context;
  3352. const helpers = Array.from(ast.helpers);
  3353. const hasHelpers = helpers.length > 0;
  3354. const useWithBlock = !prefixIdentifiers && mode !== "module";
  3355. const preambleContext = context;
  3356. {
  3357. genFunctionPreamble(ast, preambleContext);
  3358. }
  3359. const functionName = ssr ? `ssrRender` : `render`;
  3360. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  3361. const signature = args.join(", ");
  3362. {
  3363. push(`function ${functionName}(${signature}) {`);
  3364. }
  3365. indent();
  3366. if (useWithBlock) {
  3367. push(`with (_ctx) {`);
  3368. indent();
  3369. if (hasHelpers) {
  3370. push(
  3371. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  3372. `,
  3373. -1 /* End */
  3374. );
  3375. newline();
  3376. }
  3377. }
  3378. if (ast.components.length) {
  3379. genAssets(ast.components, "component", context);
  3380. if (ast.directives.length || ast.temps > 0) {
  3381. newline();
  3382. }
  3383. }
  3384. if (ast.directives.length) {
  3385. genAssets(ast.directives, "directive", context);
  3386. if (ast.temps > 0) {
  3387. newline();
  3388. }
  3389. }
  3390. if (ast.filters && ast.filters.length) {
  3391. newline();
  3392. genAssets(ast.filters, "filter", context);
  3393. newline();
  3394. }
  3395. if (ast.temps > 0) {
  3396. push(`let `);
  3397. for (let i = 0; i < ast.temps; i++) {
  3398. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  3399. }
  3400. }
  3401. if (ast.components.length || ast.directives.length || ast.temps) {
  3402. push(`
  3403. `, 0 /* Start */);
  3404. newline();
  3405. }
  3406. if (!ssr) {
  3407. push(`return `);
  3408. }
  3409. if (ast.codegenNode) {
  3410. genNode(ast.codegenNode, context);
  3411. } else {
  3412. push(`null`);
  3413. }
  3414. if (useWithBlock) {
  3415. deindent();
  3416. push(`}`);
  3417. }
  3418. deindent();
  3419. push(`}`);
  3420. return {
  3421. ast,
  3422. code: context.code,
  3423. preamble: ``,
  3424. map: context.map ? context.map.toJSON() : void 0
  3425. };
  3426. }
  3427. function genFunctionPreamble(ast, context) {
  3428. const {
  3429. ssr,
  3430. prefixIdentifiers,
  3431. push,
  3432. newline,
  3433. runtimeModuleName,
  3434. runtimeGlobalName,
  3435. ssrRuntimeModuleName
  3436. } = context;
  3437. const VueBinding = runtimeGlobalName;
  3438. const helpers = Array.from(ast.helpers);
  3439. if (helpers.length > 0) {
  3440. {
  3441. push(`const _Vue = ${VueBinding}
  3442. `, -1 /* End */);
  3443. if (ast.hoists.length) {
  3444. const staticHelpers = [
  3445. CREATE_VNODE,
  3446. CREATE_ELEMENT_VNODE,
  3447. CREATE_COMMENT,
  3448. CREATE_TEXT,
  3449. CREATE_STATIC
  3450. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  3451. push(`const { ${staticHelpers} } = _Vue
  3452. `, -1 /* End */);
  3453. }
  3454. }
  3455. }
  3456. genHoists(ast.hoists, context);
  3457. newline();
  3458. push(`return `);
  3459. }
  3460. function genAssets(assets, type, { helper, push, newline, isTS }) {
  3461. const resolver = helper(
  3462. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  3463. );
  3464. for (let i = 0; i < assets.length; i++) {
  3465. let id = assets[i];
  3466. const maybeSelfReference = id.endsWith("__self");
  3467. if (maybeSelfReference) {
  3468. id = id.slice(0, -6);
  3469. }
  3470. push(
  3471. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  3472. );
  3473. if (i < assets.length - 1) {
  3474. newline();
  3475. }
  3476. }
  3477. }
  3478. function genHoists(hoists, context) {
  3479. if (!hoists.length) {
  3480. return;
  3481. }
  3482. context.pure = true;
  3483. const { push, newline } = context;
  3484. newline();
  3485. for (let i = 0; i < hoists.length; i++) {
  3486. const exp = hoists[i];
  3487. if (exp) {
  3488. push(`const _hoisted_${i + 1} = `);
  3489. genNode(exp, context);
  3490. newline();
  3491. }
  3492. }
  3493. context.pure = false;
  3494. }
  3495. function isText(n) {
  3496. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  3497. }
  3498. function genNodeListAsArray(nodes, context) {
  3499. const multilines = nodes.length > 3 || !!(process.env.NODE_ENV !== "production") && nodes.some((n) => isArray(n) || !isText(n));
  3500. context.push(`[`);
  3501. multilines && context.indent();
  3502. genNodeList(nodes, context, multilines);
  3503. multilines && context.deindent();
  3504. context.push(`]`);
  3505. }
  3506. function genNodeList(nodes, context, multilines = false, comma = true) {
  3507. const { push, newline } = context;
  3508. for (let i = 0; i < nodes.length; i++) {
  3509. const node = nodes[i];
  3510. if (isString(node)) {
  3511. push(node, -3 /* Unknown */);
  3512. } else if (isArray(node)) {
  3513. genNodeListAsArray(node, context);
  3514. } else {
  3515. genNode(node, context);
  3516. }
  3517. if (i < nodes.length - 1) {
  3518. if (multilines) {
  3519. comma && push(",");
  3520. newline();
  3521. } else {
  3522. comma && push(", ");
  3523. }
  3524. }
  3525. }
  3526. }
  3527. function genNode(node, context) {
  3528. if (isString(node)) {
  3529. context.push(node, -3 /* Unknown */);
  3530. return;
  3531. }
  3532. if (isSymbol(node)) {
  3533. context.push(context.helper(node));
  3534. return;
  3535. }
  3536. switch (node.type) {
  3537. case 1:
  3538. case 9:
  3539. case 11:
  3540. !!(process.env.NODE_ENV !== "production") && assert(
  3541. node.codegenNode != null,
  3542. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  3543. );
  3544. genNode(node.codegenNode, context);
  3545. break;
  3546. case 2:
  3547. genText(node, context);
  3548. break;
  3549. case 4:
  3550. genExpression(node, context);
  3551. break;
  3552. case 5:
  3553. genInterpolation(node, context);
  3554. break;
  3555. case 12:
  3556. genNode(node.codegenNode, context);
  3557. break;
  3558. case 8:
  3559. genCompoundExpression(node, context);
  3560. break;
  3561. case 3:
  3562. genComment(node, context);
  3563. break;
  3564. case 13:
  3565. genVNodeCall(node, context);
  3566. break;
  3567. case 14:
  3568. genCallExpression(node, context);
  3569. break;
  3570. case 15:
  3571. genObjectExpression(node, context);
  3572. break;
  3573. case 17:
  3574. genArrayExpression(node, context);
  3575. break;
  3576. case 18:
  3577. genFunctionExpression(node, context);
  3578. break;
  3579. case 19:
  3580. genConditionalExpression(node, context);
  3581. break;
  3582. case 20:
  3583. genCacheExpression(node, context);
  3584. break;
  3585. case 21:
  3586. genNodeList(node.body, context, true, false);
  3587. break;
  3588. // SSR only types
  3589. case 22:
  3590. break;
  3591. case 23:
  3592. break;
  3593. case 24:
  3594. break;
  3595. case 25:
  3596. break;
  3597. case 26:
  3598. break;
  3599. /* v8 ignore start */
  3600. case 10:
  3601. break;
  3602. default:
  3603. if (!!(process.env.NODE_ENV !== "production")) {
  3604. assert(false, `unhandled codegen node type: ${node.type}`);
  3605. const exhaustiveCheck = node;
  3606. return exhaustiveCheck;
  3607. }
  3608. }
  3609. }
  3610. function genText(node, context) {
  3611. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  3612. }
  3613. function genExpression(node, context) {
  3614. const { content, isStatic } = node;
  3615. context.push(
  3616. isStatic ? JSON.stringify(content) : content,
  3617. -3 /* Unknown */,
  3618. node
  3619. );
  3620. }
  3621. function genInterpolation(node, context) {
  3622. const { push, helper, pure } = context;
  3623. if (pure) push(PURE_ANNOTATION);
  3624. push(`${helper(TO_DISPLAY_STRING)}(`);
  3625. genNode(node.content, context);
  3626. push(`)`);
  3627. }
  3628. function genCompoundExpression(node, context) {
  3629. for (let i = 0; i < node.children.length; i++) {
  3630. const child = node.children[i];
  3631. if (isString(child)) {
  3632. context.push(child, -3 /* Unknown */);
  3633. } else {
  3634. genNode(child, context);
  3635. }
  3636. }
  3637. }
  3638. function genExpressionAsPropertyKey(node, context) {
  3639. const { push } = context;
  3640. if (node.type === 8) {
  3641. push(`[`);
  3642. genCompoundExpression(node, context);
  3643. push(`]`);
  3644. } else if (node.isStatic) {
  3645. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  3646. push(text, -2 /* None */, node);
  3647. } else {
  3648. push(`[${node.content}]`, -3 /* Unknown */, node);
  3649. }
  3650. }
  3651. function genComment(node, context) {
  3652. const { push, helper, pure } = context;
  3653. if (pure) {
  3654. push(PURE_ANNOTATION);
  3655. }
  3656. push(
  3657. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  3658. -3 /* Unknown */,
  3659. node
  3660. );
  3661. }
  3662. function genVNodeCall(node, context) {
  3663. const { push, helper, pure } = context;
  3664. const {
  3665. tag,
  3666. props,
  3667. children,
  3668. patchFlag,
  3669. dynamicProps,
  3670. directives,
  3671. isBlock,
  3672. disableTracking,
  3673. isComponent
  3674. } = node;
  3675. let patchFlagString;
  3676. if (patchFlag) {
  3677. if (!!(process.env.NODE_ENV !== "production")) {
  3678. if (patchFlag < 0) {
  3679. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3680. } else {
  3681. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3682. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  3683. }
  3684. } else {
  3685. patchFlagString = String(patchFlag);
  3686. }
  3687. }
  3688. if (directives) {
  3689. push(helper(WITH_DIRECTIVES) + `(`);
  3690. }
  3691. if (isBlock) {
  3692. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  3693. }
  3694. if (pure) {
  3695. push(PURE_ANNOTATION);
  3696. }
  3697. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  3698. push(helper(callHelper) + `(`, -2 /* None */, node);
  3699. genNodeList(
  3700. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  3701. context
  3702. );
  3703. push(`)`);
  3704. if (isBlock) {
  3705. push(`)`);
  3706. }
  3707. if (directives) {
  3708. push(`, `);
  3709. genNode(directives, context);
  3710. push(`)`);
  3711. }
  3712. }
  3713. function genNullableArgs(args) {
  3714. let i = args.length;
  3715. while (i--) {
  3716. if (args[i] != null) break;
  3717. }
  3718. return args.slice(0, i + 1).map((arg) => arg || `null`);
  3719. }
  3720. function genCallExpression(node, context) {
  3721. const { push, helper, pure } = context;
  3722. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  3723. if (pure) {
  3724. push(PURE_ANNOTATION);
  3725. }
  3726. push(callee + `(`, -2 /* None */, node);
  3727. genNodeList(node.arguments, context);
  3728. push(`)`);
  3729. }
  3730. function genObjectExpression(node, context) {
  3731. const { push, indent, deindent, newline } = context;
  3732. const { properties } = node;
  3733. if (!properties.length) {
  3734. push(`{}`, -2 /* None */, node);
  3735. return;
  3736. }
  3737. const multilines = properties.length > 1 || !!(process.env.NODE_ENV !== "production") && properties.some((p) => p.value.type !== 4);
  3738. push(multilines ? `{` : `{ `);
  3739. multilines && indent();
  3740. for (let i = 0; i < properties.length; i++) {
  3741. const { key, value } = properties[i];
  3742. genExpressionAsPropertyKey(key, context);
  3743. push(`: `);
  3744. genNode(value, context);
  3745. if (i < properties.length - 1) {
  3746. push(`,`);
  3747. newline();
  3748. }
  3749. }
  3750. multilines && deindent();
  3751. push(multilines ? `}` : ` }`);
  3752. }
  3753. function genArrayExpression(node, context) {
  3754. genNodeListAsArray(node.elements, context);
  3755. }
  3756. function genFunctionExpression(node, context) {
  3757. const { push, indent, deindent } = context;
  3758. const { params, returns, body, newline, isSlot } = node;
  3759. if (isSlot) {
  3760. push(`_${helperNameMap[WITH_CTX]}(`);
  3761. }
  3762. push(`(`, -2 /* None */, node);
  3763. if (isArray(params)) {
  3764. genNodeList(params, context);
  3765. } else if (params) {
  3766. genNode(params, context);
  3767. }
  3768. push(`) => `);
  3769. if (newline || body) {
  3770. push(`{`);
  3771. indent();
  3772. }
  3773. if (returns) {
  3774. if (newline) {
  3775. push(`return `);
  3776. }
  3777. if (isArray(returns)) {
  3778. genNodeListAsArray(returns, context);
  3779. } else {
  3780. genNode(returns, context);
  3781. }
  3782. } else if (body) {
  3783. genNode(body, context);
  3784. }
  3785. if (newline || body) {
  3786. deindent();
  3787. push(`}`);
  3788. }
  3789. if (isSlot) {
  3790. if (node.isNonScopedSlot) {
  3791. push(`, undefined, true`);
  3792. }
  3793. push(`)`);
  3794. }
  3795. }
  3796. function genConditionalExpression(node, context) {
  3797. const { test, consequent, alternate, newline: needNewline } = node;
  3798. const { push, indent, deindent, newline } = context;
  3799. if (test.type === 4) {
  3800. const needsParens = !isSimpleIdentifier(test.content);
  3801. needsParens && push(`(`);
  3802. genExpression(test, context);
  3803. needsParens && push(`)`);
  3804. } else {
  3805. push(`(`);
  3806. genNode(test, context);
  3807. push(`)`);
  3808. }
  3809. needNewline && indent();
  3810. context.indentLevel++;
  3811. needNewline || push(` `);
  3812. push(`? `);
  3813. genNode(consequent, context);
  3814. context.indentLevel--;
  3815. needNewline && newline();
  3816. needNewline || push(` `);
  3817. push(`: `);
  3818. const isNested = alternate.type === 19;
  3819. if (!isNested) {
  3820. context.indentLevel++;
  3821. }
  3822. genNode(alternate, context);
  3823. if (!isNested) {
  3824. context.indentLevel--;
  3825. }
  3826. needNewline && deindent(
  3827. true
  3828. /* without newline */
  3829. );
  3830. }
  3831. function genCacheExpression(node, context) {
  3832. const { push, helper, indent, deindent, newline } = context;
  3833. const { needPauseTracking, needArraySpread } = node;
  3834. if (needArraySpread) {
  3835. push(`[...(`);
  3836. }
  3837. push(`_cache[${node.index}] || (`);
  3838. if (needPauseTracking) {
  3839. indent();
  3840. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  3841. if (node.inVOnce) push(`, true`);
  3842. push(`),`);
  3843. newline();
  3844. push(`(`);
  3845. }
  3846. push(`_cache[${node.index}] = `);
  3847. genNode(node.value, context);
  3848. if (needPauseTracking) {
  3849. push(`).cacheIndex = ${node.index},`);
  3850. newline();
  3851. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  3852. newline();
  3853. push(`_cache[${node.index}]`);
  3854. deindent();
  3855. }
  3856. push(`)`);
  3857. if (needArraySpread) {
  3858. push(`)]`);
  3859. }
  3860. }
  3861. const prohibitedKeywordRE = new RegExp(
  3862. "\\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"
  3863. );
  3864. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  3865. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  3866. const exp = node.content;
  3867. if (!exp.trim()) {
  3868. return;
  3869. }
  3870. try {
  3871. new Function(
  3872. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  3873. );
  3874. } catch (e) {
  3875. let message = e.message;
  3876. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  3877. if (keywordMatch) {
  3878. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  3879. }
  3880. context.onError(
  3881. createCompilerError(
  3882. 46,
  3883. node.loc,
  3884. void 0,
  3885. message
  3886. )
  3887. );
  3888. }
  3889. }
  3890. const transformExpression = (node, context) => {
  3891. if (node.type === 5) {
  3892. node.content = processExpression(
  3893. node.content,
  3894. context
  3895. );
  3896. } else if (node.type === 1) {
  3897. const memo = findDir(node, "memo");
  3898. for (let i = 0; i < node.props.length; i++) {
  3899. const dir = node.props[i];
  3900. if (dir.type === 7 && dir.name !== "for") {
  3901. const exp = dir.exp;
  3902. const arg = dir.arg;
  3903. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  3904. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  3905. dir.exp = processExpression(
  3906. exp,
  3907. context,
  3908. // slot args must be processed as function params
  3909. dir.name === "slot"
  3910. );
  3911. }
  3912. if (arg && arg.type === 4 && !arg.isStatic) {
  3913. dir.arg = processExpression(arg, context);
  3914. }
  3915. }
  3916. }
  3917. }
  3918. };
  3919. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  3920. {
  3921. if (!!(process.env.NODE_ENV !== "production")) {
  3922. validateBrowserExpression(node, context, asParams, asRawStatements);
  3923. }
  3924. return node;
  3925. }
  3926. }
  3927. function stringifyExpression(exp) {
  3928. if (isString(exp)) {
  3929. return exp;
  3930. } else if (exp.type === 4) {
  3931. return exp.content;
  3932. } else {
  3933. return exp.children.map(stringifyExpression).join("");
  3934. }
  3935. }
  3936. const transformIf = createStructuralDirectiveTransform(
  3937. /^(?:if|else|else-if)$/,
  3938. (node, dir, context) => {
  3939. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  3940. const siblings = context.parent.children;
  3941. let i = siblings.indexOf(ifNode);
  3942. let key = 0;
  3943. while (i-- >= 0) {
  3944. const sibling = siblings[i];
  3945. if (sibling && sibling.type === 9) {
  3946. key += sibling.branches.length;
  3947. }
  3948. }
  3949. return () => {
  3950. if (isRoot) {
  3951. ifNode.codegenNode = createCodegenNodeForBranch(
  3952. branch,
  3953. key,
  3954. context
  3955. );
  3956. } else {
  3957. const parentCondition = getParentCondition(ifNode.codegenNode);
  3958. parentCondition.alternate = createCodegenNodeForBranch(
  3959. branch,
  3960. key + ifNode.branches.length - 1,
  3961. context
  3962. );
  3963. }
  3964. };
  3965. });
  3966. }
  3967. );
  3968. function processIf(node, dir, context, processCodegen) {
  3969. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  3970. const loc = dir.exp ? dir.exp.loc : node.loc;
  3971. context.onError(
  3972. createCompilerError(28, dir.loc)
  3973. );
  3974. dir.exp = createSimpleExpression(`true`, false, loc);
  3975. }
  3976. if (!!(process.env.NODE_ENV !== "production") && true && dir.exp) {
  3977. validateBrowserExpression(dir.exp, context);
  3978. }
  3979. if (dir.name === "if") {
  3980. const branch = createIfBranch(node, dir);
  3981. const ifNode = {
  3982. type: 9,
  3983. loc: cloneLoc(node.loc),
  3984. branches: [branch]
  3985. };
  3986. context.replaceNode(ifNode);
  3987. if (processCodegen) {
  3988. return processCodegen(ifNode, branch, true);
  3989. }
  3990. } else {
  3991. const siblings = context.parent.children;
  3992. const comments = [];
  3993. let i = siblings.indexOf(node);
  3994. while (i-- >= -1) {
  3995. const sibling = siblings[i];
  3996. if (sibling && isCommentOrWhitespace(sibling)) {
  3997. context.removeNode(sibling);
  3998. if (!!(process.env.NODE_ENV !== "production") && sibling.type === 3) {
  3999. comments.unshift(sibling);
  4000. }
  4001. continue;
  4002. }
  4003. if (sibling && sibling.type === 9) {
  4004. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  4005. context.onError(
  4006. createCompilerError(30, node.loc)
  4007. );
  4008. }
  4009. context.removeNode();
  4010. const branch = createIfBranch(node, dir);
  4011. if (!!(process.env.NODE_ENV !== "production") && comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  4012. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  4013. branch.children = [...comments, ...branch.children];
  4014. }
  4015. if (!!(process.env.NODE_ENV !== "production") || false) {
  4016. const key = branch.userKey;
  4017. if (key) {
  4018. sibling.branches.forEach(({ userKey }) => {
  4019. if (isSameKey(userKey, key)) {
  4020. context.onError(
  4021. createCompilerError(
  4022. 29,
  4023. branch.userKey.loc
  4024. )
  4025. );
  4026. }
  4027. });
  4028. }
  4029. }
  4030. sibling.branches.push(branch);
  4031. const onExit = processCodegen && processCodegen(sibling, branch, false);
  4032. traverseNode(branch, context);
  4033. if (onExit) onExit();
  4034. context.currentNode = null;
  4035. } else {
  4036. context.onError(
  4037. createCompilerError(30, node.loc)
  4038. );
  4039. }
  4040. break;
  4041. }
  4042. }
  4043. }
  4044. function createIfBranch(node, dir) {
  4045. const isTemplateIf = node.tagType === 3;
  4046. return {
  4047. type: 10,
  4048. loc: node.loc,
  4049. condition: dir.name === "else" ? void 0 : dir.exp,
  4050. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  4051. userKey: findProp(node, `key`),
  4052. isTemplateIf
  4053. };
  4054. }
  4055. function createCodegenNodeForBranch(branch, keyIndex, context) {
  4056. if (branch.condition) {
  4057. return createConditionalExpression(
  4058. branch.condition,
  4059. createChildrenCodegenNode(branch, keyIndex, context),
  4060. // make sure to pass in asBlock: true so that the comment node call
  4061. // closes the current block.
  4062. createCallExpression(context.helper(CREATE_COMMENT), [
  4063. !!(process.env.NODE_ENV !== "production") ? '"v-if"' : '""',
  4064. "true"
  4065. ])
  4066. );
  4067. } else {
  4068. return createChildrenCodegenNode(branch, keyIndex, context);
  4069. }
  4070. }
  4071. function createChildrenCodegenNode(branch, keyIndex, context) {
  4072. const { helper } = context;
  4073. const keyProperty = createObjectProperty(
  4074. `key`,
  4075. createSimpleExpression(
  4076. `${keyIndex}`,
  4077. false,
  4078. locStub,
  4079. 2
  4080. )
  4081. );
  4082. const { children } = branch;
  4083. const firstChild = children[0];
  4084. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  4085. if (needFragmentWrapper) {
  4086. if (children.length === 1 && firstChild.type === 11) {
  4087. const vnodeCall = firstChild.codegenNode;
  4088. injectProp(vnodeCall, keyProperty, context);
  4089. return vnodeCall;
  4090. } else {
  4091. let patchFlag = 64;
  4092. if (!!(process.env.NODE_ENV !== "production") && !branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  4093. patchFlag |= 2048;
  4094. }
  4095. return createVNodeCall(
  4096. context,
  4097. helper(FRAGMENT),
  4098. createObjectExpression([keyProperty]),
  4099. children,
  4100. patchFlag,
  4101. void 0,
  4102. void 0,
  4103. true,
  4104. false,
  4105. false,
  4106. branch.loc
  4107. );
  4108. }
  4109. } else {
  4110. const ret = firstChild.codegenNode;
  4111. const vnodeCall = getMemoedVNodeCall(ret);
  4112. if (vnodeCall.type === 13) {
  4113. convertToBlock(vnodeCall, context);
  4114. }
  4115. injectProp(vnodeCall, keyProperty, context);
  4116. return ret;
  4117. }
  4118. }
  4119. function isSameKey(a, b) {
  4120. if (!a || a.type !== b.type) {
  4121. return false;
  4122. }
  4123. if (a.type === 6) {
  4124. if (a.value.content !== b.value.content) {
  4125. return false;
  4126. }
  4127. } else {
  4128. const exp = a.exp;
  4129. const branchExp = b.exp;
  4130. if (exp.type !== branchExp.type) {
  4131. return false;
  4132. }
  4133. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  4134. return false;
  4135. }
  4136. }
  4137. return true;
  4138. }
  4139. function getParentCondition(node) {
  4140. while (true) {
  4141. if (node.type === 19) {
  4142. if (node.alternate.type === 19) {
  4143. node = node.alternate;
  4144. } else {
  4145. return node;
  4146. }
  4147. } else if (node.type === 20) {
  4148. node = node.value;
  4149. }
  4150. }
  4151. }
  4152. const transformFor = createStructuralDirectiveTransform(
  4153. "for",
  4154. (node, dir, context) => {
  4155. const { helper, removeHelper } = context;
  4156. return processFor(node, dir, context, (forNode) => {
  4157. const renderExp = createCallExpression(helper(RENDER_LIST), [
  4158. forNode.source
  4159. ]);
  4160. const isTemplate = isTemplateNode(node);
  4161. const memo = findDir(node, "memo");
  4162. const keyProp = findProp(node, `key`, false, true);
  4163. keyProp && keyProp.type === 7;
  4164. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  4165. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  4166. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  4167. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  4168. forNode.codegenNode = createVNodeCall(
  4169. context,
  4170. helper(FRAGMENT),
  4171. void 0,
  4172. renderExp,
  4173. fragmentFlag,
  4174. void 0,
  4175. void 0,
  4176. true,
  4177. !isStableFragment,
  4178. false,
  4179. node.loc
  4180. );
  4181. return () => {
  4182. let childBlock;
  4183. const { children } = forNode;
  4184. if ((!!(process.env.NODE_ENV !== "production") || false) && isTemplate) {
  4185. node.children.some((c) => {
  4186. if (c.type === 1) {
  4187. const key = findProp(c, "key");
  4188. if (key) {
  4189. context.onError(
  4190. createCompilerError(
  4191. 33,
  4192. key.loc
  4193. )
  4194. );
  4195. return true;
  4196. }
  4197. }
  4198. });
  4199. }
  4200. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  4201. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  4202. if (slotOutlet) {
  4203. childBlock = slotOutlet.codegenNode;
  4204. if (isTemplate && keyProperty) {
  4205. injectProp(childBlock, keyProperty, context);
  4206. }
  4207. } else if (needFragmentWrapper) {
  4208. childBlock = createVNodeCall(
  4209. context,
  4210. helper(FRAGMENT),
  4211. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  4212. node.children,
  4213. 64,
  4214. void 0,
  4215. void 0,
  4216. true,
  4217. void 0,
  4218. false
  4219. );
  4220. } else {
  4221. childBlock = children[0].codegenNode;
  4222. if (isTemplate && keyProperty) {
  4223. injectProp(childBlock, keyProperty, context);
  4224. }
  4225. if (childBlock.isBlock !== !isStableFragment) {
  4226. if (childBlock.isBlock) {
  4227. removeHelper(OPEN_BLOCK);
  4228. removeHelper(
  4229. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  4230. );
  4231. } else {
  4232. removeHelper(
  4233. getVNodeHelper(context.inSSR, childBlock.isComponent)
  4234. );
  4235. }
  4236. }
  4237. childBlock.isBlock = !isStableFragment;
  4238. if (childBlock.isBlock) {
  4239. helper(OPEN_BLOCK);
  4240. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  4241. } else {
  4242. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  4243. }
  4244. }
  4245. if (memo) {
  4246. const loop = createFunctionExpression(
  4247. createForLoopParams(forNode.parseResult, [
  4248. createSimpleExpression(`_cached`)
  4249. ])
  4250. );
  4251. loop.body = createBlockStatement([
  4252. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  4253. createCompoundExpression([
  4254. `if (_cached`,
  4255. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  4256. ` && ${context.helperString(
  4257. IS_MEMO_SAME
  4258. )}(_cached, _memo)) return _cached`
  4259. ]),
  4260. createCompoundExpression([`const _item = `, childBlock]),
  4261. createSimpleExpression(`_item.memo = _memo`),
  4262. createSimpleExpression(`return _item`)
  4263. ]);
  4264. renderExp.arguments.push(
  4265. loop,
  4266. createSimpleExpression(`_cache`),
  4267. createSimpleExpression(String(context.cached.length))
  4268. );
  4269. context.cached.push(null);
  4270. } else {
  4271. renderExp.arguments.push(
  4272. createFunctionExpression(
  4273. createForLoopParams(forNode.parseResult),
  4274. childBlock,
  4275. true
  4276. )
  4277. );
  4278. }
  4279. };
  4280. });
  4281. }
  4282. );
  4283. function processFor(node, dir, context, processCodegen) {
  4284. if (!dir.exp) {
  4285. context.onError(
  4286. createCompilerError(31, dir.loc)
  4287. );
  4288. return;
  4289. }
  4290. const parseResult = dir.forParseResult;
  4291. if (!parseResult) {
  4292. context.onError(
  4293. createCompilerError(32, dir.loc)
  4294. );
  4295. return;
  4296. }
  4297. finalizeForParseResult(parseResult, context);
  4298. const { addIdentifiers, removeIdentifiers, scopes } = context;
  4299. const { source, value, key, index } = parseResult;
  4300. const forNode = {
  4301. type: 11,
  4302. loc: dir.loc,
  4303. source,
  4304. valueAlias: value,
  4305. keyAlias: key,
  4306. objectIndexAlias: index,
  4307. parseResult,
  4308. children: isTemplateNode(node) ? node.children : [node]
  4309. };
  4310. context.replaceNode(forNode);
  4311. scopes.vFor++;
  4312. const onExit = processCodegen && processCodegen(forNode);
  4313. return () => {
  4314. scopes.vFor--;
  4315. if (onExit) onExit();
  4316. };
  4317. }
  4318. function finalizeForParseResult(result, context) {
  4319. if (result.finalized) return;
  4320. if (!!(process.env.NODE_ENV !== "production") && true) {
  4321. validateBrowserExpression(result.source, context);
  4322. if (result.key) {
  4323. validateBrowserExpression(
  4324. result.key,
  4325. context,
  4326. true
  4327. );
  4328. }
  4329. if (result.index) {
  4330. validateBrowserExpression(
  4331. result.index,
  4332. context,
  4333. true
  4334. );
  4335. }
  4336. if (result.value) {
  4337. validateBrowserExpression(
  4338. result.value,
  4339. context,
  4340. true
  4341. );
  4342. }
  4343. }
  4344. result.finalized = true;
  4345. }
  4346. function createForLoopParams({ value, key, index }, memoArgs = []) {
  4347. return createParamsList([value, key, index, ...memoArgs]);
  4348. }
  4349. function createParamsList(args) {
  4350. let i = args.length;
  4351. while (i--) {
  4352. if (args[i]) break;
  4353. }
  4354. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  4355. }
  4356. const defaultFallback = createSimpleExpression(`undefined`, false);
  4357. const trackSlotScopes = (node, context) => {
  4358. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  4359. const vSlot = findDir(node, "slot");
  4360. if (vSlot) {
  4361. vSlot.exp;
  4362. context.scopes.vSlot++;
  4363. return () => {
  4364. context.scopes.vSlot--;
  4365. };
  4366. }
  4367. }
  4368. };
  4369. const trackVForSlotScopes = (node, context) => {
  4370. let vFor;
  4371. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  4372. const result = vFor.forParseResult;
  4373. if (result) {
  4374. finalizeForParseResult(result, context);
  4375. const { value, key, index } = result;
  4376. const { addIdentifiers, removeIdentifiers } = context;
  4377. value && addIdentifiers(value);
  4378. key && addIdentifiers(key);
  4379. index && addIdentifiers(index);
  4380. return () => {
  4381. value && removeIdentifiers(value);
  4382. key && removeIdentifiers(key);
  4383. index && removeIdentifiers(index);
  4384. };
  4385. }
  4386. }
  4387. };
  4388. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  4389. props,
  4390. children,
  4391. false,
  4392. true,
  4393. children.length ? children[0].loc : loc
  4394. );
  4395. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  4396. context.helper(WITH_CTX);
  4397. const { children, loc } = node;
  4398. const slotsProperties = [];
  4399. const dynamicSlots = [];
  4400. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  4401. const onComponentSlot = findDir(node, "slot", true);
  4402. if (onComponentSlot) {
  4403. const { arg, exp } = onComponentSlot;
  4404. if (arg && !isStaticExp(arg)) {
  4405. hasDynamicSlots = true;
  4406. }
  4407. slotsProperties.push(
  4408. createObjectProperty(
  4409. arg || createSimpleExpression("default", true),
  4410. buildSlotFn(exp, void 0, children, loc)
  4411. )
  4412. );
  4413. }
  4414. let hasTemplateSlots = false;
  4415. let hasNamedDefaultSlot = false;
  4416. const implicitDefaultChildren = [];
  4417. const seenSlotNames = /* @__PURE__ */ new Set();
  4418. let conditionalBranchIndex = 0;
  4419. for (let i = 0; i < children.length; i++) {
  4420. const slotElement = children[i];
  4421. let slotDir;
  4422. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  4423. if (slotElement.type !== 3) {
  4424. implicitDefaultChildren.push(slotElement);
  4425. }
  4426. continue;
  4427. }
  4428. if (onComponentSlot) {
  4429. context.onError(
  4430. createCompilerError(37, slotDir.loc)
  4431. );
  4432. break;
  4433. }
  4434. hasTemplateSlots = true;
  4435. const { children: slotChildren, loc: slotLoc } = slotElement;
  4436. const {
  4437. arg: slotName = createSimpleExpression(`default`, true),
  4438. exp: slotProps,
  4439. loc: dirLoc
  4440. } = slotDir;
  4441. let staticSlotName;
  4442. if (isStaticExp(slotName)) {
  4443. staticSlotName = slotName ? slotName.content : `default`;
  4444. } else {
  4445. hasDynamicSlots = true;
  4446. }
  4447. const vFor = findDir(slotElement, "for");
  4448. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  4449. let vIf;
  4450. let vElse;
  4451. if (vIf = findDir(slotElement, "if")) {
  4452. hasDynamicSlots = true;
  4453. dynamicSlots.push(
  4454. createConditionalExpression(
  4455. vIf.exp,
  4456. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  4457. defaultFallback
  4458. )
  4459. );
  4460. } else if (vElse = findDir(
  4461. slotElement,
  4462. /^else(?:-if)?$/,
  4463. true
  4464. /* allowEmpty */
  4465. )) {
  4466. let j = i;
  4467. let prev;
  4468. while (j--) {
  4469. prev = children[j];
  4470. if (!isCommentOrWhitespace(prev)) {
  4471. break;
  4472. }
  4473. }
  4474. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  4475. let conditional = dynamicSlots[dynamicSlots.length - 1];
  4476. while (conditional.alternate.type === 19) {
  4477. conditional = conditional.alternate;
  4478. }
  4479. conditional.alternate = vElse.exp ? createConditionalExpression(
  4480. vElse.exp,
  4481. buildDynamicSlot(
  4482. slotName,
  4483. slotFunction,
  4484. conditionalBranchIndex++
  4485. ),
  4486. defaultFallback
  4487. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  4488. } else {
  4489. context.onError(
  4490. createCompilerError(30, vElse.loc)
  4491. );
  4492. }
  4493. } else if (vFor) {
  4494. hasDynamicSlots = true;
  4495. const parseResult = vFor.forParseResult;
  4496. if (parseResult) {
  4497. finalizeForParseResult(parseResult, context);
  4498. dynamicSlots.push(
  4499. createCallExpression(context.helper(RENDER_LIST), [
  4500. parseResult.source,
  4501. createFunctionExpression(
  4502. createForLoopParams(parseResult),
  4503. buildDynamicSlot(slotName, slotFunction),
  4504. true
  4505. )
  4506. ])
  4507. );
  4508. } else {
  4509. context.onError(
  4510. createCompilerError(
  4511. 32,
  4512. vFor.loc
  4513. )
  4514. );
  4515. }
  4516. } else {
  4517. if (staticSlotName) {
  4518. if (seenSlotNames.has(staticSlotName)) {
  4519. context.onError(
  4520. createCompilerError(
  4521. 38,
  4522. dirLoc
  4523. )
  4524. );
  4525. continue;
  4526. }
  4527. seenSlotNames.add(staticSlotName);
  4528. if (staticSlotName === "default") {
  4529. hasNamedDefaultSlot = true;
  4530. }
  4531. }
  4532. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  4533. }
  4534. }
  4535. if (!onComponentSlot) {
  4536. const buildDefaultSlotProperty = (props, children2) => {
  4537. const fn = buildSlotFn(props, void 0, children2, loc);
  4538. if (context.compatConfig) {
  4539. fn.isNonScopedSlot = true;
  4540. }
  4541. return createObjectProperty(`default`, fn);
  4542. };
  4543. if (!hasTemplateSlots) {
  4544. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  4545. } else if (implicitDefaultChildren.length && // #3766
  4546. // with whitespace: 'preserve', whitespaces between slots will end up in
  4547. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  4548. !implicitDefaultChildren.every(isWhitespaceText)) {
  4549. if (hasNamedDefaultSlot) {
  4550. context.onError(
  4551. createCompilerError(
  4552. 39,
  4553. implicitDefaultChildren[0].loc
  4554. )
  4555. );
  4556. } else {
  4557. slotsProperties.push(
  4558. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  4559. );
  4560. }
  4561. }
  4562. }
  4563. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  4564. let slots = createObjectExpression(
  4565. slotsProperties.concat(
  4566. createObjectProperty(
  4567. `_`,
  4568. // 2 = compiled but dynamic = can skip normalization, but must run diff
  4569. // 1 = compiled and static = can skip normalization AND diff as optimized
  4570. createSimpleExpression(
  4571. slotFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${slotFlagsText[slotFlag]} */` : ``),
  4572. false
  4573. )
  4574. )
  4575. ),
  4576. loc
  4577. );
  4578. if (dynamicSlots.length) {
  4579. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  4580. slots,
  4581. createArrayExpression(dynamicSlots)
  4582. ]);
  4583. }
  4584. return {
  4585. slots,
  4586. hasDynamicSlots
  4587. };
  4588. }
  4589. function buildDynamicSlot(name, fn, index) {
  4590. const props = [
  4591. createObjectProperty(`name`, name),
  4592. createObjectProperty(`fn`, fn)
  4593. ];
  4594. if (index != null) {
  4595. props.push(
  4596. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  4597. );
  4598. }
  4599. return createObjectExpression(props);
  4600. }
  4601. function hasForwardedSlots(children) {
  4602. for (let i = 0; i < children.length; i++) {
  4603. const child = children[i];
  4604. switch (child.type) {
  4605. case 1:
  4606. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  4607. return true;
  4608. }
  4609. break;
  4610. case 9:
  4611. if (hasForwardedSlots(child.branches)) return true;
  4612. break;
  4613. case 10:
  4614. case 11:
  4615. if (hasForwardedSlots(child.children)) return true;
  4616. break;
  4617. }
  4618. }
  4619. return false;
  4620. }
  4621. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  4622. const transformElement = (node, context) => {
  4623. return function postTransformElement() {
  4624. node = context.currentNode;
  4625. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  4626. return;
  4627. }
  4628. const { tag, props } = node;
  4629. const isComponent = node.tagType === 1;
  4630. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  4631. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  4632. let vnodeProps;
  4633. let vnodeChildren;
  4634. let patchFlag = 0;
  4635. let vnodeDynamicProps;
  4636. let dynamicPropNames;
  4637. let vnodeDirectives;
  4638. let shouldUseBlock = (
  4639. // dynamic component may resolve to plain elements
  4640. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  4641. // updates inside get proper isSVG flag at runtime. (#639, #643)
  4642. // This is technically web-specific, but splitting the logic out of core
  4643. // leads to too much unnecessary complexity.
  4644. (tag === "svg" || tag === "foreignObject" || tag === "math")
  4645. );
  4646. if (props.length > 0) {
  4647. const propsBuildResult = buildProps(
  4648. node,
  4649. context,
  4650. void 0,
  4651. isComponent,
  4652. isDynamicComponent
  4653. );
  4654. vnodeProps = propsBuildResult.props;
  4655. patchFlag = propsBuildResult.patchFlag;
  4656. dynamicPropNames = propsBuildResult.dynamicPropNames;
  4657. const directives = propsBuildResult.directives;
  4658. vnodeDirectives = directives && directives.length ? createArrayExpression(
  4659. directives.map((dir) => buildDirectiveArgs(dir, context))
  4660. ) : void 0;
  4661. if (propsBuildResult.shouldUseBlock) {
  4662. shouldUseBlock = true;
  4663. }
  4664. }
  4665. if (node.children.length > 0) {
  4666. if (vnodeTag === KEEP_ALIVE) {
  4667. shouldUseBlock = true;
  4668. patchFlag |= 1024;
  4669. if (!!(process.env.NODE_ENV !== "production") && node.children.length > 1) {
  4670. context.onError(
  4671. createCompilerError(47, {
  4672. start: node.children[0].loc.start,
  4673. end: node.children[node.children.length - 1].loc.end,
  4674. source: ""
  4675. })
  4676. );
  4677. }
  4678. }
  4679. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  4680. vnodeTag !== TELEPORT && // explained above.
  4681. vnodeTag !== KEEP_ALIVE;
  4682. if (shouldBuildAsSlots) {
  4683. const { slots, hasDynamicSlots } = buildSlots(node, context);
  4684. vnodeChildren = slots;
  4685. if (hasDynamicSlots) {
  4686. patchFlag |= 1024;
  4687. }
  4688. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  4689. const child = node.children[0];
  4690. const type = child.type;
  4691. const hasDynamicTextChild = type === 5 || type === 8;
  4692. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  4693. patchFlag |= 1;
  4694. }
  4695. if (hasDynamicTextChild || type === 2) {
  4696. vnodeChildren = child;
  4697. } else {
  4698. vnodeChildren = node.children;
  4699. }
  4700. } else {
  4701. vnodeChildren = node.children;
  4702. }
  4703. }
  4704. if (dynamicPropNames && dynamicPropNames.length) {
  4705. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  4706. }
  4707. node.codegenNode = createVNodeCall(
  4708. context,
  4709. vnodeTag,
  4710. vnodeProps,
  4711. vnodeChildren,
  4712. patchFlag === 0 ? void 0 : patchFlag,
  4713. vnodeDynamicProps,
  4714. vnodeDirectives,
  4715. !!shouldUseBlock,
  4716. false,
  4717. isComponent,
  4718. node.loc
  4719. );
  4720. };
  4721. };
  4722. function resolveComponentType(node, context, ssr = false) {
  4723. let { tag } = node;
  4724. const isExplicitDynamic = isComponentTag(tag);
  4725. const isProp = findProp(
  4726. node,
  4727. "is",
  4728. false,
  4729. true
  4730. /* allow empty */
  4731. );
  4732. if (isProp) {
  4733. if (isExplicitDynamic || isCompatEnabled(
  4734. "COMPILER_IS_ON_ELEMENT",
  4735. context
  4736. )) {
  4737. let exp;
  4738. if (isProp.type === 6) {
  4739. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  4740. } else {
  4741. exp = isProp.exp;
  4742. if (!exp) {
  4743. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  4744. }
  4745. }
  4746. if (exp) {
  4747. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  4748. exp
  4749. ]);
  4750. }
  4751. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  4752. tag = isProp.value.content.slice(4);
  4753. }
  4754. }
  4755. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  4756. if (builtIn) {
  4757. if (!ssr) context.helper(builtIn);
  4758. return builtIn;
  4759. }
  4760. context.helper(RESOLVE_COMPONENT);
  4761. context.components.add(tag);
  4762. return toValidAssetId(tag, `component`);
  4763. }
  4764. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  4765. const { tag, loc: elementLoc, children } = node;
  4766. let properties = [];
  4767. const mergeArgs = [];
  4768. const runtimeDirectives = [];
  4769. const hasChildren = children.length > 0;
  4770. let shouldUseBlock = false;
  4771. let patchFlag = 0;
  4772. let hasRef = false;
  4773. let hasClassBinding = false;
  4774. let hasStyleBinding = false;
  4775. let hasHydrationEventBinding = false;
  4776. let hasDynamicKeys = false;
  4777. let hasVnodeHook = false;
  4778. const dynamicPropNames = [];
  4779. const pushMergeArg = (arg) => {
  4780. if (properties.length) {
  4781. mergeArgs.push(
  4782. createObjectExpression(dedupeProperties(properties), elementLoc)
  4783. );
  4784. properties = [];
  4785. }
  4786. if (arg) mergeArgs.push(arg);
  4787. };
  4788. const pushRefVForMarker = () => {
  4789. if (context.scopes.vFor > 0) {
  4790. properties.push(
  4791. createObjectProperty(
  4792. createSimpleExpression("ref_for", true),
  4793. createSimpleExpression("true")
  4794. )
  4795. );
  4796. }
  4797. };
  4798. const analyzePatchFlag = ({ key, value }) => {
  4799. if (isStaticExp(key)) {
  4800. const name = key.content;
  4801. const isEventHandler = isOn(name);
  4802. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  4803. // dedicated fast path.
  4804. name.toLowerCase() !== "onclick" && // omit v-model handlers
  4805. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  4806. !isReservedProp(name)) {
  4807. hasHydrationEventBinding = true;
  4808. }
  4809. if (isEventHandler && isReservedProp(name)) {
  4810. hasVnodeHook = true;
  4811. }
  4812. if (isEventHandler && value.type === 14) {
  4813. value = value.arguments[0];
  4814. }
  4815. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  4816. return;
  4817. }
  4818. if (name === "ref") {
  4819. hasRef = true;
  4820. } else if (name === "class") {
  4821. hasClassBinding = true;
  4822. } else if (name === "style") {
  4823. hasStyleBinding = true;
  4824. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  4825. dynamicPropNames.push(name);
  4826. }
  4827. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  4828. dynamicPropNames.push(name);
  4829. }
  4830. } else {
  4831. hasDynamicKeys = true;
  4832. }
  4833. };
  4834. for (let i = 0; i < props.length; i++) {
  4835. const prop = props[i];
  4836. if (prop.type === 6) {
  4837. const { loc, name, nameLoc, value } = prop;
  4838. let isStatic = true;
  4839. if (name === "ref") {
  4840. hasRef = true;
  4841. pushRefVForMarker();
  4842. }
  4843. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  4844. "COMPILER_IS_ON_ELEMENT",
  4845. context
  4846. ))) {
  4847. continue;
  4848. }
  4849. properties.push(
  4850. createObjectProperty(
  4851. createSimpleExpression(name, true, nameLoc),
  4852. createSimpleExpression(
  4853. value ? value.content : "",
  4854. isStatic,
  4855. value ? value.loc : loc
  4856. )
  4857. )
  4858. );
  4859. } else {
  4860. const { name, arg, exp, loc, modifiers } = prop;
  4861. const isVBind = name === "bind";
  4862. const isVOn = name === "on";
  4863. if (name === "slot") {
  4864. if (!isComponent) {
  4865. context.onError(
  4866. createCompilerError(40, loc)
  4867. );
  4868. }
  4869. continue;
  4870. }
  4871. if (name === "once" || name === "memo") {
  4872. continue;
  4873. }
  4874. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  4875. "COMPILER_IS_ON_ELEMENT",
  4876. context
  4877. ))) {
  4878. continue;
  4879. }
  4880. if (isVOn && ssr) {
  4881. continue;
  4882. }
  4883. if (
  4884. // #938: elements with dynamic keys should be forced into blocks
  4885. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  4886. // before children
  4887. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  4888. ) {
  4889. shouldUseBlock = true;
  4890. }
  4891. if (isVBind && isStaticArgOf(arg, "ref")) {
  4892. pushRefVForMarker();
  4893. }
  4894. if (!arg && (isVBind || isVOn)) {
  4895. hasDynamicKeys = true;
  4896. if (exp) {
  4897. if (isVBind) {
  4898. {
  4899. pushMergeArg();
  4900. if (!!(process.env.NODE_ENV !== "production")) {
  4901. const hasOverridableKeys = mergeArgs.some((arg2) => {
  4902. if (arg2.type === 15) {
  4903. return arg2.properties.some(({ key }) => {
  4904. if (key.type !== 4 || !key.isStatic) {
  4905. return true;
  4906. }
  4907. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  4908. });
  4909. } else {
  4910. return true;
  4911. }
  4912. });
  4913. if (hasOverridableKeys) {
  4914. checkCompatEnabled(
  4915. "COMPILER_V_BIND_OBJECT_ORDER",
  4916. context,
  4917. loc
  4918. );
  4919. }
  4920. }
  4921. if (isCompatEnabled(
  4922. "COMPILER_V_BIND_OBJECT_ORDER",
  4923. context
  4924. )) {
  4925. mergeArgs.unshift(exp);
  4926. continue;
  4927. }
  4928. }
  4929. pushRefVForMarker();
  4930. pushMergeArg();
  4931. mergeArgs.push(exp);
  4932. } else {
  4933. pushMergeArg({
  4934. type: 14,
  4935. loc,
  4936. callee: context.helper(TO_HANDLERS),
  4937. arguments: isComponent ? [exp] : [exp, `true`]
  4938. });
  4939. }
  4940. } else {
  4941. context.onError(
  4942. createCompilerError(
  4943. isVBind ? 34 : 35,
  4944. loc
  4945. )
  4946. );
  4947. }
  4948. continue;
  4949. }
  4950. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  4951. patchFlag |= 32;
  4952. }
  4953. const directiveTransform = context.directiveTransforms[name];
  4954. if (directiveTransform) {
  4955. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  4956. !ssr && props2.forEach(analyzePatchFlag);
  4957. if (isVOn && arg && !isStaticExp(arg)) {
  4958. pushMergeArg(createObjectExpression(props2, elementLoc));
  4959. } else {
  4960. properties.push(...props2);
  4961. }
  4962. if (needRuntime) {
  4963. runtimeDirectives.push(prop);
  4964. if (isSymbol(needRuntime)) {
  4965. directiveImportMap.set(prop, needRuntime);
  4966. }
  4967. }
  4968. } else if (!isBuiltInDirective(name)) {
  4969. runtimeDirectives.push(prop);
  4970. if (hasChildren) {
  4971. shouldUseBlock = true;
  4972. }
  4973. }
  4974. }
  4975. }
  4976. let propsExpression = void 0;
  4977. if (mergeArgs.length) {
  4978. pushMergeArg();
  4979. if (mergeArgs.length > 1) {
  4980. propsExpression = createCallExpression(
  4981. context.helper(MERGE_PROPS),
  4982. mergeArgs,
  4983. elementLoc
  4984. );
  4985. } else {
  4986. propsExpression = mergeArgs[0];
  4987. }
  4988. } else if (properties.length) {
  4989. propsExpression = createObjectExpression(
  4990. dedupeProperties(properties),
  4991. elementLoc
  4992. );
  4993. }
  4994. if (hasDynamicKeys) {
  4995. patchFlag |= 16;
  4996. } else {
  4997. if (hasClassBinding && !isComponent) {
  4998. patchFlag |= 2;
  4999. }
  5000. if (hasStyleBinding && !isComponent) {
  5001. patchFlag |= 4;
  5002. }
  5003. if (dynamicPropNames.length) {
  5004. patchFlag |= 8;
  5005. }
  5006. if (hasHydrationEventBinding) {
  5007. patchFlag |= 32;
  5008. }
  5009. }
  5010. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  5011. patchFlag |= 512;
  5012. }
  5013. if (!context.inSSR && propsExpression) {
  5014. switch (propsExpression.type) {
  5015. case 15:
  5016. let classKeyIndex = -1;
  5017. let styleKeyIndex = -1;
  5018. let hasDynamicKey = false;
  5019. for (let i = 0; i < propsExpression.properties.length; i++) {
  5020. const key = propsExpression.properties[i].key;
  5021. if (isStaticExp(key)) {
  5022. if (key.content === "class") {
  5023. classKeyIndex = i;
  5024. } else if (key.content === "style") {
  5025. styleKeyIndex = i;
  5026. }
  5027. } else if (!key.isHandlerKey) {
  5028. hasDynamicKey = true;
  5029. }
  5030. }
  5031. const classProp = propsExpression.properties[classKeyIndex];
  5032. const styleProp = propsExpression.properties[styleKeyIndex];
  5033. if (!hasDynamicKey) {
  5034. if (classProp && !isStaticExp(classProp.value)) {
  5035. classProp.value = createCallExpression(
  5036. context.helper(NORMALIZE_CLASS),
  5037. [classProp.value]
  5038. );
  5039. }
  5040. if (styleProp && // the static style is compiled into an object,
  5041. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  5042. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  5043. // v-bind:style with static literal object
  5044. styleProp.value.type === 17)) {
  5045. styleProp.value = createCallExpression(
  5046. context.helper(NORMALIZE_STYLE),
  5047. [styleProp.value]
  5048. );
  5049. }
  5050. } else {
  5051. propsExpression = createCallExpression(
  5052. context.helper(NORMALIZE_PROPS),
  5053. [propsExpression]
  5054. );
  5055. }
  5056. break;
  5057. case 14:
  5058. break;
  5059. default:
  5060. propsExpression = createCallExpression(
  5061. context.helper(NORMALIZE_PROPS),
  5062. [
  5063. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  5064. propsExpression
  5065. ])
  5066. ]
  5067. );
  5068. break;
  5069. }
  5070. }
  5071. return {
  5072. props: propsExpression,
  5073. directives: runtimeDirectives,
  5074. patchFlag,
  5075. dynamicPropNames,
  5076. shouldUseBlock
  5077. };
  5078. }
  5079. function dedupeProperties(properties) {
  5080. const knownProps = /* @__PURE__ */ new Map();
  5081. const deduped = [];
  5082. for (let i = 0; i < properties.length; i++) {
  5083. const prop = properties[i];
  5084. if (prop.key.type === 8 || !prop.key.isStatic) {
  5085. deduped.push(prop);
  5086. continue;
  5087. }
  5088. const name = prop.key.content;
  5089. const existing = knownProps.get(name);
  5090. if (existing) {
  5091. if (name === "style" || name === "class" || isOn(name)) {
  5092. mergeAsArray(existing, prop);
  5093. }
  5094. } else {
  5095. knownProps.set(name, prop);
  5096. deduped.push(prop);
  5097. }
  5098. }
  5099. return deduped;
  5100. }
  5101. function mergeAsArray(existing, incoming) {
  5102. if (existing.value.type === 17) {
  5103. existing.value.elements.push(incoming.value);
  5104. } else {
  5105. existing.value = createArrayExpression(
  5106. [existing.value, incoming.value],
  5107. existing.loc
  5108. );
  5109. }
  5110. }
  5111. function buildDirectiveArgs(dir, context) {
  5112. const dirArgs = [];
  5113. const runtime = directiveImportMap.get(dir);
  5114. if (runtime) {
  5115. dirArgs.push(context.helperString(runtime));
  5116. } else {
  5117. {
  5118. context.helper(RESOLVE_DIRECTIVE);
  5119. context.directives.add(dir.name);
  5120. dirArgs.push(toValidAssetId(dir.name, `directive`));
  5121. }
  5122. }
  5123. const { loc } = dir;
  5124. if (dir.exp) dirArgs.push(dir.exp);
  5125. if (dir.arg) {
  5126. if (!dir.exp) {
  5127. dirArgs.push(`void 0`);
  5128. }
  5129. dirArgs.push(dir.arg);
  5130. }
  5131. if (Object.keys(dir.modifiers).length) {
  5132. if (!dir.arg) {
  5133. if (!dir.exp) {
  5134. dirArgs.push(`void 0`);
  5135. }
  5136. dirArgs.push(`void 0`);
  5137. }
  5138. const trueExpression = createSimpleExpression(`true`, false, loc);
  5139. dirArgs.push(
  5140. createObjectExpression(
  5141. dir.modifiers.map(
  5142. (modifier) => createObjectProperty(modifier, trueExpression)
  5143. ),
  5144. loc
  5145. )
  5146. );
  5147. }
  5148. return createArrayExpression(dirArgs, dir.loc);
  5149. }
  5150. function stringifyDynamicPropNames(props) {
  5151. let propsNamesString = `[`;
  5152. for (let i = 0, l = props.length; i < l; i++) {
  5153. propsNamesString += JSON.stringify(props[i]);
  5154. if (i < l - 1) propsNamesString += ", ";
  5155. }
  5156. return propsNamesString + `]`;
  5157. }
  5158. function isComponentTag(tag) {
  5159. return tag === "component" || tag === "Component";
  5160. }
  5161. const transformSlotOutlet = (node, context) => {
  5162. if (isSlotOutlet(node)) {
  5163. const { children, loc } = node;
  5164. const { slotName, slotProps } = processSlotOutlet(node, context);
  5165. const slotArgs = [
  5166. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  5167. slotName,
  5168. "{}",
  5169. "undefined",
  5170. "true"
  5171. ];
  5172. let expectedLen = 2;
  5173. if (slotProps) {
  5174. slotArgs[2] = slotProps;
  5175. expectedLen = 3;
  5176. }
  5177. if (children.length) {
  5178. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  5179. expectedLen = 4;
  5180. }
  5181. if (context.scopeId && !context.slotted) {
  5182. expectedLen = 5;
  5183. }
  5184. slotArgs.splice(expectedLen);
  5185. node.codegenNode = createCallExpression(
  5186. context.helper(RENDER_SLOT),
  5187. slotArgs,
  5188. loc
  5189. );
  5190. }
  5191. };
  5192. function processSlotOutlet(node, context) {
  5193. let slotName = `"default"`;
  5194. let slotProps = void 0;
  5195. const nonNameProps = [];
  5196. for (let i = 0; i < node.props.length; i++) {
  5197. const p = node.props[i];
  5198. if (p.type === 6) {
  5199. if (p.value) {
  5200. if (p.name === "name") {
  5201. slotName = JSON.stringify(p.value.content);
  5202. } else {
  5203. p.name = camelize(p.name);
  5204. nonNameProps.push(p);
  5205. }
  5206. }
  5207. } else {
  5208. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  5209. if (p.exp) {
  5210. slotName = p.exp;
  5211. } else if (p.arg && p.arg.type === 4) {
  5212. const name = camelize(p.arg.content);
  5213. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  5214. }
  5215. } else {
  5216. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  5217. p.arg.content = camelize(p.arg.content);
  5218. }
  5219. nonNameProps.push(p);
  5220. }
  5221. }
  5222. }
  5223. if (nonNameProps.length > 0) {
  5224. const { props, directives } = buildProps(
  5225. node,
  5226. context,
  5227. nonNameProps,
  5228. false,
  5229. false
  5230. );
  5231. slotProps = props;
  5232. if (directives.length) {
  5233. context.onError(
  5234. createCompilerError(
  5235. 36,
  5236. directives[0].loc
  5237. )
  5238. );
  5239. }
  5240. }
  5241. return {
  5242. slotName,
  5243. slotProps
  5244. };
  5245. }
  5246. const transformOn = (dir, node, context, augmentor) => {
  5247. const { loc, modifiers, arg } = dir;
  5248. if (!dir.exp && !modifiers.length) {
  5249. context.onError(createCompilerError(35, loc));
  5250. }
  5251. let eventName;
  5252. if (arg.type === 4) {
  5253. if (arg.isStatic) {
  5254. let rawName = arg.content;
  5255. if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) {
  5256. context.onError(createCompilerError(52, arg.loc));
  5257. }
  5258. if (rawName.startsWith("vue:")) {
  5259. rawName = `vnode-${rawName.slice(4)}`;
  5260. }
  5261. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  5262. // for non-element and vnode lifecycle event listeners, auto convert
  5263. // it to camelCase. See issue #2249
  5264. toHandlerKey(camelize(rawName))
  5265. ) : (
  5266. // preserve case for plain element listeners that have uppercase
  5267. // letters, as these may be custom elements' custom events
  5268. `on:${rawName}`
  5269. );
  5270. eventName = createSimpleExpression(eventString, true, arg.loc);
  5271. } else {
  5272. eventName = createCompoundExpression([
  5273. `${context.helperString(TO_HANDLER_KEY)}(`,
  5274. arg,
  5275. `)`
  5276. ]);
  5277. }
  5278. } else {
  5279. eventName = arg;
  5280. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  5281. eventName.children.push(`)`);
  5282. }
  5283. let exp = dir.exp;
  5284. if (exp && !exp.content.trim()) {
  5285. exp = void 0;
  5286. }
  5287. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  5288. if (exp) {
  5289. const isMemberExp = isMemberExpression(exp);
  5290. const isInlineStatement = !(isMemberExp || isFnExpression(exp));
  5291. const hasMultipleStatements = exp.content.includes(`;`);
  5292. if (!!(process.env.NODE_ENV !== "production") && true) {
  5293. validateBrowserExpression(
  5294. exp,
  5295. context,
  5296. false,
  5297. hasMultipleStatements
  5298. );
  5299. }
  5300. if (isInlineStatement || shouldCache && isMemberExp) {
  5301. exp = createCompoundExpression([
  5302. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  5303. exp,
  5304. hasMultipleStatements ? `}` : `)`
  5305. ]);
  5306. }
  5307. }
  5308. let ret = {
  5309. props: [
  5310. createObjectProperty(
  5311. eventName,
  5312. exp || createSimpleExpression(`() => {}`, false, loc)
  5313. )
  5314. ]
  5315. };
  5316. if (augmentor) {
  5317. ret = augmentor(ret);
  5318. }
  5319. if (shouldCache) {
  5320. ret.props[0].value = context.cache(ret.props[0].value);
  5321. }
  5322. ret.props.forEach((p) => p.key.isHandlerKey = true);
  5323. return ret;
  5324. };
  5325. const transformBind = (dir, _node, context) => {
  5326. const { modifiers, loc } = dir;
  5327. const arg = dir.arg;
  5328. let { exp } = dir;
  5329. if (exp && exp.type === 4 && !exp.content.trim()) {
  5330. {
  5331. exp = void 0;
  5332. }
  5333. }
  5334. if (arg.type !== 4) {
  5335. arg.children.unshift(`(`);
  5336. arg.children.push(`) || ""`);
  5337. } else if (!arg.isStatic) {
  5338. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  5339. }
  5340. if (modifiers.some((mod) => mod.content === "camel")) {
  5341. if (arg.type === 4) {
  5342. if (arg.isStatic) {
  5343. arg.content = camelize(arg.content);
  5344. } else {
  5345. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  5346. }
  5347. } else {
  5348. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  5349. arg.children.push(`)`);
  5350. }
  5351. }
  5352. if (!context.inSSR) {
  5353. if (modifiers.some((mod) => mod.content === "prop")) {
  5354. injectPrefix(arg, ".");
  5355. }
  5356. if (modifiers.some((mod) => mod.content === "attr")) {
  5357. injectPrefix(arg, "^");
  5358. }
  5359. }
  5360. return {
  5361. props: [createObjectProperty(arg, exp)]
  5362. };
  5363. };
  5364. const injectPrefix = (arg, prefix) => {
  5365. if (arg.type === 4) {
  5366. if (arg.isStatic) {
  5367. arg.content = prefix + arg.content;
  5368. } else {
  5369. arg.content = `\`${prefix}\${${arg.content}}\``;
  5370. }
  5371. } else {
  5372. arg.children.unshift(`'${prefix}' + (`);
  5373. arg.children.push(`)`);
  5374. }
  5375. };
  5376. const transformText = (node, context) => {
  5377. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  5378. return () => {
  5379. const children = node.children;
  5380. let currentContainer = void 0;
  5381. let hasText = false;
  5382. for (let i = 0; i < children.length; i++) {
  5383. const child = children[i];
  5384. if (isText$1(child)) {
  5385. hasText = true;
  5386. for (let j = i + 1; j < children.length; j++) {
  5387. const next = children[j];
  5388. if (isText$1(next)) {
  5389. if (!currentContainer) {
  5390. currentContainer = children[i] = createCompoundExpression(
  5391. [child],
  5392. child.loc
  5393. );
  5394. }
  5395. currentContainer.children.push(` + `, next);
  5396. children.splice(j, 1);
  5397. j--;
  5398. } else {
  5399. currentContainer = void 0;
  5400. break;
  5401. }
  5402. }
  5403. }
  5404. }
  5405. if (!hasText || // if this is a plain element with a single text child, leave it
  5406. // as-is since the runtime has dedicated fast path for this by directly
  5407. // setting textContent of the element.
  5408. // for component root it's always normalized anyway.
  5409. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  5410. // custom directives can potentially add DOM elements arbitrarily,
  5411. // we need to avoid setting textContent of the element at runtime
  5412. // to avoid accidentally overwriting the DOM elements added
  5413. // by the user through custom directives.
  5414. !node.props.find(
  5415. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  5416. ) && // in compat mode, <template> tags with no special directives
  5417. // will be rendered as a fragment so its children must be
  5418. // converted into vnodes.
  5419. !(node.tag === "template"))) {
  5420. return;
  5421. }
  5422. for (let i = 0; i < children.length; i++) {
  5423. const child = children[i];
  5424. if (isText$1(child) || child.type === 8) {
  5425. const callArgs = [];
  5426. if (child.type !== 2 || child.content !== " ") {
  5427. callArgs.push(child);
  5428. }
  5429. if (!context.ssr && getConstantType(child, context) === 0) {
  5430. callArgs.push(
  5431. 1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[1]} */` : ``)
  5432. );
  5433. }
  5434. children[i] = {
  5435. type: 12,
  5436. content: child,
  5437. loc: child.loc,
  5438. codegenNode: createCallExpression(
  5439. context.helper(CREATE_TEXT),
  5440. callArgs
  5441. )
  5442. };
  5443. }
  5444. }
  5445. };
  5446. }
  5447. };
  5448. const seen$1 = /* @__PURE__ */ new WeakSet();
  5449. const transformOnce = (node, context) => {
  5450. if (node.type === 1 && findDir(node, "once", true)) {
  5451. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  5452. return;
  5453. }
  5454. seen$1.add(node);
  5455. context.inVOnce = true;
  5456. context.helper(SET_BLOCK_TRACKING);
  5457. return () => {
  5458. context.inVOnce = false;
  5459. const cur = context.currentNode;
  5460. if (cur.codegenNode) {
  5461. cur.codegenNode = context.cache(
  5462. cur.codegenNode,
  5463. true,
  5464. true
  5465. );
  5466. }
  5467. };
  5468. }
  5469. };
  5470. const transformModel = (dir, node, context) => {
  5471. const { exp, arg } = dir;
  5472. if (!exp) {
  5473. context.onError(
  5474. createCompilerError(41, dir.loc)
  5475. );
  5476. return createTransformProps();
  5477. }
  5478. const rawExp = exp.loc.source.trim();
  5479. const expString = exp.type === 4 ? exp.content : rawExp;
  5480. const bindingType = context.bindingMetadata[rawExp];
  5481. if (bindingType === "props" || bindingType === "props-aliased") {
  5482. context.onError(createCompilerError(44, exp.loc));
  5483. return createTransformProps();
  5484. }
  5485. if (bindingType === "literal-const" || bindingType === "setup-const") {
  5486. context.onError(createCompilerError(45, exp.loc));
  5487. return createTransformProps();
  5488. }
  5489. if (!expString.trim() || !isMemberExpression(exp) && true) {
  5490. context.onError(
  5491. createCompilerError(42, exp.loc)
  5492. );
  5493. return createTransformProps();
  5494. }
  5495. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  5496. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  5497. let assignmentExp;
  5498. const eventArg = context.isTS ? `($event: any)` : `$event`;
  5499. {
  5500. assignmentExp = createCompoundExpression([
  5501. `${eventArg} => ((`,
  5502. exp,
  5503. `) = $event)`
  5504. ]);
  5505. }
  5506. const props = [
  5507. // modelValue: foo
  5508. createObjectProperty(propName, dir.exp),
  5509. // "onUpdate:modelValue": $event => (foo = $event)
  5510. createObjectProperty(eventName, assignmentExp)
  5511. ];
  5512. if (dir.modifiers.length && node.tagType === 1) {
  5513. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  5514. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  5515. props.push(
  5516. createObjectProperty(
  5517. modifiersKey,
  5518. createSimpleExpression(
  5519. `{ ${modifiers} }`,
  5520. false,
  5521. dir.loc,
  5522. 2
  5523. )
  5524. )
  5525. );
  5526. }
  5527. return createTransformProps(props);
  5528. };
  5529. function createTransformProps(props = []) {
  5530. return { props };
  5531. }
  5532. const validDivisionCharRE = /[\w).+\-_$\]]/;
  5533. const transformFilter = (node, context) => {
  5534. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  5535. return;
  5536. }
  5537. if (node.type === 5) {
  5538. rewriteFilter(node.content, context);
  5539. } else if (node.type === 1) {
  5540. node.props.forEach((prop) => {
  5541. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  5542. rewriteFilter(prop.exp, context);
  5543. }
  5544. });
  5545. }
  5546. };
  5547. function rewriteFilter(node, context) {
  5548. if (node.type === 4) {
  5549. parseFilter(node, context);
  5550. } else {
  5551. for (let i = 0; i < node.children.length; i++) {
  5552. const child = node.children[i];
  5553. if (typeof child !== "object") continue;
  5554. if (child.type === 4) {
  5555. parseFilter(child, context);
  5556. } else if (child.type === 8) {
  5557. rewriteFilter(node, context);
  5558. } else if (child.type === 5) {
  5559. rewriteFilter(child.content, context);
  5560. }
  5561. }
  5562. }
  5563. }
  5564. function parseFilter(node, context) {
  5565. const exp = node.content;
  5566. let inSingle = false;
  5567. let inDouble = false;
  5568. let inTemplateString = false;
  5569. let inRegex = false;
  5570. let curly = 0;
  5571. let square = 0;
  5572. let paren = 0;
  5573. let lastFilterIndex = 0;
  5574. let c, prev, i, expression, filters = [];
  5575. for (i = 0; i < exp.length; i++) {
  5576. prev = c;
  5577. c = exp.charCodeAt(i);
  5578. if (inSingle) {
  5579. if (c === 39 && prev !== 92) inSingle = false;
  5580. } else if (inDouble) {
  5581. if (c === 34 && prev !== 92) inDouble = false;
  5582. } else if (inTemplateString) {
  5583. if (c === 96 && prev !== 92) inTemplateString = false;
  5584. } else if (inRegex) {
  5585. if (c === 47 && prev !== 92) inRegex = false;
  5586. } else if (c === 124 && // pipe
  5587. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  5588. if (expression === void 0) {
  5589. lastFilterIndex = i + 1;
  5590. expression = exp.slice(0, i).trim();
  5591. } else {
  5592. pushFilter();
  5593. }
  5594. } else {
  5595. switch (c) {
  5596. case 34:
  5597. inDouble = true;
  5598. break;
  5599. // "
  5600. case 39:
  5601. inSingle = true;
  5602. break;
  5603. // '
  5604. case 96:
  5605. inTemplateString = true;
  5606. break;
  5607. // `
  5608. case 40:
  5609. paren++;
  5610. break;
  5611. // (
  5612. case 41:
  5613. paren--;
  5614. break;
  5615. // )
  5616. case 91:
  5617. square++;
  5618. break;
  5619. // [
  5620. case 93:
  5621. square--;
  5622. break;
  5623. // ]
  5624. case 123:
  5625. curly++;
  5626. break;
  5627. // {
  5628. case 125:
  5629. curly--;
  5630. break;
  5631. }
  5632. if (c === 47) {
  5633. let j = i - 1;
  5634. let p;
  5635. for (; j >= 0; j--) {
  5636. p = exp.charAt(j);
  5637. if (p !== " ") break;
  5638. }
  5639. if (!p || !validDivisionCharRE.test(p)) {
  5640. inRegex = true;
  5641. }
  5642. }
  5643. }
  5644. }
  5645. if (expression === void 0) {
  5646. expression = exp.slice(0, i).trim();
  5647. } else if (lastFilterIndex !== 0) {
  5648. pushFilter();
  5649. }
  5650. function pushFilter() {
  5651. filters.push(exp.slice(lastFilterIndex, i).trim());
  5652. lastFilterIndex = i + 1;
  5653. }
  5654. if (filters.length) {
  5655. !!(process.env.NODE_ENV !== "production") && warnDeprecation(
  5656. "COMPILER_FILTERS",
  5657. context,
  5658. node.loc
  5659. );
  5660. for (i = 0; i < filters.length; i++) {
  5661. expression = wrapFilter(expression, filters[i], context);
  5662. }
  5663. node.content = expression;
  5664. node.ast = void 0;
  5665. }
  5666. }
  5667. function wrapFilter(exp, filter, context) {
  5668. context.helper(RESOLVE_FILTER);
  5669. const i = filter.indexOf("(");
  5670. if (i < 0) {
  5671. context.filters.add(filter);
  5672. return `${toValidAssetId(filter, "filter")}(${exp})`;
  5673. } else {
  5674. const name = filter.slice(0, i);
  5675. const args = filter.slice(i + 1);
  5676. context.filters.add(name);
  5677. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  5678. }
  5679. }
  5680. const seen = /* @__PURE__ */ new WeakSet();
  5681. const transformMemo = (node, context) => {
  5682. if (node.type === 1) {
  5683. const dir = findDir(node, "memo");
  5684. if (!dir || seen.has(node) || context.inSSR) {
  5685. return;
  5686. }
  5687. seen.add(node);
  5688. return () => {
  5689. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  5690. if (codegenNode && codegenNode.type === 13) {
  5691. if (node.tagType !== 1) {
  5692. convertToBlock(codegenNode, context);
  5693. }
  5694. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  5695. dir.exp,
  5696. createFunctionExpression(void 0, codegenNode),
  5697. `_cache`,
  5698. String(context.cached.length)
  5699. ]);
  5700. context.cached.push(null);
  5701. }
  5702. };
  5703. }
  5704. };
  5705. const transformVBindShorthand = (node, context) => {
  5706. if (node.type === 1) {
  5707. for (const prop of node.props) {
  5708. if (prop.type === 7 && prop.name === "bind" && (!prop.exp || // #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
  5709. prop.exp.type === 4 && !prop.exp.content.trim()) && prop.arg) {
  5710. const arg = prop.arg;
  5711. if (arg.type !== 4 || !arg.isStatic) {
  5712. context.onError(
  5713. createCompilerError(
  5714. 53,
  5715. arg.loc
  5716. )
  5717. );
  5718. prop.exp = createSimpleExpression("", true, arg.loc);
  5719. } else {
  5720. const propName = camelize(arg.content);
  5721. if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
  5722. propName[0] === "-") {
  5723. prop.exp = createSimpleExpression(propName, false, arg.loc);
  5724. }
  5725. }
  5726. }
  5727. }
  5728. }
  5729. };
  5730. function getBaseTransformPreset(prefixIdentifiers) {
  5731. return [
  5732. [
  5733. transformVBindShorthand,
  5734. transformOnce,
  5735. transformIf,
  5736. transformMemo,
  5737. transformFor,
  5738. ...[transformFilter] ,
  5739. ...!!(process.env.NODE_ENV !== "production") ? [transformExpression] : [],
  5740. transformSlotOutlet,
  5741. transformElement,
  5742. trackSlotScopes,
  5743. transformText
  5744. ],
  5745. {
  5746. on: transformOn,
  5747. bind: transformBind,
  5748. model: transformModel
  5749. }
  5750. ];
  5751. }
  5752. function baseCompile(source, options = {}) {
  5753. const onError = options.onError || defaultOnError;
  5754. const isModuleMode = options.mode === "module";
  5755. {
  5756. if (options.prefixIdentifiers === true) {
  5757. onError(createCompilerError(48));
  5758. } else if (isModuleMode) {
  5759. onError(createCompilerError(49));
  5760. }
  5761. }
  5762. const prefixIdentifiers = false;
  5763. if (options.cacheHandlers) {
  5764. onError(createCompilerError(50));
  5765. }
  5766. if (options.scopeId && !isModuleMode) {
  5767. onError(createCompilerError(51));
  5768. }
  5769. const resolvedOptions = extend({}, options, {
  5770. prefixIdentifiers
  5771. });
  5772. const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
  5773. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  5774. transform(
  5775. ast,
  5776. extend({}, resolvedOptions, {
  5777. nodeTransforms: [
  5778. ...nodeTransforms,
  5779. ...options.nodeTransforms || []
  5780. // user transforms
  5781. ],
  5782. directiveTransforms: extend(
  5783. {},
  5784. directiveTransforms,
  5785. options.directiveTransforms || {}
  5786. // user transforms
  5787. )
  5788. })
  5789. );
  5790. return generate(ast, resolvedOptions);
  5791. }
  5792. const BindingTypes = {
  5793. "DATA": "data",
  5794. "PROPS": "props",
  5795. "PROPS_ALIASED": "props-aliased",
  5796. "SETUP_LET": "setup-let",
  5797. "SETUP_CONST": "setup-const",
  5798. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  5799. "SETUP_MAYBE_REF": "setup-maybe-ref",
  5800. "SETUP_REF": "setup-ref",
  5801. "OPTIONS": "options",
  5802. "LITERAL_CONST": "literal-const"
  5803. };
  5804. const noopDirectiveTransform = () => ({ props: [] });
  5805. 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 };