compiler-core.esm-bundler.js 186 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858
  1. import { isString, hyphenate, NOOP, extend, isObject, NO, isArray, makeMap, isSymbol, EMPTY_OBJ, capitalize, camelize as camelize$1, PatchFlagNames, slotFlagsText, isOn, isBuiltInDirective, isReservedProp, toHandlerKey } from '@vue/shared';
  2. export { generateCodeFrame } from '@vue/shared';
  3. function defaultOnError(error) {
  4. throw error;
  5. }
  6. function defaultOnWarn(msg) {
  7. (process.env.NODE_ENV !== 'production') && console.warn(`[Vue warn] ${msg.message}`);
  8. }
  9. function createCompilerError(code, loc, messages, additionalMessage) {
  10. const msg = (process.env.NODE_ENV !== 'production') || !true
  11. ? (messages || errorMessages)[code] + (additionalMessage || ``)
  12. : code;
  13. const error = new SyntaxError(String(msg));
  14. error.code = code;
  15. error.loc = loc;
  16. return error;
  17. }
  18. const errorMessages = {
  19. // parse errors
  20. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  21. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  22. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  23. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  24. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  25. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  26. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  27. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  28. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  29. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  30. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  31. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  32. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  33. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  34. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  35. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  36. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  37. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  38. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  39. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  40. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  41. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  42. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  43. // Vue-specific parse errors
  44. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  45. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  46. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  47. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  48. 'Note that dynamic directive argument cannot contain spaces.',
  49. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  50. // transform errors
  51. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  52. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  53. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  54. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  55. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  56. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  57. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  58. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  59. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  60. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  61. `When there are multiple named slots, all slots should use <template> ` +
  62. `syntax to avoid scope ambiguity.`,
  63. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  64. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  65. `default slot. These children will be ignored.`,
  66. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  67. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  68. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  69. [43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  70. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  71. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  72. // generic errors
  73. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  74. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  75. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  76. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  77. // just to fulfill types
  78. [50 /* __EXTEND_POINT__ */]: ``
  79. };
  80. const FRAGMENT = Symbol((process.env.NODE_ENV !== 'production') ? `Fragment` : ``);
  81. const TELEPORT = Symbol((process.env.NODE_ENV !== 'production') ? `Teleport` : ``);
  82. const SUSPENSE = Symbol((process.env.NODE_ENV !== 'production') ? `Suspense` : ``);
  83. const KEEP_ALIVE = Symbol((process.env.NODE_ENV !== 'production') ? `KeepAlive` : ``);
  84. const BASE_TRANSITION = Symbol((process.env.NODE_ENV !== 'production') ? `BaseTransition` : ``);
  85. const OPEN_BLOCK = Symbol((process.env.NODE_ENV !== 'production') ? `openBlock` : ``);
  86. const CREATE_BLOCK = Symbol((process.env.NODE_ENV !== 'production') ? `createBlock` : ``);
  87. const CREATE_ELEMENT_BLOCK = Symbol((process.env.NODE_ENV !== 'production') ? `createElementBlock` : ``);
  88. const CREATE_VNODE = Symbol((process.env.NODE_ENV !== 'production') ? `createVNode` : ``);
  89. const CREATE_ELEMENT_VNODE = Symbol((process.env.NODE_ENV !== 'production') ? `createElementVNode` : ``);
  90. const CREATE_COMMENT = Symbol((process.env.NODE_ENV !== 'production') ? `createCommentVNode` : ``);
  91. const CREATE_TEXT = Symbol((process.env.NODE_ENV !== 'production') ? `createTextVNode` : ``);
  92. const CREATE_STATIC = Symbol((process.env.NODE_ENV !== 'production') ? `createStaticVNode` : ``);
  93. const RESOLVE_COMPONENT = Symbol((process.env.NODE_ENV !== 'production') ? `resolveComponent` : ``);
  94. const RESOLVE_DYNAMIC_COMPONENT = Symbol((process.env.NODE_ENV !== 'production') ? `resolveDynamicComponent` : ``);
  95. const RESOLVE_DIRECTIVE = Symbol((process.env.NODE_ENV !== 'production') ? `resolveDirective` : ``);
  96. const RESOLVE_FILTER = Symbol((process.env.NODE_ENV !== 'production') ? `resolveFilter` : ``);
  97. const WITH_DIRECTIVES = Symbol((process.env.NODE_ENV !== 'production') ? `withDirectives` : ``);
  98. const RENDER_LIST = Symbol((process.env.NODE_ENV !== 'production') ? `renderList` : ``);
  99. const RENDER_SLOT = Symbol((process.env.NODE_ENV !== 'production') ? `renderSlot` : ``);
  100. const CREATE_SLOTS = Symbol((process.env.NODE_ENV !== 'production') ? `createSlots` : ``);
  101. const TO_DISPLAY_STRING = Symbol((process.env.NODE_ENV !== 'production') ? `toDisplayString` : ``);
  102. const MERGE_PROPS = Symbol((process.env.NODE_ENV !== 'production') ? `mergeProps` : ``);
  103. const NORMALIZE_CLASS = Symbol((process.env.NODE_ENV !== 'production') ? `normalizeClass` : ``);
  104. const NORMALIZE_STYLE = Symbol((process.env.NODE_ENV !== 'production') ? `normalizeStyle` : ``);
  105. const NORMALIZE_PROPS = Symbol((process.env.NODE_ENV !== 'production') ? `normalizeProps` : ``);
  106. const GUARD_REACTIVE_PROPS = Symbol((process.env.NODE_ENV !== 'production') ? `guardReactiveProps` : ``);
  107. const TO_HANDLERS = Symbol((process.env.NODE_ENV !== 'production') ? `toHandlers` : ``);
  108. const CAMELIZE = Symbol((process.env.NODE_ENV !== 'production') ? `camelize` : ``);
  109. const CAPITALIZE = Symbol((process.env.NODE_ENV !== 'production') ? `capitalize` : ``);
  110. const TO_HANDLER_KEY = Symbol((process.env.NODE_ENV !== 'production') ? `toHandlerKey` : ``);
  111. const SET_BLOCK_TRACKING = Symbol((process.env.NODE_ENV !== 'production') ? `setBlockTracking` : ``);
  112. const PUSH_SCOPE_ID = Symbol((process.env.NODE_ENV !== 'production') ? `pushScopeId` : ``);
  113. const POP_SCOPE_ID = Symbol((process.env.NODE_ENV !== 'production') ? `popScopeId` : ``);
  114. const WITH_CTX = Symbol((process.env.NODE_ENV !== 'production') ? `withCtx` : ``);
  115. const UNREF = Symbol((process.env.NODE_ENV !== 'production') ? `unref` : ``);
  116. const IS_REF = Symbol((process.env.NODE_ENV !== 'production') ? `isRef` : ``);
  117. const WITH_MEMO = Symbol((process.env.NODE_ENV !== 'production') ? `withMemo` : ``);
  118. const IS_MEMO_SAME = Symbol((process.env.NODE_ENV !== 'production') ? `isMemoSame` : ``);
  119. // Name mapping for runtime helpers that need to be imported from 'vue' in
  120. // generated code. Make sure these are correctly exported in the runtime!
  121. // Using `any` here because TS doesn't allow symbols as index type.
  122. const helperNameMap = {
  123. [FRAGMENT]: `Fragment`,
  124. [TELEPORT]: `Teleport`,
  125. [SUSPENSE]: `Suspense`,
  126. [KEEP_ALIVE]: `KeepAlive`,
  127. [BASE_TRANSITION]: `BaseTransition`,
  128. [OPEN_BLOCK]: `openBlock`,
  129. [CREATE_BLOCK]: `createBlock`,
  130. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  131. [CREATE_VNODE]: `createVNode`,
  132. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  133. [CREATE_COMMENT]: `createCommentVNode`,
  134. [CREATE_TEXT]: `createTextVNode`,
  135. [CREATE_STATIC]: `createStaticVNode`,
  136. [RESOLVE_COMPONENT]: `resolveComponent`,
  137. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  138. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  139. [RESOLVE_FILTER]: `resolveFilter`,
  140. [WITH_DIRECTIVES]: `withDirectives`,
  141. [RENDER_LIST]: `renderList`,
  142. [RENDER_SLOT]: `renderSlot`,
  143. [CREATE_SLOTS]: `createSlots`,
  144. [TO_DISPLAY_STRING]: `toDisplayString`,
  145. [MERGE_PROPS]: `mergeProps`,
  146. [NORMALIZE_CLASS]: `normalizeClass`,
  147. [NORMALIZE_STYLE]: `normalizeStyle`,
  148. [NORMALIZE_PROPS]: `normalizeProps`,
  149. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  150. [TO_HANDLERS]: `toHandlers`,
  151. [CAMELIZE]: `camelize`,
  152. [CAPITALIZE]: `capitalize`,
  153. [TO_HANDLER_KEY]: `toHandlerKey`,
  154. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  155. [PUSH_SCOPE_ID]: `pushScopeId`,
  156. [POP_SCOPE_ID]: `popScopeId`,
  157. [WITH_CTX]: `withCtx`,
  158. [UNREF]: `unref`,
  159. [IS_REF]: `isRef`,
  160. [WITH_MEMO]: `withMemo`,
  161. [IS_MEMO_SAME]: `isMemoSame`
  162. };
  163. function registerRuntimeHelpers(helpers) {
  164. Object.getOwnPropertySymbols(helpers).forEach(s => {
  165. helperNameMap[s] = helpers[s];
  166. });
  167. }
  168. // AST Utilities ---------------------------------------------------------------
  169. // Some expressions, e.g. sequence and conditional expressions, are never
  170. // associated with template nodes, so their source locations are just a stub.
  171. // Container types like CompoundExpression also don't need a real location.
  172. const locStub = {
  173. source: '',
  174. start: { line: 1, column: 1, offset: 0 },
  175. end: { line: 1, column: 1, offset: 0 }
  176. };
  177. function createRoot(children, loc = locStub) {
  178. return {
  179. type: 0 /* ROOT */,
  180. children,
  181. helpers: [],
  182. components: [],
  183. directives: [],
  184. hoists: [],
  185. imports: [],
  186. cached: 0,
  187. temps: 0,
  188. codegenNode: undefined,
  189. loc
  190. };
  191. }
  192. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  193. if (context) {
  194. if (isBlock) {
  195. context.helper(OPEN_BLOCK);
  196. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  197. }
  198. else {
  199. context.helper(getVNodeHelper(context.inSSR, isComponent));
  200. }
  201. if (directives) {
  202. context.helper(WITH_DIRECTIVES);
  203. }
  204. }
  205. return {
  206. type: 13 /* VNODE_CALL */,
  207. tag,
  208. props,
  209. children,
  210. patchFlag,
  211. dynamicProps,
  212. directives,
  213. isBlock,
  214. disableTracking,
  215. isComponent,
  216. loc
  217. };
  218. }
  219. function createArrayExpression(elements, loc = locStub) {
  220. return {
  221. type: 17 /* JS_ARRAY_EXPRESSION */,
  222. loc,
  223. elements
  224. };
  225. }
  226. function createObjectExpression(properties, loc = locStub) {
  227. return {
  228. type: 15 /* JS_OBJECT_EXPRESSION */,
  229. loc,
  230. properties
  231. };
  232. }
  233. function createObjectProperty(key, value) {
  234. return {
  235. type: 16 /* JS_PROPERTY */,
  236. loc: locStub,
  237. key: isString(key) ? createSimpleExpression(key, true) : key,
  238. value
  239. };
  240. }
  241. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  242. return {
  243. type: 4 /* SIMPLE_EXPRESSION */,
  244. loc,
  245. content,
  246. isStatic,
  247. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  248. };
  249. }
  250. function createInterpolation(content, loc) {
  251. return {
  252. type: 5 /* INTERPOLATION */,
  253. loc,
  254. content: isString(content)
  255. ? createSimpleExpression(content, false, loc)
  256. : content
  257. };
  258. }
  259. function createCompoundExpression(children, loc = locStub) {
  260. return {
  261. type: 8 /* COMPOUND_EXPRESSION */,
  262. loc,
  263. children
  264. };
  265. }
  266. function createCallExpression(callee, args = [], loc = locStub) {
  267. return {
  268. type: 14 /* JS_CALL_EXPRESSION */,
  269. loc,
  270. callee,
  271. arguments: args
  272. };
  273. }
  274. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  275. return {
  276. type: 18 /* JS_FUNCTION_EXPRESSION */,
  277. params,
  278. returns,
  279. newline,
  280. isSlot,
  281. loc
  282. };
  283. }
  284. function createConditionalExpression(test, consequent, alternate, newline = true) {
  285. return {
  286. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  287. test,
  288. consequent,
  289. alternate,
  290. newline,
  291. loc: locStub
  292. };
  293. }
  294. function createCacheExpression(index, value, isVNode = false) {
  295. return {
  296. type: 20 /* JS_CACHE_EXPRESSION */,
  297. index,
  298. value,
  299. isVNode,
  300. loc: locStub
  301. };
  302. }
  303. function createBlockStatement(body) {
  304. return {
  305. type: 21 /* JS_BLOCK_STATEMENT */,
  306. body,
  307. loc: locStub
  308. };
  309. }
  310. function createTemplateLiteral(elements) {
  311. return {
  312. type: 22 /* JS_TEMPLATE_LITERAL */,
  313. elements,
  314. loc: locStub
  315. };
  316. }
  317. function createIfStatement(test, consequent, alternate) {
  318. return {
  319. type: 23 /* JS_IF_STATEMENT */,
  320. test,
  321. consequent,
  322. alternate,
  323. loc: locStub
  324. };
  325. }
  326. function createAssignmentExpression(left, right) {
  327. return {
  328. type: 24 /* JS_ASSIGNMENT_EXPRESSION */,
  329. left,
  330. right,
  331. loc: locStub
  332. };
  333. }
  334. function createSequenceExpression(expressions) {
  335. return {
  336. type: 25 /* JS_SEQUENCE_EXPRESSION */,
  337. expressions,
  338. loc: locStub
  339. };
  340. }
  341. function createReturnStatement(returns) {
  342. return {
  343. type: 26 /* JS_RETURN_STATEMENT */,
  344. returns,
  345. loc: locStub
  346. };
  347. }
  348. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  349. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  350. function isCoreComponent(tag) {
  351. if (isBuiltInType(tag, 'Teleport')) {
  352. return TELEPORT;
  353. }
  354. else if (isBuiltInType(tag, 'Suspense')) {
  355. return SUSPENSE;
  356. }
  357. else if (isBuiltInType(tag, 'KeepAlive')) {
  358. return KEEP_ALIVE;
  359. }
  360. else if (isBuiltInType(tag, 'BaseTransition')) {
  361. return BASE_TRANSITION;
  362. }
  363. }
  364. const nonIdentifierRE = /^\d|[^\$\w]/;
  365. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  366. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  367. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  368. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  369. /**
  370. * Simple lexer to check if an expression is a member expression. This is
  371. * lax and only checks validity at the root level (i.e. does not validate exps
  372. * inside square brackets), but it's ok since these are only used on template
  373. * expressions and false positives are invalid expressions in the first place.
  374. */
  375. const isMemberExpressionBrowser = (path) => {
  376. // remove whitespaces around . or [ first
  377. path = path.trim().replace(whitespaceRE, s => s.trim());
  378. let state = 0 /* inMemberExp */;
  379. let stateStack = [];
  380. let currentOpenBracketCount = 0;
  381. let currentOpenParensCount = 0;
  382. let currentStringType = null;
  383. for (let i = 0; i < path.length; i++) {
  384. const char = path.charAt(i);
  385. switch (state) {
  386. case 0 /* inMemberExp */:
  387. if (char === '[') {
  388. stateStack.push(state);
  389. state = 1 /* inBrackets */;
  390. currentOpenBracketCount++;
  391. }
  392. else if (char === '(') {
  393. stateStack.push(state);
  394. state = 2 /* inParens */;
  395. currentOpenParensCount++;
  396. }
  397. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  398. return false;
  399. }
  400. break;
  401. case 1 /* inBrackets */:
  402. if (char === `'` || char === `"` || char === '`') {
  403. stateStack.push(state);
  404. state = 3 /* inString */;
  405. currentStringType = char;
  406. }
  407. else if (char === `[`) {
  408. currentOpenBracketCount++;
  409. }
  410. else if (char === `]`) {
  411. if (!--currentOpenBracketCount) {
  412. state = stateStack.pop();
  413. }
  414. }
  415. break;
  416. case 2 /* inParens */:
  417. if (char === `'` || char === `"` || char === '`') {
  418. stateStack.push(state);
  419. state = 3 /* inString */;
  420. currentStringType = char;
  421. }
  422. else if (char === `(`) {
  423. currentOpenParensCount++;
  424. }
  425. else if (char === `)`) {
  426. // if the exp ends as a call then it should not be considered valid
  427. if (i === path.length - 1) {
  428. return false;
  429. }
  430. if (!--currentOpenParensCount) {
  431. state = stateStack.pop();
  432. }
  433. }
  434. break;
  435. case 3 /* inString */:
  436. if (char === currentStringType) {
  437. state = stateStack.pop();
  438. currentStringType = null;
  439. }
  440. break;
  441. }
  442. }
  443. return !currentOpenBracketCount && !currentOpenParensCount;
  444. };
  445. const isMemberExpressionNode = NOOP
  446. ;
  447. const isMemberExpression = isMemberExpressionBrowser
  448. ;
  449. function getInnerRange(loc, offset, length) {
  450. const source = loc.source.slice(offset, offset + length);
  451. const newLoc = {
  452. source,
  453. start: advancePositionWithClone(loc.start, loc.source, offset),
  454. end: loc.end
  455. };
  456. if (length != null) {
  457. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  458. }
  459. return newLoc;
  460. }
  461. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  462. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  463. }
  464. // advance by mutation without cloning (for performance reasons), since this
  465. // gets called a lot in the parser
  466. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  467. let linesCount = 0;
  468. let lastNewLinePos = -1;
  469. for (let i = 0; i < numberOfCharacters; i++) {
  470. if (source.charCodeAt(i) === 10 /* newline char code */) {
  471. linesCount++;
  472. lastNewLinePos = i;
  473. }
  474. }
  475. pos.offset += numberOfCharacters;
  476. pos.line += linesCount;
  477. pos.column =
  478. lastNewLinePos === -1
  479. ? pos.column + numberOfCharacters
  480. : numberOfCharacters - lastNewLinePos;
  481. return pos;
  482. }
  483. function assert(condition, msg) {
  484. /* istanbul ignore if */
  485. if (!condition) {
  486. throw new Error(msg || `unexpected compiler condition`);
  487. }
  488. }
  489. function findDir(node, name, allowEmpty = false) {
  490. for (let i = 0; i < node.props.length; i++) {
  491. const p = node.props[i];
  492. if (p.type === 7 /* DIRECTIVE */ &&
  493. (allowEmpty || p.exp) &&
  494. (isString(name) ? p.name === name : name.test(p.name))) {
  495. return p;
  496. }
  497. }
  498. }
  499. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  500. for (let i = 0; i < node.props.length; i++) {
  501. const p = node.props[i];
  502. if (p.type === 6 /* ATTRIBUTE */) {
  503. if (dynamicOnly)
  504. continue;
  505. if (p.name === name && (p.value || allowEmpty)) {
  506. return p;
  507. }
  508. }
  509. else if (p.name === 'bind' &&
  510. (p.exp || allowEmpty) &&
  511. isStaticArgOf(p.arg, name)) {
  512. return p;
  513. }
  514. }
  515. }
  516. function isStaticArgOf(arg, name) {
  517. return !!(arg && isStaticExp(arg) && arg.content === name);
  518. }
  519. function hasDynamicKeyVBind(node) {
  520. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  521. p.name === 'bind' &&
  522. (!p.arg || // v-bind="obj"
  523. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  524. !p.arg.isStatic) // v-bind:[foo]
  525. );
  526. }
  527. function isText(node) {
  528. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  529. }
  530. function isVSlot(p) {
  531. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  532. }
  533. function isTemplateNode(node) {
  534. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  535. }
  536. function isSlotOutlet(node) {
  537. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  538. }
  539. function getVNodeHelper(ssr, isComponent) {
  540. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  541. }
  542. function getVNodeBlockHelper(ssr, isComponent) {
  543. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  544. }
  545. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  546. function getUnnormalizedProps(props, callPath = []) {
  547. if (props &&
  548. !isString(props) &&
  549. props.type === 14 /* JS_CALL_EXPRESSION */) {
  550. const callee = props.callee;
  551. if (!isString(callee) && propsHelperSet.has(callee)) {
  552. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  553. }
  554. }
  555. return [props, callPath];
  556. }
  557. function injectProp(node, prop, context) {
  558. let propsWithInjection;
  559. /**
  560. * 1. mergeProps(...)
  561. * 2. toHandlers(...)
  562. * 3. normalizeProps(...)
  563. * 4. normalizeProps(guardReactiveProps(...))
  564. *
  565. * we need to get the real props before normalization
  566. */
  567. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  568. let callPath = [];
  569. let parentCall;
  570. if (props &&
  571. !isString(props) &&
  572. props.type === 14 /* JS_CALL_EXPRESSION */) {
  573. const ret = getUnnormalizedProps(props);
  574. props = ret[0];
  575. callPath = ret[1];
  576. parentCall = callPath[callPath.length - 1];
  577. }
  578. if (props == null || isString(props)) {
  579. propsWithInjection = createObjectExpression([prop]);
  580. }
  581. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  582. // merged props... add ours
  583. // only inject key to object literal if it's the first argument so that
  584. // if doesn't override user provided keys
  585. const first = props.arguments[0];
  586. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  587. first.properties.unshift(prop);
  588. }
  589. else {
  590. if (props.callee === TO_HANDLERS) {
  591. // #2366
  592. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  593. createObjectExpression([prop]),
  594. props
  595. ]);
  596. }
  597. else {
  598. props.arguments.unshift(createObjectExpression([prop]));
  599. }
  600. }
  601. !propsWithInjection && (propsWithInjection = props);
  602. }
  603. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  604. let alreadyExists = false;
  605. // check existing key to avoid overriding user provided keys
  606. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  607. const propKeyName = prop.key.content;
  608. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  609. p.key.content === propKeyName);
  610. }
  611. if (!alreadyExists) {
  612. props.properties.unshift(prop);
  613. }
  614. propsWithInjection = props;
  615. }
  616. else {
  617. // single v-bind with expression, return a merged replacement
  618. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  619. createObjectExpression([prop]),
  620. props
  621. ]);
  622. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  623. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  624. // the `guardReactiveProps` will no longer be needed
  625. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  626. parentCall = callPath[callPath.length - 2];
  627. }
  628. }
  629. if (node.type === 13 /* VNODE_CALL */) {
  630. if (parentCall) {
  631. parentCall.arguments[0] = propsWithInjection;
  632. }
  633. else {
  634. node.props = propsWithInjection;
  635. }
  636. }
  637. else {
  638. if (parentCall) {
  639. parentCall.arguments[0] = propsWithInjection;
  640. }
  641. else {
  642. node.arguments[2] = propsWithInjection;
  643. }
  644. }
  645. }
  646. function toValidAssetId(name, type) {
  647. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  648. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  649. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  650. })}`;
  651. }
  652. // Check if a node contains expressions that reference current context scope ids
  653. function hasScopeRef(node, ids) {
  654. if (!node || Object.keys(ids).length === 0) {
  655. return false;
  656. }
  657. switch (node.type) {
  658. case 1 /* ELEMENT */:
  659. for (let i = 0; i < node.props.length; i++) {
  660. const p = node.props[i];
  661. if (p.type === 7 /* DIRECTIVE */ &&
  662. (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  663. return true;
  664. }
  665. }
  666. return node.children.some(c => hasScopeRef(c, ids));
  667. case 11 /* FOR */:
  668. if (hasScopeRef(node.source, ids)) {
  669. return true;
  670. }
  671. return node.children.some(c => hasScopeRef(c, ids));
  672. case 9 /* IF */:
  673. return node.branches.some(b => hasScopeRef(b, ids));
  674. case 10 /* IF_BRANCH */:
  675. if (hasScopeRef(node.condition, ids)) {
  676. return true;
  677. }
  678. return node.children.some(c => hasScopeRef(c, ids));
  679. case 4 /* SIMPLE_EXPRESSION */:
  680. return (!node.isStatic &&
  681. isSimpleIdentifier(node.content) &&
  682. !!ids[node.content]);
  683. case 8 /* COMPOUND_EXPRESSION */:
  684. return node.children.some(c => isObject(c) && hasScopeRef(c, ids));
  685. case 5 /* INTERPOLATION */:
  686. case 12 /* TEXT_CALL */:
  687. return hasScopeRef(node.content, ids);
  688. case 2 /* TEXT */:
  689. case 3 /* COMMENT */:
  690. return false;
  691. default:
  692. if ((process.env.NODE_ENV !== 'production')) ;
  693. return false;
  694. }
  695. }
  696. function getMemoedVNodeCall(node) {
  697. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  698. return node.arguments[1].returns;
  699. }
  700. else {
  701. return node;
  702. }
  703. }
  704. function makeBlock(node, { helper, removeHelper, inSSR }) {
  705. if (!node.isBlock) {
  706. node.isBlock = true;
  707. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  708. helper(OPEN_BLOCK);
  709. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  710. }
  711. }
  712. const deprecationData = {
  713. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  714. message: `Platform-native elements with "is" prop will no longer be ` +
  715. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  716. `prefixed with "vue:".`,
  717. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  718. },
  719. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  720. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  721. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  722. `\`v-model:${key}\`.`,
  723. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  724. },
  725. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  726. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  727. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  728. },
  729. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  730. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  731. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  732. `that appears before v-bind in the case of conflict. ` +
  733. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  734. `You can also suppress this warning if the usage is intended.`,
  735. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  736. },
  737. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  738. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  739. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  740. },
  741. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  742. message: `v-if / v-for precedence when used on the same element has changed ` +
  743. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  744. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  745. `with <template> tags or use a computed property that filters v-for ` +
  746. `data source.`,
  747. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  748. },
  749. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  750. message: `<template> with no special directives will render as a native template ` +
  751. `element instead of its inner content in Vue 3.`
  752. },
  753. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  754. message: `"inline-template" has been removed in Vue 3.`,
  755. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  756. },
  757. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  758. message: `filters have been removed in Vue 3. ` +
  759. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  760. `Use method calls or computed properties instead.`,
  761. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  762. }
  763. };
  764. function getCompatValue(key, context) {
  765. const config = context.options
  766. ? context.options.compatConfig
  767. : context.compatConfig;
  768. const value = config && config[key];
  769. if (key === 'MODE') {
  770. return value || 3; // compiler defaults to v3 behavior
  771. }
  772. else {
  773. return value;
  774. }
  775. }
  776. function isCompatEnabled(key, context) {
  777. const mode = getCompatValue('MODE', context);
  778. const value = getCompatValue(key, context);
  779. // in v3 mode, only enable if explicitly set to true
  780. // otherwise enable for any non-false value
  781. return mode === 3 ? value === true : value !== false;
  782. }
  783. function checkCompatEnabled(key, context, loc, ...args) {
  784. const enabled = isCompatEnabled(key, context);
  785. if ((process.env.NODE_ENV !== 'production') && enabled) {
  786. warnDeprecation(key, context, loc, ...args);
  787. }
  788. return enabled;
  789. }
  790. function warnDeprecation(key, context, loc, ...args) {
  791. const val = getCompatValue(key, context);
  792. if (val === 'suppress-warning') {
  793. return;
  794. }
  795. const { message, link } = deprecationData[key];
  796. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  797. const err = new SyntaxError(msg);
  798. err.code = key;
  799. if (loc)
  800. err.loc = loc;
  801. context.onWarn(err);
  802. }
  803. // The default decoder only provides escapes for characters reserved as part of
  804. // the template syntax, and is only used if the custom renderer did not provide
  805. // a platform-specific decoder.
  806. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  807. const decodeMap = {
  808. gt: '>',
  809. lt: '<',
  810. amp: '&',
  811. apos: "'",
  812. quot: '"'
  813. };
  814. const defaultParserOptions = {
  815. delimiters: [`{{`, `}}`],
  816. getNamespace: () => 0 /* HTML */,
  817. getTextMode: () => 0 /* DATA */,
  818. isVoidTag: NO,
  819. isPreTag: NO,
  820. isCustomElement: NO,
  821. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  822. onError: defaultOnError,
  823. onWarn: defaultOnWarn,
  824. comments: (process.env.NODE_ENV !== 'production')
  825. };
  826. function baseParse(content, options = {}) {
  827. const context = createParserContext(content, options);
  828. const start = getCursor(context);
  829. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  830. }
  831. function createParserContext(content, rawOptions) {
  832. const options = extend({}, defaultParserOptions);
  833. let key;
  834. for (key in rawOptions) {
  835. // @ts-ignore
  836. options[key] =
  837. rawOptions[key] === undefined
  838. ? defaultParserOptions[key]
  839. : rawOptions[key];
  840. }
  841. return {
  842. options,
  843. column: 1,
  844. line: 1,
  845. offset: 0,
  846. originalSource: content,
  847. source: content,
  848. inPre: false,
  849. inVPre: false,
  850. onWarn: options.onWarn
  851. };
  852. }
  853. function parseChildren(context, mode, ancestors) {
  854. const parent = last(ancestors);
  855. const ns = parent ? parent.ns : 0 /* HTML */;
  856. const nodes = [];
  857. while (!isEnd(context, mode, ancestors)) {
  858. const s = context.source;
  859. let node = undefined;
  860. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  861. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  862. // '{{'
  863. node = parseInterpolation(context, mode);
  864. }
  865. else if (mode === 0 /* DATA */ && s[0] === '<') {
  866. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  867. if (s.length === 1) {
  868. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  869. }
  870. else if (s[1] === '!') {
  871. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  872. if (startsWith(s, '<!--')) {
  873. node = parseComment(context);
  874. }
  875. else if (startsWith(s, '<!DOCTYPE')) {
  876. // Ignore DOCTYPE by a limitation.
  877. node = parseBogusComment(context);
  878. }
  879. else if (startsWith(s, '<![CDATA[')) {
  880. if (ns !== 0 /* HTML */) {
  881. node = parseCDATA(context, ancestors);
  882. }
  883. else {
  884. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  885. node = parseBogusComment(context);
  886. }
  887. }
  888. else {
  889. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  890. node = parseBogusComment(context);
  891. }
  892. }
  893. else if (s[1] === '/') {
  894. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  895. if (s.length === 2) {
  896. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  897. }
  898. else if (s[2] === '>') {
  899. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  900. advanceBy(context, 3);
  901. continue;
  902. }
  903. else if (/[a-z]/i.test(s[2])) {
  904. emitError(context, 23 /* X_INVALID_END_TAG */);
  905. parseTag(context, 1 /* End */, parent);
  906. continue;
  907. }
  908. else {
  909. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  910. node = parseBogusComment(context);
  911. }
  912. }
  913. else if (/[a-z]/i.test(s[1])) {
  914. node = parseElement(context, ancestors);
  915. // 2.x <template> with no directive compat
  916. if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context) &&
  917. node &&
  918. node.tag === 'template' &&
  919. !node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  920. isSpecialTemplateDirective(p.name))) {
  921. (process.env.NODE_ENV !== 'production') &&
  922. warnDeprecation("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context, node.loc);
  923. node = node.children;
  924. }
  925. }
  926. else if (s[1] === '?') {
  927. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  928. node = parseBogusComment(context);
  929. }
  930. else {
  931. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  932. }
  933. }
  934. }
  935. if (!node) {
  936. node = parseText(context, mode);
  937. }
  938. if (isArray(node)) {
  939. for (let i = 0; i < node.length; i++) {
  940. pushNode(nodes, node[i]);
  941. }
  942. }
  943. else {
  944. pushNode(nodes, node);
  945. }
  946. }
  947. // Whitespace handling strategy like v2
  948. let removedWhitespace = false;
  949. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  950. const shouldCondense = context.options.whitespace !== 'preserve';
  951. for (let i = 0; i < nodes.length; i++) {
  952. const node = nodes[i];
  953. if (!context.inPre && node.type === 2 /* TEXT */) {
  954. if (!/[^\t\r\n\f ]/.test(node.content)) {
  955. const prev = nodes[i - 1];
  956. const next = nodes[i + 1];
  957. // Remove if:
  958. // - the whitespace is the first or last node, or:
  959. // - (condense mode) the whitespace is adjacent to a comment, or:
  960. // - (condense mode) the whitespace is between two elements AND contains newline
  961. if (!prev ||
  962. !next ||
  963. (shouldCondense &&
  964. (prev.type === 3 /* COMMENT */ ||
  965. next.type === 3 /* COMMENT */ ||
  966. (prev.type === 1 /* ELEMENT */ &&
  967. next.type === 1 /* ELEMENT */ &&
  968. /[\r\n]/.test(node.content))))) {
  969. removedWhitespace = true;
  970. nodes[i] = null;
  971. }
  972. else {
  973. // Otherwise, the whitespace is condensed into a single space
  974. node.content = ' ';
  975. }
  976. }
  977. else if (shouldCondense) {
  978. // in condense mode, consecutive whitespaces in text are condensed
  979. // down to a single space.
  980. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  981. }
  982. }
  983. // Remove comment nodes if desired by configuration.
  984. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  985. removedWhitespace = true;
  986. nodes[i] = null;
  987. }
  988. }
  989. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  990. // remove leading newline per html spec
  991. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  992. const first = nodes[0];
  993. if (first && first.type === 2 /* TEXT */) {
  994. first.content = first.content.replace(/^\r?\n/, '');
  995. }
  996. }
  997. }
  998. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  999. }
  1000. function pushNode(nodes, node) {
  1001. if (node.type === 2 /* TEXT */) {
  1002. const prev = last(nodes);
  1003. // Merge if both this and the previous node are text and those are
  1004. // consecutive. This happens for cases like "a < b".
  1005. if (prev &&
  1006. prev.type === 2 /* TEXT */ &&
  1007. prev.loc.end.offset === node.loc.start.offset) {
  1008. prev.content += node.content;
  1009. prev.loc.end = node.loc.end;
  1010. prev.loc.source += node.loc.source;
  1011. return;
  1012. }
  1013. }
  1014. nodes.push(node);
  1015. }
  1016. function parseCDATA(context, ancestors) {
  1017. advanceBy(context, 9);
  1018. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  1019. if (context.source.length === 0) {
  1020. emitError(context, 6 /* EOF_IN_CDATA */);
  1021. }
  1022. else {
  1023. advanceBy(context, 3);
  1024. }
  1025. return nodes;
  1026. }
  1027. function parseComment(context) {
  1028. const start = getCursor(context);
  1029. let content;
  1030. // Regular comment.
  1031. const match = /--(\!)?>/.exec(context.source);
  1032. if (!match) {
  1033. content = context.source.slice(4);
  1034. advanceBy(context, context.source.length);
  1035. emitError(context, 7 /* EOF_IN_COMMENT */);
  1036. }
  1037. else {
  1038. if (match.index <= 3) {
  1039. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  1040. }
  1041. if (match[1]) {
  1042. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  1043. }
  1044. content = context.source.slice(4, match.index);
  1045. // Advancing with reporting nested comments.
  1046. const s = context.source.slice(0, match.index);
  1047. let prevIndex = 1, nestedIndex = 0;
  1048. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  1049. advanceBy(context, nestedIndex - prevIndex + 1);
  1050. if (nestedIndex + 4 < s.length) {
  1051. emitError(context, 16 /* NESTED_COMMENT */);
  1052. }
  1053. prevIndex = nestedIndex + 1;
  1054. }
  1055. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  1056. }
  1057. return {
  1058. type: 3 /* COMMENT */,
  1059. content,
  1060. loc: getSelection(context, start)
  1061. };
  1062. }
  1063. function parseBogusComment(context) {
  1064. const start = getCursor(context);
  1065. const contentStart = context.source[1] === '?' ? 1 : 2;
  1066. let content;
  1067. const closeIndex = context.source.indexOf('>');
  1068. if (closeIndex === -1) {
  1069. content = context.source.slice(contentStart);
  1070. advanceBy(context, context.source.length);
  1071. }
  1072. else {
  1073. content = context.source.slice(contentStart, closeIndex);
  1074. advanceBy(context, closeIndex + 1);
  1075. }
  1076. return {
  1077. type: 3 /* COMMENT */,
  1078. content,
  1079. loc: getSelection(context, start)
  1080. };
  1081. }
  1082. function parseElement(context, ancestors) {
  1083. // Start tag.
  1084. const wasInPre = context.inPre;
  1085. const wasInVPre = context.inVPre;
  1086. const parent = last(ancestors);
  1087. const element = parseTag(context, 0 /* Start */, parent);
  1088. const isPreBoundary = context.inPre && !wasInPre;
  1089. const isVPreBoundary = context.inVPre && !wasInVPre;
  1090. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  1091. // #4030 self-closing <pre> tag
  1092. if (isPreBoundary) {
  1093. context.inPre = false;
  1094. }
  1095. if (isVPreBoundary) {
  1096. context.inVPre = false;
  1097. }
  1098. return element;
  1099. }
  1100. // Children.
  1101. ancestors.push(element);
  1102. const mode = context.options.getTextMode(element, parent);
  1103. const children = parseChildren(context, mode, ancestors);
  1104. ancestors.pop();
  1105. // 2.x inline-template compat
  1106. {
  1107. const inlineTemplateProp = element.props.find(p => p.type === 6 /* ATTRIBUTE */ && p.name === 'inline-template');
  1108. if (inlineTemplateProp &&
  1109. checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
  1110. const loc = getSelection(context, element.loc.end);
  1111. inlineTemplateProp.value = {
  1112. type: 2 /* TEXT */,
  1113. content: loc.source,
  1114. loc
  1115. };
  1116. }
  1117. }
  1118. element.children = children;
  1119. // End tag.
  1120. if (startsWithEndTagOpen(context.source, element.tag)) {
  1121. parseTag(context, 1 /* End */, parent);
  1122. }
  1123. else {
  1124. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  1125. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  1126. const first = children[0];
  1127. if (first && startsWith(first.loc.source, '<!--')) {
  1128. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  1129. }
  1130. }
  1131. }
  1132. element.loc = getSelection(context, element.loc.start);
  1133. if (isPreBoundary) {
  1134. context.inPre = false;
  1135. }
  1136. if (isVPreBoundary) {
  1137. context.inVPre = false;
  1138. }
  1139. return element;
  1140. }
  1141. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  1142. function parseTag(context, type, parent) {
  1143. // Tag open.
  1144. const start = getCursor(context);
  1145. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  1146. const tag = match[1];
  1147. const ns = context.options.getNamespace(tag, parent);
  1148. advanceBy(context, match[0].length);
  1149. advanceSpaces(context);
  1150. // save current state in case we need to re-parse attributes with v-pre
  1151. const cursor = getCursor(context);
  1152. const currentSource = context.source;
  1153. // check <pre> tag
  1154. if (context.options.isPreTag(tag)) {
  1155. context.inPre = true;
  1156. }
  1157. // Attributes.
  1158. let props = parseAttributes(context, type);
  1159. // check v-pre
  1160. if (type === 0 /* Start */ &&
  1161. !context.inVPre &&
  1162. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  1163. context.inVPre = true;
  1164. // reset context
  1165. extend(context, cursor);
  1166. context.source = currentSource;
  1167. // re-parse attrs and filter out v-pre itself
  1168. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  1169. }
  1170. // Tag close.
  1171. let isSelfClosing = false;
  1172. if (context.source.length === 0) {
  1173. emitError(context, 9 /* EOF_IN_TAG */);
  1174. }
  1175. else {
  1176. isSelfClosing = startsWith(context.source, '/>');
  1177. if (type === 1 /* End */ && isSelfClosing) {
  1178. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  1179. }
  1180. advanceBy(context, isSelfClosing ? 2 : 1);
  1181. }
  1182. if (type === 1 /* End */) {
  1183. return;
  1184. }
  1185. // 2.x deprecation checks
  1186. if ((process.env.NODE_ENV !== 'production') &&
  1187. isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context)) {
  1188. let hasIf = false;
  1189. let hasFor = false;
  1190. for (let i = 0; i < props.length; i++) {
  1191. const p = props[i];
  1192. if (p.type === 7 /* DIRECTIVE */) {
  1193. if (p.name === 'if') {
  1194. hasIf = true;
  1195. }
  1196. else if (p.name === 'for') {
  1197. hasFor = true;
  1198. }
  1199. }
  1200. if (hasIf && hasFor) {
  1201. warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context, getSelection(context, start));
  1202. break;
  1203. }
  1204. }
  1205. }
  1206. let tagType = 0 /* ELEMENT */;
  1207. if (!context.inVPre) {
  1208. if (tag === 'slot') {
  1209. tagType = 2 /* SLOT */;
  1210. }
  1211. else if (tag === 'template') {
  1212. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  1213. tagType = 3 /* TEMPLATE */;
  1214. }
  1215. }
  1216. else if (isComponent(tag, props, context)) {
  1217. tagType = 1 /* COMPONENT */;
  1218. }
  1219. }
  1220. return {
  1221. type: 1 /* ELEMENT */,
  1222. ns,
  1223. tag,
  1224. tagType,
  1225. props,
  1226. isSelfClosing,
  1227. children: [],
  1228. loc: getSelection(context, start),
  1229. codegenNode: undefined // to be created during transform phase
  1230. };
  1231. }
  1232. function isComponent(tag, props, context) {
  1233. const options = context.options;
  1234. if (options.isCustomElement(tag)) {
  1235. return false;
  1236. }
  1237. if (tag === 'component' ||
  1238. /^[A-Z]/.test(tag) ||
  1239. isCoreComponent(tag) ||
  1240. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  1241. (options.isNativeTag && !options.isNativeTag(tag))) {
  1242. return true;
  1243. }
  1244. // at this point the tag should be a native tag, but check for potential "is"
  1245. // casting
  1246. for (let i = 0; i < props.length; i++) {
  1247. const p = props[i];
  1248. if (p.type === 6 /* ATTRIBUTE */) {
  1249. if (p.name === 'is' && p.value) {
  1250. if (p.value.content.startsWith('vue:')) {
  1251. return true;
  1252. }
  1253. else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  1254. return true;
  1255. }
  1256. }
  1257. }
  1258. else {
  1259. // directive
  1260. // v-is (TODO Deprecate)
  1261. if (p.name === 'is') {
  1262. return true;
  1263. }
  1264. else if (
  1265. // :is on plain element - only treat as component in compat mode
  1266. p.name === 'bind' &&
  1267. isStaticArgOf(p.arg, 'is') &&
  1268. true &&
  1269. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  1270. return true;
  1271. }
  1272. }
  1273. }
  1274. }
  1275. function parseAttributes(context, type) {
  1276. const props = [];
  1277. const attributeNames = new Set();
  1278. while (context.source.length > 0 &&
  1279. !startsWith(context.source, '>') &&
  1280. !startsWith(context.source, '/>')) {
  1281. if (startsWith(context.source, '/')) {
  1282. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  1283. advanceBy(context, 1);
  1284. advanceSpaces(context);
  1285. continue;
  1286. }
  1287. if (type === 1 /* End */) {
  1288. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  1289. }
  1290. const attr = parseAttribute(context, attributeNames);
  1291. // Trim whitespace between class
  1292. // https://github.com/vuejs/core/issues/4251
  1293. if (attr.type === 6 /* ATTRIBUTE */ &&
  1294. attr.value &&
  1295. attr.name === 'class') {
  1296. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  1297. }
  1298. if (type === 0 /* Start */) {
  1299. props.push(attr);
  1300. }
  1301. if (/^[^\t\r\n\f />]/.test(context.source)) {
  1302. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  1303. }
  1304. advanceSpaces(context);
  1305. }
  1306. return props;
  1307. }
  1308. function parseAttribute(context, nameSet) {
  1309. // Name.
  1310. const start = getCursor(context);
  1311. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  1312. const name = match[0];
  1313. if (nameSet.has(name)) {
  1314. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  1315. }
  1316. nameSet.add(name);
  1317. if (name[0] === '=') {
  1318. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  1319. }
  1320. {
  1321. const pattern = /["'<]/g;
  1322. let m;
  1323. while ((m = pattern.exec(name))) {
  1324. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  1325. }
  1326. }
  1327. advanceBy(context, name.length);
  1328. // Value
  1329. let value = undefined;
  1330. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  1331. advanceSpaces(context);
  1332. advanceBy(context, 1);
  1333. advanceSpaces(context);
  1334. value = parseAttributeValue(context);
  1335. if (!value) {
  1336. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  1337. }
  1338. }
  1339. const loc = getSelection(context, start);
  1340. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  1341. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  1342. let isPropShorthand = startsWith(name, '.');
  1343. let dirName = match[1] ||
  1344. (isPropShorthand || startsWith(name, ':')
  1345. ? 'bind'
  1346. : startsWith(name, '@')
  1347. ? 'on'
  1348. : 'slot');
  1349. let arg;
  1350. if (match[2]) {
  1351. const isSlot = dirName === 'slot';
  1352. const startOffset = name.lastIndexOf(match[2]);
  1353. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  1354. let content = match[2];
  1355. let isStatic = true;
  1356. if (content.startsWith('[')) {
  1357. isStatic = false;
  1358. if (!content.endsWith(']')) {
  1359. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  1360. content = content.slice(1);
  1361. }
  1362. else {
  1363. content = content.slice(1, content.length - 1);
  1364. }
  1365. }
  1366. else if (isSlot) {
  1367. // #1241 special case for v-slot: vuetify relies extensively on slot
  1368. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  1369. // supports such usage so we are keeping it consistent with 2.x.
  1370. content += match[3] || '';
  1371. }
  1372. arg = {
  1373. type: 4 /* SIMPLE_EXPRESSION */,
  1374. content,
  1375. isStatic,
  1376. constType: isStatic
  1377. ? 3 /* CAN_STRINGIFY */
  1378. : 0 /* NOT_CONSTANT */,
  1379. loc
  1380. };
  1381. }
  1382. if (value && value.isQuoted) {
  1383. const valueLoc = value.loc;
  1384. valueLoc.start.offset++;
  1385. valueLoc.start.column++;
  1386. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  1387. valueLoc.source = valueLoc.source.slice(1, -1);
  1388. }
  1389. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  1390. if (isPropShorthand)
  1391. modifiers.push('prop');
  1392. // 2.x compat v-bind:foo.sync -> v-model:foo
  1393. if (dirName === 'bind' && arg) {
  1394. if (modifiers.includes('sync') &&
  1395. checkCompatEnabled("COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
  1396. dirName = 'model';
  1397. modifiers.splice(modifiers.indexOf('sync'), 1);
  1398. }
  1399. if ((process.env.NODE_ENV !== 'production') && modifiers.includes('prop')) {
  1400. checkCompatEnabled("COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */, context, loc);
  1401. }
  1402. }
  1403. return {
  1404. type: 7 /* DIRECTIVE */,
  1405. name: dirName,
  1406. exp: value && {
  1407. type: 4 /* SIMPLE_EXPRESSION */,
  1408. content: value.content,
  1409. isStatic: false,
  1410. // Treat as non-constant by default. This can be potentially set to
  1411. // other values by `transformExpression` to make it eligible for hoisting.
  1412. constType: 0 /* NOT_CONSTANT */,
  1413. loc: value.loc
  1414. },
  1415. arg,
  1416. modifiers,
  1417. loc
  1418. };
  1419. }
  1420. // missing directive name or illegal directive name
  1421. if (!context.inVPre && startsWith(name, 'v-')) {
  1422. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  1423. }
  1424. return {
  1425. type: 6 /* ATTRIBUTE */,
  1426. name,
  1427. value: value && {
  1428. type: 2 /* TEXT */,
  1429. content: value.content,
  1430. loc: value.loc
  1431. },
  1432. loc
  1433. };
  1434. }
  1435. function parseAttributeValue(context) {
  1436. const start = getCursor(context);
  1437. let content;
  1438. const quote = context.source[0];
  1439. const isQuoted = quote === `"` || quote === `'`;
  1440. if (isQuoted) {
  1441. // Quoted value.
  1442. advanceBy(context, 1);
  1443. const endIndex = context.source.indexOf(quote);
  1444. if (endIndex === -1) {
  1445. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  1446. }
  1447. else {
  1448. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  1449. advanceBy(context, 1);
  1450. }
  1451. }
  1452. else {
  1453. // Unquoted
  1454. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  1455. if (!match) {
  1456. return undefined;
  1457. }
  1458. const unexpectedChars = /["'<=`]/g;
  1459. let m;
  1460. while ((m = unexpectedChars.exec(match[0]))) {
  1461. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  1462. }
  1463. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  1464. }
  1465. return { content, isQuoted, loc: getSelection(context, start) };
  1466. }
  1467. function parseInterpolation(context, mode) {
  1468. const [open, close] = context.options.delimiters;
  1469. const closeIndex = context.source.indexOf(close, open.length);
  1470. if (closeIndex === -1) {
  1471. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  1472. return undefined;
  1473. }
  1474. const start = getCursor(context);
  1475. advanceBy(context, open.length);
  1476. const innerStart = getCursor(context);
  1477. const innerEnd = getCursor(context);
  1478. const rawContentLength = closeIndex - open.length;
  1479. const rawContent = context.source.slice(0, rawContentLength);
  1480. const preTrimContent = parseTextData(context, rawContentLength, mode);
  1481. const content = preTrimContent.trim();
  1482. const startOffset = preTrimContent.indexOf(content);
  1483. if (startOffset > 0) {
  1484. advancePositionWithMutation(innerStart, rawContent, startOffset);
  1485. }
  1486. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  1487. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  1488. advanceBy(context, close.length);
  1489. return {
  1490. type: 5 /* INTERPOLATION */,
  1491. content: {
  1492. type: 4 /* SIMPLE_EXPRESSION */,
  1493. isStatic: false,
  1494. // Set `isConstant` to false by default and will decide in transformExpression
  1495. constType: 0 /* NOT_CONSTANT */,
  1496. content,
  1497. loc: getSelection(context, innerStart, innerEnd)
  1498. },
  1499. loc: getSelection(context, start)
  1500. };
  1501. }
  1502. function parseText(context, mode) {
  1503. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  1504. let endIndex = context.source.length;
  1505. for (let i = 0; i < endTokens.length; i++) {
  1506. const index = context.source.indexOf(endTokens[i], 1);
  1507. if (index !== -1 && endIndex > index) {
  1508. endIndex = index;
  1509. }
  1510. }
  1511. const start = getCursor(context);
  1512. const content = parseTextData(context, endIndex, mode);
  1513. return {
  1514. type: 2 /* TEXT */,
  1515. content,
  1516. loc: getSelection(context, start)
  1517. };
  1518. }
  1519. /**
  1520. * Get text data with a given length from the current location.
  1521. * This translates HTML entities in the text data.
  1522. */
  1523. function parseTextData(context, length, mode) {
  1524. const rawText = context.source.slice(0, length);
  1525. advanceBy(context, length);
  1526. if (mode === 2 /* RAWTEXT */ ||
  1527. mode === 3 /* CDATA */ ||
  1528. !rawText.includes('&')) {
  1529. return rawText;
  1530. }
  1531. else {
  1532. // DATA or RCDATA containing "&"". Entity decoding required.
  1533. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  1534. }
  1535. }
  1536. function getCursor(context) {
  1537. const { column, line, offset } = context;
  1538. return { column, line, offset };
  1539. }
  1540. function getSelection(context, start, end) {
  1541. end = end || getCursor(context);
  1542. return {
  1543. start,
  1544. end,
  1545. source: context.originalSource.slice(start.offset, end.offset)
  1546. };
  1547. }
  1548. function last(xs) {
  1549. return xs[xs.length - 1];
  1550. }
  1551. function startsWith(source, searchString) {
  1552. return source.startsWith(searchString);
  1553. }
  1554. function advanceBy(context, numberOfCharacters) {
  1555. const { source } = context;
  1556. advancePositionWithMutation(context, source, numberOfCharacters);
  1557. context.source = source.slice(numberOfCharacters);
  1558. }
  1559. function advanceSpaces(context) {
  1560. const match = /^[\t\r\n\f ]+/.exec(context.source);
  1561. if (match) {
  1562. advanceBy(context, match[0].length);
  1563. }
  1564. }
  1565. function getNewPosition(context, start, numberOfCharacters) {
  1566. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  1567. }
  1568. function emitError(context, code, offset, loc = getCursor(context)) {
  1569. if (offset) {
  1570. loc.offset += offset;
  1571. loc.column += offset;
  1572. }
  1573. context.options.onError(createCompilerError(code, {
  1574. start: loc,
  1575. end: loc,
  1576. source: ''
  1577. }));
  1578. }
  1579. function isEnd(context, mode, ancestors) {
  1580. const s = context.source;
  1581. switch (mode) {
  1582. case 0 /* DATA */:
  1583. if (startsWith(s, '</')) {
  1584. // TODO: probably bad performance
  1585. for (let i = ancestors.length - 1; i >= 0; --i) {
  1586. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  1587. return true;
  1588. }
  1589. }
  1590. }
  1591. break;
  1592. case 1 /* RCDATA */:
  1593. case 2 /* RAWTEXT */: {
  1594. const parent = last(ancestors);
  1595. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  1596. return true;
  1597. }
  1598. break;
  1599. }
  1600. case 3 /* CDATA */:
  1601. if (startsWith(s, ']]>')) {
  1602. return true;
  1603. }
  1604. break;
  1605. }
  1606. return !s;
  1607. }
  1608. function startsWithEndTagOpen(source, tag) {
  1609. return (startsWith(source, '</') &&
  1610. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  1611. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  1612. }
  1613. function hoistStatic(root, context) {
  1614. walk(root, context,
  1615. // Root node is unfortunately non-hoistable due to potential parent
  1616. // fallthrough attributes.
  1617. isSingleElementRoot(root, root.children[0]));
  1618. }
  1619. function isSingleElementRoot(root, child) {
  1620. const { children } = root;
  1621. return (children.length === 1 &&
  1622. child.type === 1 /* ELEMENT */ &&
  1623. !isSlotOutlet(child));
  1624. }
  1625. function walk(node, context, doNotHoistNode = false) {
  1626. const { children } = node;
  1627. const originalCount = children.length;
  1628. let hoistedCount = 0;
  1629. for (let i = 0; i < children.length; i++) {
  1630. const child = children[i];
  1631. // only plain elements & text calls are eligible for hoisting.
  1632. if (child.type === 1 /* ELEMENT */ &&
  1633. child.tagType === 0 /* ELEMENT */) {
  1634. const constantType = doNotHoistNode
  1635. ? 0 /* NOT_CONSTANT */
  1636. : getConstantType(child, context);
  1637. if (constantType > 0 /* NOT_CONSTANT */) {
  1638. if (constantType >= 2 /* CAN_HOIST */) {
  1639. child.codegenNode.patchFlag =
  1640. -1 /* HOISTED */ + ((process.env.NODE_ENV !== 'production') ? ` /* HOISTED */` : ``);
  1641. child.codegenNode = context.hoist(child.codegenNode);
  1642. hoistedCount++;
  1643. continue;
  1644. }
  1645. }
  1646. else {
  1647. // node may contain dynamic children, but its props may be eligible for
  1648. // hoisting.
  1649. const codegenNode = child.codegenNode;
  1650. if (codegenNode.type === 13 /* VNODE_CALL */) {
  1651. const flag = getPatchFlag(codegenNode);
  1652. if ((!flag ||
  1653. flag === 512 /* NEED_PATCH */ ||
  1654. flag === 1 /* TEXT */) &&
  1655. getGeneratedPropsConstantType(child, context) >=
  1656. 2 /* CAN_HOIST */) {
  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. else if (child.type === 12 /* TEXT_CALL */ &&
  1669. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  1670. child.codegenNode = context.hoist(child.codegenNode);
  1671. hoistedCount++;
  1672. }
  1673. // walk further
  1674. if (child.type === 1 /* ELEMENT */) {
  1675. const isComponent = child.tagType === 1 /* COMPONENT */;
  1676. if (isComponent) {
  1677. context.scopes.vSlot++;
  1678. }
  1679. walk(child, context);
  1680. if (isComponent) {
  1681. context.scopes.vSlot--;
  1682. }
  1683. }
  1684. else if (child.type === 11 /* FOR */) {
  1685. // Do not hoist v-for single child because it has to be a block
  1686. walk(child, context, child.children.length === 1);
  1687. }
  1688. else if (child.type === 9 /* IF */) {
  1689. for (let i = 0; i < child.branches.length; i++) {
  1690. // Do not hoist v-if single child because it has to be a block
  1691. walk(child.branches[i], context, child.branches[i].children.length === 1);
  1692. }
  1693. }
  1694. }
  1695. if (hoistedCount && context.transformHoist) {
  1696. context.transformHoist(children, context, node);
  1697. }
  1698. // all children were hoisted - the entire children array is hoistable.
  1699. if (hoistedCount &&
  1700. hoistedCount === originalCount &&
  1701. node.type === 1 /* ELEMENT */ &&
  1702. node.tagType === 0 /* ELEMENT */ &&
  1703. node.codegenNode &&
  1704. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  1705. isArray(node.codegenNode.children)) {
  1706. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  1707. }
  1708. }
  1709. function getConstantType(node, context) {
  1710. const { constantCache } = context;
  1711. switch (node.type) {
  1712. case 1 /* ELEMENT */:
  1713. if (node.tagType !== 0 /* ELEMENT */) {
  1714. return 0 /* NOT_CONSTANT */;
  1715. }
  1716. const cached = constantCache.get(node);
  1717. if (cached !== undefined) {
  1718. return cached;
  1719. }
  1720. const codegenNode = node.codegenNode;
  1721. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  1722. return 0 /* NOT_CONSTANT */;
  1723. }
  1724. if (codegenNode.isBlock &&
  1725. node.tag !== 'svg' &&
  1726. node.tag !== 'foreignObject') {
  1727. return 0 /* NOT_CONSTANT */;
  1728. }
  1729. const flag = getPatchFlag(codegenNode);
  1730. if (!flag) {
  1731. let returnType = 3 /* CAN_STRINGIFY */;
  1732. // Element itself has no patch flag. However we still need to check:
  1733. // 1. Even for a node with no patch flag, it is possible for it to contain
  1734. // non-hoistable expressions that refers to scope variables, e.g. compiler
  1735. // injected keys or cached event handlers. Therefore we need to always
  1736. // check the codegenNode's props to be sure.
  1737. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  1738. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  1739. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1740. return 0 /* NOT_CONSTANT */;
  1741. }
  1742. if (generatedPropsType < returnType) {
  1743. returnType = generatedPropsType;
  1744. }
  1745. // 2. its children.
  1746. for (let i = 0; i < node.children.length; i++) {
  1747. const childType = getConstantType(node.children[i], context);
  1748. if (childType === 0 /* NOT_CONSTANT */) {
  1749. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1750. return 0 /* NOT_CONSTANT */;
  1751. }
  1752. if (childType < returnType) {
  1753. returnType = childType;
  1754. }
  1755. }
  1756. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  1757. // type, check if any of the props can cause the type to be lowered
  1758. // we can skip can_patch because it's guaranteed by the absence of a
  1759. // patchFlag.
  1760. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  1761. for (let i = 0; i < node.props.length; i++) {
  1762. const p = node.props[i];
  1763. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  1764. const expType = getConstantType(p.exp, context);
  1765. if (expType === 0 /* NOT_CONSTANT */) {
  1766. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1767. return 0 /* NOT_CONSTANT */;
  1768. }
  1769. if (expType < returnType) {
  1770. returnType = expType;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. // only svg/foreignObject could be block here, however if they are
  1776. // static then they don't need to be blocks since there will be no
  1777. // nested updates.
  1778. if (codegenNode.isBlock) {
  1779. context.removeHelper(OPEN_BLOCK);
  1780. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  1781. codegenNode.isBlock = false;
  1782. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  1783. }
  1784. constantCache.set(node, returnType);
  1785. return returnType;
  1786. }
  1787. else {
  1788. constantCache.set(node, 0 /* NOT_CONSTANT */);
  1789. return 0 /* NOT_CONSTANT */;
  1790. }
  1791. case 2 /* TEXT */:
  1792. case 3 /* COMMENT */:
  1793. return 3 /* CAN_STRINGIFY */;
  1794. case 9 /* IF */:
  1795. case 11 /* FOR */:
  1796. case 10 /* IF_BRANCH */:
  1797. return 0 /* NOT_CONSTANT */;
  1798. case 5 /* INTERPOLATION */:
  1799. case 12 /* TEXT_CALL */:
  1800. return getConstantType(node.content, context);
  1801. case 4 /* SIMPLE_EXPRESSION */:
  1802. return node.constType;
  1803. case 8 /* COMPOUND_EXPRESSION */:
  1804. let returnType = 3 /* CAN_STRINGIFY */;
  1805. for (let i = 0; i < node.children.length; i++) {
  1806. const child = node.children[i];
  1807. if (isString(child) || isSymbol(child)) {
  1808. continue;
  1809. }
  1810. const childType = getConstantType(child, context);
  1811. if (childType === 0 /* NOT_CONSTANT */) {
  1812. return 0 /* NOT_CONSTANT */;
  1813. }
  1814. else if (childType < returnType) {
  1815. returnType = childType;
  1816. }
  1817. }
  1818. return returnType;
  1819. default:
  1820. if ((process.env.NODE_ENV !== 'production')) ;
  1821. return 0 /* NOT_CONSTANT */;
  1822. }
  1823. }
  1824. const allowHoistedHelperSet = new Set([
  1825. NORMALIZE_CLASS,
  1826. NORMALIZE_STYLE,
  1827. NORMALIZE_PROPS,
  1828. GUARD_REACTIVE_PROPS
  1829. ]);
  1830. function getConstantTypeOfHelperCall(value, context) {
  1831. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  1832. !isString(value.callee) &&
  1833. allowHoistedHelperSet.has(value.callee)) {
  1834. const arg = value.arguments[0];
  1835. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  1836. return getConstantType(arg, context);
  1837. }
  1838. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  1839. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  1840. return getConstantTypeOfHelperCall(arg, context);
  1841. }
  1842. }
  1843. return 0 /* NOT_CONSTANT */;
  1844. }
  1845. function getGeneratedPropsConstantType(node, context) {
  1846. let returnType = 3 /* CAN_STRINGIFY */;
  1847. const props = getNodeProps(node);
  1848. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  1849. const { properties } = props;
  1850. for (let i = 0; i < properties.length; i++) {
  1851. const { key, value } = properties[i];
  1852. const keyType = getConstantType(key, context);
  1853. if (keyType === 0 /* NOT_CONSTANT */) {
  1854. return keyType;
  1855. }
  1856. if (keyType < returnType) {
  1857. returnType = keyType;
  1858. }
  1859. let valueType;
  1860. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  1861. valueType = getConstantType(value, context);
  1862. }
  1863. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  1864. // some helper calls can be hoisted,
  1865. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  1866. // in this case we need to respect the ConstantType of the helper's arguments
  1867. valueType = getConstantTypeOfHelperCall(value, context);
  1868. }
  1869. else {
  1870. valueType = 0 /* NOT_CONSTANT */;
  1871. }
  1872. if (valueType === 0 /* NOT_CONSTANT */) {
  1873. return valueType;
  1874. }
  1875. if (valueType < returnType) {
  1876. returnType = valueType;
  1877. }
  1878. }
  1879. }
  1880. return returnType;
  1881. }
  1882. function getNodeProps(node) {
  1883. const codegenNode = node.codegenNode;
  1884. if (codegenNode.type === 13 /* VNODE_CALL */) {
  1885. return codegenNode.props;
  1886. }
  1887. }
  1888. function getPatchFlag(node) {
  1889. const flag = node.patchFlag;
  1890. return flag ? parseInt(flag, 10) : undefined;
  1891. }
  1892. function createTransformContext(root, { filename = '', prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, slotted = true, ssr = false, inSSR = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError, onWarn = defaultOnWarn, compatConfig }) {
  1893. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  1894. const context = {
  1895. // options
  1896. selfName: nameMatch && capitalize(camelize$1(nameMatch[1])),
  1897. prefixIdentifiers,
  1898. hoistStatic,
  1899. cacheHandlers,
  1900. nodeTransforms,
  1901. directiveTransforms,
  1902. transformHoist,
  1903. isBuiltInComponent,
  1904. isCustomElement,
  1905. expressionPlugins,
  1906. scopeId,
  1907. slotted,
  1908. ssr,
  1909. inSSR,
  1910. ssrCssVars,
  1911. bindingMetadata,
  1912. inline,
  1913. isTS,
  1914. onError,
  1915. onWarn,
  1916. compatConfig,
  1917. // state
  1918. root,
  1919. helpers: new Map(),
  1920. components: new Set(),
  1921. directives: new Set(),
  1922. hoists: [],
  1923. imports: [],
  1924. constantCache: new Map(),
  1925. temps: 0,
  1926. cached: 0,
  1927. identifiers: Object.create(null),
  1928. scopes: {
  1929. vFor: 0,
  1930. vSlot: 0,
  1931. vPre: 0,
  1932. vOnce: 0
  1933. },
  1934. parent: null,
  1935. currentNode: root,
  1936. childIndex: 0,
  1937. inVOnce: false,
  1938. // methods
  1939. helper(name) {
  1940. const count = context.helpers.get(name) || 0;
  1941. context.helpers.set(name, count + 1);
  1942. return name;
  1943. },
  1944. removeHelper(name) {
  1945. const count = context.helpers.get(name);
  1946. if (count) {
  1947. const currentCount = count - 1;
  1948. if (!currentCount) {
  1949. context.helpers.delete(name);
  1950. }
  1951. else {
  1952. context.helpers.set(name, currentCount);
  1953. }
  1954. }
  1955. },
  1956. helperString(name) {
  1957. return `_${helperNameMap[context.helper(name)]}`;
  1958. },
  1959. replaceNode(node) {
  1960. /* istanbul ignore if */
  1961. if ((process.env.NODE_ENV !== 'production')) {
  1962. if (!context.currentNode) {
  1963. throw new Error(`Node being replaced is already removed.`);
  1964. }
  1965. if (!context.parent) {
  1966. throw new Error(`Cannot replace root node.`);
  1967. }
  1968. }
  1969. context.parent.children[context.childIndex] = context.currentNode = node;
  1970. },
  1971. removeNode(node) {
  1972. if ((process.env.NODE_ENV !== 'production') && !context.parent) {
  1973. throw new Error(`Cannot remove root node.`);
  1974. }
  1975. const list = context.parent.children;
  1976. const removalIndex = node
  1977. ? list.indexOf(node)
  1978. : context.currentNode
  1979. ? context.childIndex
  1980. : -1;
  1981. /* istanbul ignore if */
  1982. if ((process.env.NODE_ENV !== 'production') && removalIndex < 0) {
  1983. throw new Error(`node being removed is not a child of current parent`);
  1984. }
  1985. if (!node || node === context.currentNode) {
  1986. // current node removed
  1987. context.currentNode = null;
  1988. context.onNodeRemoved();
  1989. }
  1990. else {
  1991. // sibling node removed
  1992. if (context.childIndex > removalIndex) {
  1993. context.childIndex--;
  1994. context.onNodeRemoved();
  1995. }
  1996. }
  1997. context.parent.children.splice(removalIndex, 1);
  1998. },
  1999. onNodeRemoved: () => { },
  2000. addIdentifiers(exp) {
  2001. },
  2002. removeIdentifiers(exp) {
  2003. },
  2004. hoist(exp) {
  2005. if (isString(exp))
  2006. exp = createSimpleExpression(exp);
  2007. context.hoists.push(exp);
  2008. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  2009. identifier.hoisted = exp;
  2010. return identifier;
  2011. },
  2012. cache(exp, isVNode = false) {
  2013. return createCacheExpression(context.cached++, exp, isVNode);
  2014. }
  2015. };
  2016. {
  2017. context.filters = new Set();
  2018. }
  2019. return context;
  2020. }
  2021. function transform(root, options) {
  2022. const context = createTransformContext(root, options);
  2023. traverseNode(root, context);
  2024. if (options.hoistStatic) {
  2025. hoistStatic(root, context);
  2026. }
  2027. if (!options.ssr) {
  2028. createRootCodegen(root, context);
  2029. }
  2030. // finalize meta information
  2031. root.helpers = [...context.helpers.keys()];
  2032. root.components = [...context.components];
  2033. root.directives = [...context.directives];
  2034. root.imports = context.imports;
  2035. root.hoists = context.hoists;
  2036. root.temps = context.temps;
  2037. root.cached = context.cached;
  2038. {
  2039. root.filters = [...context.filters];
  2040. }
  2041. }
  2042. function createRootCodegen(root, context) {
  2043. const { helper } = context;
  2044. const { children } = root;
  2045. if (children.length === 1) {
  2046. const child = children[0];
  2047. // if the single child is an element, turn it into a block.
  2048. if (isSingleElementRoot(root, child) && child.codegenNode) {
  2049. // single element root is never hoisted so codegenNode will never be
  2050. // SimpleExpressionNode
  2051. const codegenNode = child.codegenNode;
  2052. if (codegenNode.type === 13 /* VNODE_CALL */) {
  2053. makeBlock(codegenNode, context);
  2054. }
  2055. root.codegenNode = codegenNode;
  2056. }
  2057. else {
  2058. // - single <slot/>, IfNode, ForNode: already blocks.
  2059. // - single text node: always patched.
  2060. // root codegen falls through via genNode()
  2061. root.codegenNode = child;
  2062. }
  2063. }
  2064. else if (children.length > 1) {
  2065. // root has multiple nodes - return a fragment block.
  2066. let patchFlag = 64 /* STABLE_FRAGMENT */;
  2067. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  2068. // check if the fragment actually contains a single valid child with
  2069. // the rest being comments
  2070. if ((process.env.NODE_ENV !== 'production') &&
  2071. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  2072. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  2073. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  2074. }
  2075. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, undefined, false /* isComponent */);
  2076. }
  2077. else ;
  2078. }
  2079. function traverseChildren(parent, context) {
  2080. let i = 0;
  2081. const nodeRemoved = () => {
  2082. i--;
  2083. };
  2084. for (; i < parent.children.length; i++) {
  2085. const child = parent.children[i];
  2086. if (isString(child))
  2087. continue;
  2088. context.parent = parent;
  2089. context.childIndex = i;
  2090. context.onNodeRemoved = nodeRemoved;
  2091. traverseNode(child, context);
  2092. }
  2093. }
  2094. function traverseNode(node, context) {
  2095. context.currentNode = node;
  2096. // apply transform plugins
  2097. const { nodeTransforms } = context;
  2098. const exitFns = [];
  2099. for (let i = 0; i < nodeTransforms.length; i++) {
  2100. const onExit = nodeTransforms[i](node, context);
  2101. if (onExit) {
  2102. if (isArray(onExit)) {
  2103. exitFns.push(...onExit);
  2104. }
  2105. else {
  2106. exitFns.push(onExit);
  2107. }
  2108. }
  2109. if (!context.currentNode) {
  2110. // node was removed
  2111. return;
  2112. }
  2113. else {
  2114. // node may have been replaced
  2115. node = context.currentNode;
  2116. }
  2117. }
  2118. switch (node.type) {
  2119. case 3 /* COMMENT */:
  2120. if (!context.ssr) {
  2121. // inject import for the Comment symbol, which is needed for creating
  2122. // comment nodes with `createVNode`
  2123. context.helper(CREATE_COMMENT);
  2124. }
  2125. break;
  2126. case 5 /* INTERPOLATION */:
  2127. // no need to traverse, but we need to inject toString helper
  2128. if (!context.ssr) {
  2129. context.helper(TO_DISPLAY_STRING);
  2130. }
  2131. break;
  2132. // for container types, further traverse downwards
  2133. case 9 /* IF */:
  2134. for (let i = 0; i < node.branches.length; i++) {
  2135. traverseNode(node.branches[i], context);
  2136. }
  2137. break;
  2138. case 10 /* IF_BRANCH */:
  2139. case 11 /* FOR */:
  2140. case 1 /* ELEMENT */:
  2141. case 0 /* ROOT */:
  2142. traverseChildren(node, context);
  2143. break;
  2144. }
  2145. // exit transforms
  2146. context.currentNode = node;
  2147. let i = exitFns.length;
  2148. while (i--) {
  2149. exitFns[i]();
  2150. }
  2151. }
  2152. function createStructuralDirectiveTransform(name, fn) {
  2153. const matches = isString(name)
  2154. ? (n) => n === name
  2155. : (n) => name.test(n);
  2156. return (node, context) => {
  2157. if (node.type === 1 /* ELEMENT */) {
  2158. const { props } = node;
  2159. // structural directive transforms are not concerned with slots
  2160. // as they are handled separately in vSlot.ts
  2161. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  2162. return;
  2163. }
  2164. const exitFns = [];
  2165. for (let i = 0; i < props.length; i++) {
  2166. const prop = props[i];
  2167. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  2168. // structural directives are removed to avoid infinite recursion
  2169. // also we remove them *before* applying so that it can further
  2170. // traverse itself in case it moves the node around
  2171. props.splice(i, 1);
  2172. i--;
  2173. const onExit = fn(node, prop, context);
  2174. if (onExit)
  2175. exitFns.push(onExit);
  2176. }
  2177. }
  2178. return exitFns;
  2179. }
  2180. };
  2181. }
  2182. const PURE_ANNOTATION = `/*#__PURE__*/`;
  2183. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, inSSR = false }) {
  2184. const context = {
  2185. mode,
  2186. prefixIdentifiers,
  2187. sourceMap,
  2188. filename,
  2189. scopeId,
  2190. optimizeImports,
  2191. runtimeGlobalName,
  2192. runtimeModuleName,
  2193. ssrRuntimeModuleName,
  2194. ssr,
  2195. isTS,
  2196. inSSR,
  2197. source: ast.loc.source,
  2198. code: ``,
  2199. column: 1,
  2200. line: 1,
  2201. offset: 0,
  2202. indentLevel: 0,
  2203. pure: false,
  2204. map: undefined,
  2205. helper(key) {
  2206. return `_${helperNameMap[key]}`;
  2207. },
  2208. push(code, node) {
  2209. context.code += code;
  2210. },
  2211. indent() {
  2212. newline(++context.indentLevel);
  2213. },
  2214. deindent(withoutNewLine = false) {
  2215. if (withoutNewLine) {
  2216. --context.indentLevel;
  2217. }
  2218. else {
  2219. newline(--context.indentLevel);
  2220. }
  2221. },
  2222. newline() {
  2223. newline(context.indentLevel);
  2224. }
  2225. };
  2226. function newline(n) {
  2227. context.push('\n' + ` `.repeat(n));
  2228. }
  2229. return context;
  2230. }
  2231. function generate(ast, options = {}) {
  2232. const context = createCodegenContext(ast, options);
  2233. if (options.onContextCreated)
  2234. options.onContextCreated(context);
  2235. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  2236. const hasHelpers = ast.helpers.length > 0;
  2237. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  2238. // preambles
  2239. // in setup() inline mode, the preamble is generated in a sub context
  2240. // and returned separately.
  2241. const preambleContext = context;
  2242. {
  2243. genFunctionPreamble(ast, preambleContext);
  2244. }
  2245. // enter render function
  2246. const functionName = ssr ? `ssrRender` : `render`;
  2247. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  2248. const signature = args.join(', ');
  2249. {
  2250. push(`function ${functionName}(${signature}) {`);
  2251. }
  2252. indent();
  2253. if (useWithBlock) {
  2254. push(`with (_ctx) {`);
  2255. indent();
  2256. // function mode const declarations should be inside with block
  2257. // also they should be renamed to avoid collision with user properties
  2258. if (hasHelpers) {
  2259. push(`const { ${ast.helpers
  2260. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  2261. .join(', ')} } = _Vue`);
  2262. push(`\n`);
  2263. newline();
  2264. }
  2265. }
  2266. // generate asset resolution statements
  2267. if (ast.components.length) {
  2268. genAssets(ast.components, 'component', context);
  2269. if (ast.directives.length || ast.temps > 0) {
  2270. newline();
  2271. }
  2272. }
  2273. if (ast.directives.length) {
  2274. genAssets(ast.directives, 'directive', context);
  2275. if (ast.temps > 0) {
  2276. newline();
  2277. }
  2278. }
  2279. if (ast.filters && ast.filters.length) {
  2280. newline();
  2281. genAssets(ast.filters, 'filter', context);
  2282. newline();
  2283. }
  2284. if (ast.temps > 0) {
  2285. push(`let `);
  2286. for (let i = 0; i < ast.temps; i++) {
  2287. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  2288. }
  2289. }
  2290. if (ast.components.length || ast.directives.length || ast.temps) {
  2291. push(`\n`);
  2292. newline();
  2293. }
  2294. // generate the VNode tree expression
  2295. if (!ssr) {
  2296. push(`return `);
  2297. }
  2298. if (ast.codegenNode) {
  2299. genNode(ast.codegenNode, context);
  2300. }
  2301. else {
  2302. push(`null`);
  2303. }
  2304. if (useWithBlock) {
  2305. deindent();
  2306. push(`}`);
  2307. }
  2308. deindent();
  2309. push(`}`);
  2310. return {
  2311. ast,
  2312. code: context.code,
  2313. preamble: ``,
  2314. // SourceMapGenerator does have toJSON() method but it's not in the types
  2315. map: context.map ? context.map.toJSON() : undefined
  2316. };
  2317. }
  2318. function genFunctionPreamble(ast, context) {
  2319. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  2320. const VueBinding = runtimeGlobalName;
  2321. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  2322. // Generate const declaration for helpers
  2323. // In prefix mode, we place the const declaration at top so it's done
  2324. // only once; But if we not prefixing, we place the declaration inside the
  2325. // with block so it doesn't incur the `in` check cost for every helper access.
  2326. if (ast.helpers.length > 0) {
  2327. {
  2328. // "with" mode.
  2329. // save Vue in a separate variable to avoid collision
  2330. push(`const _Vue = ${VueBinding}\n`);
  2331. // in "with" mode, helpers are declared inside the with block to avoid
  2332. // has check cost, but hoists are lifted out of the function - we need
  2333. // to provide the helper here.
  2334. if (ast.hoists.length) {
  2335. const staticHelpers = [
  2336. CREATE_VNODE,
  2337. CREATE_ELEMENT_VNODE,
  2338. CREATE_COMMENT,
  2339. CREATE_TEXT,
  2340. CREATE_STATIC
  2341. ]
  2342. .filter(helper => ast.helpers.includes(helper))
  2343. .map(aliasHelper)
  2344. .join(', ');
  2345. push(`const { ${staticHelpers} } = _Vue\n`);
  2346. }
  2347. }
  2348. }
  2349. genHoists(ast.hoists, context);
  2350. newline();
  2351. push(`return `);
  2352. }
  2353. function genAssets(assets, type, { helper, push, newline, isTS }) {
  2354. const resolver = helper(type === 'filter'
  2355. ? RESOLVE_FILTER
  2356. : type === 'component'
  2357. ? RESOLVE_COMPONENT
  2358. : RESOLVE_DIRECTIVE);
  2359. for (let i = 0; i < assets.length; i++) {
  2360. let id = assets[i];
  2361. // potential component implicit self-reference inferred from SFC filename
  2362. const maybeSelfReference = id.endsWith('__self');
  2363. if (maybeSelfReference) {
  2364. id = id.slice(0, -6);
  2365. }
  2366. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  2367. if (i < assets.length - 1) {
  2368. newline();
  2369. }
  2370. }
  2371. }
  2372. function genHoists(hoists, context) {
  2373. if (!hoists.length) {
  2374. return;
  2375. }
  2376. context.pure = true;
  2377. const { push, newline, helper, scopeId, mode } = context;
  2378. newline();
  2379. for (let i = 0; i < hoists.length; i++) {
  2380. const exp = hoists[i];
  2381. if (exp) {
  2382. push(`const _hoisted_${i + 1} = ${``}`);
  2383. genNode(exp, context);
  2384. newline();
  2385. }
  2386. }
  2387. context.pure = false;
  2388. }
  2389. function isText$1(n) {
  2390. return (isString(n) ||
  2391. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  2392. n.type === 2 /* TEXT */ ||
  2393. n.type === 5 /* INTERPOLATION */ ||
  2394. n.type === 8 /* COMPOUND_EXPRESSION */);
  2395. }
  2396. function genNodeListAsArray(nodes, context) {
  2397. const multilines = nodes.length > 3 ||
  2398. (((process.env.NODE_ENV !== 'production')) && nodes.some(n => isArray(n) || !isText$1(n)));
  2399. context.push(`[`);
  2400. multilines && context.indent();
  2401. genNodeList(nodes, context, multilines);
  2402. multilines && context.deindent();
  2403. context.push(`]`);
  2404. }
  2405. function genNodeList(nodes, context, multilines = false, comma = true) {
  2406. const { push, newline } = context;
  2407. for (let i = 0; i < nodes.length; i++) {
  2408. const node = nodes[i];
  2409. if (isString(node)) {
  2410. push(node);
  2411. }
  2412. else if (isArray(node)) {
  2413. genNodeListAsArray(node, context);
  2414. }
  2415. else {
  2416. genNode(node, context);
  2417. }
  2418. if (i < nodes.length - 1) {
  2419. if (multilines) {
  2420. comma && push(',');
  2421. newline();
  2422. }
  2423. else {
  2424. comma && push(', ');
  2425. }
  2426. }
  2427. }
  2428. }
  2429. function genNode(node, context) {
  2430. if (isString(node)) {
  2431. context.push(node);
  2432. return;
  2433. }
  2434. if (isSymbol(node)) {
  2435. context.push(context.helper(node));
  2436. return;
  2437. }
  2438. switch (node.type) {
  2439. case 1 /* ELEMENT */:
  2440. case 9 /* IF */:
  2441. case 11 /* FOR */:
  2442. (process.env.NODE_ENV !== 'production') &&
  2443. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  2444. `Apply appropriate transforms first.`);
  2445. genNode(node.codegenNode, context);
  2446. break;
  2447. case 2 /* TEXT */:
  2448. genText(node, context);
  2449. break;
  2450. case 4 /* SIMPLE_EXPRESSION */:
  2451. genExpression(node, context);
  2452. break;
  2453. case 5 /* INTERPOLATION */:
  2454. genInterpolation(node, context);
  2455. break;
  2456. case 12 /* TEXT_CALL */:
  2457. genNode(node.codegenNode, context);
  2458. break;
  2459. case 8 /* COMPOUND_EXPRESSION */:
  2460. genCompoundExpression(node, context);
  2461. break;
  2462. case 3 /* COMMENT */:
  2463. genComment(node, context);
  2464. break;
  2465. case 13 /* VNODE_CALL */:
  2466. genVNodeCall(node, context);
  2467. break;
  2468. case 14 /* JS_CALL_EXPRESSION */:
  2469. genCallExpression(node, context);
  2470. break;
  2471. case 15 /* JS_OBJECT_EXPRESSION */:
  2472. genObjectExpression(node, context);
  2473. break;
  2474. case 17 /* JS_ARRAY_EXPRESSION */:
  2475. genArrayExpression(node, context);
  2476. break;
  2477. case 18 /* JS_FUNCTION_EXPRESSION */:
  2478. genFunctionExpression(node, context);
  2479. break;
  2480. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  2481. genConditionalExpression(node, context);
  2482. break;
  2483. case 20 /* JS_CACHE_EXPRESSION */:
  2484. genCacheExpression(node, context);
  2485. break;
  2486. case 21 /* JS_BLOCK_STATEMENT */:
  2487. genNodeList(node.body, context, true, false);
  2488. break;
  2489. // SSR only types
  2490. case 22 /* JS_TEMPLATE_LITERAL */:
  2491. break;
  2492. case 23 /* JS_IF_STATEMENT */:
  2493. break;
  2494. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  2495. break;
  2496. case 25 /* JS_SEQUENCE_EXPRESSION */:
  2497. break;
  2498. case 26 /* JS_RETURN_STATEMENT */:
  2499. break;
  2500. /* istanbul ignore next */
  2501. case 10 /* IF_BRANCH */:
  2502. // noop
  2503. break;
  2504. default:
  2505. if ((process.env.NODE_ENV !== 'production')) {
  2506. assert(false, `unhandled codegen node type: ${node.type}`);
  2507. // make sure we exhaust all possible types
  2508. const exhaustiveCheck = node;
  2509. return exhaustiveCheck;
  2510. }
  2511. }
  2512. }
  2513. function genText(node, context) {
  2514. context.push(JSON.stringify(node.content), node);
  2515. }
  2516. function genExpression(node, context) {
  2517. const { content, isStatic } = node;
  2518. context.push(isStatic ? JSON.stringify(content) : content, node);
  2519. }
  2520. function genInterpolation(node, context) {
  2521. const { push, helper, pure } = context;
  2522. if (pure)
  2523. push(PURE_ANNOTATION);
  2524. push(`${helper(TO_DISPLAY_STRING)}(`);
  2525. genNode(node.content, context);
  2526. push(`)`);
  2527. }
  2528. function genCompoundExpression(node, context) {
  2529. for (let i = 0; i < node.children.length; i++) {
  2530. const child = node.children[i];
  2531. if (isString(child)) {
  2532. context.push(child);
  2533. }
  2534. else {
  2535. genNode(child, context);
  2536. }
  2537. }
  2538. }
  2539. function genExpressionAsPropertyKey(node, context) {
  2540. const { push } = context;
  2541. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  2542. push(`[`);
  2543. genCompoundExpression(node, context);
  2544. push(`]`);
  2545. }
  2546. else if (node.isStatic) {
  2547. // only quote keys if necessary
  2548. const text = isSimpleIdentifier(node.content)
  2549. ? node.content
  2550. : JSON.stringify(node.content);
  2551. push(text, node);
  2552. }
  2553. else {
  2554. push(`[${node.content}]`, node);
  2555. }
  2556. }
  2557. function genComment(node, context) {
  2558. const { push, helper, pure } = context;
  2559. if (pure) {
  2560. push(PURE_ANNOTATION);
  2561. }
  2562. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  2563. }
  2564. function genVNodeCall(node, context) {
  2565. const { push, helper, pure } = context;
  2566. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  2567. if (directives) {
  2568. push(helper(WITH_DIRECTIVES) + `(`);
  2569. }
  2570. if (isBlock) {
  2571. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  2572. }
  2573. if (pure) {
  2574. push(PURE_ANNOTATION);
  2575. }
  2576. const callHelper = isBlock
  2577. ? getVNodeBlockHelper(context.inSSR, isComponent)
  2578. : getVNodeHelper(context.inSSR, isComponent);
  2579. push(helper(callHelper) + `(`, node);
  2580. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  2581. push(`)`);
  2582. if (isBlock) {
  2583. push(`)`);
  2584. }
  2585. if (directives) {
  2586. push(`, `);
  2587. genNode(directives, context);
  2588. push(`)`);
  2589. }
  2590. }
  2591. function genNullableArgs(args) {
  2592. let i = args.length;
  2593. while (i--) {
  2594. if (args[i] != null)
  2595. break;
  2596. }
  2597. return args.slice(0, i + 1).map(arg => arg || `null`);
  2598. }
  2599. // JavaScript
  2600. function genCallExpression(node, context) {
  2601. const { push, helper, pure } = context;
  2602. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  2603. if (pure) {
  2604. push(PURE_ANNOTATION);
  2605. }
  2606. push(callee + `(`, node);
  2607. genNodeList(node.arguments, context);
  2608. push(`)`);
  2609. }
  2610. function genObjectExpression(node, context) {
  2611. const { push, indent, deindent, newline } = context;
  2612. const { properties } = node;
  2613. if (!properties.length) {
  2614. push(`{}`, node);
  2615. return;
  2616. }
  2617. const multilines = properties.length > 1 ||
  2618. (((process.env.NODE_ENV !== 'production')) &&
  2619. properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  2620. push(multilines ? `{` : `{ `);
  2621. multilines && indent();
  2622. for (let i = 0; i < properties.length; i++) {
  2623. const { key, value } = properties[i];
  2624. // key
  2625. genExpressionAsPropertyKey(key, context);
  2626. push(`: `);
  2627. // value
  2628. genNode(value, context);
  2629. if (i < properties.length - 1) {
  2630. // will only reach this if it's multilines
  2631. push(`,`);
  2632. newline();
  2633. }
  2634. }
  2635. multilines && deindent();
  2636. push(multilines ? `}` : ` }`);
  2637. }
  2638. function genArrayExpression(node, context) {
  2639. genNodeListAsArray(node.elements, context);
  2640. }
  2641. function genFunctionExpression(node, context) {
  2642. const { push, indent, deindent } = context;
  2643. const { params, returns, body, newline, isSlot } = node;
  2644. if (isSlot) {
  2645. // wrap slot functions with owner context
  2646. push(`_${helperNameMap[WITH_CTX]}(`);
  2647. }
  2648. push(`(`, node);
  2649. if (isArray(params)) {
  2650. genNodeList(params, context);
  2651. }
  2652. else if (params) {
  2653. genNode(params, context);
  2654. }
  2655. push(`) => `);
  2656. if (newline || body) {
  2657. push(`{`);
  2658. indent();
  2659. }
  2660. if (returns) {
  2661. if (newline) {
  2662. push(`return `);
  2663. }
  2664. if (isArray(returns)) {
  2665. genNodeListAsArray(returns, context);
  2666. }
  2667. else {
  2668. genNode(returns, context);
  2669. }
  2670. }
  2671. else if (body) {
  2672. genNode(body, context);
  2673. }
  2674. if (newline || body) {
  2675. deindent();
  2676. push(`}`);
  2677. }
  2678. if (isSlot) {
  2679. if (node.isNonScopedSlot) {
  2680. push(`, undefined, true`);
  2681. }
  2682. push(`)`);
  2683. }
  2684. }
  2685. function genConditionalExpression(node, context) {
  2686. const { test, consequent, alternate, newline: needNewline } = node;
  2687. const { push, indent, deindent, newline } = context;
  2688. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  2689. const needsParens = !isSimpleIdentifier(test.content);
  2690. needsParens && push(`(`);
  2691. genExpression(test, context);
  2692. needsParens && push(`)`);
  2693. }
  2694. else {
  2695. push(`(`);
  2696. genNode(test, context);
  2697. push(`)`);
  2698. }
  2699. needNewline && indent();
  2700. context.indentLevel++;
  2701. needNewline || push(` `);
  2702. push(`? `);
  2703. genNode(consequent, context);
  2704. context.indentLevel--;
  2705. needNewline && newline();
  2706. needNewline || push(` `);
  2707. push(`: `);
  2708. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  2709. if (!isNested) {
  2710. context.indentLevel++;
  2711. }
  2712. genNode(alternate, context);
  2713. if (!isNested) {
  2714. context.indentLevel--;
  2715. }
  2716. needNewline && deindent(true /* without newline */);
  2717. }
  2718. function genCacheExpression(node, context) {
  2719. const { push, helper, indent, deindent, newline } = context;
  2720. push(`_cache[${node.index}] || (`);
  2721. if (node.isVNode) {
  2722. indent();
  2723. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  2724. newline();
  2725. }
  2726. push(`_cache[${node.index}] = `);
  2727. genNode(node.value, context);
  2728. if (node.isVNode) {
  2729. push(`,`);
  2730. newline();
  2731. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  2732. newline();
  2733. push(`_cache[${node.index}]`);
  2734. deindent();
  2735. }
  2736. push(`)`);
  2737. }
  2738. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = Object.create(null)) {
  2739. {
  2740. return;
  2741. }
  2742. }
  2743. function isReferencedIdentifier(id, parent, parentStack) {
  2744. {
  2745. return false;
  2746. }
  2747. }
  2748. function isInDestructureAssignment(parent, parentStack) {
  2749. if (parent &&
  2750. (parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
  2751. let i = parentStack.length;
  2752. while (i--) {
  2753. const p = parentStack[i];
  2754. if (p.type === 'AssignmentExpression') {
  2755. return true;
  2756. }
  2757. else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
  2758. break;
  2759. }
  2760. }
  2761. }
  2762. return false;
  2763. }
  2764. function walkFunctionParams(node, onIdent) {
  2765. for (const p of node.params) {
  2766. for (const id of extractIdentifiers(p)) {
  2767. onIdent(id);
  2768. }
  2769. }
  2770. }
  2771. function walkBlockDeclarations(block, onIdent) {
  2772. for (const stmt of block.body) {
  2773. if (stmt.type === 'VariableDeclaration') {
  2774. if (stmt.declare)
  2775. continue;
  2776. for (const decl of stmt.declarations) {
  2777. for (const id of extractIdentifiers(decl.id)) {
  2778. onIdent(id);
  2779. }
  2780. }
  2781. }
  2782. else if (stmt.type === 'FunctionDeclaration' ||
  2783. stmt.type === 'ClassDeclaration') {
  2784. if (stmt.declare || !stmt.id)
  2785. continue;
  2786. onIdent(stmt.id);
  2787. }
  2788. }
  2789. }
  2790. function extractIdentifiers(param, nodes = []) {
  2791. switch (param.type) {
  2792. case 'Identifier':
  2793. nodes.push(param);
  2794. break;
  2795. case 'MemberExpression':
  2796. let object = param;
  2797. while (object.type === 'MemberExpression') {
  2798. object = object.object;
  2799. }
  2800. nodes.push(object);
  2801. break;
  2802. case 'ObjectPattern':
  2803. for (const prop of param.properties) {
  2804. if (prop.type === 'RestElement') {
  2805. extractIdentifiers(prop.argument, nodes);
  2806. }
  2807. else {
  2808. extractIdentifiers(prop.value, nodes);
  2809. }
  2810. }
  2811. break;
  2812. case 'ArrayPattern':
  2813. param.elements.forEach(element => {
  2814. if (element)
  2815. extractIdentifiers(element, nodes);
  2816. });
  2817. break;
  2818. case 'RestElement':
  2819. extractIdentifiers(param.argument, nodes);
  2820. break;
  2821. case 'AssignmentPattern':
  2822. extractIdentifiers(param.left, nodes);
  2823. break;
  2824. }
  2825. return nodes;
  2826. }
  2827. const isFunctionType = (node) => {
  2828. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  2829. };
  2830. const isStaticProperty = (node) => node &&
  2831. (node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
  2832. !node.computed;
  2833. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  2834. // these keywords should not appear inside expressions, but operators like
  2835. // typeof, instanceof and in are allowed
  2836. const prohibitedKeywordRE = new RegExp('\\b' +
  2837. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  2838. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  2839. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  2840. .split(',')
  2841. .join('\\b|\\b') +
  2842. '\\b');
  2843. // strip strings in expressions
  2844. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  2845. /**
  2846. * Validate a non-prefixed expression.
  2847. * This is only called when using the in-browser runtime compiler since it
  2848. * doesn't prefix expressions.
  2849. */
  2850. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  2851. const exp = node.content;
  2852. // empty expressions are validated per-directive since some directives
  2853. // do allow empty expressions.
  2854. if (!exp.trim()) {
  2855. return;
  2856. }
  2857. try {
  2858. new Function(asRawStatements
  2859. ? ` ${exp} `
  2860. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  2861. }
  2862. catch (e) {
  2863. let message = e.message;
  2864. const keywordMatch = exp
  2865. .replace(stripStringRE, '')
  2866. .match(prohibitedKeywordRE);
  2867. if (keywordMatch) {
  2868. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  2869. }
  2870. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  2871. }
  2872. }
  2873. const transformExpression = (node, context) => {
  2874. if (node.type === 5 /* INTERPOLATION */) {
  2875. node.content = processExpression(node.content, context);
  2876. }
  2877. else if (node.type === 1 /* ELEMENT */) {
  2878. // handle directives on element
  2879. for (let i = 0; i < node.props.length; i++) {
  2880. const dir = node.props[i];
  2881. // do not process for v-on & v-for since they are special handled
  2882. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  2883. const exp = dir.exp;
  2884. const arg = dir.arg;
  2885. // do not process exp if this is v-on:arg - we need special handling
  2886. // for wrapping inline statements.
  2887. if (exp &&
  2888. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  2889. !(dir.name === 'on' && arg)) {
  2890. dir.exp = processExpression(exp, context,
  2891. // slot args must be processed as function params
  2892. dir.name === 'slot');
  2893. }
  2894. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  2895. dir.arg = processExpression(arg, context);
  2896. }
  2897. }
  2898. }
  2899. }
  2900. };
  2901. // Important: since this function uses Node.js only dependencies, it should
  2902. // always be used with a leading !true check so that it can be
  2903. // tree-shaken from the browser build.
  2904. function processExpression(node, context,
  2905. // some expressions like v-slot props & v-for aliases should be parsed as
  2906. // function params
  2907. asParams = false,
  2908. // v-on handler values may contain multiple statements
  2909. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  2910. {
  2911. if ((process.env.NODE_ENV !== 'production')) {
  2912. // simple in-browser validation (same logic in 2.x)
  2913. validateBrowserExpression(node, context, asParams, asRawStatements);
  2914. }
  2915. return node;
  2916. }
  2917. }
  2918. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  2919. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  2920. // #1587: We need to dynamically increment the key based on the current
  2921. // node's sibling nodes, since chained v-if/else branches are
  2922. // rendered at the same depth
  2923. const siblings = context.parent.children;
  2924. let i = siblings.indexOf(ifNode);
  2925. let key = 0;
  2926. while (i-- >= 0) {
  2927. const sibling = siblings[i];
  2928. if (sibling && sibling.type === 9 /* IF */) {
  2929. key += sibling.branches.length;
  2930. }
  2931. }
  2932. // Exit callback. Complete the codegenNode when all children have been
  2933. // transformed.
  2934. return () => {
  2935. if (isRoot) {
  2936. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  2937. }
  2938. else {
  2939. // attach this branch's codegen node to the v-if root.
  2940. const parentCondition = getParentCondition(ifNode.codegenNode);
  2941. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  2942. }
  2943. };
  2944. });
  2945. });
  2946. // target-agnostic transform used for both Client and SSR
  2947. function processIf(node, dir, context, processCodegen) {
  2948. if (dir.name !== 'else' &&
  2949. (!dir.exp || !dir.exp.content.trim())) {
  2950. const loc = dir.exp ? dir.exp.loc : node.loc;
  2951. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  2952. dir.exp = createSimpleExpression(`true`, false, loc);
  2953. }
  2954. if ((process.env.NODE_ENV !== 'production') && true && dir.exp) {
  2955. validateBrowserExpression(dir.exp, context);
  2956. }
  2957. if (dir.name === 'if') {
  2958. const branch = createIfBranch(node, dir);
  2959. const ifNode = {
  2960. type: 9 /* IF */,
  2961. loc: node.loc,
  2962. branches: [branch]
  2963. };
  2964. context.replaceNode(ifNode);
  2965. if (processCodegen) {
  2966. return processCodegen(ifNode, branch, true);
  2967. }
  2968. }
  2969. else {
  2970. // locate the adjacent v-if
  2971. const siblings = context.parent.children;
  2972. const comments = [];
  2973. let i = siblings.indexOf(node);
  2974. while (i-- >= -1) {
  2975. const sibling = siblings[i];
  2976. if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* COMMENT */) {
  2977. context.removeNode(sibling);
  2978. comments.unshift(sibling);
  2979. continue;
  2980. }
  2981. if (sibling &&
  2982. sibling.type === 2 /* TEXT */ &&
  2983. !sibling.content.trim().length) {
  2984. context.removeNode(sibling);
  2985. continue;
  2986. }
  2987. if (sibling && sibling.type === 9 /* IF */) {
  2988. // Check if v-else was followed by v-else-if
  2989. if (dir.name === 'else-if' &&
  2990. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  2991. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  2992. }
  2993. // move the node to the if node's branches
  2994. context.removeNode();
  2995. const branch = createIfBranch(node, dir);
  2996. if ((process.env.NODE_ENV !== 'production') &&
  2997. comments.length &&
  2998. // #3619 ignore comments if the v-if is direct child of <transition>
  2999. !(context.parent &&
  3000. context.parent.type === 1 /* ELEMENT */ &&
  3001. isBuiltInType(context.parent.tag, 'transition'))) {
  3002. branch.children = [...comments, ...branch.children];
  3003. }
  3004. // check if user is forcing same key on different branches
  3005. if ((process.env.NODE_ENV !== 'production') || !true) {
  3006. const key = branch.userKey;
  3007. if (key) {
  3008. sibling.branches.forEach(({ userKey }) => {
  3009. if (isSameKey(userKey, key)) {
  3010. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  3011. }
  3012. });
  3013. }
  3014. }
  3015. sibling.branches.push(branch);
  3016. const onExit = processCodegen && processCodegen(sibling, branch, false);
  3017. // since the branch was removed, it will not be traversed.
  3018. // make sure to traverse here.
  3019. traverseNode(branch, context);
  3020. // call on exit
  3021. if (onExit)
  3022. onExit();
  3023. // make sure to reset currentNode after traversal to indicate this
  3024. // node has been removed.
  3025. context.currentNode = null;
  3026. }
  3027. else {
  3028. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  3029. }
  3030. break;
  3031. }
  3032. }
  3033. }
  3034. function createIfBranch(node, dir) {
  3035. return {
  3036. type: 10 /* IF_BRANCH */,
  3037. loc: node.loc,
  3038. condition: dir.name === 'else' ? undefined : dir.exp,
  3039. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  3040. ? node.children
  3041. : [node],
  3042. userKey: findProp(node, `key`)
  3043. };
  3044. }
  3045. function createCodegenNodeForBranch(branch, keyIndex, context) {
  3046. if (branch.condition) {
  3047. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  3048. // make sure to pass in asBlock: true so that the comment node call
  3049. // closes the current block.
  3050. createCallExpression(context.helper(CREATE_COMMENT), [
  3051. (process.env.NODE_ENV !== 'production') ? '"v-if"' : '""',
  3052. 'true'
  3053. ]));
  3054. }
  3055. else {
  3056. return createChildrenCodegenNode(branch, keyIndex, context);
  3057. }
  3058. }
  3059. function createChildrenCodegenNode(branch, keyIndex, context) {
  3060. const { helper } = context;
  3061. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  3062. const { children } = branch;
  3063. const firstChild = children[0];
  3064. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  3065. if (needFragmentWrapper) {
  3066. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  3067. // optimize away nested fragments when child is a ForNode
  3068. const vnodeCall = firstChild.codegenNode;
  3069. injectProp(vnodeCall, keyProperty, context);
  3070. return vnodeCall;
  3071. }
  3072. else {
  3073. let patchFlag = 64 /* STABLE_FRAGMENT */;
  3074. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  3075. // check if the fragment actually contains a single valid child with
  3076. // the rest being comments
  3077. if ((process.env.NODE_ENV !== 'production') &&
  3078. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  3079. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  3080. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  3081. }
  3082. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  3083. }
  3084. }
  3085. else {
  3086. const ret = firstChild.codegenNode;
  3087. const vnodeCall = getMemoedVNodeCall(ret);
  3088. // Change createVNode to createBlock.
  3089. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  3090. makeBlock(vnodeCall, context);
  3091. }
  3092. // inject branch key
  3093. injectProp(vnodeCall, keyProperty, context);
  3094. return ret;
  3095. }
  3096. }
  3097. function isSameKey(a, b) {
  3098. if (!a || a.type !== b.type) {
  3099. return false;
  3100. }
  3101. if (a.type === 6 /* ATTRIBUTE */) {
  3102. if (a.value.content !== b.value.content) {
  3103. return false;
  3104. }
  3105. }
  3106. else {
  3107. // directive
  3108. const exp = a.exp;
  3109. const branchExp = b.exp;
  3110. if (exp.type !== branchExp.type) {
  3111. return false;
  3112. }
  3113. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  3114. exp.isStatic !== branchExp.isStatic ||
  3115. exp.content !== branchExp.content) {
  3116. return false;
  3117. }
  3118. }
  3119. return true;
  3120. }
  3121. function getParentCondition(node) {
  3122. while (true) {
  3123. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  3124. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  3125. node = node.alternate;
  3126. }
  3127. else {
  3128. return node;
  3129. }
  3130. }
  3131. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  3132. node = node.value;
  3133. }
  3134. }
  3135. }
  3136. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  3137. const { helper, removeHelper } = context;
  3138. return processFor(node, dir, context, forNode => {
  3139. // create the loop render function expression now, and add the
  3140. // iterator on exit after all children have been traversed
  3141. const renderExp = createCallExpression(helper(RENDER_LIST), [
  3142. forNode.source
  3143. ]);
  3144. const isTemplate = isTemplateNode(node);
  3145. const memo = findDir(node, 'memo');
  3146. const keyProp = findProp(node, `key`);
  3147. const keyExp = keyProp &&
  3148. (keyProp.type === 6 /* ATTRIBUTE */
  3149. ? createSimpleExpression(keyProp.value.content, true)
  3150. : keyProp.exp);
  3151. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  3152. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  3153. forNode.source.constType > 0 /* NOT_CONSTANT */;
  3154. const fragmentFlag = isStableFragment
  3155. ? 64 /* STABLE_FRAGMENT */
  3156. : keyProp
  3157. ? 128 /* KEYED_FRAGMENT */
  3158. : 256 /* UNKEYED_FRAGMENT */;
  3159. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  3160. ((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  3161. return () => {
  3162. // finish the codegen now that all children have been traversed
  3163. let childBlock;
  3164. const { children } = forNode;
  3165. // check <template v-for> key placement
  3166. if (((process.env.NODE_ENV !== 'production') || !true) && isTemplate) {
  3167. node.children.some(c => {
  3168. if (c.type === 1 /* ELEMENT */) {
  3169. const key = findProp(c, 'key');
  3170. if (key) {
  3171. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  3172. return true;
  3173. }
  3174. }
  3175. });
  3176. }
  3177. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  3178. const slotOutlet = isSlotOutlet(node)
  3179. ? node
  3180. : isTemplate &&
  3181. node.children.length === 1 &&
  3182. isSlotOutlet(node.children[0])
  3183. ? node.children[0] // api-extractor somehow fails to infer this
  3184. : null;
  3185. if (slotOutlet) {
  3186. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  3187. childBlock = slotOutlet.codegenNode;
  3188. if (isTemplate && keyProperty) {
  3189. // <template v-for="..." :key="..."><slot/></template>
  3190. // we need to inject the key to the renderSlot() call.
  3191. // the props for renderSlot is passed as the 3rd argument.
  3192. injectProp(childBlock, keyProperty, context);
  3193. }
  3194. }
  3195. else if (needFragmentWrapper) {
  3196. // <template v-for="..."> with text or multi-elements
  3197. // should generate a fragment block for each loop
  3198. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  3199. ((process.env.NODE_ENV !== 'production')
  3200. ? ` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  3201. : ``), undefined, undefined, true, undefined, false /* isComponent */);
  3202. }
  3203. else {
  3204. // Normal element v-for. Directly use the child's codegenNode
  3205. // but mark it as a block.
  3206. childBlock = children[0]
  3207. .codegenNode;
  3208. if (isTemplate && keyProperty) {
  3209. injectProp(childBlock, keyProperty, context);
  3210. }
  3211. if (childBlock.isBlock !== !isStableFragment) {
  3212. if (childBlock.isBlock) {
  3213. // switch from block to vnode
  3214. removeHelper(OPEN_BLOCK);
  3215. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  3216. }
  3217. else {
  3218. // switch from vnode to block
  3219. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  3220. }
  3221. }
  3222. childBlock.isBlock = !isStableFragment;
  3223. if (childBlock.isBlock) {
  3224. helper(OPEN_BLOCK);
  3225. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  3226. }
  3227. else {
  3228. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  3229. }
  3230. }
  3231. if (memo) {
  3232. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  3233. createSimpleExpression(`_cached`)
  3234. ]));
  3235. loop.body = createBlockStatement([
  3236. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  3237. createCompoundExpression([
  3238. `if (_cached`,
  3239. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  3240. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  3241. ]),
  3242. createCompoundExpression([`const _item = `, childBlock]),
  3243. createSimpleExpression(`_item.memo = _memo`),
  3244. createSimpleExpression(`return _item`)
  3245. ]);
  3246. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  3247. }
  3248. else {
  3249. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  3250. }
  3251. };
  3252. });
  3253. });
  3254. // target-agnostic transform used for both Client and SSR
  3255. function processFor(node, dir, context, processCodegen) {
  3256. if (!dir.exp) {
  3257. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  3258. return;
  3259. }
  3260. const parseResult = parseForExpression(
  3261. // can only be simple expression because vFor transform is applied
  3262. // before expression transform.
  3263. dir.exp, context);
  3264. if (!parseResult) {
  3265. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  3266. return;
  3267. }
  3268. const { addIdentifiers, removeIdentifiers, scopes } = context;
  3269. const { source, value, key, index } = parseResult;
  3270. const forNode = {
  3271. type: 11 /* FOR */,
  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. // bookkeeping
  3282. scopes.vFor++;
  3283. const onExit = processCodegen && processCodegen(forNode);
  3284. return () => {
  3285. scopes.vFor--;
  3286. if (onExit)
  3287. onExit();
  3288. };
  3289. }
  3290. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  3291. // This regex doesn't cover the case if key or index aliases have destructuring,
  3292. // but those do not make sense in the first place, so this works in practice.
  3293. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  3294. const stripParensRE = /^\(|\)$/g;
  3295. function parseForExpression(input, context) {
  3296. const loc = input.loc;
  3297. const exp = input.content;
  3298. const inMatch = exp.match(forAliasRE);
  3299. if (!inMatch)
  3300. return;
  3301. const [, LHS, RHS] = inMatch;
  3302. const result = {
  3303. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  3304. value: undefined,
  3305. key: undefined,
  3306. index: undefined
  3307. };
  3308. if ((process.env.NODE_ENV !== 'production') && true) {
  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. if ((process.env.NODE_ENV !== 'production') && true) {
  3322. validateBrowserExpression(result.key, context, true);
  3323. }
  3324. }
  3325. if (iteratorMatch[2]) {
  3326. const indexContent = iteratorMatch[2].trim();
  3327. if (indexContent) {
  3328. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  3329. ? keyOffset + keyContent.length
  3330. : trimmedOffset + valueContent.length));
  3331. if ((process.env.NODE_ENV !== 'production') && true) {
  3332. validateBrowserExpression(result.index, context, true);
  3333. }
  3334. }
  3335. }
  3336. }
  3337. if (valueContent) {
  3338. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  3339. if ((process.env.NODE_ENV !== 'production') && true) {
  3340. validateBrowserExpression(result.value, context, true);
  3341. }
  3342. }
  3343. return result;
  3344. }
  3345. function createAliasExpression(range, content, offset) {
  3346. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  3347. }
  3348. function createForLoopParams({ value, key, index }, memoArgs = []) {
  3349. return createParamsList([value, key, index, ...memoArgs]);
  3350. }
  3351. function createParamsList(args) {
  3352. let i = args.length;
  3353. while (i--) {
  3354. if (args[i])
  3355. break;
  3356. }
  3357. return args
  3358. .slice(0, i + 1)
  3359. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  3360. }
  3361. const defaultFallback = createSimpleExpression(`undefined`, false);
  3362. // A NodeTransform that:
  3363. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  3364. // by transformExpression. This is only applied in non-browser builds with
  3365. // { prefixIdentifiers: true }.
  3366. // 2. Track v-slot depths so that we know a slot is inside another slot.
  3367. // Note the exit callback is executed before buildSlots() on the same node,
  3368. // so only nested slots see positive numbers.
  3369. const trackSlotScopes = (node, context) => {
  3370. if (node.type === 1 /* ELEMENT */ &&
  3371. (node.tagType === 1 /* COMPONENT */ ||
  3372. node.tagType === 3 /* TEMPLATE */)) {
  3373. // We are only checking non-empty v-slot here
  3374. // since we only care about slots that introduce scope variables.
  3375. const vSlot = findDir(node, 'slot');
  3376. if (vSlot) {
  3377. vSlot.exp;
  3378. context.scopes.vSlot++;
  3379. return () => {
  3380. context.scopes.vSlot--;
  3381. };
  3382. }
  3383. }
  3384. };
  3385. // A NodeTransform that tracks scope identifiers for scoped slots with v-for.
  3386. // This transform is only applied in non-browser builds with { prefixIdentifiers: true }
  3387. const trackVForSlotScopes = (node, context) => {
  3388. let vFor;
  3389. if (isTemplateNode(node) &&
  3390. node.props.some(isVSlot) &&
  3391. (vFor = findDir(node, 'for'))) {
  3392. const result = (vFor.parseResult = parseForExpression(vFor.exp, context));
  3393. if (result) {
  3394. const { value, key, index } = result;
  3395. const { addIdentifiers, removeIdentifiers } = context;
  3396. value && addIdentifiers(value);
  3397. key && addIdentifiers(key);
  3398. index && addIdentifiers(index);
  3399. return () => {
  3400. value && removeIdentifiers(value);
  3401. key && removeIdentifiers(key);
  3402. index && removeIdentifiers(index);
  3403. };
  3404. }
  3405. }
  3406. };
  3407. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  3408. // Instead of being a DirectiveTransform, v-slot processing is called during
  3409. // transformElement to build the slots object for a component.
  3410. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  3411. context.helper(WITH_CTX);
  3412. const { children, loc } = node;
  3413. const slotsProperties = [];
  3414. const dynamicSlots = [];
  3415. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  3416. // since it likely uses a scope variable.
  3417. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  3418. // 1. Check for slot with slotProps on component itself.
  3419. // <Comp v-slot="{ prop }"/>
  3420. const onComponentSlot = findDir(node, 'slot', true);
  3421. if (onComponentSlot) {
  3422. const { arg, exp } = onComponentSlot;
  3423. if (arg && !isStaticExp(arg)) {
  3424. hasDynamicSlots = true;
  3425. }
  3426. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  3427. }
  3428. // 2. Iterate through children and check for template slots
  3429. // <template v-slot:foo="{ prop }">
  3430. let hasTemplateSlots = false;
  3431. let hasNamedDefaultSlot = false;
  3432. const implicitDefaultChildren = [];
  3433. const seenSlotNames = new Set();
  3434. for (let i = 0; i < children.length; i++) {
  3435. const slotElement = children[i];
  3436. let slotDir;
  3437. if (!isTemplateNode(slotElement) ||
  3438. !(slotDir = findDir(slotElement, 'slot', true))) {
  3439. // not a <template v-slot>, skip.
  3440. if (slotElement.type !== 3 /* COMMENT */) {
  3441. implicitDefaultChildren.push(slotElement);
  3442. }
  3443. continue;
  3444. }
  3445. if (onComponentSlot) {
  3446. // already has on-component slot - this is incorrect usage.
  3447. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  3448. break;
  3449. }
  3450. hasTemplateSlots = true;
  3451. const { children: slotChildren, loc: slotLoc } = slotElement;
  3452. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  3453. // check if name is dynamic.
  3454. let staticSlotName;
  3455. if (isStaticExp(slotName)) {
  3456. staticSlotName = slotName ? slotName.content : `default`;
  3457. }
  3458. else {
  3459. hasDynamicSlots = true;
  3460. }
  3461. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  3462. // check if this slot is conditional (v-if/v-for)
  3463. let vIf;
  3464. let vElse;
  3465. let vFor;
  3466. if ((vIf = findDir(slotElement, 'if'))) {
  3467. hasDynamicSlots = true;
  3468. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  3469. }
  3470. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  3471. // find adjacent v-if
  3472. let j = i;
  3473. let prev;
  3474. while (j--) {
  3475. prev = children[j];
  3476. if (prev.type !== 3 /* COMMENT */) {
  3477. break;
  3478. }
  3479. }
  3480. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  3481. // remove node
  3482. children.splice(i, 1);
  3483. i--;
  3484. // attach this slot to previous conditional
  3485. let conditional = dynamicSlots[dynamicSlots.length - 1];
  3486. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  3487. conditional = conditional.alternate;
  3488. }
  3489. conditional.alternate = vElse.exp
  3490. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  3491. : buildDynamicSlot(slotName, slotFunction);
  3492. }
  3493. else {
  3494. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  3495. }
  3496. }
  3497. else if ((vFor = findDir(slotElement, 'for'))) {
  3498. hasDynamicSlots = true;
  3499. const parseResult = vFor.parseResult ||
  3500. parseForExpression(vFor.exp, context);
  3501. if (parseResult) {
  3502. // Render the dynamic slots as an array and add it to the createSlot()
  3503. // args. The runtime knows how to handle it appropriately.
  3504. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  3505. parseResult.source,
  3506. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  3507. ]));
  3508. }
  3509. else {
  3510. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  3511. }
  3512. }
  3513. else {
  3514. // check duplicate static names
  3515. if (staticSlotName) {
  3516. if (seenSlotNames.has(staticSlotName)) {
  3517. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  3518. continue;
  3519. }
  3520. seenSlotNames.add(staticSlotName);
  3521. if (staticSlotName === 'default') {
  3522. hasNamedDefaultSlot = true;
  3523. }
  3524. }
  3525. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  3526. }
  3527. }
  3528. if (!onComponentSlot) {
  3529. const buildDefaultSlotProperty = (props, children) => {
  3530. const fn = buildSlotFn(props, children, loc);
  3531. if (context.compatConfig) {
  3532. fn.isNonScopedSlot = true;
  3533. }
  3534. return createObjectProperty(`default`, fn);
  3535. };
  3536. if (!hasTemplateSlots) {
  3537. // implicit default slot (on component)
  3538. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  3539. }
  3540. else if (implicitDefaultChildren.length &&
  3541. // #3766
  3542. // with whitespace: 'preserve', whitespaces between slots will end up in
  3543. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  3544. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  3545. // implicit default slot (mixed with named slots)
  3546. if (hasNamedDefaultSlot) {
  3547. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  3548. }
  3549. else {
  3550. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  3551. }
  3552. }
  3553. }
  3554. const slotFlag = hasDynamicSlots
  3555. ? 2 /* DYNAMIC */
  3556. : hasForwardedSlots(node.children)
  3557. ? 3 /* FORWARDED */
  3558. : 1 /* STABLE */;
  3559. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  3560. // 2 = compiled but dynamic = can skip normalization, but must run diff
  3561. // 1 = compiled and static = can skip normalization AND diff as optimized
  3562. createSimpleExpression(slotFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${slotFlagsText[slotFlag]} */` : ``), false))), loc);
  3563. if (dynamicSlots.length) {
  3564. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  3565. slots,
  3566. createArrayExpression(dynamicSlots)
  3567. ]);
  3568. }
  3569. return {
  3570. slots,
  3571. hasDynamicSlots
  3572. };
  3573. }
  3574. function buildDynamicSlot(name, fn) {
  3575. return createObjectExpression([
  3576. createObjectProperty(`name`, name),
  3577. createObjectProperty(`fn`, fn)
  3578. ]);
  3579. }
  3580. function hasForwardedSlots(children) {
  3581. for (let i = 0; i < children.length; i++) {
  3582. const child = children[i];
  3583. switch (child.type) {
  3584. case 1 /* ELEMENT */:
  3585. if (child.tagType === 2 /* SLOT */ ||
  3586. hasForwardedSlots(child.children)) {
  3587. return true;
  3588. }
  3589. break;
  3590. case 9 /* IF */:
  3591. if (hasForwardedSlots(child.branches))
  3592. return true;
  3593. break;
  3594. case 10 /* IF_BRANCH */:
  3595. case 11 /* FOR */:
  3596. if (hasForwardedSlots(child.children))
  3597. return true;
  3598. break;
  3599. }
  3600. }
  3601. return false;
  3602. }
  3603. function isNonWhitespaceContent(node) {
  3604. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  3605. return true;
  3606. return node.type === 2 /* TEXT */
  3607. ? !!node.content.trim()
  3608. : isNonWhitespaceContent(node.content);
  3609. }
  3610. // some directive transforms (e.g. v-model) may return a symbol for runtime
  3611. // import, which should be used instead of a resolveDirective call.
  3612. const directiveImportMap = new WeakMap();
  3613. // generate a JavaScript AST for this element's codegen
  3614. const transformElement = (node, context) => {
  3615. // perform the work on exit, after all child expressions have been
  3616. // processed and merged.
  3617. return function postTransformElement() {
  3618. node = context.currentNode;
  3619. if (!(node.type === 1 /* ELEMENT */ &&
  3620. (node.tagType === 0 /* ELEMENT */ ||
  3621. node.tagType === 1 /* COMPONENT */))) {
  3622. return;
  3623. }
  3624. const { tag, props } = node;
  3625. const isComponent = node.tagType === 1 /* COMPONENT */;
  3626. // The goal of the transform is to create a codegenNode implementing the
  3627. // VNodeCall interface.
  3628. let vnodeTag = isComponent
  3629. ? resolveComponentType(node, context)
  3630. : `"${tag}"`;
  3631. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  3632. let vnodeProps;
  3633. let vnodeChildren;
  3634. let vnodePatchFlag;
  3635. let patchFlag = 0;
  3636. let vnodeDynamicProps;
  3637. let dynamicPropNames;
  3638. let vnodeDirectives;
  3639. let shouldUseBlock =
  3640. // dynamic component may resolve to plain elements
  3641. isDynamicComponent ||
  3642. vnodeTag === TELEPORT ||
  3643. vnodeTag === SUSPENSE ||
  3644. (!isComponent &&
  3645. // <svg> and <foreignObject> must be forced into blocks so that block
  3646. // updates inside get proper isSVG flag at runtime. (#639, #643)
  3647. // This is technically web-specific, but splitting the logic out of core
  3648. // leads to too much unnecessary complexity.
  3649. (tag === 'svg' || tag === 'foreignObject'));
  3650. // props
  3651. if (props.length > 0) {
  3652. const propsBuildResult = buildProps(node, context);
  3653. vnodeProps = propsBuildResult.props;
  3654. patchFlag = propsBuildResult.patchFlag;
  3655. dynamicPropNames = propsBuildResult.dynamicPropNames;
  3656. const directives = propsBuildResult.directives;
  3657. vnodeDirectives =
  3658. directives && directives.length
  3659. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  3660. : undefined;
  3661. if (propsBuildResult.shouldUseBlock) {
  3662. shouldUseBlock = true;
  3663. }
  3664. }
  3665. // children
  3666. if (node.children.length > 0) {
  3667. if (vnodeTag === KEEP_ALIVE) {
  3668. // Although a built-in component, we compile KeepAlive with raw children
  3669. // instead of slot functions so that it can be used inside Transition
  3670. // or other Transition-wrapping HOCs.
  3671. // To ensure correct updates with block optimizations, we need to:
  3672. // 1. Force keep-alive into a block. This avoids its children being
  3673. // collected by a parent block.
  3674. shouldUseBlock = true;
  3675. // 2. Force keep-alive to always be updated, since it uses raw children.
  3676. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  3677. if ((process.env.NODE_ENV !== 'production') && node.children.length > 1) {
  3678. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  3679. start: node.children[0].loc.start,
  3680. end: node.children[node.children.length - 1].loc.end,
  3681. source: ''
  3682. }));
  3683. }
  3684. }
  3685. const shouldBuildAsSlots = isComponent &&
  3686. // Teleport is not a real component and has dedicated runtime handling
  3687. vnodeTag !== TELEPORT &&
  3688. // explained above.
  3689. vnodeTag !== KEEP_ALIVE;
  3690. if (shouldBuildAsSlots) {
  3691. const { slots, hasDynamicSlots } = buildSlots(node, context);
  3692. vnodeChildren = slots;
  3693. if (hasDynamicSlots) {
  3694. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  3695. }
  3696. }
  3697. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  3698. const child = node.children[0];
  3699. const type = child.type;
  3700. // check for dynamic text children
  3701. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  3702. type === 8 /* COMPOUND_EXPRESSION */;
  3703. if (hasDynamicTextChild &&
  3704. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  3705. patchFlag |= 1 /* TEXT */;
  3706. }
  3707. // pass directly if the only child is a text node
  3708. // (plain / interpolation / expression)
  3709. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  3710. vnodeChildren = child;
  3711. }
  3712. else {
  3713. vnodeChildren = node.children;
  3714. }
  3715. }
  3716. else {
  3717. vnodeChildren = node.children;
  3718. }
  3719. }
  3720. // patchFlag & dynamicPropNames
  3721. if (patchFlag !== 0) {
  3722. if ((process.env.NODE_ENV !== 'production')) {
  3723. if (patchFlag < 0) {
  3724. // special flags (negative and mutually exclusive)
  3725. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3726. }
  3727. else {
  3728. // bitwise flags
  3729. const flagNames = Object.keys(PatchFlagNames)
  3730. .map(Number)
  3731. .filter(n => n > 0 && patchFlag & n)
  3732. .map(n => PatchFlagNames[n])
  3733. .join(`, `);
  3734. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  3735. }
  3736. }
  3737. else {
  3738. vnodePatchFlag = String(patchFlag);
  3739. }
  3740. if (dynamicPropNames && dynamicPropNames.length) {
  3741. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  3742. }
  3743. }
  3744. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  3745. };
  3746. };
  3747. function resolveComponentType(node, context, ssr = false) {
  3748. let { tag } = node;
  3749. // 1. dynamic component
  3750. const isExplicitDynamic = isComponentTag(tag);
  3751. const isProp = findProp(node, 'is');
  3752. if (isProp) {
  3753. if (isExplicitDynamic ||
  3754. (isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))) {
  3755. const exp = isProp.type === 6 /* ATTRIBUTE */
  3756. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  3757. : isProp.exp;
  3758. if (exp) {
  3759. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3760. exp
  3761. ]);
  3762. }
  3763. }
  3764. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  3765. isProp.value.content.startsWith('vue:')) {
  3766. // <button is="vue:xxx">
  3767. // if not <component>, only is value that starts with "vue:" will be
  3768. // treated as component by the parse phase and reach here, unless it's
  3769. // compat mode where all is values are considered components
  3770. tag = isProp.value.content.slice(4);
  3771. }
  3772. }
  3773. // 1.5 v-is (TODO: Deprecate)
  3774. const isDir = !isExplicitDynamic && findDir(node, 'is');
  3775. if (isDir && isDir.exp) {
  3776. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3777. isDir.exp
  3778. ]);
  3779. }
  3780. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  3781. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  3782. if (builtIn) {
  3783. // built-ins are simply fallthroughs / have special handling during ssr
  3784. // so we don't need to import their runtime equivalents
  3785. if (!ssr)
  3786. context.helper(builtIn);
  3787. return builtIn;
  3788. }
  3789. // 5. user component (resolve)
  3790. context.helper(RESOLVE_COMPONENT);
  3791. context.components.add(tag);
  3792. return toValidAssetId(tag, `component`);
  3793. }
  3794. function buildProps(node, context, props = node.props, ssr = false) {
  3795. const { tag, loc: elementLoc, children } = node;
  3796. const isComponent = node.tagType === 1 /* COMPONENT */;
  3797. let properties = [];
  3798. const mergeArgs = [];
  3799. const runtimeDirectives = [];
  3800. const hasChildren = children.length > 0;
  3801. let shouldUseBlock = false;
  3802. // patchFlag analysis
  3803. let patchFlag = 0;
  3804. let hasRef = false;
  3805. let hasClassBinding = false;
  3806. let hasStyleBinding = false;
  3807. let hasHydrationEventBinding = false;
  3808. let hasDynamicKeys = false;
  3809. let hasVnodeHook = false;
  3810. const dynamicPropNames = [];
  3811. const analyzePatchFlag = ({ key, value }) => {
  3812. if (isStaticExp(key)) {
  3813. const name = key.content;
  3814. const isEventHandler = isOn(name);
  3815. if (!isComponent &&
  3816. isEventHandler &&
  3817. // omit the flag for click handlers because hydration gives click
  3818. // dedicated fast path.
  3819. name.toLowerCase() !== 'onclick' &&
  3820. // omit v-model handlers
  3821. name !== 'onUpdate:modelValue' &&
  3822. // omit onVnodeXXX hooks
  3823. !isReservedProp(name)) {
  3824. hasHydrationEventBinding = true;
  3825. }
  3826. if (isEventHandler && isReservedProp(name)) {
  3827. hasVnodeHook = true;
  3828. }
  3829. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  3830. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  3831. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  3832. getConstantType(value, context) > 0)) {
  3833. // skip if the prop is a cached handler or has constant value
  3834. return;
  3835. }
  3836. if (name === 'ref') {
  3837. hasRef = true;
  3838. }
  3839. else if (name === 'class') {
  3840. hasClassBinding = true;
  3841. }
  3842. else if (name === 'style') {
  3843. hasStyleBinding = true;
  3844. }
  3845. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  3846. dynamicPropNames.push(name);
  3847. }
  3848. // treat the dynamic class and style binding of the component as dynamic props
  3849. if (isComponent &&
  3850. (name === 'class' || name === 'style') &&
  3851. !dynamicPropNames.includes(name)) {
  3852. dynamicPropNames.push(name);
  3853. }
  3854. }
  3855. else {
  3856. hasDynamicKeys = true;
  3857. }
  3858. };
  3859. for (let i = 0; i < props.length; i++) {
  3860. // static attribute
  3861. const prop = props[i];
  3862. if (prop.type === 6 /* ATTRIBUTE */) {
  3863. const { loc, name, value } = prop;
  3864. let isStatic = true;
  3865. if (name === 'ref') {
  3866. hasRef = true;
  3867. if (context.scopes.vFor > 0) {
  3868. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  3869. }
  3870. }
  3871. // skip is on <component>, or is="vue:xxx"
  3872. if (name === 'is' &&
  3873. (isComponentTag(tag) ||
  3874. (value && value.content.startsWith('vue:')) ||
  3875. (isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
  3876. continue;
  3877. }
  3878. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  3879. }
  3880. else {
  3881. // directives
  3882. const { name, arg, exp, loc } = prop;
  3883. const isVBind = name === 'bind';
  3884. const isVOn = name === 'on';
  3885. // skip v-slot - it is handled by its dedicated transform.
  3886. if (name === 'slot') {
  3887. if (!isComponent) {
  3888. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  3889. }
  3890. continue;
  3891. }
  3892. // skip v-once/v-memo - they are handled by dedicated transforms.
  3893. if (name === 'once' || name === 'memo') {
  3894. continue;
  3895. }
  3896. // skip v-is and :is on <component>
  3897. if (name === 'is' ||
  3898. (isVBind &&
  3899. isStaticArgOf(arg, 'is') &&
  3900. (isComponentTag(tag) ||
  3901. (isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))))) {
  3902. continue;
  3903. }
  3904. // skip v-on in SSR compilation
  3905. if (isVOn && ssr) {
  3906. continue;
  3907. }
  3908. if (
  3909. // #938: elements with dynamic keys should be forced into blocks
  3910. (isVBind && isStaticArgOf(arg, 'key')) ||
  3911. // inline before-update hooks need to force block so that it is invoked
  3912. // before children
  3913. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  3914. shouldUseBlock = true;
  3915. }
  3916. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  3917. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  3918. }
  3919. // special case for v-bind and v-on with no argument
  3920. if (!arg && (isVBind || isVOn)) {
  3921. hasDynamicKeys = true;
  3922. if (exp) {
  3923. if (properties.length) {
  3924. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  3925. properties = [];
  3926. }
  3927. if (isVBind) {
  3928. {
  3929. // 2.x v-bind object order compat
  3930. if ((process.env.NODE_ENV !== 'production')) {
  3931. const hasOverridableKeys = mergeArgs.some(arg => {
  3932. if (arg.type === 15 /* JS_OBJECT_EXPRESSION */) {
  3933. return arg.properties.some(({ key }) => {
  3934. if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||
  3935. !key.isStatic) {
  3936. return true;
  3937. }
  3938. return (key.content !== 'class' &&
  3939. key.content !== 'style' &&
  3940. !isOn(key.content));
  3941. });
  3942. }
  3943. else {
  3944. // dynamic expression
  3945. return true;
  3946. }
  3947. });
  3948. if (hasOverridableKeys) {
  3949. checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context, loc);
  3950. }
  3951. }
  3952. if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context)) {
  3953. mergeArgs.unshift(exp);
  3954. continue;
  3955. }
  3956. }
  3957. mergeArgs.push(exp);
  3958. }
  3959. else {
  3960. // v-on="obj" -> toHandlers(obj)
  3961. mergeArgs.push({
  3962. type: 14 /* JS_CALL_EXPRESSION */,
  3963. loc,
  3964. callee: context.helper(TO_HANDLERS),
  3965. arguments: [exp]
  3966. });
  3967. }
  3968. }
  3969. else {
  3970. context.onError(createCompilerError(isVBind
  3971. ? 34 /* X_V_BIND_NO_EXPRESSION */
  3972. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  3973. }
  3974. continue;
  3975. }
  3976. const directiveTransform = context.directiveTransforms[name];
  3977. if (directiveTransform) {
  3978. // has built-in directive transform.
  3979. const { props, needRuntime } = directiveTransform(prop, node, context);
  3980. !ssr && props.forEach(analyzePatchFlag);
  3981. properties.push(...props);
  3982. if (needRuntime) {
  3983. runtimeDirectives.push(prop);
  3984. if (isSymbol(needRuntime)) {
  3985. directiveImportMap.set(prop, needRuntime);
  3986. }
  3987. }
  3988. }
  3989. else if (!isBuiltInDirective(name)) {
  3990. // no built-in transform, this is a user custom directive.
  3991. runtimeDirectives.push(prop);
  3992. // custom dirs may use beforeUpdate so they need to force blocks
  3993. // to ensure before-update gets called before children update
  3994. if (hasChildren) {
  3995. shouldUseBlock = true;
  3996. }
  3997. }
  3998. }
  3999. }
  4000. let propsExpression = undefined;
  4001. // has v-bind="object" or v-on="object", wrap with mergeProps
  4002. if (mergeArgs.length) {
  4003. if (properties.length) {
  4004. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  4005. }
  4006. if (mergeArgs.length > 1) {
  4007. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  4008. }
  4009. else {
  4010. // single v-bind with nothing else - no need for a mergeProps call
  4011. propsExpression = mergeArgs[0];
  4012. }
  4013. }
  4014. else if (properties.length) {
  4015. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  4016. }
  4017. // patchFlag analysis
  4018. if (hasDynamicKeys) {
  4019. patchFlag |= 16 /* FULL_PROPS */;
  4020. }
  4021. else {
  4022. if (hasClassBinding && !isComponent) {
  4023. patchFlag |= 2 /* CLASS */;
  4024. }
  4025. if (hasStyleBinding && !isComponent) {
  4026. patchFlag |= 4 /* STYLE */;
  4027. }
  4028. if (dynamicPropNames.length) {
  4029. patchFlag |= 8 /* PROPS */;
  4030. }
  4031. if (hasHydrationEventBinding) {
  4032. patchFlag |= 32 /* HYDRATE_EVENTS */;
  4033. }
  4034. }
  4035. if (!shouldUseBlock &&
  4036. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  4037. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  4038. patchFlag |= 512 /* NEED_PATCH */;
  4039. }
  4040. // pre-normalize props, SSR is skipped for now
  4041. if (!context.inSSR && propsExpression) {
  4042. switch (propsExpression.type) {
  4043. case 15 /* JS_OBJECT_EXPRESSION */:
  4044. // means that there is no v-bind,
  4045. // but still need to deal with dynamic key binding
  4046. let classKeyIndex = -1;
  4047. let styleKeyIndex = -1;
  4048. let hasDynamicKey = false;
  4049. for (let i = 0; i < propsExpression.properties.length; i++) {
  4050. const key = propsExpression.properties[i].key;
  4051. if (isStaticExp(key)) {
  4052. if (key.content === 'class') {
  4053. classKeyIndex = i;
  4054. }
  4055. else if (key.content === 'style') {
  4056. styleKeyIndex = i;
  4057. }
  4058. }
  4059. else if (!key.isHandlerKey) {
  4060. hasDynamicKey = true;
  4061. }
  4062. }
  4063. const classProp = propsExpression.properties[classKeyIndex];
  4064. const styleProp = propsExpression.properties[styleKeyIndex];
  4065. // no dynamic key
  4066. if (!hasDynamicKey) {
  4067. if (classProp && !isStaticExp(classProp.value)) {
  4068. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  4069. }
  4070. if (styleProp &&
  4071. !isStaticExp(styleProp.value) &&
  4072. // the static style is compiled into an object,
  4073. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  4074. (hasStyleBinding ||
  4075. // v-bind:style and style both exist,
  4076. // v-bind:style with static literal object
  4077. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  4078. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  4079. }
  4080. }
  4081. else {
  4082. // dynamic key binding, wrap with `normalizeProps`
  4083. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  4084. }
  4085. break;
  4086. case 14 /* JS_CALL_EXPRESSION */:
  4087. // mergeProps call, do nothing
  4088. break;
  4089. default:
  4090. // single v-bind
  4091. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  4092. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  4093. propsExpression
  4094. ])
  4095. ]);
  4096. break;
  4097. }
  4098. }
  4099. return {
  4100. props: propsExpression,
  4101. directives: runtimeDirectives,
  4102. patchFlag,
  4103. dynamicPropNames,
  4104. shouldUseBlock
  4105. };
  4106. }
  4107. // Dedupe props in an object literal.
  4108. // Literal duplicated attributes would have been warned during the parse phase,
  4109. // however, it's possible to encounter duplicated `onXXX` handlers with different
  4110. // modifiers. We also need to merge static and dynamic class / style attributes.
  4111. // - onXXX handlers / style: merge into array
  4112. // - class: merge into single expression with concatenation
  4113. function dedupeProperties(properties) {
  4114. const knownProps = new Map();
  4115. const deduped = [];
  4116. for (let i = 0; i < properties.length; i++) {
  4117. const prop = properties[i];
  4118. // dynamic keys are always allowed
  4119. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  4120. deduped.push(prop);
  4121. continue;
  4122. }
  4123. const name = prop.key.content;
  4124. const existing = knownProps.get(name);
  4125. if (existing) {
  4126. if (name === 'style' || name === 'class' || isOn(name)) {
  4127. mergeAsArray(existing, prop);
  4128. }
  4129. // unexpected duplicate, should have emitted error during parse
  4130. }
  4131. else {
  4132. knownProps.set(name, prop);
  4133. deduped.push(prop);
  4134. }
  4135. }
  4136. return deduped;
  4137. }
  4138. function mergeAsArray(existing, incoming) {
  4139. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  4140. existing.value.elements.push(incoming.value);
  4141. }
  4142. else {
  4143. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  4144. }
  4145. }
  4146. function buildDirectiveArgs(dir, context) {
  4147. const dirArgs = [];
  4148. const runtime = directiveImportMap.get(dir);
  4149. if (runtime) {
  4150. // built-in directive with runtime
  4151. dirArgs.push(context.helperString(runtime));
  4152. }
  4153. else {
  4154. {
  4155. // inject statement for resolving directive
  4156. context.helper(RESOLVE_DIRECTIVE);
  4157. context.directives.add(dir.name);
  4158. dirArgs.push(toValidAssetId(dir.name, `directive`));
  4159. }
  4160. }
  4161. const { loc } = dir;
  4162. if (dir.exp)
  4163. dirArgs.push(dir.exp);
  4164. if (dir.arg) {
  4165. if (!dir.exp) {
  4166. dirArgs.push(`void 0`);
  4167. }
  4168. dirArgs.push(dir.arg);
  4169. }
  4170. if (Object.keys(dir.modifiers).length) {
  4171. if (!dir.arg) {
  4172. if (!dir.exp) {
  4173. dirArgs.push(`void 0`);
  4174. }
  4175. dirArgs.push(`void 0`);
  4176. }
  4177. const trueExpression = createSimpleExpression(`true`, false, loc);
  4178. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  4179. }
  4180. return createArrayExpression(dirArgs, dir.loc);
  4181. }
  4182. function stringifyDynamicPropNames(props) {
  4183. let propsNamesString = `[`;
  4184. for (let i = 0, l = props.length; i < l; i++) {
  4185. propsNamesString += JSON.stringify(props[i]);
  4186. if (i < l - 1)
  4187. propsNamesString += ', ';
  4188. }
  4189. return propsNamesString + `]`;
  4190. }
  4191. function isComponentTag(tag) {
  4192. return tag === 'component' || tag === 'Component';
  4193. }
  4194. (process.env.NODE_ENV !== 'production')
  4195. ? Object.freeze({})
  4196. : {};
  4197. (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
  4198. const cacheStringFunction = (fn) => {
  4199. const cache = Object.create(null);
  4200. return ((str) => {
  4201. const hit = cache[str];
  4202. return hit || (cache[str] = fn(str));
  4203. });
  4204. };
  4205. const camelizeRE = /-(\w)/g;
  4206. /**
  4207. * @private
  4208. */
  4209. const camelize = cacheStringFunction((str) => {
  4210. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  4211. });
  4212. const transformSlotOutlet = (node, context) => {
  4213. if (isSlotOutlet(node)) {
  4214. const { children, loc } = node;
  4215. const { slotName, slotProps } = processSlotOutlet(node, context);
  4216. const slotArgs = [
  4217. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  4218. slotName,
  4219. '{}',
  4220. 'undefined',
  4221. 'true'
  4222. ];
  4223. let expectedLen = 2;
  4224. if (slotProps) {
  4225. slotArgs[2] = slotProps;
  4226. expectedLen = 3;
  4227. }
  4228. if (children.length) {
  4229. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  4230. expectedLen = 4;
  4231. }
  4232. if (context.scopeId && !context.slotted) {
  4233. expectedLen = 5;
  4234. }
  4235. slotArgs.splice(expectedLen); // remove unused arguments
  4236. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  4237. }
  4238. };
  4239. function processSlotOutlet(node, context) {
  4240. let slotName = `"default"`;
  4241. let slotProps = undefined;
  4242. const nonNameProps = [];
  4243. for (let i = 0; i < node.props.length; i++) {
  4244. const p = node.props[i];
  4245. if (p.type === 6 /* ATTRIBUTE */) {
  4246. if (p.value) {
  4247. if (p.name === 'name') {
  4248. slotName = JSON.stringify(p.value.content);
  4249. }
  4250. else {
  4251. p.name = camelize(p.name);
  4252. nonNameProps.push(p);
  4253. }
  4254. }
  4255. }
  4256. else {
  4257. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  4258. if (p.exp)
  4259. slotName = p.exp;
  4260. }
  4261. else {
  4262. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  4263. p.arg.content = camelize(p.arg.content);
  4264. }
  4265. nonNameProps.push(p);
  4266. }
  4267. }
  4268. }
  4269. if (nonNameProps.length > 0) {
  4270. const { props, directives } = buildProps(node, context, nonNameProps);
  4271. slotProps = props;
  4272. if (directives.length) {
  4273. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  4274. }
  4275. }
  4276. return {
  4277. slotName,
  4278. slotProps
  4279. };
  4280. }
  4281. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  4282. const transformOn = (dir, node, context, augmentor) => {
  4283. const { loc, modifiers, arg } = dir;
  4284. if (!dir.exp && !modifiers.length) {
  4285. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  4286. }
  4287. let eventName;
  4288. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  4289. if (arg.isStatic) {
  4290. let rawName = arg.content;
  4291. // TODO deprecate @vnodeXXX usage
  4292. if (rawName.startsWith('vue:')) {
  4293. rawName = `vnode-${rawName.slice(4)}`;
  4294. }
  4295. // for all event listeners, auto convert it to camelCase. See issue #2249
  4296. eventName = createSimpleExpression(toHandlerKey(camelize$1(rawName)), true, arg.loc);
  4297. }
  4298. else {
  4299. // #2388
  4300. eventName = createCompoundExpression([
  4301. `${context.helperString(TO_HANDLER_KEY)}(`,
  4302. arg,
  4303. `)`
  4304. ]);
  4305. }
  4306. }
  4307. else {
  4308. // already a compound expression.
  4309. eventName = arg;
  4310. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  4311. eventName.children.push(`)`);
  4312. }
  4313. // handler processing
  4314. let exp = dir.exp;
  4315. if (exp && !exp.content.trim()) {
  4316. exp = undefined;
  4317. }
  4318. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  4319. if (exp) {
  4320. const isMemberExp = isMemberExpression(exp.content);
  4321. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  4322. const hasMultipleStatements = exp.content.includes(`;`);
  4323. if ((process.env.NODE_ENV !== 'production') && true) {
  4324. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  4325. }
  4326. if (isInlineStatement || (shouldCache && isMemberExp)) {
  4327. // wrap inline statement in a function expression
  4328. exp = createCompoundExpression([
  4329. `${isInlineStatement
  4330. ? `$event`
  4331. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  4332. exp,
  4333. hasMultipleStatements ? `}` : `)`
  4334. ]);
  4335. }
  4336. }
  4337. let ret = {
  4338. props: [
  4339. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  4340. ]
  4341. };
  4342. // apply extended compiler augmentor
  4343. if (augmentor) {
  4344. ret = augmentor(ret);
  4345. }
  4346. if (shouldCache) {
  4347. // cache handlers so that it's always the same handler being passed down.
  4348. // this avoids unnecessary re-renders when users use inline handlers on
  4349. // components.
  4350. ret.props[0].value = context.cache(ret.props[0].value);
  4351. }
  4352. // mark the key as handler for props normalization check
  4353. ret.props.forEach(p => (p.key.isHandlerKey = true));
  4354. return ret;
  4355. };
  4356. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  4357. // codegen for the entire props object. This transform here is only for v-bind
  4358. // *with* args.
  4359. const transformBind = (dir, _node, context) => {
  4360. const { exp, modifiers, loc } = dir;
  4361. const arg = dir.arg;
  4362. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  4363. arg.children.unshift(`(`);
  4364. arg.children.push(`) || ""`);
  4365. }
  4366. else if (!arg.isStatic) {
  4367. arg.content = `${arg.content} || ""`;
  4368. }
  4369. // .sync is replaced by v-model:arg
  4370. if (modifiers.includes('camel')) {
  4371. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  4372. if (arg.isStatic) {
  4373. arg.content = camelize$1(arg.content);
  4374. }
  4375. else {
  4376. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4377. }
  4378. }
  4379. else {
  4380. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4381. arg.children.push(`)`);
  4382. }
  4383. }
  4384. if (!context.inSSR) {
  4385. if (modifiers.includes('prop')) {
  4386. injectPrefix(arg, '.');
  4387. }
  4388. if (modifiers.includes('attr')) {
  4389. injectPrefix(arg, '^');
  4390. }
  4391. }
  4392. if (!exp ||
  4393. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  4394. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  4395. return {
  4396. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  4397. };
  4398. }
  4399. return {
  4400. props: [createObjectProperty(arg, exp)]
  4401. };
  4402. };
  4403. const injectPrefix = (arg, prefix) => {
  4404. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  4405. if (arg.isStatic) {
  4406. arg.content = prefix + arg.content;
  4407. }
  4408. else {
  4409. arg.content = `\`${prefix}\${${arg.content}}\``;
  4410. }
  4411. }
  4412. else {
  4413. arg.children.unshift(`'${prefix}' + (`);
  4414. arg.children.push(`)`);
  4415. }
  4416. };
  4417. // Merge adjacent text nodes and expressions into a single expression
  4418. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  4419. const transformText = (node, context) => {
  4420. if (node.type === 0 /* ROOT */ ||
  4421. node.type === 1 /* ELEMENT */ ||
  4422. node.type === 11 /* FOR */ ||
  4423. node.type === 10 /* IF_BRANCH */) {
  4424. // perform the transform on node exit so that all expressions have already
  4425. // been processed.
  4426. return () => {
  4427. const children = node.children;
  4428. let currentContainer = undefined;
  4429. let hasText = false;
  4430. for (let i = 0; i < children.length; i++) {
  4431. const child = children[i];
  4432. if (isText(child)) {
  4433. hasText = true;
  4434. for (let j = i + 1; j < children.length; j++) {
  4435. const next = children[j];
  4436. if (isText(next)) {
  4437. if (!currentContainer) {
  4438. currentContainer = children[i] = {
  4439. type: 8 /* COMPOUND_EXPRESSION */,
  4440. loc: child.loc,
  4441. children: [child]
  4442. };
  4443. }
  4444. // merge adjacent text node into current
  4445. currentContainer.children.push(` + `, next);
  4446. children.splice(j, 1);
  4447. j--;
  4448. }
  4449. else {
  4450. currentContainer = undefined;
  4451. break;
  4452. }
  4453. }
  4454. }
  4455. }
  4456. if (!hasText ||
  4457. // 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 &&
  4462. (node.type === 0 /* ROOT */ ||
  4463. (node.type === 1 /* ELEMENT */ &&
  4464. node.tagType === 0 /* ELEMENT */ &&
  4465. // #3756
  4466. // custom directives can potentially add DOM elements arbitrarily,
  4467. // we need to avoid setting textContent of the element at runtime
  4468. // to avoid accidentally overwriting the DOM elements added
  4469. // by the user through custom directives.
  4470. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  4471. !context.directiveTransforms[p.name]) &&
  4472. // in compat mode, <template> tags with no special directives
  4473. // will be rendered as a fragment so its children must be
  4474. // converted into vnodes.
  4475. !(node.tag === 'template'))))) {
  4476. return;
  4477. }
  4478. // pre-convert text nodes into createTextVNode(text) calls to avoid
  4479. // runtime normalization.
  4480. for (let i = 0; i < children.length; i++) {
  4481. const child = children[i];
  4482. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  4483. const callArgs = [];
  4484. // createTextVNode defaults to single whitespace, so if it is a
  4485. // single space the code could be an empty call to save bytes.
  4486. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  4487. callArgs.push(child);
  4488. }
  4489. // mark dynamic text with flag so it gets patched inside a block
  4490. if (!context.ssr &&
  4491. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  4492. callArgs.push(1 /* TEXT */ +
  4493. ((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[1 /* TEXT */]} */` : ``));
  4494. }
  4495. children[i] = {
  4496. type: 12 /* TEXT_CALL */,
  4497. content: child,
  4498. loc: child.loc,
  4499. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  4500. };
  4501. }
  4502. }
  4503. };
  4504. }
  4505. };
  4506. const seen = new WeakSet();
  4507. const transformOnce = (node, context) => {
  4508. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  4509. if (seen.has(node) || context.inVOnce) {
  4510. return;
  4511. }
  4512. seen.add(node);
  4513. context.inVOnce = true;
  4514. context.helper(SET_BLOCK_TRACKING);
  4515. return () => {
  4516. context.inVOnce = false;
  4517. const cur = context.currentNode;
  4518. if (cur.codegenNode) {
  4519. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  4520. }
  4521. };
  4522. }
  4523. };
  4524. const transformModel = (dir, node, context) => {
  4525. const { exp, arg } = dir;
  4526. if (!exp) {
  4527. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  4528. return createTransformProps();
  4529. }
  4530. const rawExp = exp.loc.source;
  4531. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  4532. // im SFC <script setup> inline mode, the exp may have been transformed into
  4533. // _unref(exp)
  4534. context.bindingMetadata[rawExp];
  4535. const maybeRef = !true /* SETUP_CONST */;
  4536. if (!expString.trim() ||
  4537. (!isMemberExpression(expString) && !maybeRef)) {
  4538. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  4539. return createTransformProps();
  4540. }
  4541. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  4542. const eventName = arg
  4543. ? isStaticExp(arg)
  4544. ? `onUpdate:${arg.content}`
  4545. : createCompoundExpression(['"onUpdate:" + ', arg])
  4546. : `onUpdate:modelValue`;
  4547. let assignmentExp;
  4548. const eventArg = context.isTS ? `($event: any)` : `$event`;
  4549. {
  4550. assignmentExp = createCompoundExpression([
  4551. `${eventArg} => ((`,
  4552. exp,
  4553. `) = $event)`
  4554. ]);
  4555. }
  4556. const props = [
  4557. // modelValue: foo
  4558. createObjectProperty(propName, dir.exp),
  4559. // "onUpdate:modelValue": $event => (foo = $event)
  4560. createObjectProperty(eventName, assignmentExp)
  4561. ];
  4562. // modelModifiers: { foo: true, "bar-baz": true }
  4563. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  4564. const modifiers = dir.modifiers
  4565. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  4566. .join(`, `);
  4567. const modifiersKey = arg
  4568. ? isStaticExp(arg)
  4569. ? `${arg.content}Modifiers`
  4570. : createCompoundExpression([arg, ' + "Modifiers"'])
  4571. : `modelModifiers`;
  4572. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  4573. }
  4574. return createTransformProps(props);
  4575. };
  4576. function createTransformProps(props = []) {
  4577. return { props };
  4578. }
  4579. const validDivisionCharRE = /[\w).+\-_$\]]/;
  4580. const transformFilter = (node, context) => {
  4581. if (!isCompatEnabled("COMPILER_FILTER" /* COMPILER_FILTERS */, context)) {
  4582. return;
  4583. }
  4584. if (node.type === 5 /* INTERPOLATION */) {
  4585. // filter rewrite is applied before expression transform so only
  4586. // simple expressions are possible at this stage
  4587. rewriteFilter(node.content, context);
  4588. }
  4589. if (node.type === 1 /* ELEMENT */) {
  4590. node.props.forEach((prop) => {
  4591. if (prop.type === 7 /* DIRECTIVE */ &&
  4592. prop.name !== 'for' &&
  4593. prop.exp) {
  4594. rewriteFilter(prop.exp, context);
  4595. }
  4596. });
  4597. }
  4598. };
  4599. function rewriteFilter(node, context) {
  4600. if (node.type === 4 /* SIMPLE_EXPRESSION */) {
  4601. parseFilter(node, context);
  4602. }
  4603. else {
  4604. for (let i = 0; i < node.children.length; i++) {
  4605. const child = node.children[i];
  4606. if (typeof child !== 'object')
  4607. continue;
  4608. if (child.type === 4 /* SIMPLE_EXPRESSION */) {
  4609. parseFilter(child, context);
  4610. }
  4611. else if (child.type === 8 /* COMPOUND_EXPRESSION */) {
  4612. rewriteFilter(node, context);
  4613. }
  4614. else if (child.type === 5 /* INTERPOLATION */) {
  4615. rewriteFilter(child.content, context);
  4616. }
  4617. }
  4618. }
  4619. }
  4620. function parseFilter(node, context) {
  4621. const exp = node.content;
  4622. let inSingle = false;
  4623. let inDouble = false;
  4624. let inTemplateString = false;
  4625. let inRegex = false;
  4626. let curly = 0;
  4627. let square = 0;
  4628. let paren = 0;
  4629. let lastFilterIndex = 0;
  4630. let c, prev, i, expression, filters = [];
  4631. for (i = 0; i < exp.length; i++) {
  4632. prev = c;
  4633. c = exp.charCodeAt(i);
  4634. if (inSingle) {
  4635. if (c === 0x27 && prev !== 0x5c)
  4636. inSingle = false;
  4637. }
  4638. else if (inDouble) {
  4639. if (c === 0x22 && prev !== 0x5c)
  4640. inDouble = false;
  4641. }
  4642. else if (inTemplateString) {
  4643. if (c === 0x60 && prev !== 0x5c)
  4644. inTemplateString = false;
  4645. }
  4646. else if (inRegex) {
  4647. if (c === 0x2f && prev !== 0x5c)
  4648. inRegex = false;
  4649. }
  4650. else if (c === 0x7c && // pipe
  4651. exp.charCodeAt(i + 1) !== 0x7c &&
  4652. exp.charCodeAt(i - 1) !== 0x7c &&
  4653. !curly &&
  4654. !square &&
  4655. !paren) {
  4656. if (expression === undefined) {
  4657. // first filter, end of expression
  4658. lastFilterIndex = i + 1;
  4659. expression = exp.slice(0, i).trim();
  4660. }
  4661. else {
  4662. pushFilter();
  4663. }
  4664. }
  4665. else {
  4666. switch (c) {
  4667. case 0x22:
  4668. inDouble = true;
  4669. break; // "
  4670. case 0x27:
  4671. inSingle = true;
  4672. break; // '
  4673. case 0x60:
  4674. inTemplateString = true;
  4675. break; // `
  4676. case 0x28:
  4677. paren++;
  4678. break; // (
  4679. case 0x29:
  4680. paren--;
  4681. break; // )
  4682. case 0x5b:
  4683. square++;
  4684. break; // [
  4685. case 0x5d:
  4686. square--;
  4687. break; // ]
  4688. case 0x7b:
  4689. curly++;
  4690. break; // {
  4691. case 0x7d:
  4692. curly--;
  4693. break; // }
  4694. }
  4695. if (c === 0x2f) {
  4696. // /
  4697. let j = i - 1;
  4698. let p;
  4699. // find first non-whitespace prev char
  4700. for (; j >= 0; j--) {
  4701. p = exp.charAt(j);
  4702. if (p !== ' ')
  4703. break;
  4704. }
  4705. if (!p || !validDivisionCharRE.test(p)) {
  4706. inRegex = true;
  4707. }
  4708. }
  4709. }
  4710. }
  4711. if (expression === undefined) {
  4712. expression = exp.slice(0, i).trim();
  4713. }
  4714. else if (lastFilterIndex !== 0) {
  4715. pushFilter();
  4716. }
  4717. function pushFilter() {
  4718. filters.push(exp.slice(lastFilterIndex, i).trim());
  4719. lastFilterIndex = i + 1;
  4720. }
  4721. if (filters.length) {
  4722. (process.env.NODE_ENV !== 'production') &&
  4723. warnDeprecation("COMPILER_FILTER" /* COMPILER_FILTERS */, context, node.loc);
  4724. for (i = 0; i < filters.length; i++) {
  4725. expression = wrapFilter(expression, filters[i], context);
  4726. }
  4727. node.content = expression;
  4728. }
  4729. }
  4730. function wrapFilter(exp, filter, context) {
  4731. context.helper(RESOLVE_FILTER);
  4732. const i = filter.indexOf('(');
  4733. if (i < 0) {
  4734. context.filters.add(filter);
  4735. return `${toValidAssetId(filter, 'filter')}(${exp})`;
  4736. }
  4737. else {
  4738. const name = filter.slice(0, i);
  4739. const args = filter.slice(i + 1);
  4740. context.filters.add(name);
  4741. return `${toValidAssetId(name, 'filter')}(${exp}${args !== ')' ? ',' + args : args}`;
  4742. }
  4743. }
  4744. const seen$1 = new WeakSet();
  4745. const transformMemo = (node, context) => {
  4746. if (node.type === 1 /* ELEMENT */) {
  4747. const dir = findDir(node, 'memo');
  4748. if (!dir || seen$1.has(node)) {
  4749. return;
  4750. }
  4751. seen$1.add(node);
  4752. return () => {
  4753. const codegenNode = node.codegenNode ||
  4754. context.currentNode.codegenNode;
  4755. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  4756. // non-component sub tree should be turned into a block
  4757. if (node.tagType !== 1 /* COMPONENT */) {
  4758. makeBlock(codegenNode, context);
  4759. }
  4760. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  4761. dir.exp,
  4762. createFunctionExpression(undefined, codegenNode),
  4763. `_cache`,
  4764. String(context.cached++)
  4765. ]);
  4766. }
  4767. };
  4768. }
  4769. };
  4770. function getBaseTransformPreset(prefixIdentifiers) {
  4771. return [
  4772. [
  4773. transformOnce,
  4774. transformIf,
  4775. transformMemo,
  4776. transformFor,
  4777. ...([transformFilter] ),
  4778. ...((process.env.NODE_ENV !== 'production')
  4779. ? [transformExpression]
  4780. : []),
  4781. transformSlotOutlet,
  4782. transformElement,
  4783. trackSlotScopes,
  4784. transformText
  4785. ],
  4786. {
  4787. on: transformOn,
  4788. bind: transformBind,
  4789. model: transformModel
  4790. }
  4791. ];
  4792. }
  4793. // we name it `baseCompile` so that higher order compilers like
  4794. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  4795. function baseCompile(template, options = {}) {
  4796. const onError = options.onError || defaultOnError;
  4797. const isModuleMode = options.mode === 'module';
  4798. /* istanbul ignore if */
  4799. {
  4800. if (options.prefixIdentifiers === true) {
  4801. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  4802. }
  4803. else if (isModuleMode) {
  4804. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  4805. }
  4806. }
  4807. const prefixIdentifiers = !true ;
  4808. if (options.cacheHandlers) {
  4809. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  4810. }
  4811. if (options.scopeId && !isModuleMode) {
  4812. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  4813. }
  4814. const ast = isString(template) ? baseParse(template, options) : template;
  4815. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  4816. transform(ast, extend({}, options, {
  4817. prefixIdentifiers,
  4818. nodeTransforms: [
  4819. ...nodeTransforms,
  4820. ...(options.nodeTransforms || []) // user transforms
  4821. ],
  4822. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  4823. )
  4824. }));
  4825. return generate(ast, extend({}, options, {
  4826. prefixIdentifiers
  4827. }));
  4828. }
  4829. const noopDirectiveTransform = () => ({ props: [] });
  4830. export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, extractIdentifiers, findDir, findProp, generate, getBaseTransformPreset, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText, isVSlot, locStub, makeBlock, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };