compiler-dom.global.js 169 KB

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