@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.
- package/dist/compiler-core.cjs.js +354 -350
- package/dist/compiler-core.cjs.prod.js +353 -349
- package/dist/compiler-core.d.ts +7 -6
- package/dist/compiler-core.esm-bundler.js +146 -141
- package/package.json +2 -2
|
@@ -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(``);
|
|
12
12
|
const TELEPORT = Symbol(``);
|
|
@@ -1420,16 +1420,16 @@ const ErrorCodes = {
|
|
|
1420
1420
|
"45": "X_INVALID_EXPRESSION",
|
|
1421
1421
|
"X_KEEP_ALIVE_INVALID_CHILDREN": 46,
|
|
1422
1422
|
"46": "X_KEEP_ALIVE_INVALID_CHILDREN",
|
|
1423
|
-
"
|
|
1424
|
-
"47": "
|
|
1425
|
-
"
|
|
1426
|
-
"48": "
|
|
1427
|
-
"
|
|
1428
|
-
"49": "
|
|
1429
|
-
"
|
|
1430
|
-
"50": "
|
|
1431
|
-
"
|
|
1432
|
-
"51": "
|
|
1423
|
+
"X_PREFIX_ID_NOT_SUPPORTED": 47,
|
|
1424
|
+
"47": "X_PREFIX_ID_NOT_SUPPORTED",
|
|
1425
|
+
"X_MODULE_MODE_NOT_SUPPORTED": 48,
|
|
1426
|
+
"48": "X_MODULE_MODE_NOT_SUPPORTED",
|
|
1427
|
+
"X_CACHE_HANDLER_NOT_SUPPORTED": 49,
|
|
1428
|
+
"49": "X_CACHE_HANDLER_NOT_SUPPORTED",
|
|
1429
|
+
"X_SCOPE_ID_NOT_SUPPORTED": 50,
|
|
1430
|
+
"50": "X_SCOPE_ID_NOT_SUPPORTED",
|
|
1431
|
+
"X_VNODE_HOOKS": 51,
|
|
1432
|
+
"51": "X_VNODE_HOOKS",
|
|
1433
1433
|
"__EXTEND_POINT__": 52,
|
|
1434
1434
|
"52": "__EXTEND_POINT__"
|
|
1435
1435
|
};
|
|
@@ -1485,16 +1485,281 @@ const errorMessages = {
|
|
|
1485
1485
|
Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
|
|
1486
1486
|
[45]: `Error parsing JavaScript expression: `,
|
|
1487
1487
|
[46]: `<KeepAlive> expects exactly one child component.`,
|
|
1488
|
-
[
|
|
1488
|
+
[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.`,
|
|
1489
1489
|
// generic errors
|
|
1490
|
-
[
|
|
1491
|
-
[
|
|
1492
|
-
[
|
|
1493
|
-
[
|
|
1490
|
+
[47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
1491
|
+
[48]: `ES module mode is not supported in this build of compiler.`,
|
|
1492
|
+
[49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
1493
|
+
[50]: `"scopeId" option is only supported in module mode.`,
|
|
1494
1494
|
// just to fulfill types
|
|
1495
1495
|
[52]: ``
|
|
1496
1496
|
};
|
|
1497
1497
|
|
|
1498
|
+
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
|
|
1499
|
+
const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
|
|
1500
|
+
estreeWalker.walk(root, {
|
|
1501
|
+
enter(node, parent) {
|
|
1502
|
+
parent && parentStack.push(parent);
|
|
1503
|
+
if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
|
|
1504
|
+
return this.skip();
|
|
1505
|
+
}
|
|
1506
|
+
if (node.type === "Identifier") {
|
|
1507
|
+
const isLocal = !!knownIds[node.name];
|
|
1508
|
+
const isRefed = isReferencedIdentifier(node, parent, parentStack);
|
|
1509
|
+
if (includeAll || isRefed && !isLocal) {
|
|
1510
|
+
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
1511
|
+
}
|
|
1512
|
+
} else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
|
|
1513
|
+
node.inPattern = true;
|
|
1514
|
+
} else if (isFunctionType(node)) {
|
|
1515
|
+
walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
|
|
1516
|
+
} else if (node.type === "BlockStatement") {
|
|
1517
|
+
walkBlockDeclarations(
|
|
1518
|
+
node,
|
|
1519
|
+
(id) => markScopeIdentifier(node, id, knownIds)
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
leave(node, parent) {
|
|
1524
|
+
parent && parentStack.pop();
|
|
1525
|
+
if (node !== rootExp && node.scopeIds) {
|
|
1526
|
+
for (const id of node.scopeIds) {
|
|
1527
|
+
knownIds[id]--;
|
|
1528
|
+
if (knownIds[id] === 0) {
|
|
1529
|
+
delete knownIds[id];
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
function isReferencedIdentifier(id, parent, parentStack) {
|
|
1537
|
+
if (!parent) {
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
if (id.name === "arguments") {
|
|
1541
|
+
return false;
|
|
1542
|
+
}
|
|
1543
|
+
if (isReferenced(id, parent)) {
|
|
1544
|
+
return true;
|
|
1545
|
+
}
|
|
1546
|
+
switch (parent.type) {
|
|
1547
|
+
case "AssignmentExpression":
|
|
1548
|
+
case "AssignmentPattern":
|
|
1549
|
+
return true;
|
|
1550
|
+
case "ObjectPattern":
|
|
1551
|
+
case "ArrayPattern":
|
|
1552
|
+
return isInDestructureAssignment(parent, parentStack);
|
|
1553
|
+
}
|
|
1554
|
+
return false;
|
|
1555
|
+
}
|
|
1556
|
+
function isInDestructureAssignment(parent, parentStack) {
|
|
1557
|
+
if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1558
|
+
let i = parentStack.length;
|
|
1559
|
+
while (i--) {
|
|
1560
|
+
const p = parentStack[i];
|
|
1561
|
+
if (p.type === "AssignmentExpression") {
|
|
1562
|
+
return true;
|
|
1563
|
+
} else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
return false;
|
|
1569
|
+
}
|
|
1570
|
+
function walkFunctionParams(node, onIdent) {
|
|
1571
|
+
for (const p of node.params) {
|
|
1572
|
+
for (const id of extractIdentifiers(p)) {
|
|
1573
|
+
onIdent(id);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
function walkBlockDeclarations(block, onIdent) {
|
|
1578
|
+
for (const stmt of block.body) {
|
|
1579
|
+
if (stmt.type === "VariableDeclaration") {
|
|
1580
|
+
if (stmt.declare)
|
|
1581
|
+
continue;
|
|
1582
|
+
for (const decl of stmt.declarations) {
|
|
1583
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
1584
|
+
onIdent(id);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
|
1588
|
+
if (stmt.declare || !stmt.id)
|
|
1589
|
+
continue;
|
|
1590
|
+
onIdent(stmt.id);
|
|
1591
|
+
} else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
|
|
1592
|
+
const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
|
1593
|
+
if (variable && variable.type === "VariableDeclaration") {
|
|
1594
|
+
for (const decl of variable.declarations) {
|
|
1595
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
1596
|
+
onIdent(id);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
function extractIdentifiers(param, nodes = []) {
|
|
1604
|
+
switch (param.type) {
|
|
1605
|
+
case "Identifier":
|
|
1606
|
+
nodes.push(param);
|
|
1607
|
+
break;
|
|
1608
|
+
case "MemberExpression":
|
|
1609
|
+
let object = param;
|
|
1610
|
+
while (object.type === "MemberExpression") {
|
|
1611
|
+
object = object.object;
|
|
1612
|
+
}
|
|
1613
|
+
nodes.push(object);
|
|
1614
|
+
break;
|
|
1615
|
+
case "ObjectPattern":
|
|
1616
|
+
for (const prop of param.properties) {
|
|
1617
|
+
if (prop.type === "RestElement") {
|
|
1618
|
+
extractIdentifiers(prop.argument, nodes);
|
|
1619
|
+
} else {
|
|
1620
|
+
extractIdentifiers(prop.value, nodes);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
break;
|
|
1624
|
+
case "ArrayPattern":
|
|
1625
|
+
param.elements.forEach((element) => {
|
|
1626
|
+
if (element)
|
|
1627
|
+
extractIdentifiers(element, nodes);
|
|
1628
|
+
});
|
|
1629
|
+
break;
|
|
1630
|
+
case "RestElement":
|
|
1631
|
+
extractIdentifiers(param.argument, nodes);
|
|
1632
|
+
break;
|
|
1633
|
+
case "AssignmentPattern":
|
|
1634
|
+
extractIdentifiers(param.left, nodes);
|
|
1635
|
+
break;
|
|
1636
|
+
}
|
|
1637
|
+
return nodes;
|
|
1638
|
+
}
|
|
1639
|
+
function markScopeIdentifier(node, child, knownIds) {
|
|
1640
|
+
const { name } = child;
|
|
1641
|
+
if (node.scopeIds && node.scopeIds.has(name)) {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
if (name in knownIds) {
|
|
1645
|
+
knownIds[name]++;
|
|
1646
|
+
} else {
|
|
1647
|
+
knownIds[name] = 1;
|
|
1648
|
+
}
|
|
1649
|
+
(node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
|
|
1650
|
+
}
|
|
1651
|
+
const isFunctionType = (node) => {
|
|
1652
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
1653
|
+
};
|
|
1654
|
+
const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
|
1655
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
1656
|
+
function isReferenced(node, parent, grandparent) {
|
|
1657
|
+
switch (parent.type) {
|
|
1658
|
+
case "MemberExpression":
|
|
1659
|
+
case "OptionalMemberExpression":
|
|
1660
|
+
if (parent.property === node) {
|
|
1661
|
+
return !!parent.computed;
|
|
1662
|
+
}
|
|
1663
|
+
return parent.object === node;
|
|
1664
|
+
case "JSXMemberExpression":
|
|
1665
|
+
return parent.object === node;
|
|
1666
|
+
case "VariableDeclarator":
|
|
1667
|
+
return parent.init === node;
|
|
1668
|
+
case "ArrowFunctionExpression":
|
|
1669
|
+
return parent.body === node;
|
|
1670
|
+
case "PrivateName":
|
|
1671
|
+
return false;
|
|
1672
|
+
case "ClassMethod":
|
|
1673
|
+
case "ClassPrivateMethod":
|
|
1674
|
+
case "ObjectMethod":
|
|
1675
|
+
if (parent.key === node) {
|
|
1676
|
+
return !!parent.computed;
|
|
1677
|
+
}
|
|
1678
|
+
return false;
|
|
1679
|
+
case "ObjectProperty":
|
|
1680
|
+
if (parent.key === node) {
|
|
1681
|
+
return !!parent.computed;
|
|
1682
|
+
}
|
|
1683
|
+
return !grandparent || grandparent.type !== "ObjectPattern";
|
|
1684
|
+
case "ClassProperty":
|
|
1685
|
+
if (parent.key === node) {
|
|
1686
|
+
return !!parent.computed;
|
|
1687
|
+
}
|
|
1688
|
+
return true;
|
|
1689
|
+
case "ClassPrivateProperty":
|
|
1690
|
+
return parent.key !== node;
|
|
1691
|
+
case "ClassDeclaration":
|
|
1692
|
+
case "ClassExpression":
|
|
1693
|
+
return parent.superClass === node;
|
|
1694
|
+
case "AssignmentExpression":
|
|
1695
|
+
return parent.right === node;
|
|
1696
|
+
case "AssignmentPattern":
|
|
1697
|
+
return parent.right === node;
|
|
1698
|
+
case "LabeledStatement":
|
|
1699
|
+
return false;
|
|
1700
|
+
case "CatchClause":
|
|
1701
|
+
return false;
|
|
1702
|
+
case "RestElement":
|
|
1703
|
+
return false;
|
|
1704
|
+
case "BreakStatement":
|
|
1705
|
+
case "ContinueStatement":
|
|
1706
|
+
return false;
|
|
1707
|
+
case "FunctionDeclaration":
|
|
1708
|
+
case "FunctionExpression":
|
|
1709
|
+
return false;
|
|
1710
|
+
case "ExportNamespaceSpecifier":
|
|
1711
|
+
case "ExportDefaultSpecifier":
|
|
1712
|
+
return false;
|
|
1713
|
+
case "ExportSpecifier":
|
|
1714
|
+
if (grandparent == null ? void 0 : grandparent.source) {
|
|
1715
|
+
return false;
|
|
1716
|
+
}
|
|
1717
|
+
return parent.local === node;
|
|
1718
|
+
case "ImportDefaultSpecifier":
|
|
1719
|
+
case "ImportNamespaceSpecifier":
|
|
1720
|
+
case "ImportSpecifier":
|
|
1721
|
+
return false;
|
|
1722
|
+
case "ImportAttribute":
|
|
1723
|
+
return false;
|
|
1724
|
+
case "JSXAttribute":
|
|
1725
|
+
return false;
|
|
1726
|
+
case "ObjectPattern":
|
|
1727
|
+
case "ArrayPattern":
|
|
1728
|
+
return false;
|
|
1729
|
+
case "MetaProperty":
|
|
1730
|
+
return false;
|
|
1731
|
+
case "ObjectTypeProperty":
|
|
1732
|
+
return parent.key !== node;
|
|
1733
|
+
case "TSEnumMember":
|
|
1734
|
+
return parent.id !== node;
|
|
1735
|
+
case "TSPropertySignature":
|
|
1736
|
+
if (parent.key === node) {
|
|
1737
|
+
return !!parent.computed;
|
|
1738
|
+
}
|
|
1739
|
+
return true;
|
|
1740
|
+
}
|
|
1741
|
+
return true;
|
|
1742
|
+
}
|
|
1743
|
+
const TS_NODE_TYPES = [
|
|
1744
|
+
"TSAsExpression",
|
|
1745
|
+
// foo as number
|
|
1746
|
+
"TSTypeAssertion",
|
|
1747
|
+
// (<number>foo)
|
|
1748
|
+
"TSNonNullExpression",
|
|
1749
|
+
// foo!
|
|
1750
|
+
"TSInstantiationExpression",
|
|
1751
|
+
// foo<string>
|
|
1752
|
+
"TSSatisfiesExpression"
|
|
1753
|
+
// foo satisfies T
|
|
1754
|
+
];
|
|
1755
|
+
function unwrapTSNode(node) {
|
|
1756
|
+
if (TS_NODE_TYPES.includes(node.type)) {
|
|
1757
|
+
return unwrapTSNode(node.expression);
|
|
1758
|
+
} else {
|
|
1759
|
+
return node;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1498
1763
|
const isStaticExp = (p) => p.type === 4 && p.isStatic;
|
|
1499
1764
|
function isCoreComponent(tag) {
|
|
1500
1765
|
switch (tag) {
|
|
@@ -1584,9 +1849,7 @@ const isMemberExpressionNode = (path, context) => {
|
|
|
1584
1849
|
let ret = parser.parseExpression(path, {
|
|
1585
1850
|
plugins: context.expressionPlugins
|
|
1586
1851
|
});
|
|
1587
|
-
|
|
1588
|
-
ret = ret.expression;
|
|
1589
|
-
}
|
|
1852
|
+
ret = unwrapTSNode(ret);
|
|
1590
1853
|
return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier";
|
|
1591
1854
|
} catch (e) {
|
|
1592
1855
|
return false;
|
|
@@ -2811,6 +3074,7 @@ function createTransformContext(root, {
|
|
|
2811
3074
|
const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
|
2812
3075
|
const context = {
|
|
2813
3076
|
// options
|
|
3077
|
+
filename,
|
|
2814
3078
|
selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
|
|
2815
3079
|
prefixIdentifiers,
|
|
2816
3080
|
hoistStatic: hoistStatic2,
|
|
@@ -3779,338 +4043,80 @@ function genCacheExpression(node, context) {
|
|
|
3779
4043
|
push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
|
|
3780
4044
|
newline();
|
|
3781
4045
|
}
|
|
3782
|
-
push(`_cache[${node.index}] = `);
|
|
3783
|
-
genNode(node.value, context);
|
|
3784
|
-
if (node.isVNode) {
|
|
3785
|
-
push(`,`);
|
|
3786
|
-
newline();
|
|
3787
|
-
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
3788
|
-
newline();
|
|
3789
|
-
push(`_cache[${node.index}]`);
|
|
3790
|
-
deindent();
|
|
3791
|
-
}
|
|
3792
|
-
push(`)`);
|
|
3793
|
-
}
|
|
3794
|
-
function genTemplateLiteral(node, context) {
|
|
3795
|
-
const { push, indent, deindent } = context;
|
|
3796
|
-
push("`");
|
|
3797
|
-
const l = node.elements.length;
|
|
3798
|
-
const multilines = l > 3;
|
|
3799
|
-
for (let i = 0; i < l; i++) {
|
|
3800
|
-
const e = node.elements[i];
|
|
3801
|
-
if (shared.isString(e)) {
|
|
3802
|
-
push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
|
|
3803
|
-
} else {
|
|
3804
|
-
push("${");
|
|
3805
|
-
if (multilines)
|
|
3806
|
-
indent();
|
|
3807
|
-
genNode(e, context);
|
|
3808
|
-
if (multilines)
|
|
3809
|
-
deindent();
|
|
3810
|
-
push("}");
|
|
3811
|
-
}
|
|
3812
|
-
}
|
|
3813
|
-
push("`");
|
|
3814
|
-
}
|
|
3815
|
-
function genIfStatement(node, context) {
|
|
3816
|
-
const { push, indent, deindent } = context;
|
|
3817
|
-
const { test, consequent, alternate } = node;
|
|
3818
|
-
push(`if (`);
|
|
3819
|
-
genNode(test, context);
|
|
3820
|
-
push(`) {`);
|
|
3821
|
-
indent();
|
|
3822
|
-
genNode(consequent, context);
|
|
3823
|
-
deindent();
|
|
3824
|
-
push(`}`);
|
|
3825
|
-
if (alternate) {
|
|
3826
|
-
push(` else `);
|
|
3827
|
-
if (alternate.type === 23) {
|
|
3828
|
-
genIfStatement(alternate, context);
|
|
3829
|
-
} else {
|
|
3830
|
-
push(`{`);
|
|
3831
|
-
indent();
|
|
3832
|
-
genNode(alternate, context);
|
|
3833
|
-
deindent();
|
|
3834
|
-
push(`}`);
|
|
3835
|
-
}
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
|
-
function genAssignmentExpression(node, context) {
|
|
3839
|
-
genNode(node.left, context);
|
|
3840
|
-
context.push(` = `);
|
|
3841
|
-
genNode(node.right, context);
|
|
3842
|
-
}
|
|
3843
|
-
function genSequenceExpression(node, context) {
|
|
3844
|
-
context.push(`(`);
|
|
3845
|
-
genNodeList(node.expressions, context);
|
|
3846
|
-
context.push(`)`);
|
|
3847
|
-
}
|
|
3848
|
-
function genReturnStatement({ returns }, context) {
|
|
3849
|
-
context.push(`return `);
|
|
3850
|
-
if (shared.isArray(returns)) {
|
|
3851
|
-
genNodeListAsArray(returns, context);
|
|
3852
|
-
} else {
|
|
3853
|
-
genNode(returns, context);
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
|
|
3857
|
-
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
|
|
3858
|
-
const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
|
|
3859
|
-
estreeWalker.walk(root, {
|
|
3860
|
-
enter(node, parent) {
|
|
3861
|
-
parent && parentStack.push(parent);
|
|
3862
|
-
if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
|
|
3863
|
-
return this.skip();
|
|
3864
|
-
}
|
|
3865
|
-
if (node.type === "Identifier") {
|
|
3866
|
-
const isLocal = !!knownIds[node.name];
|
|
3867
|
-
const isRefed = isReferencedIdentifier(node, parent, parentStack);
|
|
3868
|
-
if (includeAll || isRefed && !isLocal) {
|
|
3869
|
-
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
3870
|
-
}
|
|
3871
|
-
} else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
|
|
3872
|
-
node.inPattern = true;
|
|
3873
|
-
} else if (isFunctionType(node)) {
|
|
3874
|
-
walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
|
|
3875
|
-
} else if (node.type === "BlockStatement") {
|
|
3876
|
-
walkBlockDeclarations(
|
|
3877
|
-
node,
|
|
3878
|
-
(id) => markScopeIdentifier(node, id, knownIds)
|
|
3879
|
-
);
|
|
3880
|
-
}
|
|
3881
|
-
},
|
|
3882
|
-
leave(node, parent) {
|
|
3883
|
-
parent && parentStack.pop();
|
|
3884
|
-
if (node !== rootExp && node.scopeIds) {
|
|
3885
|
-
for (const id of node.scopeIds) {
|
|
3886
|
-
knownIds[id]--;
|
|
3887
|
-
if (knownIds[id] === 0) {
|
|
3888
|
-
delete knownIds[id];
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
}
|
|
3892
|
-
}
|
|
3893
|
-
});
|
|
3894
|
-
}
|
|
3895
|
-
function isReferencedIdentifier(id, parent, parentStack) {
|
|
3896
|
-
if (!parent) {
|
|
3897
|
-
return true;
|
|
3898
|
-
}
|
|
3899
|
-
if (id.name === "arguments") {
|
|
3900
|
-
return false;
|
|
3901
|
-
}
|
|
3902
|
-
if (isReferenced(id, parent)) {
|
|
3903
|
-
return true;
|
|
3904
|
-
}
|
|
3905
|
-
switch (parent.type) {
|
|
3906
|
-
case "AssignmentExpression":
|
|
3907
|
-
case "AssignmentPattern":
|
|
3908
|
-
return true;
|
|
3909
|
-
case "ObjectPattern":
|
|
3910
|
-
case "ArrayPattern":
|
|
3911
|
-
return isInDestructureAssignment(parent, parentStack);
|
|
4046
|
+
push(`_cache[${node.index}] = `);
|
|
4047
|
+
genNode(node.value, context);
|
|
4048
|
+
if (node.isVNode) {
|
|
4049
|
+
push(`,`);
|
|
4050
|
+
newline();
|
|
4051
|
+
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
4052
|
+
newline();
|
|
4053
|
+
push(`_cache[${node.index}]`);
|
|
4054
|
+
deindent();
|
|
3912
4055
|
}
|
|
3913
|
-
|
|
4056
|
+
push(`)`);
|
|
3914
4057
|
}
|
|
3915
|
-
function
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
4058
|
+
function genTemplateLiteral(node, context) {
|
|
4059
|
+
const { push, indent, deindent } = context;
|
|
4060
|
+
push("`");
|
|
4061
|
+
const l = node.elements.length;
|
|
4062
|
+
const multilines = l > 3;
|
|
4063
|
+
for (let i = 0; i < l; i++) {
|
|
4064
|
+
const e = node.elements[i];
|
|
4065
|
+
if (shared.isString(e)) {
|
|
4066
|
+
push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
|
|
4067
|
+
} else {
|
|
4068
|
+
push("${");
|
|
4069
|
+
if (multilines)
|
|
4070
|
+
indent();
|
|
4071
|
+
genNode(e, context);
|
|
4072
|
+
if (multilines)
|
|
4073
|
+
deindent();
|
|
4074
|
+
push("}");
|
|
3925
4075
|
}
|
|
3926
4076
|
}
|
|
3927
|
-
|
|
4077
|
+
push("`");
|
|
3928
4078
|
}
|
|
3929
|
-
function
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
4079
|
+
function genIfStatement(node, context) {
|
|
4080
|
+
const { push, indent, deindent } = context;
|
|
4081
|
+
const { test, consequent, alternate } = node;
|
|
4082
|
+
push(`if (`);
|
|
4083
|
+
genNode(test, context);
|
|
4084
|
+
push(`) {`);
|
|
4085
|
+
indent();
|
|
4086
|
+
genNode(consequent, context);
|
|
4087
|
+
deindent();
|
|
4088
|
+
push(`}`);
|
|
4089
|
+
if (alternate) {
|
|
4090
|
+
push(` else `);
|
|
4091
|
+
if (alternate.type === 23) {
|
|
4092
|
+
genIfStatement(alternate, context);
|
|
4093
|
+
} else {
|
|
4094
|
+
push(`{`);
|
|
4095
|
+
indent();
|
|
4096
|
+
genNode(alternate, context);
|
|
4097
|
+
deindent();
|
|
4098
|
+
push(`}`);
|
|
3933
4099
|
}
|
|
3934
4100
|
}
|
|
3935
4101
|
}
|
|
3936
|
-
function
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
continue;
|
|
3941
|
-
for (const decl of stmt.declarations) {
|
|
3942
|
-
for (const id of extractIdentifiers(decl.id)) {
|
|
3943
|
-
onIdent(id);
|
|
3944
|
-
}
|
|
3945
|
-
}
|
|
3946
|
-
} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
|
3947
|
-
if (stmt.declare || !stmt.id)
|
|
3948
|
-
continue;
|
|
3949
|
-
onIdent(stmt.id);
|
|
3950
|
-
} else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
|
|
3951
|
-
const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
|
3952
|
-
if (variable && variable.type === "VariableDeclaration") {
|
|
3953
|
-
for (const decl of variable.declarations) {
|
|
3954
|
-
for (const id of extractIdentifiers(decl.id)) {
|
|
3955
|
-
onIdent(id);
|
|
3956
|
-
}
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
}
|
|
3960
|
-
}
|
|
4102
|
+
function genAssignmentExpression(node, context) {
|
|
4103
|
+
genNode(node.left, context);
|
|
4104
|
+
context.push(` = `);
|
|
4105
|
+
genNode(node.right, context);
|
|
3961
4106
|
}
|
|
3962
|
-
function
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
break;
|
|
3967
|
-
case "MemberExpression":
|
|
3968
|
-
let object = param;
|
|
3969
|
-
while (object.type === "MemberExpression") {
|
|
3970
|
-
object = object.object;
|
|
3971
|
-
}
|
|
3972
|
-
nodes.push(object);
|
|
3973
|
-
break;
|
|
3974
|
-
case "ObjectPattern":
|
|
3975
|
-
for (const prop of param.properties) {
|
|
3976
|
-
if (prop.type === "RestElement") {
|
|
3977
|
-
extractIdentifiers(prop.argument, nodes);
|
|
3978
|
-
} else {
|
|
3979
|
-
extractIdentifiers(prop.value, nodes);
|
|
3980
|
-
}
|
|
3981
|
-
}
|
|
3982
|
-
break;
|
|
3983
|
-
case "ArrayPattern":
|
|
3984
|
-
param.elements.forEach((element) => {
|
|
3985
|
-
if (element)
|
|
3986
|
-
extractIdentifiers(element, nodes);
|
|
3987
|
-
});
|
|
3988
|
-
break;
|
|
3989
|
-
case "RestElement":
|
|
3990
|
-
extractIdentifiers(param.argument, nodes);
|
|
3991
|
-
break;
|
|
3992
|
-
case "AssignmentPattern":
|
|
3993
|
-
extractIdentifiers(param.left, nodes);
|
|
3994
|
-
break;
|
|
3995
|
-
}
|
|
3996
|
-
return nodes;
|
|
4107
|
+
function genSequenceExpression(node, context) {
|
|
4108
|
+
context.push(`(`);
|
|
4109
|
+
genNodeList(node.expressions, context);
|
|
4110
|
+
context.push(`)`);
|
|
3997
4111
|
}
|
|
3998
|
-
function
|
|
3999
|
-
|
|
4000
|
-
if (
|
|
4001
|
-
|
|
4002
|
-
}
|
|
4003
|
-
if (name in knownIds) {
|
|
4004
|
-
knownIds[name]++;
|
|
4112
|
+
function genReturnStatement({ returns }, context) {
|
|
4113
|
+
context.push(`return `);
|
|
4114
|
+
if (shared.isArray(returns)) {
|
|
4115
|
+
genNodeListAsArray(returns, context);
|
|
4005
4116
|
} else {
|
|
4006
|
-
|
|
4007
|
-
}
|
|
4008
|
-
(node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
|
|
4009
|
-
}
|
|
4010
|
-
const isFunctionType = (node) => {
|
|
4011
|
-
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
4012
|
-
};
|
|
4013
|
-
const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
|
4014
|
-
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
4015
|
-
function isReferenced(node, parent, grandparent) {
|
|
4016
|
-
switch (parent.type) {
|
|
4017
|
-
case "MemberExpression":
|
|
4018
|
-
case "OptionalMemberExpression":
|
|
4019
|
-
if (parent.property === node) {
|
|
4020
|
-
return !!parent.computed;
|
|
4021
|
-
}
|
|
4022
|
-
return parent.object === node;
|
|
4023
|
-
case "JSXMemberExpression":
|
|
4024
|
-
return parent.object === node;
|
|
4025
|
-
case "VariableDeclarator":
|
|
4026
|
-
return parent.init === node;
|
|
4027
|
-
case "ArrowFunctionExpression":
|
|
4028
|
-
return parent.body === node;
|
|
4029
|
-
case "PrivateName":
|
|
4030
|
-
return false;
|
|
4031
|
-
case "ClassMethod":
|
|
4032
|
-
case "ClassPrivateMethod":
|
|
4033
|
-
case "ObjectMethod":
|
|
4034
|
-
if (parent.key === node) {
|
|
4035
|
-
return !!parent.computed;
|
|
4036
|
-
}
|
|
4037
|
-
return false;
|
|
4038
|
-
case "ObjectProperty":
|
|
4039
|
-
if (parent.key === node) {
|
|
4040
|
-
return !!parent.computed;
|
|
4041
|
-
}
|
|
4042
|
-
return !grandparent || grandparent.type !== "ObjectPattern";
|
|
4043
|
-
case "ClassProperty":
|
|
4044
|
-
if (parent.key === node) {
|
|
4045
|
-
return !!parent.computed;
|
|
4046
|
-
}
|
|
4047
|
-
return true;
|
|
4048
|
-
case "ClassPrivateProperty":
|
|
4049
|
-
return parent.key !== node;
|
|
4050
|
-
case "ClassDeclaration":
|
|
4051
|
-
case "ClassExpression":
|
|
4052
|
-
return parent.superClass === node;
|
|
4053
|
-
case "AssignmentExpression":
|
|
4054
|
-
return parent.right === node;
|
|
4055
|
-
case "AssignmentPattern":
|
|
4056
|
-
return parent.right === node;
|
|
4057
|
-
case "LabeledStatement":
|
|
4058
|
-
return false;
|
|
4059
|
-
case "CatchClause":
|
|
4060
|
-
return false;
|
|
4061
|
-
case "RestElement":
|
|
4062
|
-
return false;
|
|
4063
|
-
case "BreakStatement":
|
|
4064
|
-
case "ContinueStatement":
|
|
4065
|
-
return false;
|
|
4066
|
-
case "FunctionDeclaration":
|
|
4067
|
-
case "FunctionExpression":
|
|
4068
|
-
return false;
|
|
4069
|
-
case "ExportNamespaceSpecifier":
|
|
4070
|
-
case "ExportDefaultSpecifier":
|
|
4071
|
-
return false;
|
|
4072
|
-
case "ExportSpecifier":
|
|
4073
|
-
if (grandparent == null ? void 0 : grandparent.source) {
|
|
4074
|
-
return false;
|
|
4075
|
-
}
|
|
4076
|
-
return parent.local === node;
|
|
4077
|
-
case "ImportDefaultSpecifier":
|
|
4078
|
-
case "ImportNamespaceSpecifier":
|
|
4079
|
-
case "ImportSpecifier":
|
|
4080
|
-
return false;
|
|
4081
|
-
case "ImportAttribute":
|
|
4082
|
-
return false;
|
|
4083
|
-
case "JSXAttribute":
|
|
4084
|
-
return false;
|
|
4085
|
-
case "ObjectPattern":
|
|
4086
|
-
case "ArrayPattern":
|
|
4087
|
-
return false;
|
|
4088
|
-
case "MetaProperty":
|
|
4089
|
-
return false;
|
|
4090
|
-
case "ObjectTypeProperty":
|
|
4091
|
-
return parent.key !== node;
|
|
4092
|
-
case "TSEnumMember":
|
|
4093
|
-
return parent.id !== node;
|
|
4094
|
-
case "TSPropertySignature":
|
|
4095
|
-
if (parent.key === node) {
|
|
4096
|
-
return !!parent.computed;
|
|
4097
|
-
}
|
|
4098
|
-
return true;
|
|
4117
|
+
genNode(returns, context);
|
|
4099
4118
|
}
|
|
4100
|
-
return true;
|
|
4101
4119
|
}
|
|
4102
|
-
const TS_NODE_TYPES = [
|
|
4103
|
-
"TSAsExpression",
|
|
4104
|
-
// foo as number
|
|
4105
|
-
"TSTypeAssertion",
|
|
4106
|
-
// (<number>foo)
|
|
4107
|
-
"TSNonNullExpression",
|
|
4108
|
-
// foo!
|
|
4109
|
-
"TSInstantiationExpression",
|
|
4110
|
-
// foo<string>
|
|
4111
|
-
"TSSatisfiesExpression"
|
|
4112
|
-
// foo satisfies T
|
|
4113
|
-
];
|
|
4114
4120
|
|
|
4115
4121
|
const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
|
|
4116
4122
|
const constantBailRE = /\w\s*\(|\.[^\d]/;
|
|
@@ -6260,12 +6266,15 @@ function baseCompile(source, options = {}) {
|
|
|
6260
6266
|
const isModuleMode = options.mode === "module";
|
|
6261
6267
|
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
|
|
6262
6268
|
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
6263
|
-
onError(createCompilerError(
|
|
6269
|
+
onError(createCompilerError(49));
|
|
6264
6270
|
}
|
|
6265
6271
|
if (options.scopeId && !isModuleMode) {
|
|
6266
|
-
onError(createCompilerError(
|
|
6272
|
+
onError(createCompilerError(50));
|
|
6267
6273
|
}
|
|
6268
|
-
const
|
|
6274
|
+
const resolvedOptions = shared.extend({}, options, {
|
|
6275
|
+
prefixIdentifiers
|
|
6276
|
+
});
|
|
6277
|
+
const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
|
|
6269
6278
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
|
|
6270
6279
|
if (options.isTS) {
|
|
6271
6280
|
const { expressionPlugins } = options;
|
|
@@ -6275,8 +6284,7 @@ function baseCompile(source, options = {}) {
|
|
|
6275
6284
|
}
|
|
6276
6285
|
transform(
|
|
6277
6286
|
ast,
|
|
6278
|
-
shared.extend({},
|
|
6279
|
-
prefixIdentifiers,
|
|
6287
|
+
shared.extend({}, resolvedOptions, {
|
|
6280
6288
|
nodeTransforms: [
|
|
6281
6289
|
...nodeTransforms,
|
|
6282
6290
|
...options.nodeTransforms || []
|
|
@@ -6290,12 +6298,7 @@ function baseCompile(source, options = {}) {
|
|
|
6290
6298
|
)
|
|
6291
6299
|
})
|
|
6292
6300
|
);
|
|
6293
|
-
return generate(
|
|
6294
|
-
ast,
|
|
6295
|
-
shared.extend({}, options, {
|
|
6296
|
-
prefixIdentifiers
|
|
6297
|
-
})
|
|
6298
|
-
);
|
|
6301
|
+
return generate(ast, resolvedOptions);
|
|
6299
6302
|
}
|
|
6300
6303
|
|
|
6301
6304
|
const BindingTypes = {
|
|
@@ -6443,6 +6446,7 @@ exports.transformExpression = transformExpression;
|
|
|
6443
6446
|
exports.transformModel = transformModel;
|
|
6444
6447
|
exports.transformOn = transformOn;
|
|
6445
6448
|
exports.traverseNode = traverseNode;
|
|
6449
|
+
exports.unwrapTSNode = unwrapTSNode;
|
|
6446
6450
|
exports.walkBlockDeclarations = walkBlockDeclarations;
|
|
6447
6451
|
exports.walkFunctionParams = walkFunctionParams;
|
|
6448
6452
|
exports.walkIdentifiers = walkIdentifiers;
|