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

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.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -173,8 +173,8 @@ const ConstantTypes = {
173
173
  "0": "NOT_CONSTANT",
174
174
  "CAN_SKIP_PATCH": 1,
175
175
  "1": "CAN_SKIP_PATCH",
176
- "CAN_HOIST": 2,
177
- "2": "CAN_HOIST",
176
+ "CAN_CACHE": 2,
177
+ "2": "CAN_CACHE",
178
178
  "CAN_STRINGIFY": 3,
179
179
  "3": "CAN_STRINGIFY"
180
180
  };
@@ -193,7 +193,7 @@ function createRoot(children, source = "") {
193
193
  directives: [],
194
194
  hoists: [],
195
195
  imports: [],
196
- cached: 0,
196
+ cached: [],
197
197
  temps: 0,
198
198
  codegenNode: void 0,
199
199
  loc: locStub
@@ -298,12 +298,13 @@ function createConditionalExpression(test, consequent, alternate, newline = true
298
298
  loc: locStub
299
299
  };
300
300
  }
301
- function createCacheExpression(index, value, isVNode = false) {
301
+ function createCacheExpression(index, value, needPauseTracking = false) {
302
302
  return {
303
303
  type: 20,
304
304
  index,
305
305
  value,
306
- isVNode,
306
+ needPauseTracking,
307
+ needArraySpread: false,
307
308
  loc: locStub
308
309
  };
309
310
  }
@@ -1244,8 +1245,7 @@ function warnDeprecation(key, context, loc, ...args) {
1244
1245
  Details: ${link}` : ``}`;
1245
1246
  const err = new SyntaxError(msg);
1246
1247
  err.code = key;
1247
- if (loc)
1248
- err.loc = loc;
1248
+ if (loc) err.loc = loc;
1249
1249
  context.onWarn(err);
1250
1250
  }
1251
1251
 
@@ -1481,16 +1481,14 @@ function walkFunctionParams(node, onIdent) {
1481
1481
  function walkBlockDeclarations(block, onIdent) {
1482
1482
  for (const stmt of block.body) {
1483
1483
  if (stmt.type === "VariableDeclaration") {
1484
- if (stmt.declare)
1485
- continue;
1484
+ if (stmt.declare) continue;
1486
1485
  for (const decl of stmt.declarations) {
1487
1486
  for (const id of extractIdentifiers(decl.id)) {
1488
1487
  onIdent(id);
1489
1488
  }
1490
1489
  }
1491
1490
  } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1492
- if (stmt.declare || !stmt.id)
1493
- continue;
1491
+ if (stmt.declare || !stmt.id) continue;
1494
1492
  onIdent(stmt.id);
1495
1493
  } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
1496
1494
  const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
@@ -1527,8 +1525,7 @@ function extractIdentifiers(param, nodes = []) {
1527
1525
  break;
1528
1526
  case "ArrayPattern":
1529
1527
  param.elements.forEach((element) => {
1530
- if (element)
1531
- extractIdentifiers(element, nodes);
1528
+ if (element) extractIdentifiers(element, nodes);
1532
1529
  });
1533
1530
  break;
1534
1531
  case "RestElement":
@@ -1582,7 +1579,7 @@ function isCoreComponent(tag) {
1582
1579
  return BASE_TRANSITION;
1583
1580
  }
1584
1581
  }
1585
- const nonIdentifierRE = /^\d|[^\$\w]/;
1582
+ const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
1586
1583
  const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
1587
1584
  const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
1588
1585
  const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
@@ -1693,8 +1690,7 @@ function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
1693
1690
  for (let i = 0; i < node.props.length; i++) {
1694
1691
  const p = node.props[i];
1695
1692
  if (p.type === 6) {
1696
- if (dynamicOnly)
1697
- continue;
1693
+ if (dynamicOnly) continue;
1698
1694
  if (p.name === name && (p.value || allowEmpty)) {
1699
1695
  return p;
1700
1696
  }
@@ -1846,6 +1842,7 @@ function hasScopeRef(node, ids) {
1846
1842
  return hasScopeRef(node.content, ids);
1847
1843
  case 2:
1848
1844
  case 3:
1845
+ case 20:
1849
1846
  return false;
1850
1847
  default:
1851
1848
  if (!!(process.env.NODE_ENV !== "production")) ;
@@ -1859,7 +1856,7 @@ function getMemoedVNodeCall(node) {
1859
1856
  return node;
1860
1857
  }
1861
1858
  }
1862
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
1859
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
1863
1860
 
1864
1861
  const defaultParserOptions = {
1865
1862
  parseMode: "base",
@@ -2012,8 +2009,7 @@ const tokenizer = new Tokenizer(stack, {
2012
2009
  }
2013
2010
  },
2014
2011
  ondirarg(start, end) {
2015
- if (start === end)
2016
- return;
2012
+ if (start === end) return;
2017
2013
  const arg = getSlice(start, end);
2018
2014
  if (inVPre) {
2019
2015
  currentProp.name += arg;
@@ -2045,14 +2041,12 @@ const tokenizer = new Tokenizer(stack, {
2045
2041
  },
2046
2042
  onattribdata(start, end) {
2047
2043
  currentAttrValue += getSlice(start, end);
2048
- if (currentAttrStartIndex < 0)
2049
- currentAttrStartIndex = start;
2044
+ if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2050
2045
  currentAttrEndIndex = end;
2051
2046
  },
2052
2047
  onattribentity(char, start, end) {
2053
2048
  currentAttrValue += char;
2054
- if (currentAttrStartIndex < 0)
2055
- currentAttrStartIndex = start;
2049
+ if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2056
2050
  currentAttrEndIndex = end;
2057
2051
  },
2058
2052
  onattribnameend(end) {
@@ -2199,8 +2193,7 @@ function parseForExpression(input) {
2199
2193
  const loc = input.loc;
2200
2194
  const exp = input.content;
2201
2195
  const inMatch = exp.match(forAliasRE);
2202
- if (!inMatch)
2203
- return;
2196
+ if (!inMatch) return;
2204
2197
  const [, LHS, RHS] = inMatch;
2205
2198
  const createAliasExpression = (content, offset, asParam = false) => {
2206
2199
  const start = loc.start.offset + offset;
@@ -2393,14 +2386,12 @@ function onCloseTag(el, end, isImplied = false) {
2393
2386
  }
2394
2387
  function lookAhead(index, c) {
2395
2388
  let i = index;
2396
- while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
2397
- i++;
2389
+ while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
2398
2390
  return i;
2399
2391
  }
2400
2392
  function backTrack(index, c) {
2401
2393
  let i = index;
2402
- while (currentInput.charCodeAt(i) !== c && i >= 0)
2403
- i--;
2394
+ while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
2404
2395
  return i;
2405
2396
  }
2406
2397
  const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
@@ -2610,9 +2601,10 @@ function baseParse(input, options) {
2610
2601
  return root;
2611
2602
  }
2612
2603
 
2613
- function hoistStatic(root, context) {
2604
+ function cacheStatic(root, context) {
2614
2605
  walk(
2615
2606
  root,
2607
+ void 0,
2616
2608
  context,
2617
2609
  // Root node is unfortunately non-hoistable due to potential parent
2618
2610
  // fallthrough attributes.
@@ -2623,26 +2615,24 @@ function isSingleElementRoot(root, child) {
2623
2615
  const { children } = root;
2624
2616
  return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
2625
2617
  }
2626
- function walk(node, context, doNotHoistNode = false) {
2618
+ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
2627
2619
  const { children } = node;
2628
- const originalCount = children.length;
2629
- let hoistedCount = 0;
2620
+ const toCache = [];
2630
2621
  for (let i = 0; i < children.length; i++) {
2631
2622
  const child = children[i];
2632
2623
  if (child.type === 1 && child.tagType === 0) {
2633
2624
  const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2634
2625
  if (constantType > 0) {
2635
2626
  if (constantType >= 2) {
2636
- child.codegenNode.patchFlag = -1 + (!!(process.env.NODE_ENV !== "production") ? ` /* HOISTED */` : ``);
2637
- child.codegenNode = context.hoist(child.codegenNode);
2638
- hoistedCount++;
2627
+ child.codegenNode.patchFlag = -1;
2628
+ toCache.push(child);
2639
2629
  continue;
2640
2630
  }
2641
2631
  } else {
2642
2632
  const codegenNode = child.codegenNode;
2643
2633
  if (codegenNode.type === 13) {
2644
- const flag = getPatchFlag(codegenNode);
2645
- if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
2634
+ const flag = codegenNode.patchFlag;
2635
+ if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
2646
2636
  const props = getNodeProps(child);
2647
2637
  if (props) {
2648
2638
  codegenNode.props = context.hoist(props);
@@ -2653,39 +2643,84 @@ function walk(node, context, doNotHoistNode = false) {
2653
2643
  }
2654
2644
  }
2655
2645
  }
2646
+ } else if (child.type === 12) {
2647
+ const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2648
+ if (constantType >= 2) {
2649
+ toCache.push(child);
2650
+ continue;
2651
+ }
2656
2652
  }
2657
2653
  if (child.type === 1) {
2658
2654
  const isComponent = child.tagType === 1;
2659
2655
  if (isComponent) {
2660
2656
  context.scopes.vSlot++;
2661
2657
  }
2662
- walk(child, context);
2658
+ walk(child, node, context, false, inFor);
2663
2659
  if (isComponent) {
2664
2660
  context.scopes.vSlot--;
2665
2661
  }
2666
2662
  } else if (child.type === 11) {
2667
- walk(child, context, child.children.length === 1);
2663
+ walk(child, node, context, child.children.length === 1, true);
2668
2664
  } else if (child.type === 9) {
2669
2665
  for (let i2 = 0; i2 < child.branches.length; i2++) {
2670
2666
  walk(
2671
2667
  child.branches[i2],
2668
+ node,
2672
2669
  context,
2673
- child.branches[i2].children.length === 1
2670
+ child.branches[i2].children.length === 1,
2671
+ inFor
2674
2672
  );
2675
2673
  }
2676
2674
  }
2677
2675
  }
2678
- if (hoistedCount && context.transformHoist) {
2679
- context.transformHoist(children, context, node);
2676
+ let cachedAsArray = false;
2677
+ if (toCache.length === children.length && node.type === 1) {
2678
+ if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
2679
+ node.codegenNode.children = getCacheExpression(
2680
+ createArrayExpression(node.codegenNode.children)
2681
+ );
2682
+ cachedAsArray = true;
2683
+ } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
2684
+ const slot = getSlotNode(node.codegenNode, "default");
2685
+ if (slot) {
2686
+ slot.returns = getCacheExpression(
2687
+ createArrayExpression(slot.returns)
2688
+ );
2689
+ cachedAsArray = true;
2690
+ }
2691
+ } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
2692
+ const slotName = findDir(node, "slot", true);
2693
+ const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
2694
+ if (slot) {
2695
+ slot.returns = getCacheExpression(
2696
+ createArrayExpression(slot.returns)
2697
+ );
2698
+ cachedAsArray = true;
2699
+ }
2700
+ }
2680
2701
  }
2681
- if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
2682
- const hoisted = context.hoist(
2683
- createArrayExpression(node.codegenNode.children)
2684
- );
2685
- if (context.hmr) {
2686
- hoisted.content = `[...${hoisted.content}]`;
2702
+ if (!cachedAsArray) {
2703
+ for (const child of toCache) {
2704
+ child.codegenNode = context.cache(child.codegenNode);
2705
+ }
2706
+ }
2707
+ function getCacheExpression(value) {
2708
+ const exp = context.cache(value);
2709
+ if (inFor && context.hmr) {
2710
+ exp.needArraySpread = true;
2687
2711
  }
2688
- node.codegenNode.children = hoisted;
2712
+ return exp;
2713
+ }
2714
+ function getSlotNode(node2, name) {
2715
+ if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
2716
+ const slot = node2.children.properties.find(
2717
+ (p) => p.key === name || p.key.content === name
2718
+ );
2719
+ return slot && slot.value;
2720
+ }
2721
+ }
2722
+ if (toCache.length && context.transformHoist) {
2723
+ context.transformHoist(children, context, node);
2689
2724
  }
2690
2725
  }
2691
2726
  function getConstantType(node, context) {
@@ -2703,11 +2738,10 @@ function getConstantType(node, context) {
2703
2738
  if (codegenNode.type !== 13) {
2704
2739
  return 0;
2705
2740
  }
2706
- if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
2741
+ if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
2707
2742
  return 0;
2708
2743
  }
2709
- const flag = getPatchFlag(codegenNode);
2710
- if (!flag) {
2744
+ if (codegenNode.patchFlag === void 0) {
2711
2745
  let returnType2 = 3;
2712
2746
  const generatedPropsType = getGeneratedPropsConstantType(node, context);
2713
2747
  if (generatedPropsType === 0) {
@@ -2790,6 +2824,8 @@ function getConstantType(node, context) {
2790
2824
  }
2791
2825
  }
2792
2826
  return returnType;
2827
+ case 20:
2828
+ return 2;
2793
2829
  default:
2794
2830
  if (!!(process.env.NODE_ENV !== "production")) ;
2795
2831
  return 0;
@@ -2850,15 +2886,11 @@ function getNodeProps(node) {
2850
2886
  return codegenNode.props;
2851
2887
  }
2852
2888
  }
2853
- function getPatchFlag(node) {
2854
- const flag = node.patchFlag;
2855
- return flag ? parseInt(flag, 10) : void 0;
2856
- }
2857
2889
 
2858
2890
  function createTransformContext(root, {
2859
2891
  filename = "",
2860
2892
  prefixIdentifiers = false,
2861
- hoistStatic: hoistStatic2 = false,
2893
+ hoistStatic = false,
2862
2894
  hmr = false,
2863
2895
  cacheHandlers = false,
2864
2896
  nodeTransforms = [],
@@ -2885,7 +2917,7 @@ function createTransformContext(root, {
2885
2917
  filename,
2886
2918
  selfName: nameMatch && capitalize(camelize(nameMatch[1])),
2887
2919
  prefixIdentifiers,
2888
- hoistStatic: hoistStatic2,
2920
+ hoistStatic,
2889
2921
  hmr,
2890
2922
  cacheHandlers,
2891
2923
  nodeTransforms,
@@ -2912,9 +2944,9 @@ function createTransformContext(root, {
2912
2944
  directives: /* @__PURE__ */ new Set(),
2913
2945
  hoists: [],
2914
2946
  imports: [],
2947
+ cached: [],
2915
2948
  constantCache: /* @__PURE__ */ new WeakMap(),
2916
2949
  temps: 0,
2917
- cached: 0,
2918
2950
  identifiers: /* @__PURE__ */ Object.create(null),
2919
2951
  scopes: {
2920
2952
  vFor: 0,
@@ -2984,8 +3016,7 @@ function createTransformContext(root, {
2984
3016
  removeIdentifiers(exp) {
2985
3017
  },
2986
3018
  hoist(exp) {
2987
- if (isString(exp))
2988
- exp = createSimpleExpression(exp);
3019
+ if (isString(exp)) exp = createSimpleExpression(exp);
2989
3020
  context.hoists.push(exp);
2990
3021
  const identifier = createSimpleExpression(
2991
3022
  `_hoisted_${context.hoists.length}`,
@@ -2997,7 +3028,13 @@ function createTransformContext(root, {
2997
3028
  return identifier;
2998
3029
  },
2999
3030
  cache(exp, isVNode = false) {
3000
- return createCacheExpression(context.cached++, exp, isVNode);
3031
+ const cacheExp = createCacheExpression(
3032
+ context.cached.length,
3033
+ exp,
3034
+ isVNode
3035
+ );
3036
+ context.cached.push(cacheExp);
3037
+ return cacheExp;
3001
3038
  }
3002
3039
  };
3003
3040
  {
@@ -3009,7 +3046,7 @@ function transform(root, options) {
3009
3046
  const context = createTransformContext(root, options);
3010
3047
  traverseNode(root, context);
3011
3048
  if (options.hoistStatic) {
3012
- hoistStatic(root, context);
3049
+ cacheStatic(root, context);
3013
3050
  }
3014
3051
  if (!options.ssr) {
3015
3052
  createRootCodegen(root, context);
@@ -3052,7 +3089,7 @@ function createRootCodegen(root, context) {
3052
3089
  helper(FRAGMENT),
3053
3090
  void 0,
3054
3091
  root.children,
3055
- patchFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${patchFlagText} */` : ``),
3092
+ patchFlag,
3056
3093
  void 0,
3057
3094
  void 0,
3058
3095
  true,
@@ -3068,8 +3105,7 @@ function traverseChildren(parent, context) {
3068
3105
  };
3069
3106
  for (; i < parent.children.length; i++) {
3070
3107
  const child = parent.children[i];
3071
- if (isString(child))
3072
- continue;
3108
+ if (isString(child)) continue;
3073
3109
  context.grandParent = context.parent;
3074
3110
  context.parent = parent;
3075
3111
  context.childIndex = i;
@@ -3140,8 +3176,7 @@ function createStructuralDirectiveTransform(name, fn) {
3140
3176
  props.splice(i, 1);
3141
3177
  i--;
3142
3178
  const onExit = fn(node, prop, context);
3143
- if (onExit)
3144
- exitFns.push(onExit);
3179
+ if (onExit) exitFns.push(onExit);
3145
3180
  }
3146
3181
  }
3147
3182
  return exitFns;
@@ -3213,8 +3248,7 @@ function createCodegenContext(ast, {
3213
3248
  }
3214
3249
  function generate(ast, options = {}) {
3215
3250
  const context = createCodegenContext(ast, options);
3216
- if (options.onContextCreated)
3217
- options.onContextCreated(context);
3251
+ if (options.onContextCreated) options.onContextCreated(context);
3218
3252
  const {
3219
3253
  mode,
3220
3254
  push,
@@ -3356,14 +3390,12 @@ function genHoists(hoists, context) {
3356
3390
  return;
3357
3391
  }
3358
3392
  context.pure = true;
3359
- const { push, newline, helper, scopeId, mode } = context;
3393
+ const { push, newline } = context;
3360
3394
  newline();
3361
3395
  for (let i = 0; i < hoists.length; i++) {
3362
3396
  const exp = hoists[i];
3363
3397
  if (exp) {
3364
- push(
3365
- `const _hoisted_${i + 1} = ${``}`
3366
- );
3398
+ push(`const _hoisted_${i + 1} = `);
3367
3399
  genNode(exp, context);
3368
3400
  newline();
3369
3401
  }
@@ -3496,8 +3528,7 @@ function genExpression(node, context) {
3496
3528
  }
3497
3529
  function genInterpolation(node, context) {
3498
3530
  const { push, helper, pure } = context;
3499
- if (pure)
3500
- push(PURE_ANNOTATION);
3531
+ if (pure) push(PURE_ANNOTATION);
3501
3532
  push(`${helper(TO_DISPLAY_STRING)}(`);
3502
3533
  genNode(node.content, context);
3503
3534
  push(`)`);
@@ -3549,6 +3580,19 @@ function genVNodeCall(node, context) {
3549
3580
  disableTracking,
3550
3581
  isComponent
3551
3582
  } = node;
3583
+ let patchFlagString;
3584
+ if (patchFlag) {
3585
+ if (!!(process.env.NODE_ENV !== "production")) {
3586
+ if (patchFlag < 0) {
3587
+ patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
3588
+ } else {
3589
+ const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
3590
+ patchFlagString = patchFlag + ` /* ${flagNames} */`;
3591
+ }
3592
+ } else {
3593
+ patchFlagString = String(patchFlag);
3594
+ }
3595
+ }
3552
3596
  if (directives) {
3553
3597
  push(helper(WITH_DIRECTIVES) + `(`);
3554
3598
  }
@@ -3561,7 +3605,7 @@ function genVNodeCall(node, context) {
3561
3605
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
3562
3606
  push(helper(callHelper) + `(`, -2 /* None */, node);
3563
3607
  genNodeList(
3564
- genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
3608
+ genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
3565
3609
  context
3566
3610
  );
3567
3611
  push(`)`);
@@ -3577,8 +3621,7 @@ function genVNodeCall(node, context) {
3577
3621
  function genNullableArgs(args) {
3578
3622
  let i = args.length;
3579
3623
  while (i--) {
3580
- if (args[i] != null)
3581
- break;
3624
+ if (args[i] != null) break;
3582
3625
  }
3583
3626
  return args.slice(0, i + 1).map((arg) => arg || `null`);
3584
3627
  }
@@ -3695,16 +3738,21 @@ function genConditionalExpression(node, context) {
3695
3738
  }
3696
3739
  function genCacheExpression(node, context) {
3697
3740
  const { push, helper, indent, deindent, newline } = context;
3741
+ const { needPauseTracking, needArraySpread } = node;
3742
+ if (needArraySpread) {
3743
+ push(`[...(`);
3744
+ }
3698
3745
  push(`_cache[${node.index}] || (`);
3699
- if (node.isVNode) {
3746
+ if (needPauseTracking) {
3700
3747
  indent();
3701
3748
  push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
3702
3749
  newline();
3750
+ push(`(`);
3703
3751
  }
3704
3752
  push(`_cache[${node.index}] = `);
3705
3753
  genNode(node.value, context);
3706
- if (node.isVNode) {
3707
- push(`,`);
3754
+ if (needPauseTracking) {
3755
+ push(`).cacheIndex = ${node.index},`);
3708
3756
  newline();
3709
3757
  push(`${helper(SET_BLOCK_TRACKING)}(1),`);
3710
3758
  newline();
@@ -3712,6 +3760,9 @@ function genCacheExpression(node, context) {
3712
3760
  deindent();
3713
3761
  }
3714
3762
  push(`)`);
3763
+ if (needArraySpread) {
3764
+ push(`)]`);
3765
+ }
3715
3766
  }
3716
3767
 
3717
3768
  const prohibitedKeywordRE = new RegExp(
@@ -3888,8 +3939,7 @@ function processIf(node, dir, context, processCodegen) {
3888
3939
  sibling.branches.push(branch);
3889
3940
  const onExit = processCodegen && processCodegen(sibling, branch, false);
3890
3941
  traverseNode(branch, context);
3891
- if (onExit)
3892
- onExit();
3942
+ if (onExit) onExit();
3893
3943
  context.currentNode = null;
3894
3944
  } else {
3895
3945
  context.onError(
@@ -3958,7 +4008,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
3958
4008
  helper(FRAGMENT),
3959
4009
  createObjectExpression([keyProperty]),
3960
4010
  children,
3961
- patchFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${patchFlagText} */` : ``),
4011
+ patchFlag,
3962
4012
  void 0,
3963
4013
  void 0,
3964
4014
  true,
@@ -4011,6 +4061,80 @@ function getParentCondition(node) {
4011
4061
  }
4012
4062
  }
4013
4063
 
4064
+ const transformBind = (dir, _node, context) => {
4065
+ const { modifiers, loc } = dir;
4066
+ const arg = dir.arg;
4067
+ let { exp } = dir;
4068
+ if (exp && exp.type === 4 && !exp.content.trim()) {
4069
+ {
4070
+ exp = void 0;
4071
+ }
4072
+ }
4073
+ if (!exp) {
4074
+ if (arg.type !== 4 || !arg.isStatic) {
4075
+ context.onError(
4076
+ createCompilerError(
4077
+ 52,
4078
+ arg.loc
4079
+ )
4080
+ );
4081
+ return {
4082
+ props: [
4083
+ createObjectProperty(arg, createSimpleExpression("", true, loc))
4084
+ ]
4085
+ };
4086
+ }
4087
+ transformBindShorthand(dir);
4088
+ exp = dir.exp;
4089
+ }
4090
+ if (arg.type !== 4) {
4091
+ arg.children.unshift(`(`);
4092
+ arg.children.push(`) || ""`);
4093
+ } else if (!arg.isStatic) {
4094
+ arg.content = `${arg.content} || ""`;
4095
+ }
4096
+ if (modifiers.includes("camel")) {
4097
+ if (arg.type === 4) {
4098
+ if (arg.isStatic) {
4099
+ arg.content = camelize(arg.content);
4100
+ } else {
4101
+ arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
4102
+ }
4103
+ } else {
4104
+ arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
4105
+ arg.children.push(`)`);
4106
+ }
4107
+ }
4108
+ if (!context.inSSR) {
4109
+ if (modifiers.includes("prop")) {
4110
+ injectPrefix(arg, ".");
4111
+ }
4112
+ if (modifiers.includes("attr")) {
4113
+ injectPrefix(arg, "^");
4114
+ }
4115
+ }
4116
+ return {
4117
+ props: [createObjectProperty(arg, exp)]
4118
+ };
4119
+ };
4120
+ const transformBindShorthand = (dir, context) => {
4121
+ const arg = dir.arg;
4122
+ const propName = camelize(arg.content);
4123
+ dir.exp = createSimpleExpression(propName, false, arg.loc);
4124
+ };
4125
+ const injectPrefix = (arg, prefix) => {
4126
+ if (arg.type === 4) {
4127
+ if (arg.isStatic) {
4128
+ arg.content = prefix + arg.content;
4129
+ } else {
4130
+ arg.content = `\`${prefix}\${${arg.content}}\``;
4131
+ }
4132
+ } else {
4133
+ arg.children.unshift(`'${prefix}' + (`);
4134
+ arg.children.push(`)`);
4135
+ }
4136
+ };
4137
+
4014
4138
  const transformFor = createStructuralDirectiveTransform(
4015
4139
  "for",
4016
4140
  (node, dir, context) => {
@@ -4021,9 +4145,12 @@ const transformFor = createStructuralDirectiveTransform(
4021
4145
  ]);
4022
4146
  const isTemplate = isTemplateNode(node);
4023
4147
  const memo = findDir(node, "memo");
4024
- const keyProp = findProp(node, `key`);
4025
- const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
4026
- const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
4148
+ const keyProp = findProp(node, `key`, false, true);
4149
+ if (keyProp && keyProp.type === 7 && !keyProp.exp) {
4150
+ transformBindShorthand(keyProp);
4151
+ }
4152
+ const keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
4153
+ const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
4027
4154
  const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
4028
4155
  const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
4029
4156
  forNode.codegenNode = createVNodeCall(
@@ -4031,7 +4158,7 @@ const transformFor = createStructuralDirectiveTransform(
4031
4158
  helper(FRAGMENT),
4032
4159
  void 0,
4033
4160
  renderExp,
4034
- fragmentFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``),
4161
+ fragmentFlag,
4035
4162
  void 0,
4036
4163
  void 0,
4037
4164
  true,
@@ -4071,7 +4198,7 @@ const transformFor = createStructuralDirectiveTransform(
4071
4198
  helper(FRAGMENT),
4072
4199
  keyProperty ? createObjectExpression([keyProperty]) : void 0,
4073
4200
  node.children,
4074
- 64 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[64]} */` : ``),
4201
+ 64,
4075
4202
  void 0,
4076
4203
  void 0,
4077
4204
  true,
@@ -4125,8 +4252,9 @@ const transformFor = createStructuralDirectiveTransform(
4125
4252
  renderExp.arguments.push(
4126
4253
  loop,
4127
4254
  createSimpleExpression(`_cache`),
4128
- createSimpleExpression(String(context.cached++))
4255
+ createSimpleExpression(String(context.cached.length))
4129
4256
  );
4257
+ context.cached.push(null);
4130
4258
  } else {
4131
4259
  renderExp.arguments.push(
4132
4260
  createFunctionExpression(
@@ -4172,13 +4300,11 @@ function processFor(node, dir, context, processCodegen) {
4172
4300
  const onExit = processCodegen && processCodegen(forNode);
4173
4301
  return () => {
4174
4302
  scopes.vFor--;
4175
- if (onExit)
4176
- onExit();
4303
+ if (onExit) onExit();
4177
4304
  };
4178
4305
  }
4179
4306
  function finalizeForParseResult(result, context) {
4180
- if (result.finalized)
4181
- return;
4307
+ if (result.finalized) return;
4182
4308
  if (!!(process.env.NODE_ENV !== "production") && true) {
4183
4309
  validateBrowserExpression(result.source, context);
4184
4310
  if (result.key) {
@@ -4211,8 +4337,7 @@ function createForLoopParams({ value, key, index }, memoArgs = []) {
4211
4337
  function createParamsList(args) {
4212
4338
  let i = args.length;
4213
4339
  while (i--) {
4214
- if (args[i])
4215
- break;
4340
+ if (args[i]) break;
4216
4341
  }
4217
4342
  return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
4218
4343
  }
@@ -4335,9 +4460,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
4335
4460
  break;
4336
4461
  }
4337
4462
  }
4338
- if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
4339
- children.splice(i, 1);
4340
- i--;
4463
+ if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
4341
4464
  let conditional = dynamicSlots[dynamicSlots.length - 1];
4342
4465
  while (conditional.alternate.type === 19) {
4343
4466
  conditional = conditional.alternate;
@@ -4474,13 +4597,11 @@ function hasForwardedSlots(children) {
4474
4597
  }
4475
4598
  break;
4476
4599
  case 9:
4477
- if (hasForwardedSlots(child.branches))
4478
- return true;
4600
+ if (hasForwardedSlots(child.branches)) return true;
4479
4601
  break;
4480
4602
  case 10:
4481
4603
  case 11:
4482
- if (hasForwardedSlots(child.children))
4483
- return true;
4604
+ if (hasForwardedSlots(child.children)) return true;
4484
4605
  break;
4485
4606
  }
4486
4607
  }
@@ -4505,7 +4626,6 @@ const transformElement = (node, context) => {
4505
4626
  const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
4506
4627
  let vnodeProps;
4507
4628
  let vnodeChildren;
4508
- let vnodePatchFlag;
4509
4629
  let patchFlag = 0;
4510
4630
  let vnodeDynamicProps;
4511
4631
  let dynamicPropNames;
@@ -4516,7 +4636,7 @@ const transformElement = (node, context) => {
4516
4636
  // updates inside get proper isSVG flag at runtime. (#639, #643)
4517
4637
  // This is technically web-specific, but splitting the logic out of core
4518
4638
  // leads to too much unnecessary complexity.
4519
- (tag === "svg" || tag === "foreignObject")
4639
+ (tag === "svg" || tag === "foreignObject" || tag === "math")
4520
4640
  );
4521
4641
  if (props.length > 0) {
4522
4642
  const propsBuildResult = buildProps(
@@ -4576,27 +4696,15 @@ const transformElement = (node, context) => {
4576
4696
  vnodeChildren = node.children;
4577
4697
  }
4578
4698
  }
4579
- if (patchFlag !== 0) {
4580
- if (!!(process.env.NODE_ENV !== "production")) {
4581
- if (patchFlag < 0) {
4582
- vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
4583
- } else {
4584
- const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
4585
- vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
4586
- }
4587
- } else {
4588
- vnodePatchFlag = String(patchFlag);
4589
- }
4590
- if (dynamicPropNames && dynamicPropNames.length) {
4591
- vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
4592
- }
4699
+ if (dynamicPropNames && dynamicPropNames.length) {
4700
+ vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
4593
4701
  }
4594
4702
  node.codegenNode = createVNodeCall(
4595
4703
  context,
4596
4704
  vnodeTag,
4597
4705
  vnodeProps,
4598
4706
  vnodeChildren,
4599
- vnodePatchFlag,
4707
+ patchFlag === 0 ? void 0 : patchFlag,
4600
4708
  vnodeDynamicProps,
4601
4709
  vnodeDirectives,
4602
4710
  !!shouldUseBlock,
@@ -4641,8 +4749,7 @@ function resolveComponentType(node, context, ssr = false) {
4641
4749
  }
4642
4750
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
4643
4751
  if (builtIn) {
4644
- if (!ssr)
4645
- context.helper(builtIn);
4752
+ if (!ssr) context.helper(builtIn);
4646
4753
  return builtIn;
4647
4754
  }
4648
4755
  context.helper(RESOLVE_COMPONENT);
@@ -4671,8 +4778,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4671
4778
  );
4672
4779
  properties = [];
4673
4780
  }
4674
- if (arg)
4675
- mergeArgs.push(arg);
4781
+ if (arg) mergeArgs.push(arg);
4676
4782
  };
4677
4783
  const pushRefVForMarker = () => {
4678
4784
  if (context.scopes.vFor > 0) {
@@ -5009,8 +5115,7 @@ function buildDirectiveArgs(dir, context) {
5009
5115
  }
5010
5116
  }
5011
5117
  const { loc } = dir;
5012
- if (dir.exp)
5013
- dirArgs.push(dir.exp);
5118
+ if (dir.exp) dirArgs.push(dir.exp);
5014
5119
  if (dir.arg) {
5015
5120
  if (!dir.exp) {
5016
5121
  dirArgs.push(`void 0`);
@@ -5040,8 +5145,7 @@ function stringifyDynamicPropNames(props) {
5040
5145
  let propsNamesString = `[`;
5041
5146
  for (let i = 0, l = props.length; i < l; i++) {
5042
5147
  propsNamesString += JSON.stringify(props[i]);
5043
- if (i < l - 1)
5044
- propsNamesString += ", ";
5148
+ if (i < l - 1) propsNamesString += ", ";
5045
5149
  }
5046
5150
  return propsNamesString + `]`;
5047
5151
  }
@@ -5135,7 +5239,7 @@ function processSlotOutlet(node, context) {
5135
5239
  };
5136
5240
  }
5137
5241
 
5138
- const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
5242
+ const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
5139
5243
  const transformOn = (dir, node, context, augmentor) => {
5140
5244
  const { loc, modifiers, arg } = dir;
5141
5245
  if (!dir.exp && !modifiers.length) {
@@ -5216,75 +5320,6 @@ const transformOn = (dir, node, context, augmentor) => {
5216
5320
  return ret;
5217
5321
  };
5218
5322
 
5219
- const transformBind = (dir, _node, context) => {
5220
- const { modifiers, loc } = dir;
5221
- const arg = dir.arg;
5222
- let { exp } = dir;
5223
- if (exp && exp.type === 4 && !exp.content.trim()) {
5224
- {
5225
- exp = void 0;
5226
- }
5227
- }
5228
- if (!exp) {
5229
- if (arg.type !== 4 || !arg.isStatic) {
5230
- context.onError(
5231
- createCompilerError(
5232
- 52,
5233
- arg.loc
5234
- )
5235
- );
5236
- return {
5237
- props: [
5238
- createObjectProperty(arg, createSimpleExpression("", true, loc))
5239
- ]
5240
- };
5241
- }
5242
- const propName = camelize(arg.content);
5243
- exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5244
- }
5245
- if (arg.type !== 4) {
5246
- arg.children.unshift(`(`);
5247
- arg.children.push(`) || ""`);
5248
- } else if (!arg.isStatic) {
5249
- arg.content = `${arg.content} || ""`;
5250
- }
5251
- if (modifiers.includes("camel")) {
5252
- if (arg.type === 4) {
5253
- if (arg.isStatic) {
5254
- arg.content = camelize(arg.content);
5255
- } else {
5256
- arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
5257
- }
5258
- } else {
5259
- arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
5260
- arg.children.push(`)`);
5261
- }
5262
- }
5263
- if (!context.inSSR) {
5264
- if (modifiers.includes("prop")) {
5265
- injectPrefix(arg, ".");
5266
- }
5267
- if (modifiers.includes("attr")) {
5268
- injectPrefix(arg, "^");
5269
- }
5270
- }
5271
- return {
5272
- props: [createObjectProperty(arg, exp)]
5273
- };
5274
- };
5275
- const injectPrefix = (arg, prefix) => {
5276
- if (arg.type === 4) {
5277
- if (arg.isStatic) {
5278
- arg.content = prefix + arg.content;
5279
- } else {
5280
- arg.content = `\`${prefix}\${${arg.content}}\``;
5281
- }
5282
- } else {
5283
- arg.children.unshift(`'${prefix}' + (`);
5284
- arg.children.push(`)`);
5285
- }
5286
- };
5287
-
5288
5323
  const transformText = (node, context) => {
5289
5324
  if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
5290
5325
  return () => {
@@ -5448,8 +5483,7 @@ const transformFilter = (node, context) => {
5448
5483
  }
5449
5484
  if (node.type === 5) {
5450
5485
  rewriteFilter(node.content, context);
5451
- }
5452
- if (node.type === 1) {
5486
+ } else if (node.type === 1) {
5453
5487
  node.props.forEach((prop) => {
5454
5488
  if (prop.type === 7 && prop.name !== "for" && prop.exp) {
5455
5489
  rewriteFilter(prop.exp, context);
@@ -5463,8 +5497,7 @@ function rewriteFilter(node, context) {
5463
5497
  } else {
5464
5498
  for (let i = 0; i < node.children.length; i++) {
5465
5499
  const child = node.children[i];
5466
- if (typeof child !== "object")
5467
- continue;
5500
+ if (typeof child !== "object") continue;
5468
5501
  if (child.type === 4) {
5469
5502
  parseFilter(child, context);
5470
5503
  } else if (child.type === 8) {
@@ -5490,17 +5523,13 @@ function parseFilter(node, context) {
5490
5523
  prev = c;
5491
5524
  c = exp.charCodeAt(i);
5492
5525
  if (inSingle) {
5493
- if (c === 39 && prev !== 92)
5494
- inSingle = false;
5526
+ if (c === 39 && prev !== 92) inSingle = false;
5495
5527
  } else if (inDouble) {
5496
- if (c === 34 && prev !== 92)
5497
- inDouble = false;
5528
+ if (c === 34 && prev !== 92) inDouble = false;
5498
5529
  } else if (inTemplateString) {
5499
- if (c === 96 && prev !== 92)
5500
- inTemplateString = false;
5530
+ if (c === 96 && prev !== 92) inTemplateString = false;
5501
5531
  } else if (inRegex) {
5502
- if (c === 47 && prev !== 92)
5503
- inRegex = false;
5532
+ if (c === 47 && prev !== 92) inRegex = false;
5504
5533
  } else if (c === 124 && // pipe
5505
5534
  exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
5506
5535
  if (expression === void 0) {
@@ -5544,8 +5573,7 @@ function parseFilter(node, context) {
5544
5573
  let p;
5545
5574
  for (; j >= 0; j--) {
5546
5575
  p = exp.charAt(j);
5547
- if (p !== " ")
5548
- break;
5576
+ if (p !== " ") break;
5549
5577
  }
5550
5578
  if (!p || !validDivisionCharRE.test(p)) {
5551
5579
  inRegex = true;
@@ -5572,6 +5600,7 @@ function parseFilter(node, context) {
5572
5600
  expression = wrapFilter(expression, filters[i], context);
5573
5601
  }
5574
5602
  node.content = expression;
5603
+ node.ast = void 0;
5575
5604
  }
5576
5605
  }
5577
5606
  function wrapFilter(exp, filter, context) {
@@ -5606,8 +5635,9 @@ const transformMemo = (node, context) => {
5606
5635
  dir.exp,
5607
5636
  createFunctionExpression(void 0, codegenNode),
5608
5637
  `_cache`,
5609
- String(context.cached++)
5638
+ String(context.cached.length)
5610
5639
  ]);
5640
+ context.cached.push(null);
5611
5641
  }
5612
5642
  };
5613
5643
  }