@vue/compiler-core 3.5.16 → 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-core v3.5.16
2
+ * @vue/compiler-core v3.6.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -1063,7 +1063,7 @@ class Tokenizer {
1063
1063
  this.buffer = input;
1064
1064
  while (this.index < this.buffer.length) {
1065
1065
  const c = this.buffer.charCodeAt(this.index);
1066
- if (c === 10) {
1066
+ if (c === 10 && this.state !== 33) {
1067
1067
  this.newlines.push(this.index);
1068
1068
  }
1069
1069
  switch (this.state) {
@@ -1735,7 +1735,7 @@ function markScopeIdentifier(node, child, knownIds) {
1735
1735
  const isFunctionType = (node) => {
1736
1736
  return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1737
1737
  };
1738
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1738
+ const isStaticProperty = (node) => !!node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1739
1739
  const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1740
1740
  function isReferenced(node, parent, grandparent) {
1741
1741
  switch (parent.type) {
@@ -1894,6 +1894,59 @@ function unwrapTSNode(node) {
1894
1894
  return node;
1895
1895
  }
1896
1896
  }
1897
+ function isStaticNode(node) {
1898
+ node = unwrapTSNode(node);
1899
+ switch (node.type) {
1900
+ case "UnaryExpression":
1901
+ return isStaticNode(node.argument);
1902
+ case "LogicalExpression":
1903
+ // 1 > 2
1904
+ case "BinaryExpression":
1905
+ return isStaticNode(node.left) && isStaticNode(node.right);
1906
+ case "ConditionalExpression": {
1907
+ return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
1908
+ }
1909
+ case "SequenceExpression":
1910
+ // (1, 2)
1911
+ case "TemplateLiteral":
1912
+ return node.expressions.every((expr) => isStaticNode(expr));
1913
+ case "ParenthesizedExpression":
1914
+ return isStaticNode(node.expression);
1915
+ case "StringLiteral":
1916
+ case "NumericLiteral":
1917
+ case "BooleanLiteral":
1918
+ case "NullLiteral":
1919
+ case "BigIntLiteral":
1920
+ return true;
1921
+ }
1922
+ return false;
1923
+ }
1924
+ function isConstantNode(node, bindings) {
1925
+ if (isStaticNode(node)) return true;
1926
+ node = unwrapTSNode(node);
1927
+ switch (node.type) {
1928
+ case "Identifier":
1929
+ const type = bindings[node.name];
1930
+ return type === "literal-const";
1931
+ case "RegExpLiteral":
1932
+ return true;
1933
+ case "ObjectExpression":
1934
+ return node.properties.every((prop) => {
1935
+ if (prop.type === "ObjectMethod") return false;
1936
+ if (prop.type === "SpreadElement")
1937
+ return isConstantNode(prop.argument, bindings);
1938
+ return (!prop.computed || isConstantNode(prop.key, bindings)) && isConstantNode(prop.value, bindings);
1939
+ });
1940
+ case "ArrayExpression":
1941
+ return node.elements.every((element) => {
1942
+ if (element === null) return true;
1943
+ if (element.type === "SpreadElement")
1944
+ return isConstantNode(element.argument, bindings);
1945
+ return isConstantNode(element, bindings);
1946
+ });
1947
+ }
1948
+ return false;
1949
+ }
1897
1950
 
1898
1951
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
1899
1952
  function isCoreComponent(tag) {
@@ -2813,7 +2866,7 @@ function isUpperCase(c) {
2813
2866
  return c > 64 && c < 91;
2814
2867
  }
2815
2868
  const windowsNewlineRE = /\r\n/g;
2816
- function condenseWhitespace(nodes, tag) {
2869
+ function condenseWhitespace(nodes) {
2817
2870
  const shouldCondense = currentOptions.whitespace !== "preserve";
2818
2871
  let removedWhitespace = false;
2819
2872
  for (let i = 0; i < nodes.length; i++) {
@@ -2999,12 +3052,12 @@ function cacheStatic(root, context) {
2999
3052
  context,
3000
3053
  // Root node is unfortunately non-hoistable due to potential parent
3001
3054
  // fallthrough attributes.
3002
- isSingleElementRoot(root, root.children[0])
3055
+ !!getSingleElementRoot(root)
3003
3056
  );
3004
3057
  }
3005
- function isSingleElementRoot(root, child) {
3006
- const { children } = root;
3007
- return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
3058
+ function getSingleElementRoot(root) {
3059
+ const children = root.children.filter((x) => x.type !== 3);
3060
+ return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
3008
3061
  }
3009
3062
  function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
3010
3063
  const { children } = node;
@@ -3289,6 +3342,10 @@ function getNodeProps(node) {
3289
3342
  }
3290
3343
  }
3291
3344
 
3345
+ function getSelfName(filename) {
3346
+ const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
3347
+ return nameMatch ? shared.capitalize(shared.camelize(nameMatch[1])) : null;
3348
+ }
3292
3349
  function createTransformContext(root, {
3293
3350
  filename = "",
3294
3351
  prefixIdentifiers = false,
@@ -3313,11 +3370,10 @@ function createTransformContext(root, {
3313
3370
  onWarn = defaultOnWarn,
3314
3371
  compatConfig
3315
3372
  }) {
3316
- const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
3317
3373
  const context = {
3318
3374
  // options
3319
3375
  filename,
3320
- selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
3376
+ selfName: getSelfName(filename),
3321
3377
  prefixIdentifiers,
3322
3378
  hoistStatic,
3323
3379
  hmr,
@@ -3498,15 +3554,15 @@ function createRootCodegen(root, context) {
3498
3554
  const { helper } = context;
3499
3555
  const { children } = root;
3500
3556
  if (children.length === 1) {
3501
- const child = children[0];
3502
- if (isSingleElementRoot(root, child) && child.codegenNode) {
3503
- const codegenNode = child.codegenNode;
3557
+ const singleElementRootChild = getSingleElementRoot(root);
3558
+ if (singleElementRootChild && singleElementRootChild.codegenNode) {
3559
+ const codegenNode = singleElementRootChild.codegenNode;
3504
3560
  if (codegenNode.type === 13) {
3505
3561
  convertToBlock(codegenNode, context);
3506
3562
  }
3507
3563
  root.codegenNode = codegenNode;
3508
3564
  } else {
3509
- root.codegenNode = child;
3565
+ root.codegenNode = children[0];
3510
3566
  }
3511
3567
  } else if (children.length > 1) {
3512
3568
  let patchFlag = 64;
@@ -3616,6 +3672,16 @@ function createStructuralDirectiveTransform(name, fn) {
3616
3672
 
3617
3673
  const PURE_ANNOTATION = `/*@__PURE__*/`;
3618
3674
  const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
3675
+ const NewlineType = {
3676
+ "Start": 0,
3677
+ "0": "Start",
3678
+ "End": -1,
3679
+ "-1": "End",
3680
+ "None": -2,
3681
+ "-2": "None",
3682
+ "Unknown": -3,
3683
+ "-3": "Unknown"
3684
+ };
3619
3685
  function createCodegenContext(ast, {
3620
3686
  mode = "function",
3621
3687
  prefixIdentifiers = mode === "module",
@@ -3654,7 +3720,7 @@ function createCodegenContext(ast, {
3654
3720
  helper(key) {
3655
3721
  return `_${helperNameMap[key]}`;
3656
3722
  },
3657
- push(code, newlineIndex = -2 /* None */, node) {
3723
+ push(code, newlineIndex = -2, node) {
3658
3724
  context.code += code;
3659
3725
  if (context.map) {
3660
3726
  if (node) {
@@ -3669,14 +3735,14 @@ function createCodegenContext(ast, {
3669
3735
  addMapping(node.loc.start, name);
3670
3736
  }
3671
3737
  }
3672
- if (newlineIndex === -3 /* Unknown */) {
3738
+ if (newlineIndex === -3) {
3673
3739
  advancePositionWithMutation(context, code);
3674
3740
  } else {
3675
3741
  context.offset += code.length;
3676
- if (newlineIndex === -2 /* None */) {
3742
+ if (newlineIndex === -2) {
3677
3743
  context.column += code.length;
3678
3744
  } else {
3679
- if (newlineIndex === -1 /* End */) {
3745
+ if (newlineIndex === -1) {
3680
3746
  newlineIndex = code.length - 1;
3681
3747
  }
3682
3748
  context.line++;
@@ -3703,7 +3769,7 @@ function createCodegenContext(ast, {
3703
3769
  }
3704
3770
  };
3705
3771
  function newline(n) {
3706
- context.push("\n" + ` `.repeat(n), 0 /* Start */);
3772
+ context.push("\n" + ` `.repeat(n), 0);
3707
3773
  }
3708
3774
  function addMapping(loc, name = null) {
3709
3775
  const { _names, _mappings } = context.map;
@@ -3768,7 +3834,7 @@ function generate(ast, options = {}) {
3768
3834
  push(
3769
3835
  `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3770
3836
  `,
3771
- -1 /* End */
3837
+ -1
3772
3838
  );
3773
3839
  newline();
3774
3840
  }
@@ -3798,7 +3864,7 @@ function generate(ast, options = {}) {
3798
3864
  }
3799
3865
  if (ast.components.length || ast.directives.length || ast.temps) {
3800
3866
  push(`
3801
- `, 0 /* Start */);
3867
+ `, 0);
3802
3868
  newline();
3803
3869
  }
3804
3870
  if (!ssr) {
@@ -3819,7 +3885,8 @@ function generate(ast, options = {}) {
3819
3885
  ast,
3820
3886
  code: context.code,
3821
3887
  preamble: isSetupInlined ? preambleContext.code : ``,
3822
- map: context.map ? context.map.toJSON() : void 0
3888
+ map: context.map ? context.map.toJSON() : void 0,
3889
+ helpers: ast.helpers
3823
3890
  };
3824
3891
  }
3825
3892
  function genFunctionPreamble(ast, context) {
@@ -3839,11 +3906,11 @@ function genFunctionPreamble(ast, context) {
3839
3906
  push(
3840
3907
  `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
3841
3908
  `,
3842
- -1 /* End */
3909
+ -1
3843
3910
  );
3844
3911
  } else {
3845
3912
  push(`const _Vue = ${VueBinding}
3846
- `, -1 /* End */);
3913
+ `, -1);
3847
3914
  if (ast.hoists.length) {
3848
3915
  const staticHelpers = [
3849
3916
  CREATE_VNODE,
@@ -3853,7 +3920,7 @@ function genFunctionPreamble(ast, context) {
3853
3920
  CREATE_STATIC
3854
3921
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
3855
3922
  push(`const { ${staticHelpers} } = _Vue
3856
- `, -1 /* End */);
3923
+ `, -1);
3857
3924
  }
3858
3925
  }
3859
3926
  }
@@ -3861,7 +3928,7 @@ function genFunctionPreamble(ast, context) {
3861
3928
  push(
3862
3929
  `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
3863
3930
  `,
3864
- -1 /* End */
3931
+ -1
3865
3932
  );
3866
3933
  }
3867
3934
  genHoists(ast.hoists, context);
@@ -3882,20 +3949,20 @@ function genModulePreamble(ast, context, genScopeId, inline) {
3882
3949
  push(
3883
3950
  `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
3884
3951
  `,
3885
- -1 /* End */
3952
+ -1
3886
3953
  );
3887
3954
  push(
3888
3955
  `
3889
3956
  // Binding optimization for webpack code-split
3890
3957
  const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
3891
3958
  `,
3892
- -1 /* End */
3959
+ -1
3893
3960
  );
3894
3961
  } else {
3895
3962
  push(
3896
3963
  `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
3897
3964
  `,
3898
- -1 /* End */
3965
+ -1
3899
3966
  );
3900
3967
  }
3901
3968
  }
@@ -3903,7 +3970,7 @@ const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(",
3903
3970
  push(
3904
3971
  `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
3905
3972
  `,
3906
- -1 /* End */
3973
+ -1
3907
3974
  );
3908
3975
  }
3909
3976
  if (ast.imports.length) {
@@ -3978,7 +4045,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
3978
4045
  for (let i = 0; i < nodes.length; i++) {
3979
4046
  const node = nodes[i];
3980
4047
  if (shared.isString(node)) {
3981
- push(node, -3 /* Unknown */);
4048
+ push(node, -3);
3982
4049
  } else if (shared.isArray(node)) {
3983
4050
  genNodeListAsArray(node, context);
3984
4051
  } else {
@@ -3996,7 +4063,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
3996
4063
  }
3997
4064
  function genNode(node, context) {
3998
4065
  if (shared.isString(node)) {
3999
- context.push(node, -3 /* Unknown */);
4066
+ context.push(node, -3);
4000
4067
  return;
4001
4068
  }
4002
4069
  if (shared.isSymbol(node)) {
@@ -4083,13 +4150,13 @@ function genNode(node, context) {
4083
4150
  }
4084
4151
  }
4085
4152
  function genText(node, context) {
4086
- context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
4153
+ context.push(JSON.stringify(node.content), -3, node);
4087
4154
  }
4088
4155
  function genExpression(node, context) {
4089
4156
  const { content, isStatic } = node;
4090
4157
  context.push(
4091
4158
  isStatic ? JSON.stringify(content) : content,
4092
- -3 /* Unknown */,
4159
+ -3,
4093
4160
  node
4094
4161
  );
4095
4162
  }
@@ -4104,7 +4171,7 @@ function genCompoundExpression(node, context) {
4104
4171
  for (let i = 0; i < node.children.length; i++) {
4105
4172
  const child = node.children[i];
4106
4173
  if (shared.isString(child)) {
4107
- context.push(child, -3 /* Unknown */);
4174
+ context.push(child, -3);
4108
4175
  } else {
4109
4176
  genNode(child, context);
4110
4177
  }
@@ -4118,9 +4185,9 @@ function genExpressionAsPropertyKey(node, context) {
4118
4185
  push(`]`);
4119
4186
  } else if (node.isStatic) {
4120
4187
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
4121
- push(text, -2 /* None */, node);
4188
+ push(text, -2, node);
4122
4189
  } else {
4123
- push(`[${node.content}]`, -3 /* Unknown */, node);
4190
+ push(`[${node.content}]`, -3, node);
4124
4191
  }
4125
4192
  }
4126
4193
  function genComment(node, context) {
@@ -4130,7 +4197,7 @@ function genComment(node, context) {
4130
4197
  }
4131
4198
  push(
4132
4199
  `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
4133
- -3 /* Unknown */,
4200
+ -3,
4134
4201
  node
4135
4202
  );
4136
4203
  }
@@ -4168,7 +4235,7 @@ function genVNodeCall(node, context) {
4168
4235
  push(PURE_ANNOTATION);
4169
4236
  }
4170
4237
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
4171
- push(helper(callHelper) + `(`, -2 /* None */, node);
4238
+ push(helper(callHelper) + `(`, -2, node);
4172
4239
  genNodeList(
4173
4240
  genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
4174
4241
  context
@@ -4196,7 +4263,7 @@ function genCallExpression(node, context) {
4196
4263
  if (pure) {
4197
4264
  push(PURE_ANNOTATION);
4198
4265
  }
4199
- push(callee + `(`, -2 /* None */, node);
4266
+ push(callee + `(`, -2, node);
4200
4267
  genNodeList(node.arguments, context);
4201
4268
  push(`)`);
4202
4269
  }
@@ -4204,7 +4271,7 @@ function genObjectExpression(node, context) {
4204
4271
  const { push, indent, deindent, newline } = context;
4205
4272
  const { properties } = node;
4206
4273
  if (!properties.length) {
4207
- push(`{}`, -2 /* None */, node);
4274
+ push(`{}`, -2, node);
4208
4275
  return;
4209
4276
  }
4210
4277
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -4232,7 +4299,7 @@ function genFunctionExpression(node, context) {
4232
4299
  if (isSlot) {
4233
4300
  push(`_${helperNameMap[WITH_CTX]}(`);
4234
4301
  }
4235
- push(`(`, -2 /* None */, node);
4302
+ push(`(`, -2, node);
4236
4303
  if (shared.isArray(params)) {
4237
4304
  genNodeList(params, context);
4238
4305
  } else if (params) {
@@ -4339,7 +4406,7 @@ function genTemplateLiteral(node, context) {
4339
4406
  for (let i = 0; i < l; i++) {
4340
4407
  const e = node.elements[i];
4341
4408
  if (shared.isString(e)) {
4342
- push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
4409
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3);
4343
4410
  } else {
4344
4411
  push("${");
4345
4412
  if (multilines) indent();
@@ -5290,7 +5357,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
5290
5357
  let prev;
5291
5358
  while (j--) {
5292
5359
  prev = children[j];
5293
- if (prev.type !== 3) {
5360
+ if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
5294
5361
  break;
5295
5362
  }
5296
5363
  }
@@ -6714,6 +6781,7 @@ exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
6714
6781
  exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
6715
6782
  exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
6716
6783
  exports.Namespaces = Namespaces;
6784
+ exports.NewlineType = NewlineType;
6717
6785
  exports.NodeTypes = NodeTypes;
6718
6786
  exports.OPEN_BLOCK = OPEN_BLOCK;
6719
6787
  exports.POP_SCOPE_ID = POP_SCOPE_ID;
@@ -6767,6 +6835,8 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
6767
6835
  exports.createTemplateLiteral = createTemplateLiteral;
6768
6836
  exports.createTransformContext = createTransformContext;
6769
6837
  exports.createVNodeCall = createVNodeCall;
6838
+ exports.defaultOnError = defaultOnError;
6839
+ exports.defaultOnWarn = defaultOnWarn;
6770
6840
  exports.errorMessages = errorMessages;
6771
6841
  exports.extractIdentifiers = extractIdentifiers;
6772
6842
  exports.findDir = findDir;
@@ -6776,12 +6846,14 @@ exports.generate = generate;
6776
6846
  exports.getBaseTransformPreset = getBaseTransformPreset;
6777
6847
  exports.getConstantType = getConstantType;
6778
6848
  exports.getMemoedVNodeCall = getMemoedVNodeCall;
6849
+ exports.getSelfName = getSelfName;
6779
6850
  exports.getVNodeBlockHelper = getVNodeBlockHelper;
6780
6851
  exports.getVNodeHelper = getVNodeHelper;
6781
6852
  exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
6782
6853
  exports.hasScopeRef = hasScopeRef;
6783
6854
  exports.helperNameMap = helperNameMap;
6784
6855
  exports.injectProp = injectProp;
6856
+ exports.isConstantNode = isConstantNode;
6785
6857
  exports.isCoreComponent = isCoreComponent;
6786
6858
  exports.isFnExpression = isFnExpression;
6787
6859
  exports.isFnExpressionBrowser = isFnExpressionBrowser;
@@ -6789,6 +6861,7 @@ exports.isFnExpressionNode = isFnExpressionNode;
6789
6861
  exports.isFunctionType = isFunctionType;
6790
6862
  exports.isInDestructureAssignment = isInDestructureAssignment;
6791
6863
  exports.isInNewExpression = isInNewExpression;
6864
+ exports.isLiteralWhitelisted = isLiteralWhitelisted;
6792
6865
  exports.isMemberExpression = isMemberExpression;
6793
6866
  exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
6794
6867
  exports.isMemberExpressionNode = isMemberExpressionNode;
@@ -6797,6 +6870,7 @@ exports.isSimpleIdentifier = isSimpleIdentifier;
6797
6870
  exports.isSlotOutlet = isSlotOutlet;
6798
6871
  exports.isStaticArgOf = isStaticArgOf;
6799
6872
  exports.isStaticExp = isStaticExp;
6873
+ exports.isStaticNode = isStaticNode;
6800
6874
  exports.isStaticProperty = isStaticProperty;
6801
6875
  exports.isStaticPropertyKey = isStaticPropertyKey;
6802
6876
  exports.isTemplateNode = isTemplateNode;