@vue/compiler-dom 3.5.17 → 3.6.0-alpha.1

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-dom v3.5.17
2
+ * @vue/compiler-dom v3.6.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -40,10 +40,9 @@ var VueCompilerDOM = (function (exports) {
40
40
  };
41
41
  };
42
42
  const camelizeRE = /-(\w)/g;
43
+ const camelizeReplacer = (_, c) => c ? c.toUpperCase() : "";
43
44
  const camelize = cacheStringFunction(
44
- (str) => {
45
- return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
46
- }
45
+ (str) => str.replace(camelizeRE, camelizeReplacer)
47
46
  );
48
47
  const capitalize = cacheStringFunction((str) => {
49
48
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -1718,7 +1717,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1718
1717
  const isFunctionType = (node) => {
1719
1718
  return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1720
1719
  };
1721
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1720
+ const isStaticProperty = (node) => !!node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1722
1721
  const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1723
1722
  const TS_NODE_TYPES = [
1724
1723
  "TSAsExpression",
@@ -1739,6 +1738,59 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1739
1738
  return node;
1740
1739
  }
1741
1740
  }
1741
+ function isStaticNode(node) {
1742
+ node = unwrapTSNode(node);
1743
+ switch (node.type) {
1744
+ case "UnaryExpression":
1745
+ return isStaticNode(node.argument);
1746
+ case "LogicalExpression":
1747
+ // 1 > 2
1748
+ case "BinaryExpression":
1749
+ return isStaticNode(node.left) && isStaticNode(node.right);
1750
+ case "ConditionalExpression": {
1751
+ return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
1752
+ }
1753
+ case "SequenceExpression":
1754
+ // (1, 2)
1755
+ case "TemplateLiteral":
1756
+ return node.expressions.every((expr) => isStaticNode(expr));
1757
+ case "ParenthesizedExpression":
1758
+ return isStaticNode(node.expression);
1759
+ case "StringLiteral":
1760
+ case "NumericLiteral":
1761
+ case "BooleanLiteral":
1762
+ case "NullLiteral":
1763
+ case "BigIntLiteral":
1764
+ return true;
1765
+ }
1766
+ return false;
1767
+ }
1768
+ function isConstantNode(node, bindings) {
1769
+ if (isStaticNode(node)) return true;
1770
+ node = unwrapTSNode(node);
1771
+ switch (node.type) {
1772
+ case "Identifier":
1773
+ const type = bindings[node.name];
1774
+ return type === "literal-const";
1775
+ case "RegExpLiteral":
1776
+ return true;
1777
+ case "ObjectExpression":
1778
+ return node.properties.every((prop) => {
1779
+ if (prop.type === "ObjectMethod") return false;
1780
+ if (prop.type === "SpreadElement")
1781
+ return isConstantNode(prop.argument, bindings);
1782
+ return (!prop.computed || isConstantNode(prop.key, bindings)) && isConstantNode(prop.value, bindings);
1783
+ });
1784
+ case "ArrayExpression":
1785
+ return node.elements.every((element) => {
1786
+ if (element === null) return true;
1787
+ if (element.type === "SpreadElement")
1788
+ return isConstantNode(element.argument, bindings);
1789
+ return isConstantNode(element, bindings);
1790
+ });
1791
+ }
1792
+ return false;
1793
+ }
1742
1794
 
1743
1795
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
1744
1796
  function isCoreComponent(tag) {
@@ -3089,6 +3141,10 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3089
3141
  }
3090
3142
  }
3091
3143
 
3144
+ function getSelfName(filename) {
3145
+ const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
3146
+ return nameMatch ? capitalize(camelize(nameMatch[1])) : null;
3147
+ }
3092
3148
  function createTransformContext(root, {
3093
3149
  filename = "",
3094
3150
  prefixIdentifiers = false,
@@ -3113,11 +3169,10 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3113
3169
  onWarn = defaultOnWarn,
3114
3170
  compatConfig
3115
3171
  }) {
3116
- const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
3117
3172
  const context = {
3118
3173
  // options
3119
3174
  filename,
3120
- selfName: nameMatch && capitalize(camelize(nameMatch[1])),
3175
+ selfName: getSelfName(filename),
3121
3176
  prefixIdentifiers,
3122
3177
  hoistStatic,
3123
3178
  hmr,
@@ -3388,6 +3443,16 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3388
3443
 
3389
3444
  const PURE_ANNOTATION = `/*@__PURE__*/`;
3390
3445
  const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
3446
+ const NewlineType = {
3447
+ "Start": 0,
3448
+ "0": "Start",
3449
+ "End": -1,
3450
+ "-1": "End",
3451
+ "None": -2,
3452
+ "-2": "None",
3453
+ "Unknown": -3,
3454
+ "-3": "Unknown"
3455
+ };
3391
3456
  function createCodegenContext(ast, {
3392
3457
  mode = "function",
3393
3458
  prefixIdentifiers = mode === "module",
@@ -3426,7 +3491,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3426
3491
  helper(key) {
3427
3492
  return `_${helperNameMap[key]}`;
3428
3493
  },
3429
- push(code, newlineIndex = -2 /* None */, node) {
3494
+ push(code, newlineIndex = -2, node) {
3430
3495
  context.code += code;
3431
3496
  },
3432
3497
  indent() {
@@ -3444,7 +3509,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3444
3509
  }
3445
3510
  };
3446
3511
  function newline(n) {
3447
- context.push("\n" + ` `.repeat(n), 0 /* Start */);
3512
+ context.push("\n" + ` `.repeat(n), 0);
3448
3513
  }
3449
3514
  return context;
3450
3515
  }
@@ -3482,7 +3547,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3482
3547
  push(
3483
3548
  `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3484
3549
  `,
3485
- -1 /* End */
3550
+ -1
3486
3551
  );
3487
3552
  newline();
3488
3553
  }
@@ -3512,7 +3577,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3512
3577
  }
3513
3578
  if (ast.components.length || ast.directives.length || ast.temps) {
3514
3579
  push(`
3515
- `, 0 /* Start */);
3580
+ `, 0);
3516
3581
  newline();
3517
3582
  }
3518
3583
  if (!ssr) {
@@ -3533,7 +3598,8 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3533
3598
  ast,
3534
3599
  code: context.code,
3535
3600
  preamble: ``,
3536
- map: context.map ? context.map.toJSON() : void 0
3601
+ map: context.map ? context.map.toJSON() : void 0,
3602
+ helpers: ast.helpers
3537
3603
  };
3538
3604
  }
3539
3605
  function genFunctionPreamble(ast, context) {
@@ -3551,7 +3617,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3551
3617
  if (helpers.length > 0) {
3552
3618
  {
3553
3619
  push(`const _Vue = ${VueBinding}
3554
- `, -1 /* End */);
3620
+ `, -1);
3555
3621
  if (ast.hoists.length) {
3556
3622
  const staticHelpers = [
3557
3623
  CREATE_VNODE,
@@ -3561,7 +3627,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3561
3627
  CREATE_STATIC
3562
3628
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
3563
3629
  push(`const { ${staticHelpers} } = _Vue
3564
- `, -1 /* End */);
3630
+ `, -1);
3565
3631
  }
3566
3632
  }
3567
3633
  }
@@ -3620,7 +3686,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3620
3686
  for (let i = 0; i < nodes.length; i++) {
3621
3687
  const node = nodes[i];
3622
3688
  if (isString(node)) {
3623
- push(node, -3 /* Unknown */);
3689
+ push(node, -3);
3624
3690
  } else if (isArray(node)) {
3625
3691
  genNodeListAsArray(node, context);
3626
3692
  } else {
@@ -3638,7 +3704,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3638
3704
  }
3639
3705
  function genNode(node, context) {
3640
3706
  if (isString(node)) {
3641
- context.push(node, -3 /* Unknown */);
3707
+ context.push(node, -3);
3642
3708
  return;
3643
3709
  }
3644
3710
  if (isSymbol(node)) {
@@ -3720,13 +3786,13 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3720
3786
  }
3721
3787
  }
3722
3788
  function genText(node, context) {
3723
- context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
3789
+ context.push(JSON.stringify(node.content), -3, node);
3724
3790
  }
3725
3791
  function genExpression(node, context) {
3726
3792
  const { content, isStatic } = node;
3727
3793
  context.push(
3728
3794
  isStatic ? JSON.stringify(content) : content,
3729
- -3 /* Unknown */,
3795
+ -3,
3730
3796
  node
3731
3797
  );
3732
3798
  }
@@ -3741,7 +3807,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3741
3807
  for (let i = 0; i < node.children.length; i++) {
3742
3808
  const child = node.children[i];
3743
3809
  if (isString(child)) {
3744
- context.push(child, -3 /* Unknown */);
3810
+ context.push(child, -3);
3745
3811
  } else {
3746
3812
  genNode(child, context);
3747
3813
  }
@@ -3755,9 +3821,9 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3755
3821
  push(`]`);
3756
3822
  } else if (node.isStatic) {
3757
3823
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
3758
- push(text, -2 /* None */, node);
3824
+ push(text, -2, node);
3759
3825
  } else {
3760
- push(`[${node.content}]`, -3 /* Unknown */, node);
3826
+ push(`[${node.content}]`, -3, node);
3761
3827
  }
3762
3828
  }
3763
3829
  function genComment(node, context) {
@@ -3767,7 +3833,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3767
3833
  }
3768
3834
  push(
3769
3835
  `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
3770
- -3 /* Unknown */,
3836
+ -3,
3771
3837
  node
3772
3838
  );
3773
3839
  }
@@ -3805,7 +3871,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3805
3871
  push(PURE_ANNOTATION);
3806
3872
  }
3807
3873
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
3808
- push(helper(callHelper) + `(`, -2 /* None */, node);
3874
+ push(helper(callHelper) + `(`, -2, node);
3809
3875
  genNodeList(
3810
3876
  genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
3811
3877
  context
@@ -3833,7 +3899,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3833
3899
  if (pure) {
3834
3900
  push(PURE_ANNOTATION);
3835
3901
  }
3836
- push(callee + `(`, -2 /* None */, node);
3902
+ push(callee + `(`, -2, node);
3837
3903
  genNodeList(node.arguments, context);
3838
3904
  push(`)`);
3839
3905
  }
@@ -3841,7 +3907,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3841
3907
  const { push, indent, deindent, newline } = context;
3842
3908
  const { properties } = node;
3843
3909
  if (!properties.length) {
3844
- push(`{}`, -2 /* None */, node);
3910
+ push(`{}`, -2, node);
3845
3911
  return;
3846
3912
  }
3847
3913
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -3869,7 +3935,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3869
3935
  if (isSlot) {
3870
3936
  push(`_${helperNameMap[WITH_CTX]}(`);
3871
3937
  }
3872
- push(`(`, -2 /* None */, node);
3938
+ push(`(`, -2, node);
3873
3939
  if (isArray(params)) {
3874
3940
  genNodeList(params, context);
3875
3941
  } else if (params) {
@@ -3999,6 +4065,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
3999
4065
  }
4000
4066
  }
4001
4067
 
4068
+ const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
4002
4069
  const transformExpression = (node, context) => {
4003
4070
  if (node.type === 5) {
4004
4071
  node.content = processExpression(
@@ -6098,7 +6165,9 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6098
6165
  [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
6099
6166
  [61]: `v-show is missing expression.`,
6100
6167
  [62]: `<Transition> expects exactly one child element or component.`,
6101
- [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
6168
+ [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`,
6169
+ // just to fulfill types
6170
+ [64]: ``
6102
6171
  };
6103
6172
 
6104
6173
  const transformVHtml = (dir, node, context) => {
@@ -6247,7 +6316,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6247
6316
  const eventOptionModifiers = [];
6248
6317
  for (let i = 0; i < modifiers.length; i++) {
6249
6318
  const modifier = modifiers[i].content;
6250
- if (modifier === "native" && checkCompatEnabled(
6319
+ if (modifier === "native" && context && checkCompatEnabled(
6251
6320
  "COMPILER_V_ON_NATIVE",
6252
6321
  context,
6253
6322
  loc
@@ -6256,9 +6325,10 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6256
6325
  } else if (isEventOptionModifier(modifier)) {
6257
6326
  eventOptionModifiers.push(modifier);
6258
6327
  } else {
6328
+ const keyString = isString(key) ? key : isStaticExp(key) ? key.content : null;
6259
6329
  if (maybeKeyModifier(modifier)) {
6260
- if (isStaticExp(key)) {
6261
- if (isKeyboardEvent(key.content.toLowerCase())) {
6330
+ if (keyString) {
6331
+ if (isKeyboardEvent(keyString.toLowerCase())) {
6262
6332
  keyModifiers.push(modifier);
6263
6333
  } else {
6264
6334
  nonKeyModifiers.push(modifier);
@@ -6642,6 +6712,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6642
6712
  exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
6643
6713
  exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
6644
6714
  exports.Namespaces = Namespaces;
6715
+ exports.NewlineType = NewlineType;
6645
6716
  exports.NodeTypes = NodeTypes;
6646
6717
  exports.OPEN_BLOCK = OPEN_BLOCK;
6647
6718
  exports.POP_SCOPE_ID = POP_SCOPE_ID;
@@ -6707,6 +6778,8 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6707
6778
  exports.createTemplateLiteral = createTemplateLiteral;
6708
6779
  exports.createTransformContext = createTransformContext;
6709
6780
  exports.createVNodeCall = createVNodeCall;
6781
+ exports.defaultOnError = defaultOnError;
6782
+ exports.defaultOnWarn = defaultOnWarn;
6710
6783
  exports.errorMessages = errorMessages;
6711
6784
  exports.extractIdentifiers = extractIdentifiers;
6712
6785
  exports.findDir = findDir;
@@ -6717,12 +6790,14 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6717
6790
  exports.getBaseTransformPreset = getBaseTransformPreset;
6718
6791
  exports.getConstantType = getConstantType;
6719
6792
  exports.getMemoedVNodeCall = getMemoedVNodeCall;
6793
+ exports.getSelfName = getSelfName;
6720
6794
  exports.getVNodeBlockHelper = getVNodeBlockHelper;
6721
6795
  exports.getVNodeHelper = getVNodeHelper;
6722
6796
  exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
6723
6797
  exports.hasScopeRef = hasScopeRef;
6724
6798
  exports.helperNameMap = helperNameMap;
6725
6799
  exports.injectProp = injectProp;
6800
+ exports.isConstantNode = isConstantNode;
6726
6801
  exports.isCoreComponent = isCoreComponent;
6727
6802
  exports.isFnExpression = isFnExpression;
6728
6803
  exports.isFnExpressionBrowser = isFnExpressionBrowser;
@@ -6730,6 +6805,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6730
6805
  exports.isFunctionType = isFunctionType;
6731
6806
  exports.isInDestructureAssignment = isInDestructureAssignment;
6732
6807
  exports.isInNewExpression = isInNewExpression;
6808
+ exports.isLiteralWhitelisted = isLiteralWhitelisted;
6733
6809
  exports.isMemberExpression = isMemberExpression;
6734
6810
  exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
6735
6811
  exports.isMemberExpressionNode = isMemberExpressionNode;
@@ -6738,11 +6814,13 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6738
6814
  exports.isSlotOutlet = isSlotOutlet;
6739
6815
  exports.isStaticArgOf = isStaticArgOf;
6740
6816
  exports.isStaticExp = isStaticExp;
6817
+ exports.isStaticNode = isStaticNode;
6741
6818
  exports.isStaticProperty = isStaticProperty;
6742
6819
  exports.isStaticPropertyKey = isStaticPropertyKey;
6743
6820
  exports.isTemplateNode = isTemplateNode;
6744
6821
  exports.isText = isText$1;
6745
6822
  exports.isVSlot = isVSlot;
6823
+ exports.isValidHTMLNesting = isValidHTMLNesting;
6746
6824
  exports.locStub = locStub;
6747
6825
  exports.noopDirectiveTransform = noopDirectiveTransform;
6748
6826
  exports.parse = parse;
@@ -6753,6 +6831,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6753
6831
  exports.processSlotOutlet = processSlotOutlet;
6754
6832
  exports.registerRuntimeHelpers = registerRuntimeHelpers;
6755
6833
  exports.resolveComponentType = resolveComponentType;
6834
+ exports.resolveModifiers = resolveModifiers;
6756
6835
  exports.stringifyExpression = stringifyExpression;
6757
6836
  exports.toValidAssetId = toValidAssetId;
6758
6837
  exports.trackSlotScopes = trackSlotScopes;