@vue/compiler-core 3.5.0-alpha.2 → 3.5.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-core v3.5.0-alpha.2
2
+ * @vue/compiler-core v3.5.0-alpha.4
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -180,8 +180,8 @@ const ConstantTypes = {
180
180
  "0": "NOT_CONSTANT",
181
181
  "CAN_SKIP_PATCH": 1,
182
182
  "1": "CAN_SKIP_PATCH",
183
- "CAN_HOIST": 2,
184
- "2": "CAN_HOIST",
183
+ "CAN_CACHE": 2,
184
+ "2": "CAN_CACHE",
185
185
  "CAN_STRINGIFY": 3,
186
186
  "3": "CAN_STRINGIFY"
187
187
  };
@@ -200,7 +200,7 @@ function createRoot(children, source = "") {
200
200
  directives: [],
201
201
  hoists: [],
202
202
  imports: [],
203
- cached: 0,
203
+ cached: [],
204
204
  temps: 0,
205
205
  codegenNode: void 0,
206
206
  loc: locStub
@@ -305,12 +305,13 @@ function createConditionalExpression(test, consequent, alternate, newline = true
305
305
  loc: locStub
306
306
  };
307
307
  }
308
- function createCacheExpression(index, value, isVNode = false) {
308
+ function createCacheExpression(index, value, needPauseTracking = false) {
309
309
  return {
310
310
  type: 20,
311
311
  index,
312
312
  value,
313
- isVNode,
313
+ needPauseTracking,
314
+ needArraySpread: false,
314
315
  loc: locStub
315
316
  };
316
317
  }
@@ -1310,8 +1311,7 @@ function warnDeprecation(key, context, loc, ...args) {
1310
1311
  Details: ${link}` : ``}`;
1311
1312
  const err = new SyntaxError(msg);
1312
1313
  err.code = key;
1313
- if (loc)
1314
- err.loc = loc;
1314
+ if (loc) err.loc = loc;
1315
1315
  context.onWarn(err);
1316
1316
  }
1317
1317
 
@@ -1514,7 +1514,8 @@ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [
1514
1514
  if (includeAll || isRefed && !isLocal) {
1515
1515
  onIdentifier(node, parent, parentStack, isRefed, isLocal);
1516
1516
  }
1517
- } else if (node.type === "ObjectProperty" && (parent == null ? void 0 : parent.type) === "ObjectPattern") {
1517
+ } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
1518
+ (parent == null ? void 0 : parent.type) === "ObjectPattern") {
1518
1519
  node.inPattern = true;
1519
1520
  } else if (isFunctionType(node)) {
1520
1521
  if (node.scopeIds) {
@@ -1605,16 +1606,14 @@ function walkFunctionParams(node, onIdent) {
1605
1606
  function walkBlockDeclarations(block, onIdent) {
1606
1607
  for (const stmt of block.body) {
1607
1608
  if (stmt.type === "VariableDeclaration") {
1608
- if (stmt.declare)
1609
- continue;
1609
+ if (stmt.declare) continue;
1610
1610
  for (const decl of stmt.declarations) {
1611
1611
  for (const id of extractIdentifiers(decl.id)) {
1612
1612
  onIdent(id);
1613
1613
  }
1614
1614
  }
1615
1615
  } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1616
- if (stmt.declare || !stmt.id)
1617
- continue;
1616
+ if (stmt.declare || !stmt.id) continue;
1618
1617
  onIdent(stmt.id);
1619
1618
  } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
1620
1619
  const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
@@ -1651,8 +1650,7 @@ function extractIdentifiers(param, nodes = []) {
1651
1650
  break;
1652
1651
  case "ArrayPattern":
1653
1652
  param.elements.forEach((element) => {
1654
- if (element)
1655
- extractIdentifiers(element, nodes);
1653
+ if (element) extractIdentifiers(element, nodes);
1656
1654
  });
1657
1655
  break;
1658
1656
  case "RestElement":
@@ -1805,7 +1803,7 @@ function isCoreComponent(tag) {
1805
1803
  return BASE_TRANSITION;
1806
1804
  }
1807
1805
  }
1808
- const nonIdentifierRE = /^\d|[^\$\w]/;
1806
+ const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
1809
1807
  const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
1810
1808
  const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
1811
1809
  const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
@@ -1926,8 +1924,7 @@ function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
1926
1924
  for (let i = 0; i < node.props.length; i++) {
1927
1925
  const p = node.props[i];
1928
1926
  if (p.type === 6) {
1929
- if (dynamicOnly)
1930
- continue;
1927
+ if (dynamicOnly) continue;
1931
1928
  if (p.name === name && (p.value || allowEmpty)) {
1932
1929
  return p;
1933
1930
  }
@@ -2079,6 +2076,7 @@ function hasScopeRef(node, ids) {
2079
2076
  return hasScopeRef(node.content, ids);
2080
2077
  case 2:
2081
2078
  case 3:
2079
+ case 20:
2082
2080
  return false;
2083
2081
  default:
2084
2082
  return false;
@@ -2091,7 +2089,7 @@ function getMemoedVNodeCall(node) {
2091
2089
  return node;
2092
2090
  }
2093
2091
  }
2094
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
2092
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
2095
2093
 
2096
2094
  const defaultParserOptions = {
2097
2095
  parseMode: "base",
@@ -2244,8 +2242,7 @@ const tokenizer = new Tokenizer(stack, {
2244
2242
  }
2245
2243
  },
2246
2244
  ondirarg(start, end) {
2247
- if (start === end)
2248
- return;
2245
+ if (start === end) return;
2249
2246
  const arg = getSlice(start, end);
2250
2247
  if (inVPre) {
2251
2248
  currentProp.name += arg;
@@ -2277,14 +2274,12 @@ const tokenizer = new Tokenizer(stack, {
2277
2274
  },
2278
2275
  onattribdata(start, end) {
2279
2276
  currentAttrValue += getSlice(start, end);
2280
- if (currentAttrStartIndex < 0)
2281
- currentAttrStartIndex = start;
2277
+ if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2282
2278
  currentAttrEndIndex = end;
2283
2279
  },
2284
2280
  onattribentity(char, start, end) {
2285
2281
  currentAttrValue += char;
2286
- if (currentAttrStartIndex < 0)
2287
- currentAttrStartIndex = start;
2282
+ if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2288
2283
  currentAttrEndIndex = end;
2289
2284
  },
2290
2285
  onattribnameend(end) {
@@ -2434,8 +2429,7 @@ function parseForExpression(input) {
2434
2429
  const loc = input.loc;
2435
2430
  const exp = input.content;
2436
2431
  const inMatch = exp.match(forAliasRE);
2437
- if (!inMatch)
2438
- return;
2432
+ if (!inMatch) return;
2439
2433
  const [, LHS, RHS] = inMatch;
2440
2434
  const createAliasExpression = (content, offset, asParam = false) => {
2441
2435
  const start = loc.start.offset + offset;
@@ -2592,14 +2586,12 @@ function onCloseTag(el, end, isImplied = false) {
2592
2586
  }
2593
2587
  function lookAhead(index, c) {
2594
2588
  let i = index;
2595
- while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
2596
- i++;
2589
+ while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
2597
2590
  return i;
2598
2591
  }
2599
2592
  function backTrack(index, c) {
2600
2593
  let i = index;
2601
- while (currentInput.charCodeAt(i) !== c && i >= 0)
2602
- i--;
2594
+ while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
2603
2595
  return i;
2604
2596
  }
2605
2597
  const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
@@ -2824,9 +2816,10 @@ function baseParse(input, options) {
2824
2816
  return root;
2825
2817
  }
2826
2818
 
2827
- function hoistStatic(root, context) {
2819
+ function cacheStatic(root, context) {
2828
2820
  walk(
2829
2821
  root,
2822
+ void 0,
2830
2823
  context,
2831
2824
  // Root node is unfortunately non-hoistable due to potential parent
2832
2825
  // fallthrough attributes.
@@ -2837,26 +2830,24 @@ function isSingleElementRoot(root, child) {
2837
2830
  const { children } = root;
2838
2831
  return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
2839
2832
  }
2840
- function walk(node, context, doNotHoistNode = false) {
2833
+ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
2841
2834
  const { children } = node;
2842
- const originalCount = children.length;
2843
- let hoistedCount = 0;
2835
+ const toCache = [];
2844
2836
  for (let i = 0; i < children.length; i++) {
2845
2837
  const child = children[i];
2846
2838
  if (child.type === 1 && child.tagType === 0) {
2847
2839
  const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2848
2840
  if (constantType > 0) {
2849
2841
  if (constantType >= 2) {
2850
- child.codegenNode.patchFlag = -1 + (``);
2851
- child.codegenNode = context.hoist(child.codegenNode);
2852
- hoistedCount++;
2842
+ child.codegenNode.patchFlag = -1;
2843
+ toCache.push(child);
2853
2844
  continue;
2854
2845
  }
2855
2846
  } else {
2856
2847
  const codegenNode = child.codegenNode;
2857
2848
  if (codegenNode.type === 13) {
2858
- const flag = getPatchFlag(codegenNode);
2859
- if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
2849
+ const flag = codegenNode.patchFlag;
2850
+ if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
2860
2851
  const props = getNodeProps(child);
2861
2852
  if (props) {
2862
2853
  codegenNode.props = context.hoist(props);
@@ -2867,39 +2858,84 @@ function walk(node, context, doNotHoistNode = false) {
2867
2858
  }
2868
2859
  }
2869
2860
  }
2861
+ } else if (child.type === 12) {
2862
+ const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2863
+ if (constantType >= 2) {
2864
+ toCache.push(child);
2865
+ continue;
2866
+ }
2870
2867
  }
2871
2868
  if (child.type === 1) {
2872
2869
  const isComponent = child.tagType === 1;
2873
2870
  if (isComponent) {
2874
2871
  context.scopes.vSlot++;
2875
2872
  }
2876
- walk(child, context);
2873
+ walk(child, node, context, false, inFor);
2877
2874
  if (isComponent) {
2878
2875
  context.scopes.vSlot--;
2879
2876
  }
2880
2877
  } else if (child.type === 11) {
2881
- walk(child, context, child.children.length === 1);
2878
+ walk(child, node, context, child.children.length === 1, true);
2882
2879
  } else if (child.type === 9) {
2883
2880
  for (let i2 = 0; i2 < child.branches.length; i2++) {
2884
2881
  walk(
2885
2882
  child.branches[i2],
2883
+ node,
2886
2884
  context,
2887
- child.branches[i2].children.length === 1
2885
+ child.branches[i2].children.length === 1,
2886
+ inFor
2888
2887
  );
2889
2888
  }
2890
2889
  }
2891
2890
  }
2892
- if (hoistedCount && context.transformHoist) {
2893
- context.transformHoist(children, context, node);
2891
+ let cachedAsArray = false;
2892
+ if (toCache.length === children.length && node.type === 1) {
2893
+ if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
2894
+ node.codegenNode.children = getCacheExpression(
2895
+ createArrayExpression(node.codegenNode.children)
2896
+ );
2897
+ cachedAsArray = true;
2898
+ } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
2899
+ const slot = getSlotNode(node.codegenNode, "default");
2900
+ if (slot) {
2901
+ slot.returns = getCacheExpression(
2902
+ createArrayExpression(slot.returns)
2903
+ );
2904
+ cachedAsArray = true;
2905
+ }
2906
+ } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
2907
+ const slotName = findDir(node, "slot", true);
2908
+ const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
2909
+ if (slot) {
2910
+ slot.returns = getCacheExpression(
2911
+ createArrayExpression(slot.returns)
2912
+ );
2913
+ cachedAsArray = true;
2914
+ }
2915
+ }
2894
2916
  }
2895
- if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
2896
- const hoisted = context.hoist(
2897
- createArrayExpression(node.codegenNode.children)
2898
- );
2899
- if (context.hmr) {
2900
- hoisted.content = `[...${hoisted.content}]`;
2917
+ if (!cachedAsArray) {
2918
+ for (const child of toCache) {
2919
+ child.codegenNode = context.cache(child.codegenNode);
2901
2920
  }
2902
- node.codegenNode.children = hoisted;
2921
+ }
2922
+ function getCacheExpression(value) {
2923
+ const exp = context.cache(value);
2924
+ if (inFor && context.hmr) {
2925
+ exp.needArraySpread = true;
2926
+ }
2927
+ return exp;
2928
+ }
2929
+ function getSlotNode(node2, name) {
2930
+ if (node2.children && !shared.isArray(node2.children) && node2.children.type === 15) {
2931
+ const slot = node2.children.properties.find(
2932
+ (p) => p.key === name || p.key.content === name
2933
+ );
2934
+ return slot && slot.value;
2935
+ }
2936
+ }
2937
+ if (toCache.length && context.transformHoist) {
2938
+ context.transformHoist(children, context, node);
2903
2939
  }
2904
2940
  }
2905
2941
  function getConstantType(node, context) {
@@ -2917,11 +2953,10 @@ function getConstantType(node, context) {
2917
2953
  if (codegenNode.type !== 13) {
2918
2954
  return 0;
2919
2955
  }
2920
- if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
2956
+ if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
2921
2957
  return 0;
2922
2958
  }
2923
- const flag = getPatchFlag(codegenNode);
2924
- if (!flag) {
2959
+ if (codegenNode.patchFlag === void 0) {
2925
2960
  let returnType2 = 3;
2926
2961
  const generatedPropsType = getGeneratedPropsConstantType(node, context);
2927
2962
  if (generatedPropsType === 0) {
@@ -3004,6 +3039,8 @@ function getConstantType(node, context) {
3004
3039
  }
3005
3040
  }
3006
3041
  return returnType;
3042
+ case 20:
3043
+ return 2;
3007
3044
  default:
3008
3045
  return 0;
3009
3046
  }
@@ -3063,15 +3100,11 @@ function getNodeProps(node) {
3063
3100
  return codegenNode.props;
3064
3101
  }
3065
3102
  }
3066
- function getPatchFlag(node) {
3067
- const flag = node.patchFlag;
3068
- return flag ? parseInt(flag, 10) : void 0;
3069
- }
3070
3103
 
3071
3104
  function createTransformContext(root, {
3072
3105
  filename = "",
3073
3106
  prefixIdentifiers = false,
3074
- hoistStatic: hoistStatic2 = false,
3107
+ hoistStatic = false,
3075
3108
  hmr = false,
3076
3109
  cacheHandlers = false,
3077
3110
  nodeTransforms = [],
@@ -3098,7 +3131,7 @@ function createTransformContext(root, {
3098
3131
  filename,
3099
3132
  selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
3100
3133
  prefixIdentifiers,
3101
- hoistStatic: hoistStatic2,
3134
+ hoistStatic,
3102
3135
  hmr,
3103
3136
  cacheHandlers,
3104
3137
  nodeTransforms,
@@ -3125,9 +3158,9 @@ function createTransformContext(root, {
3125
3158
  directives: /* @__PURE__ */ new Set(),
3126
3159
  hoists: [],
3127
3160
  imports: [],
3161
+ cached: [],
3128
3162
  constantCache: /* @__PURE__ */ new WeakMap(),
3129
3163
  temps: 0,
3130
- cached: 0,
3131
3164
  identifiers: /* @__PURE__ */ Object.create(null),
3132
3165
  scopes: {
3133
3166
  vFor: 0,
@@ -3201,8 +3234,7 @@ function createTransformContext(root, {
3201
3234
  }
3202
3235
  },
3203
3236
  hoist(exp) {
3204
- if (shared.isString(exp))
3205
- exp = createSimpleExpression(exp);
3237
+ if (shared.isString(exp)) exp = createSimpleExpression(exp);
3206
3238
  context.hoists.push(exp);
3207
3239
  const identifier = createSimpleExpression(
3208
3240
  `_hoisted_${context.hoists.length}`,
@@ -3214,7 +3246,13 @@ function createTransformContext(root, {
3214
3246
  return identifier;
3215
3247
  },
3216
3248
  cache(exp, isVNode = false) {
3217
- return createCacheExpression(context.cached++, exp, isVNode);
3249
+ const cacheExp = createCacheExpression(
3250
+ context.cached.length,
3251
+ exp,
3252
+ isVNode
3253
+ );
3254
+ context.cached.push(cacheExp);
3255
+ return cacheExp;
3218
3256
  }
3219
3257
  };
3220
3258
  {
@@ -3236,7 +3274,7 @@ function transform(root, options) {
3236
3274
  const context = createTransformContext(root, options);
3237
3275
  traverseNode(root, context);
3238
3276
  if (options.hoistStatic) {
3239
- hoistStatic(root, context);
3277
+ cacheStatic(root, context);
3240
3278
  }
3241
3279
  if (!options.ssr) {
3242
3280
  createRootCodegen(root, context);
@@ -3275,7 +3313,7 @@ function createRootCodegen(root, context) {
3275
3313
  helper(FRAGMENT),
3276
3314
  void 0,
3277
3315
  root.children,
3278
- patchFlag + (``),
3316
+ patchFlag,
3279
3317
  void 0,
3280
3318
  void 0,
3281
3319
  true,
@@ -3291,8 +3329,7 @@ function traverseChildren(parent, context) {
3291
3329
  };
3292
3330
  for (; i < parent.children.length; i++) {
3293
3331
  const child = parent.children[i];
3294
- if (shared.isString(child))
3295
- continue;
3332
+ if (shared.isString(child)) continue;
3296
3333
  context.grandParent = context.parent;
3297
3334
  context.parent = parent;
3298
3335
  context.childIndex = i;
@@ -3363,8 +3400,7 @@ function createStructuralDirectiveTransform(name, fn) {
3363
3400
  props.splice(i, 1);
3364
3401
  i--;
3365
3402
  const onExit = fn(node, prop, context);
3366
- if (onExit)
3367
- exitFns.push(onExit);
3403
+ if (onExit) exitFns.push(onExit);
3368
3404
  }
3369
3405
  }
3370
3406
  return exitFns;
@@ -3463,8 +3499,7 @@ function createCodegenContext(ast, {
3463
3499
  }
3464
3500
  function addMapping(loc, name = null) {
3465
3501
  const { _names, _mappings } = context.map;
3466
- if (name !== null && !_names.has(name))
3467
- _names.add(name);
3502
+ if (name !== null && !_names.has(name)) _names.add(name);
3468
3503
  _mappings.add({
3469
3504
  originalLine: loc.line,
3470
3505
  originalColumn: loc.column - 1,
@@ -3484,8 +3519,7 @@ function createCodegenContext(ast, {
3484
3519
  }
3485
3520
  function generate(ast, options = {}) {
3486
3521
  const context = createCodegenContext(ast, options);
3487
- if (options.onContextCreated)
3488
- options.onContextCreated(context);
3522
+ if (options.onContextCreated) options.onContextCreated(context);
3489
3523
  const {
3490
3524
  mode,
3491
3525
  push,
@@ -3634,10 +3668,6 @@ function genModulePreamble(ast, context, genScopeId, inline) {
3634
3668
  runtimeModuleName,
3635
3669
  ssrRuntimeModuleName
3636
3670
  } = context;
3637
- if (genScopeId && ast.hoists.length) {
3638
- ast.helpers.add(PUSH_SCOPE_ID);
3639
- ast.helpers.add(POP_SCOPE_ID);
3640
- }
3641
3671
  if (ast.helpers.size) {
3642
3672
  const helpers = Array.from(ast.helpers);
3643
3673
  if (optimizeImports) {
@@ -3701,28 +3731,13 @@ function genHoists(hoists, context) {
3701
3731
  return;
3702
3732
  }
3703
3733
  context.pure = true;
3704
- const { push, newline, helper, scopeId, mode } = context;
3705
- const genScopeId = scopeId != null && mode !== "function";
3734
+ const { push, newline } = context;
3706
3735
  newline();
3707
- if (genScopeId) {
3708
- push(
3709
- `const _withScopeId = n => (${helper(
3710
- PUSH_SCOPE_ID
3711
- )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`
3712
- );
3713
- newline();
3714
- }
3715
3736
  for (let i = 0; i < hoists.length; i++) {
3716
3737
  const exp = hoists[i];
3717
3738
  if (exp) {
3718
- const needScopeIdWrapper = genScopeId && exp.type === 13;
3719
- push(
3720
- `const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`
3721
- );
3739
+ push(`const _hoisted_${i + 1} = `);
3722
3740
  genNode(exp, context);
3723
- if (needScopeIdWrapper) {
3724
- push(`)`);
3725
- }
3726
3741
  newline();
3727
3742
  }
3728
3743
  }
@@ -3858,8 +3873,7 @@ function genExpression(node, context) {
3858
3873
  }
3859
3874
  function genInterpolation(node, context) {
3860
3875
  const { push, helper, pure } = context;
3861
- if (pure)
3862
- push(PURE_ANNOTATION);
3876
+ if (pure) push(PURE_ANNOTATION);
3863
3877
  push(`${helper(TO_DISPLAY_STRING)}(`);
3864
3878
  genNode(node.content, context);
3865
3879
  push(`)`);
@@ -3911,6 +3925,12 @@ function genVNodeCall(node, context) {
3911
3925
  disableTracking,
3912
3926
  isComponent
3913
3927
  } = node;
3928
+ let patchFlagString;
3929
+ if (patchFlag) {
3930
+ {
3931
+ patchFlagString = String(patchFlag);
3932
+ }
3933
+ }
3914
3934
  if (directives) {
3915
3935
  push(helper(WITH_DIRECTIVES) + `(`);
3916
3936
  }
@@ -3923,7 +3943,7 @@ function genVNodeCall(node, context) {
3923
3943
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
3924
3944
  push(helper(callHelper) + `(`, -2 /* None */, node);
3925
3945
  genNodeList(
3926
- genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
3946
+ genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
3927
3947
  context
3928
3948
  );
3929
3949
  push(`)`);
@@ -3939,8 +3959,7 @@ function genVNodeCall(node, context) {
3939
3959
  function genNullableArgs(args) {
3940
3960
  let i = args.length;
3941
3961
  while (i--) {
3942
- if (args[i] != null)
3943
- break;
3962
+ if (args[i] != null) break;
3944
3963
  }
3945
3964
  return args.slice(0, i + 1).map((arg) => arg || `null`);
3946
3965
  }
@@ -4057,16 +4076,21 @@ function genConditionalExpression(node, context) {
4057
4076
  }
4058
4077
  function genCacheExpression(node, context) {
4059
4078
  const { push, helper, indent, deindent, newline } = context;
4079
+ const { needPauseTracking, needArraySpread } = node;
4080
+ if (needArraySpread) {
4081
+ push(`[...(`);
4082
+ }
4060
4083
  push(`_cache[${node.index}] || (`);
4061
- if (node.isVNode) {
4084
+ if (needPauseTracking) {
4062
4085
  indent();
4063
4086
  push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
4064
4087
  newline();
4088
+ push(`(`);
4065
4089
  }
4066
4090
  push(`_cache[${node.index}] = `);
4067
4091
  genNode(node.value, context);
4068
- if (node.isVNode) {
4069
- push(`,`);
4092
+ if (needPauseTracking) {
4093
+ push(`).cacheIndex = ${node.index},`);
4070
4094
  newline();
4071
4095
  push(`${helper(SET_BLOCK_TRACKING)}(1),`);
4072
4096
  newline();
@@ -4074,6 +4098,9 @@ function genCacheExpression(node, context) {
4074
4098
  deindent();
4075
4099
  }
4076
4100
  push(`)`);
4101
+ if (needArraySpread) {
4102
+ push(`)]`);
4103
+ }
4077
4104
  }
4078
4105
  function genTemplateLiteral(node, context) {
4079
4106
  const { push, indent, deindent } = context;
@@ -4086,11 +4113,9 @@ function genTemplateLiteral(node, context) {
4086
4113
  push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
4087
4114
  } else {
4088
4115
  push("${");
4089
- if (multilines)
4090
- indent();
4116
+ if (multilines) indent();
4091
4117
  genNode(e, context);
4092
- if (multilines)
4093
- deindent();
4118
+ if (multilines) deindent();
4094
4119
  push("}");
4095
4120
  }
4096
4121
  }
@@ -4294,7 +4319,7 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
4294
4319
  node2.name = rewriteIdentifier(node2.name, parent, node2);
4295
4320
  ids.push(node2);
4296
4321
  } else {
4297
- if (!(needPrefix && isLocal) && parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression") {
4322
+ if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
4298
4323
  node2.isConstant = true;
4299
4324
  }
4300
4325
  ids.push(node2);
@@ -4458,8 +4483,7 @@ function processIf(node, dir, context, processCodegen) {
4458
4483
  sibling.branches.push(branch);
4459
4484
  const onExit = processCodegen && processCodegen(sibling, branch, false);
4460
4485
  traverseNode(branch, context);
4461
- if (onExit)
4462
- onExit();
4486
+ if (onExit) onExit();
4463
4487
  context.currentNode = null;
4464
4488
  } else {
4465
4489
  context.onError(
@@ -4524,7 +4548,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
4524
4548
  helper(FRAGMENT),
4525
4549
  createObjectExpression([keyProperty]),
4526
4550
  children,
4527
- patchFlag + (``),
4551
+ patchFlag,
4528
4552
  void 0,
4529
4553
  void 0,
4530
4554
  true,
@@ -4577,6 +4601,90 @@ function getParentCondition(node) {
4577
4601
  }
4578
4602
  }
4579
4603
 
4604
+ const transformBind = (dir, _node, context) => {
4605
+ const { modifiers, loc } = dir;
4606
+ const arg = dir.arg;
4607
+ let { exp } = dir;
4608
+ if (exp && exp.type === 4 && !exp.content.trim()) {
4609
+ {
4610
+ context.onError(
4611
+ createCompilerError(34, loc)
4612
+ );
4613
+ return {
4614
+ props: [
4615
+ createObjectProperty(arg, createSimpleExpression("", true, loc))
4616
+ ]
4617
+ };
4618
+ }
4619
+ }
4620
+ if (!exp) {
4621
+ if (arg.type !== 4 || !arg.isStatic) {
4622
+ context.onError(
4623
+ createCompilerError(
4624
+ 52,
4625
+ arg.loc
4626
+ )
4627
+ );
4628
+ return {
4629
+ props: [
4630
+ createObjectProperty(arg, createSimpleExpression("", true, loc))
4631
+ ]
4632
+ };
4633
+ }
4634
+ transformBindShorthand(dir, context);
4635
+ exp = dir.exp;
4636
+ }
4637
+ if (arg.type !== 4) {
4638
+ arg.children.unshift(`(`);
4639
+ arg.children.push(`) || ""`);
4640
+ } else if (!arg.isStatic) {
4641
+ arg.content = `${arg.content} || ""`;
4642
+ }
4643
+ if (modifiers.includes("camel")) {
4644
+ if (arg.type === 4) {
4645
+ if (arg.isStatic) {
4646
+ arg.content = shared.camelize(arg.content);
4647
+ } else {
4648
+ arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
4649
+ }
4650
+ } else {
4651
+ arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
4652
+ arg.children.push(`)`);
4653
+ }
4654
+ }
4655
+ if (!context.inSSR) {
4656
+ if (modifiers.includes("prop")) {
4657
+ injectPrefix(arg, ".");
4658
+ }
4659
+ if (modifiers.includes("attr")) {
4660
+ injectPrefix(arg, "^");
4661
+ }
4662
+ }
4663
+ return {
4664
+ props: [createObjectProperty(arg, exp)]
4665
+ };
4666
+ };
4667
+ const transformBindShorthand = (dir, context) => {
4668
+ const arg = dir.arg;
4669
+ const propName = shared.camelize(arg.content);
4670
+ dir.exp = createSimpleExpression(propName, false, arg.loc);
4671
+ {
4672
+ dir.exp = processExpression(dir.exp, context);
4673
+ }
4674
+ };
4675
+ const injectPrefix = (arg, prefix) => {
4676
+ if (arg.type === 4) {
4677
+ if (arg.isStatic) {
4678
+ arg.content = prefix + arg.content;
4679
+ } else {
4680
+ arg.content = `\`${prefix}\${${arg.content}}\``;
4681
+ }
4682
+ } else {
4683
+ arg.children.unshift(`'${prefix}' + (`);
4684
+ arg.children.push(`)`);
4685
+ }
4686
+ };
4687
+
4580
4688
  const transformFor = createStructuralDirectiveTransform(
4581
4689
  "for",
4582
4690
  (node, dir, context) => {
@@ -4587,9 +4695,12 @@ const transformFor = createStructuralDirectiveTransform(
4587
4695
  ]);
4588
4696
  const isTemplate = isTemplateNode(node);
4589
4697
  const memo = findDir(node, "memo");
4590
- const keyProp = findProp(node, `key`);
4591
- const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
4592
- const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
4698
+ const keyProp = findProp(node, `key`, false, true);
4699
+ if (keyProp && keyProp.type === 7 && !keyProp.exp) {
4700
+ transformBindShorthand(keyProp, context);
4701
+ }
4702
+ const keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
4703
+ const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
4593
4704
  if (isTemplate) {
4594
4705
  if (memo) {
4595
4706
  memo.exp = processExpression(
@@ -4611,7 +4722,7 @@ const transformFor = createStructuralDirectiveTransform(
4611
4722
  helper(FRAGMENT),
4612
4723
  void 0,
4613
4724
  renderExp,
4614
- fragmentFlag + (``),
4725
+ fragmentFlag,
4615
4726
  void 0,
4616
4727
  void 0,
4617
4728
  true,
@@ -4651,7 +4762,7 @@ const transformFor = createStructuralDirectiveTransform(
4651
4762
  helper(FRAGMENT),
4652
4763
  keyProperty ? createObjectExpression([keyProperty]) : void 0,
4653
4764
  node.children,
4654
- 64 + (``),
4765
+ 64,
4655
4766
  void 0,
4656
4767
  void 0,
4657
4768
  true,
@@ -4705,8 +4816,9 @@ const transformFor = createStructuralDirectiveTransform(
4705
4816
  renderExp.arguments.push(
4706
4817
  loop,
4707
4818
  createSimpleExpression(`_cache`),
4708
- createSimpleExpression(String(context.cached++))
4819
+ createSimpleExpression(String(context.cached.length))
4709
4820
  );
4821
+ context.cached.push(null);
4710
4822
  } else {
4711
4823
  renderExp.arguments.push(
4712
4824
  createFunctionExpression(
@@ -4762,13 +4874,11 @@ function processFor(node, dir, context, processCodegen) {
4762
4874
  key && removeIdentifiers(key);
4763
4875
  index && removeIdentifiers(index);
4764
4876
  }
4765
- if (onExit)
4766
- onExit();
4877
+ if (onExit) onExit();
4767
4878
  };
4768
4879
  }
4769
4880
  function finalizeForParseResult(result, context) {
4770
- if (result.finalized)
4771
- return;
4881
+ if (result.finalized) return;
4772
4882
  if (context.prefixIdentifiers) {
4773
4883
  result.source = processExpression(
4774
4884
  result.source,
@@ -4804,8 +4914,7 @@ function createForLoopParams({ value, key, index }, memoArgs = []) {
4804
4914
  function createParamsList(args) {
4805
4915
  let i = args.length;
4806
4916
  while (i--) {
4807
- if (args[i])
4808
- break;
4917
+ if (args[i]) break;
4809
4918
  }
4810
4919
  return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
4811
4920
  }
@@ -4937,9 +5046,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
4937
5046
  break;
4938
5047
  }
4939
5048
  }
4940
- if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
4941
- children.splice(i, 1);
4942
- i--;
5049
+ if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
4943
5050
  let conditional = dynamicSlots[dynamicSlots.length - 1];
4944
5051
  while (conditional.alternate.type === 19) {
4945
5052
  conditional = conditional.alternate;
@@ -5076,13 +5183,11 @@ function hasForwardedSlots(children) {
5076
5183
  }
5077
5184
  break;
5078
5185
  case 9:
5079
- if (hasForwardedSlots(child.branches))
5080
- return true;
5186
+ if (hasForwardedSlots(child.branches)) return true;
5081
5187
  break;
5082
5188
  case 10:
5083
5189
  case 11:
5084
- if (hasForwardedSlots(child.children))
5085
- return true;
5190
+ if (hasForwardedSlots(child.children)) return true;
5086
5191
  break;
5087
5192
  }
5088
5193
  }
@@ -5107,7 +5212,6 @@ const transformElement = (node, context) => {
5107
5212
  const isDynamicComponent = shared.isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
5108
5213
  let vnodeProps;
5109
5214
  let vnodeChildren;
5110
- let vnodePatchFlag;
5111
5215
  let patchFlag = 0;
5112
5216
  let vnodeDynamicProps;
5113
5217
  let dynamicPropNames;
@@ -5118,7 +5222,7 @@ const transformElement = (node, context) => {
5118
5222
  // updates inside get proper isSVG flag at runtime. (#639, #643)
5119
5223
  // This is technically web-specific, but splitting the logic out of core
5120
5224
  // leads to too much unnecessary complexity.
5121
- (tag === "svg" || tag === "foreignObject")
5225
+ (tag === "svg" || tag === "foreignObject" || tag === "math")
5122
5226
  );
5123
5227
  if (props.length > 0) {
5124
5228
  const propsBuildResult = buildProps(
@@ -5169,20 +5273,15 @@ const transformElement = (node, context) => {
5169
5273
  vnodeChildren = node.children;
5170
5274
  }
5171
5275
  }
5172
- if (patchFlag !== 0) {
5173
- {
5174
- vnodePatchFlag = String(patchFlag);
5175
- }
5176
- if (dynamicPropNames && dynamicPropNames.length) {
5177
- vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
5178
- }
5276
+ if (dynamicPropNames && dynamicPropNames.length) {
5277
+ vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
5179
5278
  }
5180
5279
  node.codegenNode = createVNodeCall(
5181
5280
  context,
5182
5281
  vnodeTag,
5183
5282
  vnodeProps,
5184
5283
  vnodeChildren,
5185
- vnodePatchFlag,
5284
+ patchFlag === 0 ? void 0 : patchFlag,
5186
5285
  vnodeDynamicProps,
5187
5286
  vnodeDirectives,
5188
5287
  !!shouldUseBlock,
@@ -5230,8 +5329,7 @@ function resolveComponentType(node, context, ssr = false) {
5230
5329
  }
5231
5330
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
5232
5331
  if (builtIn) {
5233
- if (!ssr)
5234
- context.helper(builtIn);
5332
+ if (!ssr) context.helper(builtIn);
5235
5333
  return builtIn;
5236
5334
  }
5237
5335
  {
@@ -5315,8 +5413,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
5315
5413
  );
5316
5414
  properties = [];
5317
5415
  }
5318
- if (arg)
5319
- mergeArgs.push(arg);
5416
+ if (arg) mergeArgs.push(arg);
5320
5417
  };
5321
5418
  const pushRefVForMarker = () => {
5322
5419
  if (context.scopes.vFor > 0) {
@@ -5647,8 +5744,7 @@ function buildDirectiveArgs(dir, context) {
5647
5744
  }
5648
5745
  }
5649
5746
  const { loc } = dir;
5650
- if (dir.exp)
5651
- dirArgs.push(dir.exp);
5747
+ if (dir.exp) dirArgs.push(dir.exp);
5652
5748
  if (dir.arg) {
5653
5749
  if (!dir.exp) {
5654
5750
  dirArgs.push(`void 0`);
@@ -5678,8 +5774,7 @@ function stringifyDynamicPropNames(props) {
5678
5774
  let propsNamesString = `[`;
5679
5775
  for (let i = 0, l = props.length; i < l; i++) {
5680
5776
  propsNamesString += JSON.stringify(props[i]);
5681
- if (i < l - 1)
5682
- propsNamesString += ", ";
5777
+ if (i < l - 1) propsNamesString += ", ";
5683
5778
  }
5684
5779
  return propsNamesString + `]`;
5685
5780
  }
@@ -5776,7 +5871,7 @@ function processSlotOutlet(node, context) {
5776
5871
  };
5777
5872
  }
5778
5873
 
5779
- const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
5874
+ const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
5780
5875
  const transformOn = (dir, node, context, augmentor) => {
5781
5876
  const { loc, modifiers, arg } = dir;
5782
5877
  if (!dir.exp && !modifiers.length) {
@@ -5876,85 +5971,6 @@ const transformOn = (dir, node, context, augmentor) => {
5876
5971
  return ret;
5877
5972
  };
5878
5973
 
5879
- const transformBind = (dir, _node, context) => {
5880
- const { modifiers, loc } = dir;
5881
- const arg = dir.arg;
5882
- let { exp } = dir;
5883
- if (exp && exp.type === 4 && !exp.content.trim()) {
5884
- {
5885
- context.onError(
5886
- createCompilerError(34, loc)
5887
- );
5888
- return {
5889
- props: [
5890
- createObjectProperty(arg, createSimpleExpression("", true, loc))
5891
- ]
5892
- };
5893
- }
5894
- }
5895
- if (!exp) {
5896
- if (arg.type !== 4 || !arg.isStatic) {
5897
- context.onError(
5898
- createCompilerError(
5899
- 52,
5900
- arg.loc
5901
- )
5902
- );
5903
- return {
5904
- props: [
5905
- createObjectProperty(arg, createSimpleExpression("", true, loc))
5906
- ]
5907
- };
5908
- }
5909
- const propName = shared.camelize(arg.content);
5910
- exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5911
- {
5912
- exp = dir.exp = processExpression(exp, context);
5913
- }
5914
- }
5915
- if (arg.type !== 4) {
5916
- arg.children.unshift(`(`);
5917
- arg.children.push(`) || ""`);
5918
- } else if (!arg.isStatic) {
5919
- arg.content = `${arg.content} || ""`;
5920
- }
5921
- if (modifiers.includes("camel")) {
5922
- if (arg.type === 4) {
5923
- if (arg.isStatic) {
5924
- arg.content = shared.camelize(arg.content);
5925
- } else {
5926
- arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
5927
- }
5928
- } else {
5929
- arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
5930
- arg.children.push(`)`);
5931
- }
5932
- }
5933
- if (!context.inSSR) {
5934
- if (modifiers.includes("prop")) {
5935
- injectPrefix(arg, ".");
5936
- }
5937
- if (modifiers.includes("attr")) {
5938
- injectPrefix(arg, "^");
5939
- }
5940
- }
5941
- return {
5942
- props: [createObjectProperty(arg, exp)]
5943
- };
5944
- };
5945
- const injectPrefix = (arg, prefix) => {
5946
- if (arg.type === 4) {
5947
- if (arg.isStatic) {
5948
- arg.content = prefix + arg.content;
5949
- } else {
5950
- arg.content = `\`${prefix}\${${arg.content}}\``;
5951
- }
5952
- } else {
5953
- arg.children.unshift(`'${prefix}' + (`);
5954
- arg.children.push(`)`);
5955
- }
5956
- };
5957
-
5958
5974
  const transformText = (node, context) => {
5959
5975
  if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
5960
5976
  return () => {
@@ -6142,8 +6158,7 @@ const transformFilter = (node, context) => {
6142
6158
  }
6143
6159
  if (node.type === 5) {
6144
6160
  rewriteFilter(node.content, context);
6145
- }
6146
- if (node.type === 1) {
6161
+ } else if (node.type === 1) {
6147
6162
  node.props.forEach((prop) => {
6148
6163
  if (prop.type === 7 && prop.name !== "for" && prop.exp) {
6149
6164
  rewriteFilter(prop.exp, context);
@@ -6157,8 +6172,7 @@ function rewriteFilter(node, context) {
6157
6172
  } else {
6158
6173
  for (let i = 0; i < node.children.length; i++) {
6159
6174
  const child = node.children[i];
6160
- if (typeof child !== "object")
6161
- continue;
6175
+ if (typeof child !== "object") continue;
6162
6176
  if (child.type === 4) {
6163
6177
  parseFilter(child, context);
6164
6178
  } else if (child.type === 8) {
@@ -6184,17 +6198,13 @@ function parseFilter(node, context) {
6184
6198
  prev = c;
6185
6199
  c = exp.charCodeAt(i);
6186
6200
  if (inSingle) {
6187
- if (c === 39 && prev !== 92)
6188
- inSingle = false;
6201
+ if (c === 39 && prev !== 92) inSingle = false;
6189
6202
  } else if (inDouble) {
6190
- if (c === 34 && prev !== 92)
6191
- inDouble = false;
6203
+ if (c === 34 && prev !== 92) inDouble = false;
6192
6204
  } else if (inTemplateString) {
6193
- if (c === 96 && prev !== 92)
6194
- inTemplateString = false;
6205
+ if (c === 96 && prev !== 92) inTemplateString = false;
6195
6206
  } else if (inRegex) {
6196
- if (c === 47 && prev !== 92)
6197
- inRegex = false;
6207
+ if (c === 47 && prev !== 92) inRegex = false;
6198
6208
  } else if (c === 124 && // pipe
6199
6209
  exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
6200
6210
  if (expression === void 0) {
@@ -6238,8 +6248,7 @@ function parseFilter(node, context) {
6238
6248
  let p;
6239
6249
  for (; j >= 0; j--) {
6240
6250
  p = exp.charAt(j);
6241
- if (p !== " ")
6242
- break;
6251
+ if (p !== " ") break;
6243
6252
  }
6244
6253
  if (!p || !validDivisionCharRE.test(p)) {
6245
6254
  inRegex = true;
@@ -6261,6 +6270,7 @@ function parseFilter(node, context) {
6261
6270
  expression = wrapFilter(expression, filters[i], context);
6262
6271
  }
6263
6272
  node.content = expression;
6273
+ node.ast = void 0;
6264
6274
  }
6265
6275
  }
6266
6276
  function wrapFilter(exp, filter, context) {
@@ -6295,8 +6305,9 @@ const transformMemo = (node, context) => {
6295
6305
  dir.exp,
6296
6306
  createFunctionExpression(void 0, codegenNode),
6297
6307
  `_cache`,
6298
- String(context.cached++)
6308
+ String(context.cached.length)
6299
6309
  ]);
6310
+ context.cached.push(null);
6300
6311
  }
6301
6312
  };
6302
6313
  }