@vue/compiler-core 3.4.0-alpha.4 → 3.4.0-beta.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.
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var shared = require('@vue/shared');
6
6
  var decode_js = require('entities/lib/decode.js');
7
7
  var parser = require('@babel/parser');
8
- var sourceMapJs = require('source-map-js');
9
8
  var estreeWalker = require('estree-walker');
9
+ var sourceMapJs = require('source-map-js');
10
10
 
11
11
  const FRAGMENT = Symbol(`Fragment` );
12
12
  const TELEPORT = Symbol(`Teleport` );
@@ -1424,16 +1424,16 @@ const ErrorCodes = {
1424
1424
  "45": "X_INVALID_EXPRESSION",
1425
1425
  "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
1426
1426
  "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
1427
- "X_VNODE_HOOKS": 47,
1428
- "47": "X_VNODE_HOOKS",
1429
- "X_PREFIX_ID_NOT_SUPPORTED": 48,
1430
- "48": "X_PREFIX_ID_NOT_SUPPORTED",
1431
- "X_MODULE_MODE_NOT_SUPPORTED": 49,
1432
- "49": "X_MODULE_MODE_NOT_SUPPORTED",
1433
- "X_CACHE_HANDLER_NOT_SUPPORTED": 50,
1434
- "50": "X_CACHE_HANDLER_NOT_SUPPORTED",
1435
- "X_SCOPE_ID_NOT_SUPPORTED": 51,
1436
- "51": "X_SCOPE_ID_NOT_SUPPORTED",
1427
+ "X_PREFIX_ID_NOT_SUPPORTED": 47,
1428
+ "47": "X_PREFIX_ID_NOT_SUPPORTED",
1429
+ "X_MODULE_MODE_NOT_SUPPORTED": 48,
1430
+ "48": "X_MODULE_MODE_NOT_SUPPORTED",
1431
+ "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
1432
+ "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
1433
+ "X_SCOPE_ID_NOT_SUPPORTED": 50,
1434
+ "50": "X_SCOPE_ID_NOT_SUPPORTED",
1435
+ "X_VNODE_HOOKS": 51,
1436
+ "51": "X_VNODE_HOOKS",
1437
1437
  "__EXTEND_POINT__": 52,
1438
1438
  "52": "__EXTEND_POINT__"
1439
1439
  };
@@ -1489,16 +1489,281 @@ const errorMessages = {
1489
1489
  Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1490
1490
  [45]: `Error parsing JavaScript expression: `,
1491
1491
  [46]: `<KeepAlive> expects exactly one child component.`,
1492
- [47]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
1492
+ [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
1493
1493
  // generic errors
1494
- [48]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1495
- [49]: `ES module mode is not supported in this build of compiler.`,
1496
- [50]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1497
- [51]: `"scopeId" option is only supported in module mode.`,
1494
+ [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1495
+ [48]: `ES module mode is not supported in this build of compiler.`,
1496
+ [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1497
+ [50]: `"scopeId" option is only supported in module mode.`,
1498
1498
  // just to fulfill types
1499
1499
  [52]: ``
1500
1500
  };
1501
1501
 
1502
+ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
1503
+ const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
1504
+ estreeWalker.walk(root, {
1505
+ enter(node, parent) {
1506
+ parent && parentStack.push(parent);
1507
+ if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
1508
+ return this.skip();
1509
+ }
1510
+ if (node.type === "Identifier") {
1511
+ const isLocal = !!knownIds[node.name];
1512
+ const isRefed = isReferencedIdentifier(node, parent, parentStack);
1513
+ if (includeAll || isRefed && !isLocal) {
1514
+ onIdentifier(node, parent, parentStack, isRefed, isLocal);
1515
+ }
1516
+ } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
1517
+ node.inPattern = true;
1518
+ } else if (isFunctionType(node)) {
1519
+ walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
1520
+ } else if (node.type === "BlockStatement") {
1521
+ walkBlockDeclarations(
1522
+ node,
1523
+ (id) => markScopeIdentifier(node, id, knownIds)
1524
+ );
1525
+ }
1526
+ },
1527
+ leave(node, parent) {
1528
+ parent && parentStack.pop();
1529
+ if (node !== rootExp && node.scopeIds) {
1530
+ for (const id of node.scopeIds) {
1531
+ knownIds[id]--;
1532
+ if (knownIds[id] === 0) {
1533
+ delete knownIds[id];
1534
+ }
1535
+ }
1536
+ }
1537
+ }
1538
+ });
1539
+ }
1540
+ function isReferencedIdentifier(id, parent, parentStack) {
1541
+ if (!parent) {
1542
+ return true;
1543
+ }
1544
+ if (id.name === "arguments") {
1545
+ return false;
1546
+ }
1547
+ if (isReferenced(id, parent)) {
1548
+ return true;
1549
+ }
1550
+ switch (parent.type) {
1551
+ case "AssignmentExpression":
1552
+ case "AssignmentPattern":
1553
+ return true;
1554
+ case "ObjectPattern":
1555
+ case "ArrayPattern":
1556
+ return isInDestructureAssignment(parent, parentStack);
1557
+ }
1558
+ return false;
1559
+ }
1560
+ function isInDestructureAssignment(parent, parentStack) {
1561
+ if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
1562
+ let i = parentStack.length;
1563
+ while (i--) {
1564
+ const p = parentStack[i];
1565
+ if (p.type === "AssignmentExpression") {
1566
+ return true;
1567
+ } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
1568
+ break;
1569
+ }
1570
+ }
1571
+ }
1572
+ return false;
1573
+ }
1574
+ function walkFunctionParams(node, onIdent) {
1575
+ for (const p of node.params) {
1576
+ for (const id of extractIdentifiers(p)) {
1577
+ onIdent(id);
1578
+ }
1579
+ }
1580
+ }
1581
+ function walkBlockDeclarations(block, onIdent) {
1582
+ for (const stmt of block.body) {
1583
+ if (stmt.type === "VariableDeclaration") {
1584
+ if (stmt.declare)
1585
+ continue;
1586
+ for (const decl of stmt.declarations) {
1587
+ for (const id of extractIdentifiers(decl.id)) {
1588
+ onIdent(id);
1589
+ }
1590
+ }
1591
+ } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1592
+ if (stmt.declare || !stmt.id)
1593
+ continue;
1594
+ onIdent(stmt.id);
1595
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
1596
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
1597
+ if (variable && variable.type === "VariableDeclaration") {
1598
+ for (const decl of variable.declarations) {
1599
+ for (const id of extractIdentifiers(decl.id)) {
1600
+ onIdent(id);
1601
+ }
1602
+ }
1603
+ }
1604
+ }
1605
+ }
1606
+ }
1607
+ function extractIdentifiers(param, nodes = []) {
1608
+ switch (param.type) {
1609
+ case "Identifier":
1610
+ nodes.push(param);
1611
+ break;
1612
+ case "MemberExpression":
1613
+ let object = param;
1614
+ while (object.type === "MemberExpression") {
1615
+ object = object.object;
1616
+ }
1617
+ nodes.push(object);
1618
+ break;
1619
+ case "ObjectPattern":
1620
+ for (const prop of param.properties) {
1621
+ if (prop.type === "RestElement") {
1622
+ extractIdentifiers(prop.argument, nodes);
1623
+ } else {
1624
+ extractIdentifiers(prop.value, nodes);
1625
+ }
1626
+ }
1627
+ break;
1628
+ case "ArrayPattern":
1629
+ param.elements.forEach((element) => {
1630
+ if (element)
1631
+ extractIdentifiers(element, nodes);
1632
+ });
1633
+ break;
1634
+ case "RestElement":
1635
+ extractIdentifiers(param.argument, nodes);
1636
+ break;
1637
+ case "AssignmentPattern":
1638
+ extractIdentifiers(param.left, nodes);
1639
+ break;
1640
+ }
1641
+ return nodes;
1642
+ }
1643
+ function markScopeIdentifier(node, child, knownIds) {
1644
+ const { name } = child;
1645
+ if (node.scopeIds && node.scopeIds.has(name)) {
1646
+ return;
1647
+ }
1648
+ if (name in knownIds) {
1649
+ knownIds[name]++;
1650
+ } else {
1651
+ knownIds[name] = 1;
1652
+ }
1653
+ (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
1654
+ }
1655
+ const isFunctionType = (node) => {
1656
+ return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1657
+ };
1658
+ const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1659
+ const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1660
+ function isReferenced(node, parent, grandparent) {
1661
+ switch (parent.type) {
1662
+ case "MemberExpression":
1663
+ case "OptionalMemberExpression":
1664
+ if (parent.property === node) {
1665
+ return !!parent.computed;
1666
+ }
1667
+ return parent.object === node;
1668
+ case "JSXMemberExpression":
1669
+ return parent.object === node;
1670
+ case "VariableDeclarator":
1671
+ return parent.init === node;
1672
+ case "ArrowFunctionExpression":
1673
+ return parent.body === node;
1674
+ case "PrivateName":
1675
+ return false;
1676
+ case "ClassMethod":
1677
+ case "ClassPrivateMethod":
1678
+ case "ObjectMethod":
1679
+ if (parent.key === node) {
1680
+ return !!parent.computed;
1681
+ }
1682
+ return false;
1683
+ case "ObjectProperty":
1684
+ if (parent.key === node) {
1685
+ return !!parent.computed;
1686
+ }
1687
+ return !grandparent || grandparent.type !== "ObjectPattern";
1688
+ case "ClassProperty":
1689
+ if (parent.key === node) {
1690
+ return !!parent.computed;
1691
+ }
1692
+ return true;
1693
+ case "ClassPrivateProperty":
1694
+ return parent.key !== node;
1695
+ case "ClassDeclaration":
1696
+ case "ClassExpression":
1697
+ return parent.superClass === node;
1698
+ case "AssignmentExpression":
1699
+ return parent.right === node;
1700
+ case "AssignmentPattern":
1701
+ return parent.right === node;
1702
+ case "LabeledStatement":
1703
+ return false;
1704
+ case "CatchClause":
1705
+ return false;
1706
+ case "RestElement":
1707
+ return false;
1708
+ case "BreakStatement":
1709
+ case "ContinueStatement":
1710
+ return false;
1711
+ case "FunctionDeclaration":
1712
+ case "FunctionExpression":
1713
+ return false;
1714
+ case "ExportNamespaceSpecifier":
1715
+ case "ExportDefaultSpecifier":
1716
+ return false;
1717
+ case "ExportSpecifier":
1718
+ if (grandparent == null ? void 0 : grandparent.source) {
1719
+ return false;
1720
+ }
1721
+ return parent.local === node;
1722
+ case "ImportDefaultSpecifier":
1723
+ case "ImportNamespaceSpecifier":
1724
+ case "ImportSpecifier":
1725
+ return false;
1726
+ case "ImportAttribute":
1727
+ return false;
1728
+ case "JSXAttribute":
1729
+ return false;
1730
+ case "ObjectPattern":
1731
+ case "ArrayPattern":
1732
+ return false;
1733
+ case "MetaProperty":
1734
+ return false;
1735
+ case "ObjectTypeProperty":
1736
+ return parent.key !== node;
1737
+ case "TSEnumMember":
1738
+ return parent.id !== node;
1739
+ case "TSPropertySignature":
1740
+ if (parent.key === node) {
1741
+ return !!parent.computed;
1742
+ }
1743
+ return true;
1744
+ }
1745
+ return true;
1746
+ }
1747
+ const TS_NODE_TYPES = [
1748
+ "TSAsExpression",
1749
+ // foo as number
1750
+ "TSTypeAssertion",
1751
+ // (<number>foo)
1752
+ "TSNonNullExpression",
1753
+ // foo!
1754
+ "TSInstantiationExpression",
1755
+ // foo<string>
1756
+ "TSSatisfiesExpression"
1757
+ // foo satisfies T
1758
+ ];
1759
+ function unwrapTSNode(node) {
1760
+ if (TS_NODE_TYPES.includes(node.type)) {
1761
+ return unwrapTSNode(node.expression);
1762
+ } else {
1763
+ return node;
1764
+ }
1765
+ }
1766
+
1502
1767
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
1503
1768
  function isCoreComponent(tag) {
1504
1769
  switch (tag) {
@@ -1588,9 +1853,7 @@ const isMemberExpressionNode = (path, context) => {
1588
1853
  let ret = parser.parseExpression(path, {
1589
1854
  plugins: context.expressionPlugins
1590
1855
  });
1591
- if (ret.type === "TSAsExpression" || ret.type === "TSTypeAssertion") {
1592
- ret = ret.expression;
1593
- }
1856
+ ret = unwrapTSNode(ret);
1594
1857
  return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier";
1595
1858
  } catch (e) {
1596
1859
  return false;
@@ -2852,6 +3115,7 @@ function createTransformContext(root, {
2852
3115
  const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
2853
3116
  const context = {
2854
3117
  // options
3118
+ filename,
2855
3119
  selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
2856
3120
  prefixIdentifiers,
2857
3121
  hoistStatic: hoistStatic2,
@@ -3850,338 +4114,80 @@ function genCacheExpression(node, context) {
3850
4114
  push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
3851
4115
  newline();
3852
4116
  }
3853
- push(`_cache[${node.index}] = `);
3854
- genNode(node.value, context);
3855
- if (node.isVNode) {
3856
- push(`,`);
3857
- newline();
3858
- push(`${helper(SET_BLOCK_TRACKING)}(1),`);
3859
- newline();
3860
- push(`_cache[${node.index}]`);
3861
- deindent();
3862
- }
3863
- push(`)`);
3864
- }
3865
- function genTemplateLiteral(node, context) {
3866
- const { push, indent, deindent } = context;
3867
- push("`");
3868
- const l = node.elements.length;
3869
- const multilines = l > 3;
3870
- for (let i = 0; i < l; i++) {
3871
- const e = node.elements[i];
3872
- if (shared.isString(e)) {
3873
- push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
3874
- } else {
3875
- push("${");
3876
- if (multilines)
3877
- indent();
3878
- genNode(e, context);
3879
- if (multilines)
3880
- deindent();
3881
- push("}");
3882
- }
3883
- }
3884
- push("`");
3885
- }
3886
- function genIfStatement(node, context) {
3887
- const { push, indent, deindent } = context;
3888
- const { test, consequent, alternate } = node;
3889
- push(`if (`);
3890
- genNode(test, context);
3891
- push(`) {`);
3892
- indent();
3893
- genNode(consequent, context);
3894
- deindent();
3895
- push(`}`);
3896
- if (alternate) {
3897
- push(` else `);
3898
- if (alternate.type === 23) {
3899
- genIfStatement(alternate, context);
3900
- } else {
3901
- push(`{`);
3902
- indent();
3903
- genNode(alternate, context);
3904
- deindent();
3905
- push(`}`);
3906
- }
3907
- }
3908
- }
3909
- function genAssignmentExpression(node, context) {
3910
- genNode(node.left, context);
3911
- context.push(` = `);
3912
- genNode(node.right, context);
3913
- }
3914
- function genSequenceExpression(node, context) {
3915
- context.push(`(`);
3916
- genNodeList(node.expressions, context);
3917
- context.push(`)`);
3918
- }
3919
- function genReturnStatement({ returns }, context) {
3920
- context.push(`return `);
3921
- if (shared.isArray(returns)) {
3922
- genNodeListAsArray(returns, context);
3923
- } else {
3924
- genNode(returns, context);
3925
- }
3926
- }
3927
-
3928
- function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
3929
- const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
3930
- estreeWalker.walk(root, {
3931
- enter(node, parent) {
3932
- parent && parentStack.push(parent);
3933
- if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
3934
- return this.skip();
3935
- }
3936
- if (node.type === "Identifier") {
3937
- const isLocal = !!knownIds[node.name];
3938
- const isRefed = isReferencedIdentifier(node, parent, parentStack);
3939
- if (includeAll || isRefed && !isLocal) {
3940
- onIdentifier(node, parent, parentStack, isRefed, isLocal);
3941
- }
3942
- } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
3943
- node.inPattern = true;
3944
- } else if (isFunctionType(node)) {
3945
- walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
3946
- } else if (node.type === "BlockStatement") {
3947
- walkBlockDeclarations(
3948
- node,
3949
- (id) => markScopeIdentifier(node, id, knownIds)
3950
- );
3951
- }
3952
- },
3953
- leave(node, parent) {
3954
- parent && parentStack.pop();
3955
- if (node !== rootExp && node.scopeIds) {
3956
- for (const id of node.scopeIds) {
3957
- knownIds[id]--;
3958
- if (knownIds[id] === 0) {
3959
- delete knownIds[id];
3960
- }
3961
- }
3962
- }
3963
- }
3964
- });
3965
- }
3966
- function isReferencedIdentifier(id, parent, parentStack) {
3967
- if (!parent) {
3968
- return true;
3969
- }
3970
- if (id.name === "arguments") {
3971
- return false;
3972
- }
3973
- if (isReferenced(id, parent)) {
3974
- return true;
3975
- }
3976
- switch (parent.type) {
3977
- case "AssignmentExpression":
3978
- case "AssignmentPattern":
3979
- return true;
3980
- case "ObjectPattern":
3981
- case "ArrayPattern":
3982
- return isInDestructureAssignment(parent, parentStack);
4117
+ push(`_cache[${node.index}] = `);
4118
+ genNode(node.value, context);
4119
+ if (node.isVNode) {
4120
+ push(`,`);
4121
+ newline();
4122
+ push(`${helper(SET_BLOCK_TRACKING)}(1),`);
4123
+ newline();
4124
+ push(`_cache[${node.index}]`);
4125
+ deindent();
3983
4126
  }
3984
- return false;
4127
+ push(`)`);
3985
4128
  }
3986
- function isInDestructureAssignment(parent, parentStack) {
3987
- if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
3988
- let i = parentStack.length;
3989
- while (i--) {
3990
- const p = parentStack[i];
3991
- if (p.type === "AssignmentExpression") {
3992
- return true;
3993
- } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
3994
- break;
3995
- }
4129
+ function genTemplateLiteral(node, context) {
4130
+ const { push, indent, deindent } = context;
4131
+ push("`");
4132
+ const l = node.elements.length;
4133
+ const multilines = l > 3;
4134
+ for (let i = 0; i < l; i++) {
4135
+ const e = node.elements[i];
4136
+ if (shared.isString(e)) {
4137
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
4138
+ } else {
4139
+ push("${");
4140
+ if (multilines)
4141
+ indent();
4142
+ genNode(e, context);
4143
+ if (multilines)
4144
+ deindent();
4145
+ push("}");
3996
4146
  }
3997
4147
  }
3998
- return false;
4148
+ push("`");
3999
4149
  }
4000
- function walkFunctionParams(node, onIdent) {
4001
- for (const p of node.params) {
4002
- for (const id of extractIdentifiers(p)) {
4003
- onIdent(id);
4150
+ function genIfStatement(node, context) {
4151
+ const { push, indent, deindent } = context;
4152
+ const { test, consequent, alternate } = node;
4153
+ push(`if (`);
4154
+ genNode(test, context);
4155
+ push(`) {`);
4156
+ indent();
4157
+ genNode(consequent, context);
4158
+ deindent();
4159
+ push(`}`);
4160
+ if (alternate) {
4161
+ push(` else `);
4162
+ if (alternate.type === 23) {
4163
+ genIfStatement(alternate, context);
4164
+ } else {
4165
+ push(`{`);
4166
+ indent();
4167
+ genNode(alternate, context);
4168
+ deindent();
4169
+ push(`}`);
4004
4170
  }
4005
4171
  }
4006
4172
  }
4007
- function walkBlockDeclarations(block, onIdent) {
4008
- for (const stmt of block.body) {
4009
- if (stmt.type === "VariableDeclaration") {
4010
- if (stmt.declare)
4011
- continue;
4012
- for (const decl of stmt.declarations) {
4013
- for (const id of extractIdentifiers(decl.id)) {
4014
- onIdent(id);
4015
- }
4016
- }
4017
- } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
4018
- if (stmt.declare || !stmt.id)
4019
- continue;
4020
- onIdent(stmt.id);
4021
- } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
4022
- const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
4023
- if (variable && variable.type === "VariableDeclaration") {
4024
- for (const decl of variable.declarations) {
4025
- for (const id of extractIdentifiers(decl.id)) {
4026
- onIdent(id);
4027
- }
4028
- }
4029
- }
4030
- }
4031
- }
4173
+ function genAssignmentExpression(node, context) {
4174
+ genNode(node.left, context);
4175
+ context.push(` = `);
4176
+ genNode(node.right, context);
4032
4177
  }
4033
- function extractIdentifiers(param, nodes = []) {
4034
- switch (param.type) {
4035
- case "Identifier":
4036
- nodes.push(param);
4037
- break;
4038
- case "MemberExpression":
4039
- let object = param;
4040
- while (object.type === "MemberExpression") {
4041
- object = object.object;
4042
- }
4043
- nodes.push(object);
4044
- break;
4045
- case "ObjectPattern":
4046
- for (const prop of param.properties) {
4047
- if (prop.type === "RestElement") {
4048
- extractIdentifiers(prop.argument, nodes);
4049
- } else {
4050
- extractIdentifiers(prop.value, nodes);
4051
- }
4052
- }
4053
- break;
4054
- case "ArrayPattern":
4055
- param.elements.forEach((element) => {
4056
- if (element)
4057
- extractIdentifiers(element, nodes);
4058
- });
4059
- break;
4060
- case "RestElement":
4061
- extractIdentifiers(param.argument, nodes);
4062
- break;
4063
- case "AssignmentPattern":
4064
- extractIdentifiers(param.left, nodes);
4065
- break;
4066
- }
4067
- return nodes;
4178
+ function genSequenceExpression(node, context) {
4179
+ context.push(`(`);
4180
+ genNodeList(node.expressions, context);
4181
+ context.push(`)`);
4068
4182
  }
4069
- function markScopeIdentifier(node, child, knownIds) {
4070
- const { name } = child;
4071
- if (node.scopeIds && node.scopeIds.has(name)) {
4072
- return;
4073
- }
4074
- if (name in knownIds) {
4075
- knownIds[name]++;
4183
+ function genReturnStatement({ returns }, context) {
4184
+ context.push(`return `);
4185
+ if (shared.isArray(returns)) {
4186
+ genNodeListAsArray(returns, context);
4076
4187
  } else {
4077
- knownIds[name] = 1;
4078
- }
4079
- (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
4080
- }
4081
- const isFunctionType = (node) => {
4082
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
4083
- };
4084
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
4085
- const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
4086
- function isReferenced(node, parent, grandparent) {
4087
- switch (parent.type) {
4088
- case "MemberExpression":
4089
- case "OptionalMemberExpression":
4090
- if (parent.property === node) {
4091
- return !!parent.computed;
4092
- }
4093
- return parent.object === node;
4094
- case "JSXMemberExpression":
4095
- return parent.object === node;
4096
- case "VariableDeclarator":
4097
- return parent.init === node;
4098
- case "ArrowFunctionExpression":
4099
- return parent.body === node;
4100
- case "PrivateName":
4101
- return false;
4102
- case "ClassMethod":
4103
- case "ClassPrivateMethod":
4104
- case "ObjectMethod":
4105
- if (parent.key === node) {
4106
- return !!parent.computed;
4107
- }
4108
- return false;
4109
- case "ObjectProperty":
4110
- if (parent.key === node) {
4111
- return !!parent.computed;
4112
- }
4113
- return !grandparent || grandparent.type !== "ObjectPattern";
4114
- case "ClassProperty":
4115
- if (parent.key === node) {
4116
- return !!parent.computed;
4117
- }
4118
- return true;
4119
- case "ClassPrivateProperty":
4120
- return parent.key !== node;
4121
- case "ClassDeclaration":
4122
- case "ClassExpression":
4123
- return parent.superClass === node;
4124
- case "AssignmentExpression":
4125
- return parent.right === node;
4126
- case "AssignmentPattern":
4127
- return parent.right === node;
4128
- case "LabeledStatement":
4129
- return false;
4130
- case "CatchClause":
4131
- return false;
4132
- case "RestElement":
4133
- return false;
4134
- case "BreakStatement":
4135
- case "ContinueStatement":
4136
- return false;
4137
- case "FunctionDeclaration":
4138
- case "FunctionExpression":
4139
- return false;
4140
- case "ExportNamespaceSpecifier":
4141
- case "ExportDefaultSpecifier":
4142
- return false;
4143
- case "ExportSpecifier":
4144
- if (grandparent == null ? void 0 : grandparent.source) {
4145
- return false;
4146
- }
4147
- return parent.local === node;
4148
- case "ImportDefaultSpecifier":
4149
- case "ImportNamespaceSpecifier":
4150
- case "ImportSpecifier":
4151
- return false;
4152
- case "ImportAttribute":
4153
- return false;
4154
- case "JSXAttribute":
4155
- return false;
4156
- case "ObjectPattern":
4157
- case "ArrayPattern":
4158
- return false;
4159
- case "MetaProperty":
4160
- return false;
4161
- case "ObjectTypeProperty":
4162
- return parent.key !== node;
4163
- case "TSEnumMember":
4164
- return parent.id !== node;
4165
- case "TSPropertySignature":
4166
- if (parent.key === node) {
4167
- return !!parent.computed;
4168
- }
4169
- return true;
4188
+ genNode(returns, context);
4170
4189
  }
4171
- return true;
4172
4190
  }
4173
- const TS_NODE_TYPES = [
4174
- "TSAsExpression",
4175
- // foo as number
4176
- "TSTypeAssertion",
4177
- // (<number>foo)
4178
- "TSNonNullExpression",
4179
- // foo!
4180
- "TSInstantiationExpression",
4181
- // foo<string>
4182
- "TSSatisfiesExpression"
4183
- // foo satisfies T
4184
- ];
4185
4191
 
4186
4192
  const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
4187
4193
  const constantBailRE = /\w\s*\(|\.[^\d]/;
@@ -5850,7 +5856,7 @@ const transformOn = (dir, node, context, augmentor) => {
5850
5856
  if (arg.isStatic) {
5851
5857
  let rawName = arg.content;
5852
5858
  if (rawName.startsWith("vnode")) {
5853
- context.onError(createCompilerError(47, arg.loc));
5859
+ context.onError(createCompilerError(51, arg.loc));
5854
5860
  }
5855
5861
  if (rawName.startsWith("vue:")) {
5856
5862
  rawName = `vnode-${rawName.slice(4)}`;
@@ -6384,12 +6390,15 @@ function baseCompile(source, options = {}) {
6384
6390
  const isModuleMode = options.mode === "module";
6385
6391
  const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
6386
6392
  if (!prefixIdentifiers && options.cacheHandlers) {
6387
- onError(createCompilerError(50));
6393
+ onError(createCompilerError(49));
6388
6394
  }
6389
6395
  if (options.scopeId && !isModuleMode) {
6390
- onError(createCompilerError(51));
6396
+ onError(createCompilerError(50));
6391
6397
  }
6392
- const ast = shared.isString(source) ? baseParse(source, options) : source;
6398
+ const resolvedOptions = shared.extend({}, options, {
6399
+ prefixIdentifiers
6400
+ });
6401
+ const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
6393
6402
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
6394
6403
  if (options.isTS) {
6395
6404
  const { expressionPlugins } = options;
@@ -6399,8 +6408,7 @@ function baseCompile(source, options = {}) {
6399
6408
  }
6400
6409
  transform(
6401
6410
  ast,
6402
- shared.extend({}, options, {
6403
- prefixIdentifiers,
6411
+ shared.extend({}, resolvedOptions, {
6404
6412
  nodeTransforms: [
6405
6413
  ...nodeTransforms,
6406
6414
  ...options.nodeTransforms || []
@@ -6414,12 +6422,7 @@ function baseCompile(source, options = {}) {
6414
6422
  )
6415
6423
  })
6416
6424
  );
6417
- return generate(
6418
- ast,
6419
- shared.extend({}, options, {
6420
- prefixIdentifiers
6421
- })
6422
- );
6425
+ return generate(ast, resolvedOptions);
6423
6426
  }
6424
6427
 
6425
6428
  const BindingTypes = {
@@ -6567,6 +6570,7 @@ exports.transformExpression = transformExpression;
6567
6570
  exports.transformModel = transformModel;
6568
6571
  exports.transformOn = transformOn;
6569
6572
  exports.traverseNode = traverseNode;
6573
+ exports.unwrapTSNode = unwrapTSNode;
6570
6574
  exports.walkBlockDeclarations = walkBlockDeclarations;
6571
6575
  exports.walkFunctionParams = walkFunctionParams;
6572
6576
  exports.walkIdentifiers = walkIdentifiers;