@vue/compiler-dom 3.5.20 → 3.5.22

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,12 +1,11 @@
1
1
  /**
2
- * @vue/compiler-dom v3.5.20
2
+ * @vue/compiler-dom v3.5.22
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
6
  var VueCompilerDOM = (function (exports) {
7
7
  'use strict';
8
8
 
9
- /*! #__NO_SIDE_EFFECTS__ */
10
9
  // @__NO_SIDE_EFFECTS__
11
10
  function makeMap(str) {
12
11
  const map = /* @__PURE__ */ Object.create(null);
@@ -39,10 +38,10 @@ var VueCompilerDOM = (function (exports) {
39
38
  return hit || (cache[str] = fn(str));
40
39
  });
41
40
  };
42
- const camelizeRE = /-(\w)/g;
41
+ const camelizeRE = /-\w/g;
43
42
  const camelize = cacheStringFunction(
44
43
  (str) => {
45
- return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
44
+ return str.replace(camelizeRE, (c) => c.slice(1).toUpperCase());
46
45
  }
47
46
  );
48
47
  const capitalize = cacheStringFunction((str) => {
@@ -1651,7 +1650,8 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1651
1650
  }
1652
1651
  }
1653
1652
  function walkBlockDeclarations(block, onIdent) {
1654
- for (const stmt of block.body) {
1653
+ const body = block.type === "SwitchCase" ? block.consequent : block.body;
1654
+ for (const stmt of body) {
1655
1655
  if (stmt.type === "VariableDeclaration") {
1656
1656
  if (stmt.declare) continue;
1657
1657
  for (const decl of stmt.declarations) {
@@ -1664,6 +1664,8 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1664
1664
  onIdent(stmt.id);
1665
1665
  } else if (isForStatement(stmt)) {
1666
1666
  walkForStatement(stmt, true, onIdent);
1667
+ } else if (stmt.type === "SwitchStatement") {
1668
+ walkSwitchStatement(stmt, true, onIdent);
1667
1669
  }
1668
1670
  }
1669
1671
  }
@@ -1680,6 +1682,20 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1680
1682
  }
1681
1683
  }
1682
1684
  }
1685
+ function walkSwitchStatement(stmt, isVar, onIdent) {
1686
+ for (const cs of stmt.cases) {
1687
+ for (const stmt2 of cs.consequent) {
1688
+ if (stmt2.type === "VariableDeclaration" && (stmt2.kind === "var" ? isVar : !isVar)) {
1689
+ for (const decl of stmt2.declarations) {
1690
+ for (const id of extractIdentifiers(decl.id)) {
1691
+ onIdent(id);
1692
+ }
1693
+ }
1694
+ }
1695
+ }
1696
+ walkBlockDeclarations(cs, onIdent);
1697
+ }
1698
+ }
1683
1699
  function extractIdentifiers(param, nodes = []) {
1684
1700
  switch (param.type) {
1685
1701
  case "Identifier":
@@ -1827,7 +1843,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
1827
1843
  };
1828
1844
  const isMemberExpressionNode = NOOP ;
1829
1845
  const isMemberExpression = isMemberExpressionBrowser ;
1830
- const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
1846
+ const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
1831
1847
  const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
1832
1848
  const isFnExpressionNode = NOOP ;
1833
1849
  const isFnExpression = isFnExpressionBrowser ;
@@ -4041,7 +4057,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
4041
4057
  }
4042
4058
 
4043
4059
  const transformIf = createStructuralDirectiveTransform(
4044
- /^(if|else|else-if)$/,
4060
+ /^(?:if|else|else-if)$/,
4045
4061
  (node, dir, context) => {
4046
4062
  return processIf(node, dir, context, (ifNode, branch, isRoot) => {
4047
4063
  const siblings = context.parent.children;
@@ -4259,80 +4275,6 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
4259
4275
  }
4260
4276
  }
4261
4277
 
4262
- const transformBind = (dir, _node, context) => {
4263
- const { modifiers, loc } = dir;
4264
- const arg = dir.arg;
4265
- let { exp } = dir;
4266
- if (exp && exp.type === 4 && !exp.content.trim()) {
4267
- {
4268
- exp = void 0;
4269
- }
4270
- }
4271
- if (!exp) {
4272
- if (arg.type !== 4 || !arg.isStatic) {
4273
- context.onError(
4274
- createCompilerError(
4275
- 52,
4276
- arg.loc
4277
- )
4278
- );
4279
- return {
4280
- props: [
4281
- createObjectProperty(arg, createSimpleExpression("", true, loc))
4282
- ]
4283
- };
4284
- }
4285
- transformBindShorthand(dir);
4286
- exp = dir.exp;
4287
- }
4288
- if (arg.type !== 4) {
4289
- arg.children.unshift(`(`);
4290
- arg.children.push(`) || ""`);
4291
- } else if (!arg.isStatic) {
4292
- arg.content = arg.content ? `${arg.content} || ""` : `""`;
4293
- }
4294
- if (modifiers.some((mod) => mod.content === "camel")) {
4295
- if (arg.type === 4) {
4296
- if (arg.isStatic) {
4297
- arg.content = camelize(arg.content);
4298
- } else {
4299
- arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
4300
- }
4301
- } else {
4302
- arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
4303
- arg.children.push(`)`);
4304
- }
4305
- }
4306
- if (!context.inSSR) {
4307
- if (modifiers.some((mod) => mod.content === "prop")) {
4308
- injectPrefix(arg, ".");
4309
- }
4310
- if (modifiers.some((mod) => mod.content === "attr")) {
4311
- injectPrefix(arg, "^");
4312
- }
4313
- }
4314
- return {
4315
- props: [createObjectProperty(arg, exp)]
4316
- };
4317
- };
4318
- const transformBindShorthand = (dir, context) => {
4319
- const arg = dir.arg;
4320
- const propName = camelize(arg.content);
4321
- dir.exp = createSimpleExpression(propName, false, arg.loc);
4322
- };
4323
- const injectPrefix = (arg, prefix) => {
4324
- if (arg.type === 4) {
4325
- if (arg.isStatic) {
4326
- arg.content = prefix + arg.content;
4327
- } else {
4328
- arg.content = `\`${prefix}\${${arg.content}}\``;
4329
- }
4330
- } else {
4331
- arg.children.unshift(`'${prefix}' + (`);
4332
- arg.children.push(`)`);
4333
- }
4334
- };
4335
-
4336
4278
  const transformFor = createStructuralDirectiveTransform(
4337
4279
  "for",
4338
4280
  (node, dir, context) => {
@@ -4344,10 +4286,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
4344
4286
  const isTemplate = isTemplateNode(node);
4345
4287
  const memo = findDir(node, "memo");
4346
4288
  const keyProp = findProp(node, `key`, false, true);
4347
- const isDirKey = keyProp && keyProp.type === 7;
4348
- if (isDirKey && !keyProp.exp) {
4349
- transformBindShorthand(keyProp);
4350
- }
4289
+ keyProp && keyProp.type === 7;
4351
4290
  let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
4352
4291
  const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
4353
4292
  const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
@@ -4647,7 +4586,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
4647
4586
  );
4648
4587
  } else if (vElse = findDir(
4649
4588
  slotElement,
4650
- /^else(-if)?$/,
4589
+ /^else(?:-if)?$/,
4651
4590
  true
4652
4591
  /* allowEmpty */
4653
4592
  )) {
@@ -4659,7 +4598,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
4659
4598
  break;
4660
4599
  }
4661
4600
  }
4662
- if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
4601
+ if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
4663
4602
  let conditional = dynamicSlots[dynamicSlots.length - 1];
4664
4603
  while (conditional.alternate.type === 19) {
4665
4604
  conditional = conditional.alternate;
@@ -5519,6 +5458,58 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
5519
5458
  return ret;
5520
5459
  };
5521
5460
 
5461
+ const transformBind = (dir, _node, context) => {
5462
+ const { modifiers, loc } = dir;
5463
+ const arg = dir.arg;
5464
+ let { exp } = dir;
5465
+ if (exp && exp.type === 4 && !exp.content.trim()) {
5466
+ {
5467
+ exp = void 0;
5468
+ }
5469
+ }
5470
+ if (arg.type !== 4) {
5471
+ arg.children.unshift(`(`);
5472
+ arg.children.push(`) || ""`);
5473
+ } else if (!arg.isStatic) {
5474
+ arg.content = arg.content ? `${arg.content} || ""` : `""`;
5475
+ }
5476
+ if (modifiers.some((mod) => mod.content === "camel")) {
5477
+ if (arg.type === 4) {
5478
+ if (arg.isStatic) {
5479
+ arg.content = camelize(arg.content);
5480
+ } else {
5481
+ arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
5482
+ }
5483
+ } else {
5484
+ arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
5485
+ arg.children.push(`)`);
5486
+ }
5487
+ }
5488
+ if (!context.inSSR) {
5489
+ if (modifiers.some((mod) => mod.content === "prop")) {
5490
+ injectPrefix(arg, ".");
5491
+ }
5492
+ if (modifiers.some((mod) => mod.content === "attr")) {
5493
+ injectPrefix(arg, "^");
5494
+ }
5495
+ }
5496
+ return {
5497
+ props: [createObjectProperty(arg, exp)]
5498
+ };
5499
+ };
5500
+ const injectPrefix = (arg, prefix) => {
5501
+ if (arg.type === 4) {
5502
+ if (arg.isStatic) {
5503
+ arg.content = prefix + arg.content;
5504
+ } else {
5505
+ arg.content = `\`${prefix}\${${arg.content}}\``;
5506
+ }
5507
+ } else {
5508
+ arg.children.unshift(`'${prefix}' + (`);
5509
+ arg.children.push(`)`);
5510
+ }
5511
+ };
5512
+
5522
5513
  const transformText = (node, context) => {
5523
5514
  if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
5524
5515
  return () => {
@@ -5849,9 +5840,35 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
5849
5840
  }
5850
5841
  };
5851
5842
 
5843
+ const transformVBindShorthand = (node, context) => {
5844
+ if (node.type === 1) {
5845
+ for (const prop of node.props) {
5846
+ if (prop.type === 7 && prop.name === "bind" && !prop.exp) {
5847
+ const arg = prop.arg;
5848
+ if (arg.type !== 4 || !arg.isStatic) {
5849
+ context.onError(
5850
+ createCompilerError(
5851
+ 52,
5852
+ arg.loc
5853
+ )
5854
+ );
5855
+ prop.exp = createSimpleExpression("", true, arg.loc);
5856
+ } else {
5857
+ const propName = camelize(arg.content);
5858
+ if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
5859
+ propName[0] === "-") {
5860
+ prop.exp = createSimpleExpression(propName, false, arg.loc);
5861
+ }
5862
+ }
5863
+ }
5864
+ }
5865
+ }
5866
+ };
5867
+
5852
5868
  function getBaseTransformPreset(prefixIdentifiers) {
5853
5869
  return [
5854
5870
  [
5871
+ transformVBindShorthand,
5855
5872
  transformOnce,
5856
5873
  transformIf,
5857
5874
  transformMemo,
@@ -6759,8 +6776,10 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
6759
6776
  exports.transformModel = transformModel$1;
6760
6777
  exports.transformOn = transformOn$1;
6761
6778
  exports.transformStyle = transformStyle;
6779
+ exports.transformVBindShorthand = transformVBindShorthand;
6762
6780
  exports.traverseNode = traverseNode;
6763
6781
  exports.unwrapTSNode = unwrapTSNode;
6782
+ exports.validFirstIdentCharRE = validFirstIdentCharRE;
6764
6783
  exports.walkBlockDeclarations = walkBlockDeclarations;
6765
6784
  exports.walkFunctionParams = walkFunctionParams;
6766
6785
  exports.walkIdentifiers = walkIdentifiers;