@vureact/compiler-core 1.6.2 → 1.8.0
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/README.en.md +22 -235
- package/README.md +23 -236
- package/lib/{chunk-SRBJ5B5X.esm.js → chunk-6MTN25KZ.esm.js} +1293 -919
- package/lib/{chunk-FLZ5AUPG.js → chunk-V7G7OQWK.js} +1408 -1034
- package/lib/cli.esm.js +3 -2
- package/lib/cli.js +11 -10
- package/lib/compiler-core.d.cts +72 -57
- package/lib/compiler-core.d.ts +72 -57
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +6 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.8.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,7 +24,7 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var
|
|
27
|
+
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t43 = _interopRequireWildcard(_types); var t42 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types); var t41 = _interopRequireWildcard(_types); var t44 = _interopRequireWildcard(_types); var t45 = _interopRequireWildcard(_types); var t46 = _interopRequireWildcard(_types); var t47 = _interopRequireWildcard(_types); var t48 = _interopRequireWildcard(_types); var t50 = _interopRequireWildcard(_types); var t49 = _interopRequireWildcard(_types); var t51 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -451,8 +451,8 @@ function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
|
451
451
|
function stringToExpr(input, lang, filename = "") {
|
|
452
452
|
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
453
453
|
}
|
|
454
|
-
function atComponentOrHookRoot(
|
|
455
|
-
const { parentPath, scope } =
|
|
454
|
+
function atComponentOrHookRoot(path8, rootScope, inScriptFile = false) {
|
|
455
|
+
const { parentPath, scope } = path8;
|
|
456
456
|
const parentBlock = scope.block;
|
|
457
457
|
if (!parentPath) return !inScriptFile;
|
|
458
458
|
if (parentBlock === rootScope) {
|
|
@@ -653,7 +653,7 @@ function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
|
653
653
|
const newContent = resolveSpecialExpression(input, ctx);
|
|
654
654
|
try {
|
|
655
655
|
return stringToExpr(newContent, scriptData.lang, filename);
|
|
656
|
-
} catch (
|
|
656
|
+
} catch (e2) {
|
|
657
657
|
return t5.identifier(newContent);
|
|
658
658
|
}
|
|
659
659
|
}
|
|
@@ -809,7 +809,7 @@ function normalizePath(filePath) {
|
|
|
809
809
|
if (fp.startsWith("file:")) {
|
|
810
810
|
fp = _url.fileURLToPath.call(void 0, fp);
|
|
811
811
|
}
|
|
812
|
-
} catch (
|
|
812
|
+
} catch (e3) {
|
|
813
813
|
}
|
|
814
814
|
fp = fp.replace(/\\/g, "/").replace(/\/\/+/, "/");
|
|
815
815
|
return fp;
|
|
@@ -1024,7 +1024,7 @@ function buildSlotCallbackParams(nodeIR, ctx) {
|
|
|
1024
1024
|
return [];
|
|
1025
1025
|
}
|
|
1026
1026
|
return expression.params;
|
|
1027
|
-
} catch (
|
|
1027
|
+
} catch (e4) {
|
|
1028
1028
|
logger.warn(`Failed to parse slot params "${rawArg}". Falling back to no-arg slot function.`, {
|
|
1029
1029
|
file: ctx.filename
|
|
1030
1030
|
});
|
|
@@ -1058,7 +1058,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1058
1058
|
babelExp: { ast: keyAST },
|
|
1059
1059
|
value: {
|
|
1060
1060
|
content,
|
|
1061
|
-
isStringLiteral:
|
|
1061
|
+
isStringLiteral: isStringLiteral14,
|
|
1062
1062
|
babelExp: { ast: valueAST }
|
|
1063
1063
|
}
|
|
1064
1064
|
} = nodeIR;
|
|
@@ -1067,7 +1067,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1067
1067
|
}
|
|
1068
1068
|
let value;
|
|
1069
1069
|
if (content !== "true") {
|
|
1070
|
-
value =
|
|
1070
|
+
value = isStringLiteral14 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
1071
1071
|
}
|
|
1072
1072
|
return t9.jsxAttribute(keyAST, value);
|
|
1073
1073
|
}
|
|
@@ -1159,7 +1159,7 @@ function buildCtxProviderNode(nodeIR, ctx, children) {
|
|
|
1159
1159
|
if (!raw) return t11.stringLiteral("");
|
|
1160
1160
|
try {
|
|
1161
1161
|
return stringToExpr(raw, ctx.scriptData.lang, ctx.filename);
|
|
1162
|
-
} catch (
|
|
1162
|
+
} catch (e5) {
|
|
1163
1163
|
return t11.stringLiteral(raw);
|
|
1164
1164
|
}
|
|
1165
1165
|
};
|
|
@@ -1521,10 +1521,10 @@ var _core = require('@babel/core');
|
|
|
1521
1521
|
|
|
1522
1522
|
// src/core/transform/sfc/script/shared/babel-utils.ts
|
|
1523
1523
|
|
|
1524
|
-
function findRootVariablePath(
|
|
1525
|
-
const rootId = findRootIdentifier(
|
|
1524
|
+
function findRootVariablePath(path8) {
|
|
1525
|
+
const rootId = findRootIdentifier(path8.node);
|
|
1526
1526
|
if (!_optionalChain([rootId, 'optionalAccess', _46 => _46.name])) return null;
|
|
1527
|
-
const binding =
|
|
1527
|
+
const binding = path8.scope.getBinding(rootId.name);
|
|
1528
1528
|
if (!binding) return null;
|
|
1529
1529
|
const rootPath = getVariableDeclaratorPath(binding.path);
|
|
1530
1530
|
return rootPath;
|
|
@@ -1536,14 +1536,14 @@ function findRootIdentifier(node) {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
return t15.isIdentifier(current) ? current : null;
|
|
1538
1538
|
}
|
|
1539
|
-
function getVariableDeclaratorPath(
|
|
1540
|
-
if (
|
|
1541
|
-
return
|
|
1539
|
+
function getVariableDeclaratorPath(path8) {
|
|
1540
|
+
if (path8.isVariableDeclarator()) {
|
|
1541
|
+
return path8;
|
|
1542
1542
|
}
|
|
1543
|
-
return
|
|
1543
|
+
return path8.findParent((p) => p.isVariableDeclarator());
|
|
1544
1544
|
}
|
|
1545
|
-
function isVariableDeclTopLevel(
|
|
1546
|
-
const variableDeclaratorPath =
|
|
1545
|
+
function isVariableDeclTopLevel(path8) {
|
|
1546
|
+
const variableDeclaratorPath = path8;
|
|
1547
1547
|
const variableDeclarationPath = variableDeclaratorPath.parentPath;
|
|
1548
1548
|
if (!variableDeclarationPath) {
|
|
1549
1549
|
return false;
|
|
@@ -1557,61 +1557,61 @@ function isVariableDeclTopLevel(path9) {
|
|
|
1557
1557
|
}
|
|
1558
1558
|
return false;
|
|
1559
1559
|
}
|
|
1560
|
-
function isRealVariableAccess(
|
|
1561
|
-
return isIdentifierAccess(
|
|
1560
|
+
function isRealVariableAccess(path8) {
|
|
1561
|
+
return isIdentifierAccess(path8) && !isPropertyName(path8);
|
|
1562
1562
|
}
|
|
1563
|
-
function isIdentifierAccess(
|
|
1564
|
-
if (isIdentifierDeclaration(
|
|
1563
|
+
function isIdentifierAccess(path8) {
|
|
1564
|
+
if (isIdentifierDeclaration(path8)) {
|
|
1565
1565
|
return false;
|
|
1566
1566
|
}
|
|
1567
|
-
const binding =
|
|
1567
|
+
const binding = path8.scope.getBinding(path8.node.name);
|
|
1568
1568
|
if (!binding) {
|
|
1569
1569
|
return true;
|
|
1570
1570
|
}
|
|
1571
|
-
return binding.identifier !==
|
|
1571
|
+
return binding.identifier !== path8.node;
|
|
1572
1572
|
}
|
|
1573
|
-
function isIdentifierDeclaration(
|
|
1574
|
-
const parent =
|
|
1573
|
+
function isIdentifierDeclaration(path8) {
|
|
1574
|
+
const parent = path8.parentPath;
|
|
1575
1575
|
if (!parent) return false;
|
|
1576
|
-
if (parent.isVariableDeclarator() && parent.node.id ===
|
|
1576
|
+
if (parent.isVariableDeclarator() && parent.node.id === path8.node) {
|
|
1577
1577
|
return true;
|
|
1578
1578
|
}
|
|
1579
|
-
if (parent.isFunctionDeclaration() && parent.node.id ===
|
|
1579
|
+
if (parent.isFunctionDeclaration() && parent.node.id === path8.node) {
|
|
1580
1580
|
return true;
|
|
1581
1581
|
}
|
|
1582
|
-
if (parent.isFunctionExpression() && parent.node.id ===
|
|
1582
|
+
if (parent.isFunctionExpression() && parent.node.id === path8.node) {
|
|
1583
1583
|
return true;
|
|
1584
1584
|
}
|
|
1585
|
-
if (parent.isClassDeclaration() && parent.node.id ===
|
|
1585
|
+
if (parent.isClassDeclaration() && parent.node.id === path8.node) {
|
|
1586
1586
|
return true;
|
|
1587
1587
|
}
|
|
1588
|
-
if (parent.isImportSpecifier() && parent.node.local ===
|
|
1588
|
+
if (parent.isImportSpecifier() && parent.node.local === path8.node) {
|
|
1589
1589
|
return true;
|
|
1590
1590
|
}
|
|
1591
|
-
if (parent.isImportDefaultSpecifier() && parent.node.local ===
|
|
1591
|
+
if (parent.isImportDefaultSpecifier() && parent.node.local === path8.node) {
|
|
1592
1592
|
return true;
|
|
1593
1593
|
}
|
|
1594
|
-
if (parent.isImportNamespaceSpecifier() && parent.node.local ===
|
|
1594
|
+
if (parent.isImportNamespaceSpecifier() && parent.node.local === path8.node) {
|
|
1595
1595
|
return true;
|
|
1596
1596
|
}
|
|
1597
|
-
if (parent.isFunction() && parent.node.params.includes(
|
|
1597
|
+
if (parent.isFunction() && parent.node.params.includes(path8.node)) {
|
|
1598
1598
|
return true;
|
|
1599
1599
|
}
|
|
1600
|
-
if (parent.isCatchClause() && parent.node.param ===
|
|
1600
|
+
if (parent.isCatchClause() && parent.node.param === path8.node) {
|
|
1601
1601
|
return true;
|
|
1602
1602
|
}
|
|
1603
1603
|
return false;
|
|
1604
1604
|
}
|
|
1605
|
-
function isPropertyName(
|
|
1606
|
-
const parent =
|
|
1605
|
+
function isPropertyName(path8) {
|
|
1606
|
+
const parent = path8.parentPath;
|
|
1607
1607
|
if (!parent) return false;
|
|
1608
|
-
if (parent.isObjectProperty() && parent.node.key ===
|
|
1608
|
+
if (parent.isObjectProperty() && parent.node.key === path8.node) {
|
|
1609
1609
|
return true;
|
|
1610
1610
|
}
|
|
1611
|
-
if (parent.isClassProperty() && parent.node.key ===
|
|
1611
|
+
if (parent.isClassProperty() && parent.node.key === path8.node) {
|
|
1612
1612
|
return true;
|
|
1613
1613
|
}
|
|
1614
|
-
if (parent.isMemberExpression() && parent.node.property ===
|
|
1614
|
+
if (parent.isMemberExpression() && parent.node.property === path8.node) {
|
|
1615
1615
|
return true;
|
|
1616
1616
|
}
|
|
1617
1617
|
return false;
|
|
@@ -1707,7 +1707,7 @@ function forkNode(node, deep = true) {
|
|
|
1707
1707
|
cleanNodeComments(node);
|
|
1708
1708
|
return newNode;
|
|
1709
1709
|
}
|
|
1710
|
-
function replaceNode(
|
|
1710
|
+
function replaceNode(path8, target, source) {
|
|
1711
1711
|
const { start, end, loc, leadingComments, innerComments, trailingComments } = source;
|
|
1712
1712
|
target.start = start;
|
|
1713
1713
|
target.end = end;
|
|
@@ -1717,7 +1717,7 @@ function replaceNode(path9, target, source) {
|
|
|
1717
1717
|
target.trailingComments = trailingComments;
|
|
1718
1718
|
cleanNodeLoc(source);
|
|
1719
1719
|
cleanNodeComments(source);
|
|
1720
|
-
|
|
1720
|
+
path8.replaceWith(target);
|
|
1721
1721
|
}
|
|
1722
1722
|
function cleanNodeLoc(node) {
|
|
1723
1723
|
node.start = null;
|
|
@@ -1731,8 +1731,8 @@ function cleanNodeComments(node) {
|
|
|
1731
1731
|
}
|
|
1732
1732
|
|
|
1733
1733
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-options.ts
|
|
1734
|
-
function resolveDeclaredOptions(
|
|
1735
|
-
const { node } =
|
|
1734
|
+
function resolveDeclaredOptions(path8, ctx) {
|
|
1735
|
+
const { node } = path8;
|
|
1736
1736
|
const { filename, scriptData } = ctx;
|
|
1737
1737
|
if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
|
|
1738
1738
|
return;
|
|
@@ -1854,11 +1854,11 @@ function resolveStaticName(key) {
|
|
|
1854
1854
|
}
|
|
1855
1855
|
return null;
|
|
1856
1856
|
}
|
|
1857
|
-
function resolveLocalTypeFromReference(
|
|
1857
|
+
function resolveLocalTypeFromReference(path8, typeRef, ctx, macroName, visitedTypeRefs, warnedImportedTypeRefs) {
|
|
1858
1858
|
const refName = resolveTypeReferenceName(typeRef.typeName);
|
|
1859
1859
|
if (!refName) return null;
|
|
1860
1860
|
if (visitedTypeRefs.has(refName)) return null;
|
|
1861
|
-
const binding =
|
|
1861
|
+
const binding = path8.scope.getBinding(refName);
|
|
1862
1862
|
if (binding) {
|
|
1863
1863
|
if (binding.path.isImportSpecifier() || binding.path.isImportDefaultSpecifier() || binding.path.isImportNamespaceSpecifier()) {
|
|
1864
1864
|
const key = `${macroName}:${refName}`;
|
|
@@ -1869,7 +1869,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
|
|
|
1869
1869
|
{
|
|
1870
1870
|
file: ctx.filename,
|
|
1871
1871
|
source: ctx.source,
|
|
1872
|
-
loc: typeRef.loc ||
|
|
1872
|
+
loc: typeRef.loc || path8.node.loc
|
|
1873
1873
|
}
|
|
1874
1874
|
);
|
|
1875
1875
|
}
|
|
@@ -1883,7 +1883,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
|
|
|
1883
1883
|
return binding.path.node.typeAnnotation;
|
|
1884
1884
|
}
|
|
1885
1885
|
}
|
|
1886
|
-
const programPath =
|
|
1886
|
+
const programPath = path8.findParent((p) => p.isProgram());
|
|
1887
1887
|
if (!_optionalChain([programPath, 'optionalAccess', _51 => _51.isProgram, 'call', _52 => _52()])) {
|
|
1888
1888
|
return null;
|
|
1889
1889
|
}
|
|
@@ -1902,7 +1902,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
|
|
|
1902
1902
|
{
|
|
1903
1903
|
file: ctx.filename,
|
|
1904
1904
|
source: ctx.source,
|
|
1905
|
-
loc: typeRef.loc ||
|
|
1905
|
+
loc: typeRef.loc || path8.node.loc
|
|
1906
1906
|
}
|
|
1907
1907
|
);
|
|
1908
1908
|
}
|
|
@@ -1959,8 +1959,8 @@ function resolveImportedTypeSourceInProgram(body, typeName) {
|
|
|
1959
1959
|
}
|
|
1960
1960
|
|
|
1961
1961
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/resolve-declared-emits.ts
|
|
1962
|
-
function resolveDeclaredEmits(
|
|
1963
|
-
const { node } =
|
|
1962
|
+
function resolveDeclaredEmits(path8, ctx) {
|
|
1963
|
+
const { node } = path8;
|
|
1964
1964
|
const { templateData, scriptData } = ctx;
|
|
1965
1965
|
if (!isCalleeNamed(node, MACRO_API_NAMES.emits)) {
|
|
1966
1966
|
return;
|
|
@@ -1971,28 +1971,28 @@ function resolveDeclaredEmits(path9, ctx) {
|
|
|
1971
1971
|
mergeNames(templateData.declaredEmits, resolveObjectOrArrayLiteralNames(initValue));
|
|
1972
1972
|
return;
|
|
1973
1973
|
}
|
|
1974
|
-
const namesFromType = resolveDeclaredEmitsFromTypeParams(tsTypeDef,
|
|
1974
|
+
const namesFromType = resolveDeclaredEmitsFromTypeParams(tsTypeDef, path8, ctx);
|
|
1975
1975
|
if (namesFromType.size) {
|
|
1976
1976
|
mergeNames(templateData.declaredEmits, namesFromType);
|
|
1977
1977
|
return;
|
|
1978
1978
|
}
|
|
1979
1979
|
mergeNames(templateData.declaredEmits, resolveObjectOrArrayLiteralNames(initValue));
|
|
1980
1980
|
}
|
|
1981
|
-
function resolveDeclaredEmitsFromTypeParams(typeParams,
|
|
1981
|
+
function resolveDeclaredEmitsFromTypeParams(typeParams, path8, ctx) {
|
|
1982
1982
|
const names = /* @__PURE__ */ new Set();
|
|
1983
1983
|
const visitedTypeRefs = /* @__PURE__ */ new Set();
|
|
1984
1984
|
const warnedImportedTypeRefs = /* @__PURE__ */ new Set();
|
|
1985
1985
|
for (const tsType of resolveTsTypes(typeParams)) {
|
|
1986
|
-
collectEmitsFromTsType(tsType, names,
|
|
1986
|
+
collectEmitsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
1987
1987
|
}
|
|
1988
1988
|
return names;
|
|
1989
1989
|
}
|
|
1990
|
-
function collectEmitsFromTsType(tsType, names,
|
|
1990
|
+
function collectEmitsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
|
|
1991
1991
|
if (t18.isTSParenthesizedType(tsType)) {
|
|
1992
1992
|
collectEmitsFromTsType(
|
|
1993
1993
|
tsType.typeAnnotation,
|
|
1994
1994
|
names,
|
|
1995
|
-
|
|
1995
|
+
path8,
|
|
1996
1996
|
ctx,
|
|
1997
1997
|
visitedTypeRefs,
|
|
1998
1998
|
warnedImportedTypeRefs
|
|
@@ -2001,17 +2001,17 @@ function collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
|
|
|
2001
2001
|
}
|
|
2002
2002
|
if (t18.isTSIntersectionType(tsType) || t18.isTSUnionType(tsType)) {
|
|
2003
2003
|
for (const type of tsType.types) {
|
|
2004
|
-
collectEmitsFromTsType(type, names,
|
|
2004
|
+
collectEmitsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2005
2005
|
}
|
|
2006
2006
|
return;
|
|
2007
2007
|
}
|
|
2008
2008
|
if (t18.isTSTypeReference(tsType)) {
|
|
2009
2009
|
const innerTypes = _optionalChain([tsType, 'access', _53 => _53.typeParameters, 'optionalAccess', _54 => _54.params]) || [];
|
|
2010
2010
|
for (const type of innerTypes) {
|
|
2011
|
-
collectEmitsFromTsType(type, names,
|
|
2011
|
+
collectEmitsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2012
2012
|
}
|
|
2013
2013
|
const localType = resolveLocalTypeFromReference(
|
|
2014
|
-
|
|
2014
|
+
path8,
|
|
2015
2015
|
tsType,
|
|
2016
2016
|
ctx,
|
|
2017
2017
|
MACRO_API_NAMES.emits,
|
|
@@ -2019,7 +2019,7 @@ function collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
|
|
|
2019
2019
|
warnedImportedTypeRefs
|
|
2020
2020
|
);
|
|
2021
2021
|
if (localType) {
|
|
2022
|
-
collectEmitsFromTsType(localType, names,
|
|
2022
|
+
collectEmitsFromTsType(localType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2023
2023
|
}
|
|
2024
2024
|
return;
|
|
2025
2025
|
}
|
|
@@ -2095,8 +2095,8 @@ function resolveStringLiteralTypeNames(type) {
|
|
|
2095
2095
|
|
|
2096
2096
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/resolve-declared-props.ts
|
|
2097
2097
|
|
|
2098
|
-
function resolveDeclaredProps(
|
|
2099
|
-
const { node } =
|
|
2098
|
+
function resolveDeclaredProps(path8, ctx) {
|
|
2099
|
+
const { node } = path8;
|
|
2100
2100
|
const { templateData, scriptData } = ctx;
|
|
2101
2101
|
if (!isCalleeNamed(node, MACRO_API_NAMES.props)) {
|
|
2102
2102
|
return;
|
|
@@ -2107,28 +2107,28 @@ function resolveDeclaredProps(path9, ctx) {
|
|
|
2107
2107
|
mergeNames(templateData.declaredProps, resolveObjectOrArrayLiteralNames(initValue));
|
|
2108
2108
|
return;
|
|
2109
2109
|
}
|
|
2110
|
-
const namesFromType = resolveDeclaredPropsFromTypeParams(tsTypeDef,
|
|
2110
|
+
const namesFromType = resolveDeclaredPropsFromTypeParams(tsTypeDef, path8, ctx);
|
|
2111
2111
|
if (namesFromType.size) {
|
|
2112
2112
|
mergeNames(templateData.declaredProps, namesFromType);
|
|
2113
2113
|
return;
|
|
2114
2114
|
}
|
|
2115
2115
|
mergeNames(templateData.declaredProps, resolveObjectOrArrayLiteralNames(initValue));
|
|
2116
2116
|
}
|
|
2117
|
-
function resolveDeclaredPropsFromTypeParams(typeParams,
|
|
2117
|
+
function resolveDeclaredPropsFromTypeParams(typeParams, path8, ctx) {
|
|
2118
2118
|
const names = /* @__PURE__ */ new Set();
|
|
2119
2119
|
const visitedTypeRefs = /* @__PURE__ */ new Set();
|
|
2120
2120
|
const warnedImportedTypeRefs = /* @__PURE__ */ new Set();
|
|
2121
2121
|
for (const tsType of resolveTsTypes(typeParams)) {
|
|
2122
|
-
collectPropsFromTsType(tsType, names,
|
|
2122
|
+
collectPropsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2123
2123
|
}
|
|
2124
2124
|
return names;
|
|
2125
2125
|
}
|
|
2126
|
-
function collectPropsFromTsType(tsType, names,
|
|
2126
|
+
function collectPropsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
|
|
2127
2127
|
if (t19.isTSParenthesizedType(tsType)) {
|
|
2128
2128
|
collectPropsFromTsType(
|
|
2129
2129
|
tsType.typeAnnotation,
|
|
2130
2130
|
names,
|
|
2131
|
-
|
|
2131
|
+
path8,
|
|
2132
2132
|
ctx,
|
|
2133
2133
|
visitedTypeRefs,
|
|
2134
2134
|
warnedImportedTypeRefs
|
|
@@ -2137,17 +2137,17 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
|
|
|
2137
2137
|
}
|
|
2138
2138
|
if (t19.isTSIntersectionType(tsType) || t19.isTSUnionType(tsType)) {
|
|
2139
2139
|
for (const type of tsType.types) {
|
|
2140
|
-
collectPropsFromTsType(type, names,
|
|
2140
|
+
collectPropsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2141
2141
|
}
|
|
2142
2142
|
return;
|
|
2143
2143
|
}
|
|
2144
2144
|
if (t19.isTSTypeReference(tsType)) {
|
|
2145
2145
|
const innerTypes = _optionalChain([tsType, 'access', _55 => _55.typeParameters, 'optionalAccess', _56 => _56.params]) || [];
|
|
2146
2146
|
for (const type of innerTypes) {
|
|
2147
|
-
collectPropsFromTsType(type, names,
|
|
2147
|
+
collectPropsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2148
2148
|
}
|
|
2149
2149
|
const localType = resolveLocalTypeFromReference(
|
|
2150
|
-
|
|
2150
|
+
path8,
|
|
2151
2151
|
tsType,
|
|
2152
2152
|
ctx,
|
|
2153
2153
|
MACRO_API_NAMES.props,
|
|
@@ -2155,7 +2155,7 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
|
|
|
2155
2155
|
warnedImportedTypeRefs
|
|
2156
2156
|
);
|
|
2157
2157
|
if (localType) {
|
|
2158
|
-
collectPropsFromTsType(localType, names,
|
|
2158
|
+
collectPropsFromTsType(localType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
|
|
2159
2159
|
}
|
|
2160
2160
|
return;
|
|
2161
2161
|
}
|
|
@@ -2174,15 +2174,15 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
|
|
|
2174
2174
|
}
|
|
2175
2175
|
|
|
2176
2176
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/index.ts
|
|
2177
|
-
function resolveDeclaredPropsAndEmits(
|
|
2178
|
-
resolveDeclaredProps(
|
|
2179
|
-
resolveDeclaredEmits(
|
|
2177
|
+
function resolveDeclaredPropsAndEmits(path8, ctx) {
|
|
2178
|
+
resolveDeclaredProps(path8, ctx);
|
|
2179
|
+
resolveDeclaredEmits(path8, ctx);
|
|
2180
2180
|
}
|
|
2181
2181
|
|
|
2182
2182
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-use-attrs-exists.ts
|
|
2183
2183
|
|
|
2184
|
-
function resolveUseAttrsExists(
|
|
2185
|
-
const { node } =
|
|
2184
|
+
function resolveUseAttrsExists(path8, ctx) {
|
|
2185
|
+
const { node } = path8;
|
|
2186
2186
|
const { templateData, scriptData } = ctx;
|
|
2187
2187
|
if (!isCalleeNamed(node, VUE_API_MAP.useAttrs)) {
|
|
2188
2188
|
return;
|
|
@@ -2191,7 +2191,7 @@ function resolveUseAttrsExists(path9, ctx) {
|
|
|
2191
2191
|
return;
|
|
2192
2192
|
}
|
|
2193
2193
|
scriptData.hasUseAttrsCall = true;
|
|
2194
|
-
const parent = _optionalChain([
|
|
2194
|
+
const parent = _optionalChain([path8, 'access', _58 => _58.parentPath, 'optionalAccess', _59 => _59.node]);
|
|
2195
2195
|
if (parent && t20.isVariableDeclarator(parent) && t20.isIdentifier(parent.id)) {
|
|
2196
2196
|
templateData.declaredAttrs = parent.id.name;
|
|
2197
2197
|
}
|
|
@@ -2356,16 +2356,16 @@ function resolveScriptMeta(result, ctx) {
|
|
|
2356
2356
|
return;
|
|
2357
2357
|
}
|
|
2358
2358
|
_core.traverse.call(void 0, scriptAst, {
|
|
2359
|
-
VariableDeclarator(
|
|
2360
|
-
if (!atComponentOrHookRoot(
|
|
2359
|
+
VariableDeclarator(path8) {
|
|
2360
|
+
if (!atComponentOrHookRoot(path8, scriptAst.program)) {
|
|
2361
2361
|
return;
|
|
2362
2362
|
}
|
|
2363
|
-
resolveVarBindings(
|
|
2363
|
+
resolveVarBindings(path8.node, ctx);
|
|
2364
2364
|
},
|
|
2365
|
-
CallExpression(
|
|
2366
|
-
resolveDeclaredOptions(
|
|
2367
|
-
resolveDeclaredPropsAndEmits(
|
|
2368
|
-
resolveUseAttrsExists(
|
|
2365
|
+
CallExpression(path8) {
|
|
2366
|
+
resolveDeclaredOptions(path8, ctx);
|
|
2367
|
+
resolveDeclaredPropsAndEmits(path8, ctx);
|
|
2368
|
+
resolveUseAttrsExists(path8, ctx);
|
|
2369
2369
|
}
|
|
2370
2370
|
});
|
|
2371
2371
|
}
|
|
@@ -2408,33 +2408,270 @@ function resolveContext(scriptSetup, ctx) {
|
|
|
2408
2408
|
scriptSetup.content = content;
|
|
2409
2409
|
}
|
|
2410
2410
|
|
|
2411
|
-
// src/plugins/postcss.ts
|
|
2411
|
+
// src/plugins/postcss/index.ts
|
|
2412
2412
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
2413
|
+
|
|
2414
|
+
// src/plugins/postcss/deep.ts
|
|
2415
|
+
var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
|
|
2416
|
+
|
|
2417
|
+
// src/plugins/postcss/standard.ts
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
// src/plugins/postcss/utils.ts
|
|
2421
|
+
function findFirstPseudoIndex(nodes, start, end) {
|
|
2422
|
+
for (let i = start; i <= end; i++) {
|
|
2423
|
+
if (_optionalChain([nodes, 'access', _72 => _72[i], 'optionalAccess', _73 => _73.type]) === "pseudo") {
|
|
2424
|
+
return i;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
return end + 1;
|
|
2428
|
+
}
|
|
2429
|
+
function hasScopeAttribute(nodes, start, end, scopeId) {
|
|
2430
|
+
if (start > end) {
|
|
2431
|
+
return false;
|
|
2432
|
+
}
|
|
2433
|
+
for (let i = start; i <= end; i++) {
|
|
2434
|
+
const node = nodes[i];
|
|
2435
|
+
if (_optionalChain([node, 'optionalAccess', _74 => _74.type]) === "attribute" && node.attribute === scopeId) {
|
|
2436
|
+
return true;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
return false;
|
|
2440
|
+
}
|
|
2441
|
+
function hasNestingSelector(nodes, start, end) {
|
|
2442
|
+
if (start > end) {
|
|
2443
|
+
return false;
|
|
2444
|
+
}
|
|
2445
|
+
for (let i = start; i <= end; i++) {
|
|
2446
|
+
if (_optionalChain([nodes, 'access', _75 => _75[i], 'optionalAccess', _76 => _76.type]) === "nesting") {
|
|
2447
|
+
return true;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
return false;
|
|
2451
|
+
}
|
|
2452
|
+
function findScopeTargetIndex(nodes, start, end) {
|
|
2453
|
+
if (start > end) {
|
|
2454
|
+
return -1;
|
|
2455
|
+
}
|
|
2456
|
+
let candidate = -1;
|
|
2457
|
+
let nestingFallback = -1;
|
|
2458
|
+
for (let i = start; i <= end; i++) {
|
|
2459
|
+
const node = nodes[i];
|
|
2460
|
+
if (_optionalChain([node, 'optionalAccess', _77 => _77.type]) === "nesting") {
|
|
2461
|
+
nestingFallback = i;
|
|
2462
|
+
continue;
|
|
2463
|
+
}
|
|
2464
|
+
if (_optionalChain([node, 'optionalAccess', _78 => _78.type]) === "tag" || _optionalChain([node, 'optionalAccess', _79 => _79.type]) === "class" || _optionalChain([node, 'optionalAccess', _80 => _80.type]) === "id") {
|
|
2465
|
+
candidate = i;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
return candidate === -1 ? nestingFallback : candidate;
|
|
2469
|
+
}
|
|
2470
|
+
function isRuleIgnored(rule) {
|
|
2471
|
+
return rule.parent != null && rule.parent.type === "atrule" && _optionalChain([rule, 'access', _81 => _81.parent, 'optionalAccess', _82 => _82.name]) === "keyframes";
|
|
2472
|
+
}
|
|
2473
|
+
function isNestedInRule(rule) {
|
|
2474
|
+
let current = rule.parent;
|
|
2475
|
+
while (current) {
|
|
2476
|
+
if (current.type === "rule") {
|
|
2477
|
+
return true;
|
|
2478
|
+
}
|
|
2479
|
+
current = current.parent;
|
|
2480
|
+
}
|
|
2481
|
+
return false;
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
// src/plugins/postcss/standard.ts
|
|
2485
|
+
function resolveStandard(s, scopeId) {
|
|
2486
|
+
try {
|
|
2487
|
+
return _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
2488
|
+
selectors.each((selector) => {
|
|
2489
|
+
const compoundEnd = selector.nodes.length - 1;
|
|
2490
|
+
if (compoundEnd < 0) {
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
let compoundStart = 0;
|
|
2494
|
+
for (let i = compoundEnd; i >= 0; i--) {
|
|
2495
|
+
if (_optionalChain([selector, 'access', _83 => _83.nodes, 'access', _84 => _84[i], 'optionalAccess', _85 => _85.type]) === "combinator") {
|
|
2496
|
+
compoundStart = i + 1;
|
|
2497
|
+
break;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
const firstPseudoIndex = findFirstPseudoIndex(selector.nodes, compoundStart, compoundEnd);
|
|
2501
|
+
if (hasNestingSelector(selector.nodes, compoundStart, firstPseudoIndex - 1)) {
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
if (hasScopeAttribute(selector.nodes, compoundStart, firstPseudoIndex - 1, scopeId)) {
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
const insertTargetIndex = findScopeTargetIndex(
|
|
2508
|
+
selector.nodes,
|
|
2509
|
+
compoundStart,
|
|
2510
|
+
firstPseudoIndex - 1
|
|
2511
|
+
);
|
|
2512
|
+
if (insertTargetIndex === -1) {
|
|
2513
|
+
return;
|
|
2514
|
+
}
|
|
2515
|
+
selector.insertAfter(
|
|
2516
|
+
selector.nodes[insertTargetIndex],
|
|
2517
|
+
_postcssselectorparser2.default.attribute({
|
|
2518
|
+
attribute: scopeId,
|
|
2519
|
+
raws: {},
|
|
2520
|
+
value: void 0
|
|
2521
|
+
// 不加 = 值,等同于 [data-css-xxx]
|
|
2522
|
+
})
|
|
2523
|
+
);
|
|
2524
|
+
});
|
|
2525
|
+
}).processSync(s);
|
|
2526
|
+
} catch (e) {
|
|
2527
|
+
console.warn(e);
|
|
2528
|
+
return `${s}[${scopeId}]`;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
// src/plugins/postcss/deep.ts
|
|
2533
|
+
function resolveDeep(s, scopeId, nestedInRule) {
|
|
2534
|
+
try {
|
|
2535
|
+
const root = _postcssselectorparser2.default.call(void 0, ).astSync(s);
|
|
2536
|
+
const resolvedSelectors = [];
|
|
2537
|
+
root.nodes.forEach((selector) => {
|
|
2538
|
+
const resolved = resolveSingleSelectorWithDeep(selector, scopeId, nestedInRule);
|
|
2539
|
+
resolvedSelectors.push(...resolved);
|
|
2540
|
+
});
|
|
2541
|
+
return resolvedSelectors.join(", ");
|
|
2542
|
+
} catch (e) {
|
|
2543
|
+
console.warn(e);
|
|
2544
|
+
return s.replace(/:deep\((.*)\)/g, "$1");
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
function resolveSingleSelectorWithDeep(selector, scopeId, nestedInRule) {
|
|
2548
|
+
const deepIndex = findTopLevelDeepIndex(selector.nodes);
|
|
2549
|
+
if (deepIndex === -1) {
|
|
2550
|
+
return [resolveStandard(selector.toString(), scopeId)];
|
|
2551
|
+
}
|
|
2552
|
+
const deepNode = selector.nodes[deepIndex];
|
|
2553
|
+
if (_optionalChain([deepNode, 'optionalAccess', _86 => _86.type]) !== "pseudo") {
|
|
2554
|
+
return [resolveStandard(selector.toString(), scopeId)];
|
|
2555
|
+
}
|
|
2556
|
+
const leftRaw = selector.nodes.slice(0, deepIndex).map((node) => node.toString()).join("");
|
|
2557
|
+
const rightRaw = selector.nodes.slice(deepIndex + 1).map((node) => node.toString()).join("");
|
|
2558
|
+
const leftScoped = scopeDeepLeftSide(leftRaw, scopeId, nestedInRule);
|
|
2559
|
+
const deepInnerSelectors = _optionalChain([deepNode, 'access', _87 => _87.nodes, 'optionalAccess', _88 => _88.length]) ? deepNode.nodes : [];
|
|
2560
|
+
if (!deepInnerSelectors.length) {
|
|
2561
|
+
return [leftScoped + rightRaw];
|
|
2562
|
+
}
|
|
2563
|
+
const results = [];
|
|
2564
|
+
for (const innerSelector of deepInnerSelectors) {
|
|
2565
|
+
const combined = joinDeepParts(leftScoped, innerSelector.toString().trim(), rightRaw);
|
|
2566
|
+
if (combined.includes(":deep(")) {
|
|
2567
|
+
results.push(resolveDeep(combined, scopeId, nestedInRule));
|
|
2568
|
+
continue;
|
|
2569
|
+
}
|
|
2570
|
+
results.push(combined);
|
|
2571
|
+
}
|
|
2572
|
+
return results;
|
|
2573
|
+
}
|
|
2574
|
+
function findTopLevelDeepIndex(nodes) {
|
|
2575
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
2576
|
+
const node = nodes[i];
|
|
2577
|
+
if (_optionalChain([node, 'optionalAccess', _89 => _89.type]) === "pseudo" && (node.value === ":deep" || node.value === "::v-deep")) {
|
|
2578
|
+
return i;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
return -1;
|
|
2582
|
+
}
|
|
2583
|
+
function scopeDeepLeftSide(leftRaw, scopeId, nestedInRule) {
|
|
2584
|
+
if (!leftRaw.trim()) {
|
|
2585
|
+
return nestedInRule ? "&" : `[${scopeId}]`;
|
|
2586
|
+
}
|
|
2587
|
+
try {
|
|
2588
|
+
const root = _postcssselectorparser2.default.call(void 0, ).astSync(leftRaw);
|
|
2589
|
+
root.each((selector) => {
|
|
2590
|
+
injectScopeToRightMostCompound(selector, scopeId);
|
|
2591
|
+
});
|
|
2592
|
+
return root.toString();
|
|
2593
|
+
} catch (e) {
|
|
2594
|
+
console.warn(e);
|
|
2595
|
+
return resolveStandard(leftRaw, scopeId);
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
function injectScopeToRightMostCompound(selector, scopeId) {
|
|
2599
|
+
const nodes = selector.nodes;
|
|
2600
|
+
if (!nodes.length) {
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
let compoundEnd = nodes.length - 1;
|
|
2604
|
+
while (compoundEnd >= 0 && _optionalChain([nodes, 'access', _90 => _90[compoundEnd], 'optionalAccess', _91 => _91.type]) === "combinator") {
|
|
2605
|
+
compoundEnd--;
|
|
2606
|
+
}
|
|
2607
|
+
if (compoundEnd < 0) {
|
|
2608
|
+
return;
|
|
2609
|
+
}
|
|
2610
|
+
let compoundStart = 0;
|
|
2611
|
+
for (let i = compoundEnd; i >= 0; i--) {
|
|
2612
|
+
if (_optionalChain([nodes, 'access', _92 => _92[i], 'optionalAccess', _93 => _93.type]) === "combinator") {
|
|
2613
|
+
compoundStart = i + 1;
|
|
2614
|
+
break;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
const firstPseudoIndex = findFirstPseudoIndex(nodes, compoundStart, compoundEnd);
|
|
2618
|
+
if (hasScopeAttribute(nodes, compoundStart, firstPseudoIndex - 1, scopeId)) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
const insertTargetIndex = findScopeTargetIndex(nodes, compoundStart, firstPseudoIndex - 1);
|
|
2622
|
+
if (insertTargetIndex === -1) {
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
const insertTarget = nodes[insertTargetIndex];
|
|
2626
|
+
insertTarget.spaces = {
|
|
2627
|
+
...insertTarget.spaces,
|
|
2628
|
+
after: ""
|
|
2629
|
+
};
|
|
2630
|
+
selector.insertAfter(
|
|
2631
|
+
insertTarget,
|
|
2632
|
+
_postcssselectorparser2.default.attribute({
|
|
2633
|
+
attribute: scopeId,
|
|
2634
|
+
raws: {},
|
|
2635
|
+
value: void 0
|
|
2636
|
+
})
|
|
2637
|
+
);
|
|
2638
|
+
}
|
|
2639
|
+
function joinDeepParts(leftScoped, innerRaw, rightRaw) {
|
|
2640
|
+
if (!leftScoped) {
|
|
2641
|
+
return `${innerRaw}${rightRaw}`;
|
|
2642
|
+
}
|
|
2643
|
+
const needsGap = !/\s$/.test(leftScoped);
|
|
2644
|
+
const gap = needsGap ? " " : "";
|
|
2645
|
+
return `${leftScoped}${gap}${innerRaw}${rightRaw}`;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
// src/plugins/postcss/selector.ts
|
|
2649
|
+
function resolveSelector(s, scopeId, options) {
|
|
2650
|
+
if (s.includes(":global(")) {
|
|
2651
|
+
return s.replace(/:global\(([^)]+)\)/g, (_, inner) => inner);
|
|
2652
|
+
}
|
|
2653
|
+
if (s.includes(":deep(")) {
|
|
2654
|
+
return resolveDeep(s, scopeId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _94 => _94.nestedInRule]), () => ( false)));
|
|
2655
|
+
}
|
|
2656
|
+
if (s.includes(":slotted(")) {
|
|
2657
|
+
return s.replace(/:slotted\((.*)\)/, "$1");
|
|
2658
|
+
}
|
|
2659
|
+
return resolveStandard(s, scopeId);
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
// src/plugins/postcss/index.ts
|
|
2413
2663
|
function processScopedWithPostCss(input, hash) {
|
|
2414
2664
|
const scopeId = `data-css-${hash}`;
|
|
2415
2665
|
const result = _postcss2.default.call(void 0, [
|
|
2416
2666
|
{
|
|
2417
|
-
postcssPlugin: "postcss-scoped-
|
|
2667
|
+
postcssPlugin: "postcss-scoped-vureact",
|
|
2418
2668
|
Rule(rule) {
|
|
2419
|
-
if (rule
|
|
2669
|
+
if (isRuleIgnored(rule)) {
|
|
2420
2670
|
return;
|
|
2421
2671
|
}
|
|
2422
|
-
rule.selectors = rule.selectors.map(
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
}
|
|
2426
|
-
if (selector.includes(":deep(")) {
|
|
2427
|
-
return selector.replace(/:deep\((.*)\)/, "$1");
|
|
2428
|
-
}
|
|
2429
|
-
const pseudoElementRegex = /(::[a-zA-Z-]+)$/;
|
|
2430
|
-
const match = selector.match(pseudoElementRegex);
|
|
2431
|
-
if (match) {
|
|
2432
|
-
const base = selector.replace(pseudoElementRegex, "");
|
|
2433
|
-
const pseudo = match[1];
|
|
2434
|
-
return `${base}[${scopeId}]${pseudo}`;
|
|
2435
|
-
}
|
|
2436
|
-
return `${selector}[${scopeId}]`;
|
|
2437
|
-
});
|
|
2672
|
+
rule.selectors = rule.selectors.map(
|
|
2673
|
+
(selector) => resolveSelector(selector, scopeId, { nestedInRule: isNestedInRule(rule) })
|
|
2674
|
+
);
|
|
2438
2675
|
}
|
|
2439
2676
|
}
|
|
2440
2677
|
]).process(input);
|
|
@@ -2568,7 +2805,7 @@ function resolveStyles(descriptor, ctx, result) {
|
|
|
2568
2805
|
var _compilercore = require('@vue/compiler-core');
|
|
2569
2806
|
function resolveTemplate(descriptor, _, result) {
|
|
2570
2807
|
const block = descriptor.template;
|
|
2571
|
-
if (!_optionalChain([block, 'optionalAccess',
|
|
2808
|
+
if (!_optionalChain([block, 'optionalAccess', _95 => _95.content])) return null;
|
|
2572
2809
|
result.template = {
|
|
2573
2810
|
ast: _compilercore.baseParse.call(void 0, block.content),
|
|
2574
2811
|
source: block
|
|
@@ -2585,7 +2822,7 @@ function processVueSyntax(descriptor, ctx, result) {
|
|
|
2585
2822
|
}
|
|
2586
2823
|
function vueSyntaxProcessor(descriptor, ctx, result, options) {
|
|
2587
2824
|
const run = (p, type) => {
|
|
2588
|
-
_optionalChain([p, 'optionalAccess',
|
|
2825
|
+
_optionalChain([p, 'optionalAccess', _96 => _96.forEach, 'call', _97 => _97((handler) => {
|
|
2589
2826
|
if (type === "post") {
|
|
2590
2827
|
handler(result, ctx);
|
|
2591
2828
|
return;
|
|
@@ -2609,7 +2846,7 @@ function parseSFC(source, ctx, options) {
|
|
|
2609
2846
|
};
|
|
2610
2847
|
collectErrs(descriptor, errors);
|
|
2611
2848
|
processVueSyntax(descriptor, ctx, result);
|
|
2612
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
2849
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _98 => _98.plugins]), result, ctx);
|
|
2613
2850
|
return result;
|
|
2614
2851
|
}
|
|
2615
2852
|
function collectErrs(descriptor, errors) {
|
|
@@ -2617,7 +2854,7 @@ function collectErrs(descriptor, errors) {
|
|
|
2617
2854
|
logger.error(err.message, {
|
|
2618
2855
|
source: descriptor.source,
|
|
2619
2856
|
file: descriptor.filename,
|
|
2620
|
-
loc: _optionalChain([err, 'optionalAccess',
|
|
2857
|
+
loc: _optionalChain([err, 'optionalAccess', _99 => _99.loc])
|
|
2621
2858
|
});
|
|
2622
2859
|
}
|
|
2623
2860
|
if (descriptor.cssVars.length) {
|
|
@@ -2640,25 +2877,25 @@ function parse(source, ctx, options) {
|
|
|
2640
2877
|
|
|
2641
2878
|
|
|
2642
2879
|
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-global-type-chunk.ts
|
|
2643
|
-
function resolveGlobalTypeChunks(
|
|
2644
|
-
if (!_optionalChain([
|
|
2880
|
+
function resolveGlobalTypeChunks(path8, ir) {
|
|
2881
|
+
if (!_optionalChain([path8, 'access', _100 => _100.parentPath, 'optionalAccess', _101 => _101.isProgram, 'call', _102 => _102()])) {
|
|
2645
2882
|
return;
|
|
2646
2883
|
}
|
|
2647
|
-
const forked = forkNode(
|
|
2884
|
+
const forked = forkNode(path8.node);
|
|
2648
2885
|
ir.tsTypes.push(forked);
|
|
2649
|
-
|
|
2886
|
+
path8.remove();
|
|
2650
2887
|
}
|
|
2651
2888
|
|
|
2652
2889
|
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-module-chunk.ts
|
|
2653
2890
|
|
|
2654
|
-
function resolveModuleChunks(
|
|
2655
|
-
const forked = forkNode(
|
|
2891
|
+
function resolveModuleChunks(path8, ir) {
|
|
2892
|
+
const forked = forkNode(path8.node);
|
|
2656
2893
|
if (t22.isImportDeclaration(forked)) {
|
|
2657
2894
|
ir.imports.push(forked);
|
|
2658
2895
|
} else if (t22.isExportDeclaration(forked)) {
|
|
2659
2896
|
ir.exports.push(forked);
|
|
2660
2897
|
}
|
|
2661
|
-
|
|
2898
|
+
path8.remove();
|
|
2662
2899
|
}
|
|
2663
2900
|
|
|
2664
2901
|
// src/core/transform/sfc/script/shared/metadata-utils.ts
|
|
@@ -2678,10 +2915,10 @@ function setScriptNodeMeta(node, opts) {
|
|
|
2678
2915
|
}
|
|
2679
2916
|
|
|
2680
2917
|
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-static-const-chunk.ts
|
|
2681
|
-
function resolveStaticConstChunks(
|
|
2682
|
-
const { node, parentPath } =
|
|
2918
|
+
function resolveStaticConstChunks(path8, ir) {
|
|
2919
|
+
const { node, parentPath } = path8;
|
|
2683
2920
|
const parent = parentPath.node;
|
|
2684
|
-
if (!isVariableDeclTopLevel(
|
|
2921
|
+
if (!isVariableDeclTopLevel(path8) || !parentPath.isVariableDeclaration() || parent.kind !== "const" || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
|
|
2685
2922
|
return;
|
|
2686
2923
|
}
|
|
2687
2924
|
const forked = forkNode(parent);
|
|
@@ -2698,16 +2935,16 @@ function resolveASTChunks(ctx, ast) {
|
|
|
2698
2935
|
scriptIR.statement.local = ast;
|
|
2699
2936
|
return {
|
|
2700
2937
|
// 提取 import/export
|
|
2701
|
-
"ImportDeclaration|ExportDeclaration"(
|
|
2702
|
-
resolveModuleChunks(
|
|
2938
|
+
"ImportDeclaration|ExportDeclaration"(path8) {
|
|
2939
|
+
resolveModuleChunks(path8, scriptIR);
|
|
2703
2940
|
},
|
|
2704
2941
|
// 提取全局类型声明
|
|
2705
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(
|
|
2706
|
-
resolveGlobalTypeChunks(
|
|
2942
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path8) {
|
|
2943
|
+
resolveGlobalTypeChunks(path8, scriptIR);
|
|
2707
2944
|
},
|
|
2708
2945
|
// 提升顶层常量声明
|
|
2709
|
-
VariableDeclarator(
|
|
2710
|
-
resolveStaticConstChunks(
|
|
2946
|
+
VariableDeclarator(path8) {
|
|
2947
|
+
resolveStaticConstChunks(path8, scriptIR);
|
|
2711
2948
|
}
|
|
2712
2949
|
};
|
|
2713
2950
|
}
|
|
@@ -2793,11 +3030,11 @@ var StyleFileStrategy = (_class3 = class {constructor() { _class3.prototype.__in
|
|
|
2793
3030
|
matches(moduleName) {
|
|
2794
3031
|
return this.regExp.test(moduleName);
|
|
2795
3032
|
}
|
|
2796
|
-
process(
|
|
3033
|
+
process(path8, ctx) {
|
|
2797
3034
|
if (!ctx.preprocessStyles) {
|
|
2798
3035
|
return {};
|
|
2799
3036
|
}
|
|
2800
|
-
const importSource =
|
|
3037
|
+
const importSource = path8.node.source.value;
|
|
2801
3038
|
if (typeof importSource !== "string") {
|
|
2802
3039
|
return {};
|
|
2803
3040
|
}
|
|
@@ -2842,25 +3079,25 @@ function resolveRuntimeImports(ctx) {
|
|
|
2842
3079
|
const processedModules = /* @__PURE__ */ new Set();
|
|
2843
3080
|
let hasImports = false;
|
|
2844
3081
|
return {
|
|
2845
|
-
ImportDeclaration(
|
|
2846
|
-
const { node } =
|
|
3082
|
+
ImportDeclaration(path8) {
|
|
3083
|
+
const { node } = path8;
|
|
2847
3084
|
const originalModuleName = node.source.value.toLowerCase();
|
|
2848
3085
|
const strategy = strategyManager.findStrategy(originalModuleName);
|
|
2849
3086
|
let strategyResult = null;
|
|
2850
3087
|
if (strategy) {
|
|
2851
|
-
strategyResult = strategy.process(
|
|
3088
|
+
strategyResult = strategy.process(path8, ctx, originalModuleName);
|
|
2852
3089
|
if (strategyResult.shouldReplaceSource && strategyResult.newSource) {
|
|
2853
3090
|
node.source.value = strategyResult.newSource;
|
|
2854
3091
|
}
|
|
2855
|
-
if (strategyResult.shouldRemove && !
|
|
2856
|
-
|
|
3092
|
+
if (strategyResult.shouldRemove && !path8.removed) {
|
|
3093
|
+
path8.remove();
|
|
2857
3094
|
return;
|
|
2858
3095
|
}
|
|
2859
3096
|
}
|
|
2860
3097
|
replaceVueSuffix(node.source);
|
|
2861
3098
|
const finalModuleName = node.source.value.toLowerCase();
|
|
2862
|
-
if (processedModules.has(finalModuleName) && !
|
|
2863
|
-
|
|
3099
|
+
if (processedModules.has(finalModuleName) && !path8.removed) {
|
|
3100
|
+
path8.remove();
|
|
2864
3101
|
return;
|
|
2865
3102
|
}
|
|
2866
3103
|
processedModules.add(finalModuleName);
|
|
@@ -2868,13 +3105,13 @@ function resolveRuntimeImports(ctx) {
|
|
|
2868
3105
|
if (!hasImports) {
|
|
2869
3106
|
const importNodes = createImportNodes(ctx);
|
|
2870
3107
|
if (importNodes.length) {
|
|
2871
|
-
if (_optionalChain([strategyResult, 'optionalAccess',
|
|
2872
|
-
|
|
3108
|
+
if (_optionalChain([strategyResult, 'optionalAccess', _103 => _103.shouldInjectRuntimeImports])) {
|
|
3109
|
+
path8.insertAfter(importNodes);
|
|
2873
3110
|
} else if (finalModuleName === PACKAGE_NAME.react) {
|
|
2874
|
-
|
|
3111
|
+
path8.insertAfter(importNodes);
|
|
2875
3112
|
} else {
|
|
2876
3113
|
forkFilePreambleLeadingComments(importNodes[0], node);
|
|
2877
|
-
|
|
3114
|
+
path8.insertBefore(importNodes);
|
|
2878
3115
|
}
|
|
2879
3116
|
}
|
|
2880
3117
|
hasImports = true;
|
|
@@ -2882,21 +3119,21 @@ function resolveRuntimeImports(ctx) {
|
|
|
2882
3119
|
},
|
|
2883
3120
|
// 兜底:无 ImportDeclaration 的文件也要能注入必需依赖。
|
|
2884
3121
|
Program: {
|
|
2885
|
-
exit(
|
|
3122
|
+
exit(path8) {
|
|
2886
3123
|
if (hasImports) return;
|
|
2887
3124
|
hasImports = true;
|
|
2888
|
-
const { node } =
|
|
3125
|
+
const { node } = path8;
|
|
2889
3126
|
const importNodes = createImportNodes(ctx);
|
|
2890
3127
|
if (!importNodes.length) return;
|
|
2891
3128
|
forkProgramTopLeadingComments(importNodes[0], node);
|
|
2892
|
-
|
|
3129
|
+
path8.unshiftContainer("body", importNodes);
|
|
2893
3130
|
}
|
|
2894
3131
|
}
|
|
2895
3132
|
};
|
|
2896
3133
|
}
|
|
2897
3134
|
function mergeImports(currentNode, ctx, moduleName) {
|
|
2898
3135
|
const ctxImportItems = ctx.imports.get(moduleName);
|
|
2899
|
-
if (!_optionalChain([ctxImportItems, 'optionalAccess',
|
|
3136
|
+
if (!_optionalChain([ctxImportItems, 'optionalAccess', _104 => _104.length])) {
|
|
2900
3137
|
return;
|
|
2901
3138
|
}
|
|
2902
3139
|
const currentImports = /* @__PURE__ */ new Set();
|
|
@@ -2946,7 +3183,7 @@ function forkProgramTopLeadingComments(target, program3) {
|
|
|
2946
3183
|
}
|
|
2947
3184
|
function forkFilePreambleLeadingComments(target, source) {
|
|
2948
3185
|
const { leadingComments } = source;
|
|
2949
|
-
if (!_optionalChain([leadingComments, 'optionalAccess',
|
|
3186
|
+
if (!_optionalChain([leadingComments, 'optionalAccess', _105 => _105.length])) {
|
|
2950
3187
|
return;
|
|
2951
3188
|
}
|
|
2952
3189
|
const commentsToMove = [];
|
|
@@ -2990,8 +3227,8 @@ function resolveSfcCssImport(ctx) {
|
|
|
2990
3227
|
|
|
2991
3228
|
function resolveDefineAsyncComponent(ctx) {
|
|
2992
3229
|
return {
|
|
2993
|
-
CallExpression(
|
|
2994
|
-
const { node } =
|
|
3230
|
+
CallExpression(path8) {
|
|
3231
|
+
const { node } = path8;
|
|
2995
3232
|
if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
|
|
2996
3233
|
return;
|
|
2997
3234
|
}
|
|
@@ -3039,15 +3276,15 @@ function createUseImperativeHandle(refId, init) {
|
|
|
3039
3276
|
function resolveDefineExpose(ctx) {
|
|
3040
3277
|
if (ctx.inputType !== "sfc") return {};
|
|
3041
3278
|
return {
|
|
3042
|
-
CallExpression(
|
|
3043
|
-
const { node } =
|
|
3279
|
+
CallExpression(path8) {
|
|
3280
|
+
const { node } = path8;
|
|
3044
3281
|
const { filename, scriptData } = ctx;
|
|
3045
3282
|
if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
|
|
3046
3283
|
return;
|
|
3047
3284
|
}
|
|
3048
3285
|
const [expose] = node.arguments;
|
|
3049
3286
|
if (!expose) {
|
|
3050
|
-
|
|
3287
|
+
path8.remove();
|
|
3051
3288
|
return;
|
|
3052
3289
|
}
|
|
3053
3290
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
@@ -3064,7 +3301,7 @@ function resolveDefineExpose(ctx) {
|
|
|
3064
3301
|
const { forwardRef } = scriptData;
|
|
3065
3302
|
const newNode = createUseImperativeHandle(t27.identifier(forwardRef.refField), init);
|
|
3066
3303
|
forwardRef.enabled = true;
|
|
3067
|
-
replaceNode(
|
|
3304
|
+
replaceNode(path8, newNode, node);
|
|
3068
3305
|
}
|
|
3069
3306
|
};
|
|
3070
3307
|
}
|
|
@@ -3072,12 +3309,12 @@ function resolveDefineExpose(ctx) {
|
|
|
3072
3309
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-options.ts
|
|
3073
3310
|
function resolveDefineOptions(ctx) {
|
|
3074
3311
|
return {
|
|
3075
|
-
CallExpression(
|
|
3076
|
-
const { node } =
|
|
3312
|
+
CallExpression(path8) {
|
|
3313
|
+
const { node } = path8;
|
|
3077
3314
|
if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
|
|
3078
3315
|
return;
|
|
3079
3316
|
}
|
|
3080
|
-
|
|
3317
|
+
path8.remove();
|
|
3081
3318
|
}
|
|
3082
3319
|
};
|
|
3083
3320
|
}
|
|
@@ -3094,8 +3331,8 @@ function resolveEmitCalls(ctx) {
|
|
|
3094
3331
|
return `on${capitalize(camelCase(normalized))}`;
|
|
3095
3332
|
};
|
|
3096
3333
|
return {
|
|
3097
|
-
CallExpression(
|
|
3098
|
-
const { node } =
|
|
3334
|
+
CallExpression(path8) {
|
|
3335
|
+
const { node } = path8;
|
|
3099
3336
|
const { filename, templateData, scriptData } = ctx;
|
|
3100
3337
|
if (!t28.isIdentifier(node.callee)) return;
|
|
3101
3338
|
const { name } = node.callee;
|
|
@@ -3106,7 +3343,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3106
3343
|
result = meta.source === MACRO_API_NAMES.emits;
|
|
3107
3344
|
}
|
|
3108
3345
|
if (!result) {
|
|
3109
|
-
const binding =
|
|
3346
|
+
const binding = path8.scope.getBinding(name);
|
|
3110
3347
|
if (binding) {
|
|
3111
3348
|
const parent = binding.path.node;
|
|
3112
3349
|
if (t28.isVariableDeclarator(parent) && t28.isCallExpression(parent.init) && t28.isIdentifier(parent.init.callee)) {
|
|
@@ -3118,30 +3355,32 @@ function resolveEmitCalls(ctx) {
|
|
|
3118
3355
|
};
|
|
3119
3356
|
if (!checkIfFromDefineEmits()) return;
|
|
3120
3357
|
const [callee, ...args] = node.arguments;
|
|
3121
|
-
|
|
3122
|
-
if (
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3358
|
+
let propCall;
|
|
3359
|
+
if (t28.isStringLiteral(callee)) {
|
|
3360
|
+
const eventName = formatEmitEventName(callee.value);
|
|
3361
|
+
propCall = createPropCall(ctx.propField, t28.identifier(eventName), args);
|
|
3362
|
+
} else {
|
|
3363
|
+
propCall = createPropCall(ctx.propField, callee, args, true);
|
|
3364
|
+
logger.error(
|
|
3365
|
+
`Non-string event name cannot be converted to React onXxx style. The emit call will not work as expected.`,
|
|
3366
|
+
{
|
|
3367
|
+
file: filename,
|
|
3368
|
+
source: scriptData.source,
|
|
3369
|
+
loc: _optionalChain([callee, 'optionalAccess', _106 => _106.loc])
|
|
3370
|
+
}
|
|
3371
|
+
);
|
|
3130
3372
|
}
|
|
3131
|
-
|
|
3132
|
-
t28.optionalMemberExpression(
|
|
3133
|
-
t28.identifier(ctx.propField),
|
|
3134
|
-
t28.identifier(eventName),
|
|
3135
|
-
false,
|
|
3136
|
-
true
|
|
3137
|
-
),
|
|
3138
|
-
args,
|
|
3139
|
-
true
|
|
3140
|
-
);
|
|
3141
|
-
replaceNode(path9, propCall, node);
|
|
3373
|
+
replaceNode(path8, propCall, node);
|
|
3142
3374
|
}
|
|
3143
3375
|
};
|
|
3144
3376
|
}
|
|
3377
|
+
function createPropCall(rootName, callee, args, computed = false) {
|
|
3378
|
+
return t28.optionalCallExpression(
|
|
3379
|
+
t28.memberExpression(t28.identifier(rootName), callee, computed),
|
|
3380
|
+
args,
|
|
3381
|
+
true
|
|
3382
|
+
);
|
|
3383
|
+
}
|
|
3145
3384
|
|
|
3146
3385
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/index.ts
|
|
3147
3386
|
|
|
@@ -3176,9 +3415,9 @@ function cloneCallableParams(params) {
|
|
|
3176
3415
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
|
|
3177
3416
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
3178
3417
|
return {
|
|
3179
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(
|
|
3180
|
-
if (!t30.isProgram(
|
|
3181
|
-
const { node } =
|
|
3418
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3419
|
+
if (!t30.isProgram(path8.parent)) return;
|
|
3420
|
+
const { node } = path8;
|
|
3182
3421
|
if (t30.isTSInterfaceDeclaration(node)) {
|
|
3183
3422
|
const typeLiteral = t30.tsTypeLiteral(node.body.body);
|
|
3184
3423
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
@@ -3243,11 +3482,11 @@ function resolveTopLevelEmitType(tsType) {
|
|
|
3243
3482
|
}
|
|
3244
3483
|
return tsType;
|
|
3245
3484
|
}
|
|
3246
|
-
function resolveDefineEmitsIface(
|
|
3247
|
-
const { node } =
|
|
3485
|
+
function resolveDefineEmitsIface(path8, ctx) {
|
|
3486
|
+
const { node } = path8;
|
|
3248
3487
|
const [runtimeArg] = node.arguments;
|
|
3249
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3250
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
3488
|
+
const tsParams = _optionalChain([node, 'access', _107 => _107.typeParameters, 'optionalAccess', _108 => _108.params]);
|
|
3489
|
+
if (_optionalChain([tsParams, 'optionalAccess', _109 => _109.length])) {
|
|
3251
3490
|
processExplicitType(ctx, tsParams);
|
|
3252
3491
|
return;
|
|
3253
3492
|
}
|
|
@@ -3445,12 +3684,12 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3445
3684
|
if (!rawName) return null;
|
|
3446
3685
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3447
3686
|
const key = buildKey(handlerName);
|
|
3448
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3687
|
+
const typeAnnotation = _optionalChain([member, 'access', _110 => _110.typeAnnotation, 'optionalAccess', _111 => _111.typeAnnotation]);
|
|
3449
3688
|
let params = [];
|
|
3450
3689
|
let returnType = t30.tsAnyKeyword();
|
|
3451
3690
|
if (typeAnnotation && t30.isTSFunctionType(typeAnnotation)) {
|
|
3452
3691
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3453
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
3692
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _112 => _112.typeAnnotation, 'optionalAccess', _113 => _113.typeAnnotation]), () => ( returnType));
|
|
3454
3693
|
} else if (typeAnnotation && t30.isTSTupleType(typeAnnotation)) {
|
|
3455
3694
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
3456
3695
|
} else if (typeAnnotation) {
|
|
@@ -3475,7 +3714,7 @@ function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
|
3475
3714
|
if (t30.isNoop(paramTypeAnnotation)) return [];
|
|
3476
3715
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
3477
3716
|
if (!eventNames.length) return [];
|
|
3478
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
3717
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _114 => _114.typeAnnotation]), () => ( t30.tsAnyKeyword()));
|
|
3479
3718
|
return eventNames.map((eventName) => {
|
|
3480
3719
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
3481
3720
|
const key = buildKey(handlerName);
|
|
@@ -3509,7 +3748,7 @@ function resolveTupleElementParam(element, index) {
|
|
|
3509
3748
|
const isNamedTuple = typeof t30.isTSNamedTupleMember === "function" && t30.isTSNamedTupleMember(element);
|
|
3510
3749
|
if (isNamedTuple) {
|
|
3511
3750
|
const tupleMember = element;
|
|
3512
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
3751
|
+
const name = _optionalChain([tupleMember, 'access', _115 => _115.label, 'optionalAccess', _116 => _116.name]) || `arg${index}`;
|
|
3513
3752
|
let innerType = tupleMember.elementType;
|
|
3514
3753
|
let optional = tupleMember.optional;
|
|
3515
3754
|
if (t30.isTSOptionalType(innerType)) {
|
|
@@ -3544,11 +3783,11 @@ function resolveTupleElementParam(element, index) {
|
|
|
3544
3783
|
|
|
3545
3784
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
3546
3785
|
|
|
3547
|
-
function resolveDefinePropsIface(
|
|
3548
|
-
const { node } =
|
|
3786
|
+
function resolveDefinePropsIface(path8, ctx) {
|
|
3787
|
+
const { node } = path8;
|
|
3549
3788
|
const [runtimeArg] = node.arguments;
|
|
3550
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3551
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
3789
|
+
const tsParams = _optionalChain([node, 'access', _117 => _117.typeParameters, 'optionalAccess', _118 => _118.params]);
|
|
3790
|
+
if (_optionalChain([tsParams, 'optionalAccess', _119 => _119.length])) {
|
|
3552
3791
|
const { propsTSIface } = ctx.scriptData;
|
|
3553
3792
|
propsTSIface.propsTypes = tsParams;
|
|
3554
3793
|
return;
|
|
@@ -3603,7 +3842,7 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3603
3842
|
{
|
|
3604
3843
|
source,
|
|
3605
3844
|
file: filename,
|
|
3606
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
3845
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _120 => _120.loc])
|
|
3607
3846
|
}
|
|
3608
3847
|
);
|
|
3609
3848
|
}
|
|
@@ -3714,7 +3953,7 @@ function createSlotScopeParam(props, ctx) {
|
|
|
3714
3953
|
const propsSigns = [];
|
|
3715
3954
|
const { reactiveBindings } = ctx.templateData;
|
|
3716
3955
|
props.forEach(({ prop, tsType }) => {
|
|
3717
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
3956
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _121 => _121[prop], 'optionalAccess', _122 => _122.value]);
|
|
3718
3957
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3719
3958
|
const typeAnnotation = foundBindingTypes ? t32.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
3720
3959
|
const key = t32.isValidIdentifier(prop) ? t32.identifier(prop) : t32.stringLiteral(prop);
|
|
@@ -3733,9 +3972,9 @@ function recordReactNode(ctx) {
|
|
|
3733
3972
|
}
|
|
3734
3973
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
|
|
3735
3974
|
}
|
|
3736
|
-
function collectLocalTypeDeclarations(
|
|
3975
|
+
function collectLocalTypeDeclarations(path8) {
|
|
3737
3976
|
const declarations = /* @__PURE__ */ new Map();
|
|
3738
|
-
const programPath =
|
|
3977
|
+
const programPath = path8.findParent(
|
|
3739
3978
|
(parentPath) => parentPath.isProgram()
|
|
3740
3979
|
);
|
|
3741
3980
|
if (!programPath) {
|
|
@@ -3746,7 +3985,7 @@ function collectLocalTypeDeclarations(path9) {
|
|
|
3746
3985
|
declarations.set(statement.id.name, {
|
|
3747
3986
|
type: t33.tsTypeLiteral(statement.body.body),
|
|
3748
3987
|
// 将接口体转换为类型字面量
|
|
3749
|
-
hasTypeParameters: !!_optionalChain([statement, 'access',
|
|
3988
|
+
hasTypeParameters: !!_optionalChain([statement, 'access', _123 => _123.typeParameters, 'optionalAccess', _124 => _124.params, 'access', _125 => _125.length])
|
|
3750
3989
|
// 检查是否有泛型参数
|
|
3751
3990
|
});
|
|
3752
3991
|
continue;
|
|
@@ -3755,7 +3994,7 @@ function collectLocalTypeDeclarations(path9) {
|
|
|
3755
3994
|
declarations.set(statement.id.name, {
|
|
3756
3995
|
type: statement.typeAnnotation,
|
|
3757
3996
|
// 直接使用类型注解
|
|
3758
|
-
hasTypeParameters: !!_optionalChain([statement, 'access',
|
|
3997
|
+
hasTypeParameters: !!_optionalChain([statement, 'access', _126 => _126.typeParameters, 'optionalAccess', _127 => _127.params, 'access', _128 => _128.length])
|
|
3759
3998
|
// 检查是否有泛型参数
|
|
3760
3999
|
});
|
|
3761
4000
|
continue;
|
|
@@ -3766,14 +4005,14 @@ function collectLocalTypeDeclarations(path9) {
|
|
|
3766
4005
|
declarations.set(declaration.id.name, {
|
|
3767
4006
|
type: t33.tsTypeLiteral(declaration.body.body),
|
|
3768
4007
|
// 将接口体转换为类型字面量
|
|
3769
|
-
hasTypeParameters: !!_optionalChain([declaration, 'access',
|
|
4008
|
+
hasTypeParameters: !!_optionalChain([declaration, 'access', _129 => _129.typeParameters, 'optionalAccess', _130 => _130.params, 'access', _131 => _131.length])
|
|
3770
4009
|
// 检查是否有泛型参数
|
|
3771
4010
|
});
|
|
3772
4011
|
} else if (t33.isTSTypeAliasDeclaration(declaration)) {
|
|
3773
4012
|
declarations.set(declaration.id.name, {
|
|
3774
4013
|
type: declaration.typeAnnotation,
|
|
3775
4014
|
// 直接使用类型注解
|
|
3776
|
-
hasTypeParameters: !!_optionalChain([declaration, 'access',
|
|
4015
|
+
hasTypeParameters: !!_optionalChain([declaration, 'access', _132 => _132.typeParameters, 'optionalAccess', _133 => _133.params, 'access', _134 => _134.length])
|
|
3777
4016
|
// 检查是否有泛型参数
|
|
3778
4017
|
});
|
|
3779
4018
|
}
|
|
@@ -3811,7 +4050,7 @@ function resolveSlotType(tsType, options) {
|
|
|
3811
4050
|
}
|
|
3812
4051
|
if (t34.isTSTypeReference(tsType)) {
|
|
3813
4052
|
let shouldRecordReactNode = false;
|
|
3814
|
-
if (_optionalChain([tsType, 'access',
|
|
4053
|
+
if (_optionalChain([tsType, 'access', _135 => _135.typeParameters, 'optionalAccess', _136 => _136.params, 'access', _137 => _137.length])) {
|
|
3815
4054
|
const params = [];
|
|
3816
4055
|
for (const param of tsType.typeParameters.params) {
|
|
3817
4056
|
const resolved2 = resolveSlotType(param, options);
|
|
@@ -3975,7 +4214,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
3975
4214
|
shouldRecordReactNode: false
|
|
3976
4215
|
};
|
|
3977
4216
|
}
|
|
3978
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
4217
|
+
const typeAnnotation = _optionalChain([member, 'access', _138 => _138.typeAnnotation, 'optionalAccess', _139 => _139.typeAnnotation]);
|
|
3979
4218
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
3980
4219
|
if (!callable) {
|
|
3981
4220
|
return {
|
|
@@ -4005,14 +4244,14 @@ function resolveSlotPropFromMember(member) {
|
|
|
4005
4244
|
}
|
|
4006
4245
|
|
|
4007
4246
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/define-slots.ts
|
|
4008
|
-
function resolveDefineSlotsIface(
|
|
4009
|
-
const { node } =
|
|
4010
|
-
const tsParams = _optionalChain([node, 'access',
|
|
4011
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
4247
|
+
function resolveDefineSlotsIface(path8, ctx) {
|
|
4248
|
+
const { node } = path8;
|
|
4249
|
+
const tsParams = _optionalChain([node, 'access', _140 => _140.typeParameters, 'optionalAccess', _141 => _141.params]);
|
|
4250
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _142 => _142.length])) return;
|
|
4012
4251
|
const {
|
|
4013
4252
|
propsTSIface: { slotTypes }
|
|
4014
4253
|
} = ctx.scriptData;
|
|
4015
|
-
const localTypeDeclarations = collectLocalTypeDeclarations(
|
|
4254
|
+
const localTypeDeclarations = collectLocalTypeDeclarations(path8);
|
|
4016
4255
|
let shouldRecordReactNode = false;
|
|
4017
4256
|
for (const tsType of tsParams) {
|
|
4018
4257
|
const { type: resolved, shouldRecordReactNode: needsReactNode } = resolveSlotType(tsType, {
|
|
@@ -4056,8 +4295,8 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
4056
4295
|
function resolvePropsIface(ctx) {
|
|
4057
4296
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
4058
4297
|
return {
|
|
4059
|
-
CallExpression(
|
|
4060
|
-
const { node, parentPath } =
|
|
4298
|
+
CallExpression(path8) {
|
|
4299
|
+
const { node, parentPath } = path8;
|
|
4061
4300
|
const name = node.callee.name;
|
|
4062
4301
|
if (!isCalleeNamed(node, MACRO_API_NAMES.props) && !isCalleeNamed(node, MACRO_API_NAMES.emits) && !isCalleeNamed(node, MACRO_API_NAMES.slots)) {
|
|
4063
4302
|
return;
|
|
@@ -4066,7 +4305,7 @@ function resolvePropsIface(ctx) {
|
|
|
4066
4305
|
if (parentPath.isVariableDeclaration() || parentPath.isVariableDeclarator()) {
|
|
4067
4306
|
parentPath.remove();
|
|
4068
4307
|
} else {
|
|
4069
|
-
|
|
4308
|
+
path8.remove();
|
|
4070
4309
|
}
|
|
4071
4310
|
};
|
|
4072
4311
|
if (ctx.inputType !== "sfc") {
|
|
@@ -4080,11 +4319,11 @@ function resolvePropsIface(ctx) {
|
|
|
4080
4319
|
propsTSIface.hasPropsInJsEnv = true;
|
|
4081
4320
|
} else {
|
|
4082
4321
|
if (name === MACRO_API_NAMES.props) {
|
|
4083
|
-
resolveDefinePropsIface(
|
|
4322
|
+
resolveDefinePropsIface(path8, ctx);
|
|
4084
4323
|
} else if (name === MACRO_API_NAMES.emits) {
|
|
4085
|
-
resolveDefineEmitsIface(
|
|
4324
|
+
resolveDefineEmitsIface(path8, ctx);
|
|
4086
4325
|
} else if (name === MACRO_API_NAMES.slots) {
|
|
4087
|
-
resolveDefineSlotsIface(
|
|
4326
|
+
resolveDefineSlotsIface(path8, ctx);
|
|
4088
4327
|
}
|
|
4089
4328
|
}
|
|
4090
4329
|
removePath();
|
|
@@ -4113,10 +4352,10 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4113
4352
|
|
|
4114
4353
|
function resolveUseAttrs(ctx) {
|
|
4115
4354
|
return {
|
|
4116
|
-
VariableDeclarator(
|
|
4117
|
-
const { init, id } =
|
|
4355
|
+
VariableDeclarator(path8) {
|
|
4356
|
+
const { init, id } = path8.node;
|
|
4118
4357
|
if (!init) return;
|
|
4119
|
-
const initPath =
|
|
4358
|
+
const initPath = path8.get("init");
|
|
4120
4359
|
const propsIdentifier = t37.identifier(ctx.propField);
|
|
4121
4360
|
if (t37.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
|
|
4122
4361
|
const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
|
|
@@ -4156,18 +4395,247 @@ function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
|
4156
4395
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4157
4396
|
|
|
4158
4397
|
|
|
4159
|
-
// src/core/transform/sfc/script/shared/dependency-analyzer.ts
|
|
4398
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4399
|
+
|
|
4400
|
+
|
|
4401
|
+
|
|
4402
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/binding-utils.ts
|
|
4403
|
+
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
4404
|
+
let current = binding.path;
|
|
4405
|
+
while (current) {
|
|
4406
|
+
if (current.node === boundary) {
|
|
4407
|
+
return true;
|
|
4408
|
+
}
|
|
4409
|
+
current = current.parentPath;
|
|
4410
|
+
}
|
|
4411
|
+
return false;
|
|
4412
|
+
}
|
|
4413
|
+
function isReactiveBinding(node) {
|
|
4414
|
+
if (!node) return false;
|
|
4415
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _143 => _143(node), 'optionalAccess', _144 => _144.is_reactive]);
|
|
4416
|
+
}
|
|
4417
|
+
|
|
4418
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
|
|
4419
|
+
|
|
4420
|
+
function isEligibleBindingSource(binding) {
|
|
4421
|
+
if (binding.kind === "param") {
|
|
4422
|
+
return false;
|
|
4423
|
+
}
|
|
4424
|
+
const reactiveStateApis = getReactiveStateApis();
|
|
4425
|
+
const bindingPath = binding.path;
|
|
4426
|
+
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4427
|
+
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4428
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _145 => _145.node, 'access', _146 => _146.init]);
|
|
4429
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && t38.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4430
|
+
const isHookCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4431
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t38.isArrowFunctionExpression(nodeInit) || t38.isFunctionExpression(nodeInit));
|
|
4432
|
+
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _147 => _147.node])) || isReactiveBinding(bindingPath.node));
|
|
4433
|
+
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4434
|
+
}
|
|
4435
|
+
function isReactValidDependencyExpr(node) {
|
|
4436
|
+
if (t38.isIdentifier(node)) {
|
|
4437
|
+
return true;
|
|
4438
|
+
}
|
|
4439
|
+
if (t38.isMemberExpression(node) || t38.isOptionalMemberExpression(node)) {
|
|
4440
|
+
return isStaticMemberChain(node);
|
|
4441
|
+
}
|
|
4442
|
+
return false;
|
|
4443
|
+
}
|
|
4444
|
+
function isStaticMemberChain(node) {
|
|
4445
|
+
let current = node;
|
|
4446
|
+
while (t38.isMemberExpression(current) || t38.isOptionalMemberExpression(current)) {
|
|
4447
|
+
if (!current.computed && !t38.isIdentifier(current.property)) {
|
|
4448
|
+
return false;
|
|
4449
|
+
}
|
|
4450
|
+
if (current.computed && !t38.isStringLiteral(current.property) && !t38.isNumericLiteral(current.property)) {
|
|
4451
|
+
return false;
|
|
4452
|
+
}
|
|
4453
|
+
current = current.object;
|
|
4454
|
+
}
|
|
4455
|
+
return t38.isIdentifier(current);
|
|
4456
|
+
}
|
|
4457
|
+
function isHookLikeCallee(callee) {
|
|
4458
|
+
if (t38.isIdentifier(callee)) {
|
|
4459
|
+
return callee.name.startsWith("use");
|
|
4460
|
+
}
|
|
4461
|
+
if (t38.isMemberExpression(callee) && !callee.computed && t38.isIdentifier(callee.property)) {
|
|
4462
|
+
return callee.property.name.startsWith("use");
|
|
4463
|
+
}
|
|
4464
|
+
return false;
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
|
|
4468
|
+
|
|
4469
|
+
function getDependencyKey(exp) {
|
|
4470
|
+
if (t39.isIdentifier(exp)) {
|
|
4471
|
+
return exp.name;
|
|
4472
|
+
}
|
|
4473
|
+
if (t39.isMemberExpression(exp) || t39.isOptionalMemberExpression(exp)) {
|
|
4474
|
+
const objectKey = getDependencyKey(exp.object);
|
|
4475
|
+
const opt = exp.optional ? "?" : "";
|
|
4476
|
+
if (!exp.computed && t39.isIdentifier(exp.property)) {
|
|
4477
|
+
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4478
|
+
}
|
|
4479
|
+
if (t39.isStringLiteral(exp.property) || t39.isNumericLiteral(exp.property)) {
|
|
4480
|
+
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4481
|
+
}
|
|
4482
|
+
return `${objectKey}${opt}[*]`;
|
|
4483
|
+
}
|
|
4484
|
+
return exp.type;
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
|
|
4160
4488
|
|
|
4489
|
+
function normalizeDependencyExpr(path8, rootName, ctx) {
|
|
4490
|
+
if (t40.isIdentifier(path8.node)) {
|
|
4491
|
+
return t40.identifier(path8.node.name);
|
|
4492
|
+
}
|
|
4493
|
+
if (t40.isMemberExpression(path8.node) || t40.isOptionalMemberExpression(path8.node)) {
|
|
4494
|
+
if (rootName === ctx.propField) {
|
|
4495
|
+
const safePropsExp = ensureOptionalForMemberChain(path8.node);
|
|
4496
|
+
if (isReactValidDependencyExpr(safePropsExp)) {
|
|
4497
|
+
return t40.cloneNode(safePropsExp, true);
|
|
4498
|
+
}
|
|
4499
|
+
return t40.identifier(rootName);
|
|
4500
|
+
}
|
|
4501
|
+
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
4502
|
+
const safeExp = t40.isMemberExpression(normalizedExp) || t40.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
4503
|
+
if (isReactValidDependencyExpr(safeExp)) {
|
|
4504
|
+
return t40.cloneNode(safeExp, true);
|
|
4505
|
+
}
|
|
4506
|
+
return t40.identifier(rootName);
|
|
4507
|
+
}
|
|
4508
|
+
return null;
|
|
4509
|
+
}
|
|
4510
|
+
function normalizeSourcedDependency(exp) {
|
|
4511
|
+
if (t40.isIdentifier(exp)) {
|
|
4512
|
+
return t40.identifier(exp.name);
|
|
4513
|
+
}
|
|
4514
|
+
if (t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp)) {
|
|
4515
|
+
const root = findRootIdentifier(exp);
|
|
4516
|
+
if (!root) return null;
|
|
4517
|
+
const safeExp = t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4518
|
+
if (isReactValidDependencyExpr(safeExp)) {
|
|
4519
|
+
return t40.cloneNode(safeExp, true);
|
|
4520
|
+
}
|
|
4521
|
+
return t40.identifier(root.name);
|
|
4522
|
+
}
|
|
4523
|
+
return null;
|
|
4524
|
+
}
|
|
4525
|
+
function normalizeMemberForCallSite(path8, node) {
|
|
4526
|
+
const parent = path8.parentPath;
|
|
4527
|
+
const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node || parent.isOptionalCallExpression() && parent.node.callee === node);
|
|
4528
|
+
if (!isDirectCallee) {
|
|
4529
|
+
return node;
|
|
4530
|
+
}
|
|
4531
|
+
if (!t40.isExpression(node.object)) {
|
|
4532
|
+
return node;
|
|
4533
|
+
}
|
|
4534
|
+
return node.object;
|
|
4535
|
+
}
|
|
4536
|
+
function ensureOptionalForMemberChain(node) {
|
|
4537
|
+
if (!hasTrailingMemberAccess(node)) {
|
|
4538
|
+
return node;
|
|
4539
|
+
}
|
|
4540
|
+
if (t40.isOptionalMemberExpression(node) && node.optional) {
|
|
4541
|
+
return node;
|
|
4542
|
+
}
|
|
4543
|
+
const object = t40.cloneNode(node.object, true);
|
|
4544
|
+
const property = t40.cloneNode(node.property, true);
|
|
4545
|
+
return t40.optionalMemberExpression(object, property, node.computed, true);
|
|
4546
|
+
}
|
|
4547
|
+
function hasTrailingMemberAccess(node) {
|
|
4548
|
+
return t40.isMemberExpression(node.object) || t40.isOptionalMemberExpression(node.object);
|
|
4549
|
+
}
|
|
4161
4550
|
|
|
4551
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
|
|
4162
4552
|
var TRACE_MAX_DEPTH = 20;
|
|
4553
|
+
function isNestedMemberObject(path8) {
|
|
4554
|
+
const parent = path8.parentPath;
|
|
4555
|
+
if (!parent) return false;
|
|
4556
|
+
if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
|
|
4557
|
+
return parent.node.object === path8.node;
|
|
4558
|
+
}
|
|
4559
|
+
return false;
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/trace-utils.ts
|
|
4563
|
+
|
|
4564
|
+
function traceBindingSource(binding, seen, depth) {
|
|
4565
|
+
if (depth <= 0) return null;
|
|
4566
|
+
const declaratorPath = getVariableDeclaratorPath(binding.path);
|
|
4567
|
+
if (!declaratorPath || !declaratorPath.node.init) return null;
|
|
4568
|
+
if (seen.has(declaratorPath.node)) return null;
|
|
4569
|
+
seen.add(declaratorPath.node);
|
|
4570
|
+
const { init } = declaratorPath.node;
|
|
4571
|
+
return isExpressionSourcedFromEligibleBinding(init, declaratorPath.scope, seen, depth - 1);
|
|
4572
|
+
}
|
|
4573
|
+
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4574
|
+
if (depth <= 0) return null;
|
|
4575
|
+
if (t41.isIdentifier(exp)) {
|
|
4576
|
+
const sourceBinding = scope.getBinding(exp.name);
|
|
4577
|
+
if (!sourceBinding) return null;
|
|
4578
|
+
if (isEligibleBindingSource(sourceBinding)) {
|
|
4579
|
+
return exp;
|
|
4580
|
+
}
|
|
4581
|
+
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4582
|
+
}
|
|
4583
|
+
if (t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp)) {
|
|
4584
|
+
const root = findRootIdentifier(exp);
|
|
4585
|
+
if (!root) return null;
|
|
4586
|
+
const sourceBinding = scope.getBinding(root.name);
|
|
4587
|
+
if (!sourceBinding) return null;
|
|
4588
|
+
if (isEligibleBindingSource(sourceBinding)) {
|
|
4589
|
+
return t41.cloneNode(exp);
|
|
4590
|
+
}
|
|
4591
|
+
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4592
|
+
if (sourcedRoot) {
|
|
4593
|
+
const rebuilt = rebuildMemberWithNewRoot(exp, sourcedRoot);
|
|
4594
|
+
if (rebuilt) {
|
|
4595
|
+
return rebuilt;
|
|
4596
|
+
}
|
|
4597
|
+
return t41.cloneNode(sourcedRoot, true);
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
return null;
|
|
4601
|
+
}
|
|
4602
|
+
function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
4603
|
+
const replacedObject = (() => {
|
|
4604
|
+
if (t41.isIdentifier(node.object)) {
|
|
4605
|
+
return t41.cloneNode(nextRoot, true);
|
|
4606
|
+
}
|
|
4607
|
+
if (t41.isMemberExpression(node.object) || t41.isOptionalMemberExpression(node.object)) {
|
|
4608
|
+
return rebuildMemberWithNewRoot(node.object, nextRoot);
|
|
4609
|
+
}
|
|
4610
|
+
return null;
|
|
4611
|
+
})();
|
|
4612
|
+
if (!replacedObject) {
|
|
4613
|
+
return null;
|
|
4614
|
+
}
|
|
4615
|
+
const property = t41.cloneNode(node.property, true);
|
|
4616
|
+
if (t41.isMemberExpression(node)) {
|
|
4617
|
+
return t41.memberExpression(
|
|
4618
|
+
replacedObject,
|
|
4619
|
+
property,
|
|
4620
|
+
node.computed
|
|
4621
|
+
);
|
|
4622
|
+
}
|
|
4623
|
+
return t41.optionalMemberExpression(
|
|
4624
|
+
replacedObject,
|
|
4625
|
+
property,
|
|
4626
|
+
node.computed,
|
|
4627
|
+
node.optional
|
|
4628
|
+
);
|
|
4629
|
+
}
|
|
4630
|
+
|
|
4631
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4163
4632
|
function analyzeDeps(node, ctx, parentPath) {
|
|
4164
4633
|
if (!parentPath) {
|
|
4165
|
-
return
|
|
4634
|
+
return t42.arrayExpression([]);
|
|
4166
4635
|
}
|
|
4167
|
-
const isFnExpr =
|
|
4636
|
+
const isFnExpr = t42.isArrowFunctionExpression(node) || t42.isFunctionExpression(node);
|
|
4168
4637
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
4169
4638
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
4170
|
-
const reactiveStateApis = getReactiveStateApis();
|
|
4171
4639
|
const deps = /* @__PURE__ */ new Map();
|
|
4172
4640
|
const processedIdentifiers = /* @__PURE__ */ new WeakSet();
|
|
4173
4641
|
function addDependency(exp) {
|
|
@@ -4175,13 +4643,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4175
4643
|
}
|
|
4176
4644
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
4177
4645
|
if (analyzeTargetPath) {
|
|
4178
|
-
if (
|
|
4646
|
+
if (t42.isMemberExpression(analyzeTarget) || t42.isOptionalMemberExpression(analyzeTarget)) {
|
|
4179
4647
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
4180
4648
|
if (rootId) {
|
|
4181
4649
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
4182
4650
|
processedIdentifiers.add(rootId);
|
|
4183
4651
|
}
|
|
4184
|
-
} else if (
|
|
4652
|
+
} else if (t42.isIdentifier(analyzeTarget)) {
|
|
4185
4653
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
4186
4654
|
}
|
|
4187
4655
|
}
|
|
@@ -4189,11 +4657,11 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4189
4657
|
analyzeTarget,
|
|
4190
4658
|
{
|
|
4191
4659
|
"MemberExpression|OptionalMemberExpression"(memberPath) {
|
|
4192
|
-
const
|
|
4193
|
-
if (isNestedMemberObject(
|
|
4194
|
-
const rootId = findRootIdentifier(
|
|
4660
|
+
const path8 = memberPath;
|
|
4661
|
+
if (isNestedMemberObject(path8)) return;
|
|
4662
|
+
const rootId = findRootIdentifier(path8.node);
|
|
4195
4663
|
if (!rootId) return;
|
|
4196
|
-
tryAddDependency(
|
|
4664
|
+
tryAddDependency(path8, rootId.name, path8.scope);
|
|
4197
4665
|
processedIdentifiers.add(rootId);
|
|
4198
4666
|
},
|
|
4199
4667
|
Identifier(idPath) {
|
|
@@ -4207,17 +4675,19 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4207
4675
|
parentPath.scope
|
|
4208
4676
|
);
|
|
4209
4677
|
function tryAddDependency(depPath, rootName, scope) {
|
|
4210
|
-
const normalized = normalizeDependencyExpr(depPath, rootName);
|
|
4678
|
+
const normalized = normalizeDependencyExpr(depPath, rootName, ctx);
|
|
4211
4679
|
if (!normalized) return;
|
|
4212
|
-
const binding = scope.getBinding(rootName);
|
|
4213
|
-
if (!binding) return;
|
|
4214
|
-
const isLocalBinding = isBindingDeclaredInsideBoundary(binding, bindingLocalBoundary);
|
|
4215
4680
|
if (rootName === ctx.propField) {
|
|
4216
|
-
|
|
4681
|
+
const propsBinding = scope.getBinding(rootName);
|
|
4682
|
+
const isLocalPropsBinding = !!propsBinding && isBindingDeclaredInsideBoundary(propsBinding, bindingLocalBoundary);
|
|
4683
|
+
if (!isLocalPropsBinding) {
|
|
4217
4684
|
addDependency(normalized);
|
|
4218
4685
|
}
|
|
4219
4686
|
return;
|
|
4220
4687
|
}
|
|
4688
|
+
const binding = scope.getBinding(rootName);
|
|
4689
|
+
if (!binding) return;
|
|
4690
|
+
const isLocalBinding = isBindingDeclaredInsideBoundary(binding, bindingLocalBoundary);
|
|
4221
4691
|
const directEligible = !isLocalBinding && isEligibleBindingSource(binding);
|
|
4222
4692
|
if (directEligible) {
|
|
4223
4693
|
addDependency(normalized);
|
|
@@ -4231,274 +4701,70 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4231
4701
|
}
|
|
4232
4702
|
}
|
|
4233
4703
|
}
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4704
|
+
return t42.arrayExpression(Array.from(deps.values()));
|
|
4705
|
+
}
|
|
4706
|
+
|
|
4707
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4708
|
+
function resolveAnalysisOnlyAdapter(ctx) {
|
|
4709
|
+
return {
|
|
4710
|
+
"CallExpression|Identifier"(path8) {
|
|
4711
|
+
const node = path8.node;
|
|
4712
|
+
const apiName = getApiName(node);
|
|
4713
|
+
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
4714
|
+
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
4715
|
+
return;
|
|
4243
4716
|
}
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
}
|
|
4252
|
-
if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
|
|
4253
|
-
const root = findRootIdentifier(exp);
|
|
4254
|
-
if (!root) return null;
|
|
4255
|
-
const safeExp = t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4256
|
-
if (isReactValidDependencyExpr(safeExp)) {
|
|
4257
|
-
return t38.cloneNode(safeExp, true);
|
|
4717
|
+
if (!isVueApiReference(path8, apiName)) {
|
|
4718
|
+
return;
|
|
4719
|
+
}
|
|
4720
|
+
if (t43.isCallExpression(node)) {
|
|
4721
|
+
resolveCallNode(path8, adapter, ctx);
|
|
4722
|
+
} else {
|
|
4723
|
+
replaceIdName(node, adapter.target);
|
|
4258
4724
|
}
|
|
4259
|
-
|
|
4725
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
4260
4726
|
}
|
|
4261
|
-
|
|
4727
|
+
};
|
|
4728
|
+
}
|
|
4729
|
+
function getApiName(node) {
|
|
4730
|
+
const isCallNode = t43.isCallExpression(node);
|
|
4731
|
+
let apiName = "";
|
|
4732
|
+
if (t43.isIdentifier(node)) {
|
|
4733
|
+
apiName = node.name;
|
|
4734
|
+
} else if (isCallNode && t43.isIdentifier(node.callee)) {
|
|
4735
|
+
apiName = node.callee.name;
|
|
4262
4736
|
}
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4737
|
+
return apiName;
|
|
4738
|
+
}
|
|
4739
|
+
function resolveCallNode(path8, adapter, ctx) {
|
|
4740
|
+
const { node } = path8;
|
|
4741
|
+
const { arguments: args } = node;
|
|
4742
|
+
if (!args.length) return;
|
|
4743
|
+
const fn = args[0];
|
|
4744
|
+
if (!t43.isArrowFunctionExpression(fn) && !t43.isFunctionExpression(fn)) {
|
|
4745
|
+
return;
|
|
4746
|
+
}
|
|
4747
|
+
const fnPath = path8.get("arguments")[0];
|
|
4748
|
+
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
4749
|
+
args.push(deps);
|
|
4750
|
+
replaceCallName(node, adapter.target);
|
|
4751
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
4752
|
+
}
|
|
4753
|
+
function isVueApiReference(path8, apiName) {
|
|
4754
|
+
if (path8.isIdentifier()) {
|
|
4755
|
+
if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
|
|
4756
|
+
return false;
|
|
4266
4757
|
}
|
|
4267
|
-
if (
|
|
4268
|
-
return
|
|
4758
|
+
if (!path8.isReferencedIdentifier()) {
|
|
4759
|
+
return false;
|
|
4269
4760
|
}
|
|
4270
|
-
return false;
|
|
4271
4761
|
}
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
while (t38.isMemberExpression(current) || t38.isOptionalMemberExpression(current)) {
|
|
4275
|
-
if (!current.computed && !t38.isIdentifier(current.property)) {
|
|
4276
|
-
return false;
|
|
4277
|
-
}
|
|
4278
|
-
if (current.computed && !t38.isStringLiteral(current.property) && !t38.isNumericLiteral(current.property)) {
|
|
4279
|
-
return false;
|
|
4280
|
-
}
|
|
4281
|
-
current = current.object;
|
|
4282
|
-
}
|
|
4283
|
-
return t38.isIdentifier(current);
|
|
4284
|
-
}
|
|
4285
|
-
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
4286
|
-
let current = binding.path;
|
|
4287
|
-
while (current) {
|
|
4288
|
-
if (current.node === boundary) {
|
|
4289
|
-
return true;
|
|
4290
|
-
}
|
|
4291
|
-
current = current.parentPath;
|
|
4292
|
-
}
|
|
4293
|
-
return false;
|
|
4294
|
-
}
|
|
4295
|
-
function normalizeMemberForCallSite(path9, node2) {
|
|
4296
|
-
const parent = path9.parentPath;
|
|
4297
|
-
const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node2 || parent.isOptionalCallExpression() && parent.node.callee === node2);
|
|
4298
|
-
if (!isDirectCallee) {
|
|
4299
|
-
return node2;
|
|
4300
|
-
}
|
|
4301
|
-
if (!t38.isExpression(node2.object)) {
|
|
4302
|
-
return node2;
|
|
4303
|
-
}
|
|
4304
|
-
return node2.object;
|
|
4305
|
-
}
|
|
4306
|
-
function ensureOptionalForMemberChain(node2) {
|
|
4307
|
-
if (!hasTrailingMemberAccess(node2)) {
|
|
4308
|
-
return node2;
|
|
4309
|
-
}
|
|
4310
|
-
if (t38.isOptionalMemberExpression(node2) && node2.optional) {
|
|
4311
|
-
return node2;
|
|
4312
|
-
}
|
|
4313
|
-
const object = t38.cloneNode(node2.object, true);
|
|
4314
|
-
const property = t38.cloneNode(node2.property, true);
|
|
4315
|
-
return t38.optionalMemberExpression(object, property, node2.computed, true);
|
|
4316
|
-
}
|
|
4317
|
-
function hasTrailingMemberAccess(node2) {
|
|
4318
|
-
return t38.isMemberExpression(node2.object) || t38.isOptionalMemberExpression(node2.object);
|
|
4319
|
-
}
|
|
4320
|
-
function isEligibleBindingSource(binding) {
|
|
4321
|
-
if (binding.kind === "param") {
|
|
4322
|
-
return false;
|
|
4323
|
-
}
|
|
4324
|
-
const bindingPath = binding.path;
|
|
4325
|
-
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4326
|
-
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4327
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _121 => _121.node, 'access', _122 => _122.init]);
|
|
4328
|
-
const isReactiveApiCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && t38.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4329
|
-
const isHookCallVarBinding = !!declaratorPath && t38.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4330
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t38.isArrowFunctionExpression(nodeInit) || t38.isFunctionExpression(nodeInit));
|
|
4331
|
-
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _123 => _123.node])) || isReactiveBinding(bindingPath.node));
|
|
4332
|
-
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4333
|
-
}
|
|
4334
|
-
function isHookLikeCallee(callee) {
|
|
4335
|
-
if (t38.isIdentifier(callee)) {
|
|
4336
|
-
return callee.name.startsWith("use");
|
|
4337
|
-
}
|
|
4338
|
-
if (t38.isMemberExpression(callee) && !callee.computed && t38.isIdentifier(callee.property)) {
|
|
4339
|
-
return callee.property.name.startsWith("use");
|
|
4340
|
-
}
|
|
4341
|
-
return false;
|
|
4342
|
-
}
|
|
4343
|
-
function traceBindingSource(binding, seen, depth) {
|
|
4344
|
-
if (depth <= 0) return null;
|
|
4345
|
-
const declaratorPath = getVariableDeclaratorPath(binding.path);
|
|
4346
|
-
if (!declaratorPath || !declaratorPath.node.init) return null;
|
|
4347
|
-
if (seen.has(declaratorPath.node)) return null;
|
|
4348
|
-
seen.add(declaratorPath.node);
|
|
4349
|
-
const { init } = declaratorPath.node;
|
|
4350
|
-
return isExpressionSourcedFromEligibleBinding(init, declaratorPath.scope, seen, depth - 1);
|
|
4351
|
-
}
|
|
4352
|
-
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4353
|
-
if (depth <= 0) return null;
|
|
4354
|
-
if (t38.isIdentifier(exp)) {
|
|
4355
|
-
const sourceBinding = scope.getBinding(exp.name);
|
|
4356
|
-
if (!sourceBinding) return null;
|
|
4357
|
-
if (isEligibleBindingSource(sourceBinding)) {
|
|
4358
|
-
return exp;
|
|
4359
|
-
}
|
|
4360
|
-
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4361
|
-
}
|
|
4362
|
-
if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
|
|
4363
|
-
const root = findRootIdentifier(exp);
|
|
4364
|
-
if (!root) return null;
|
|
4365
|
-
const sourceBinding = scope.getBinding(root.name);
|
|
4366
|
-
if (!sourceBinding) return null;
|
|
4367
|
-
if (isEligibleBindingSource(sourceBinding)) {
|
|
4368
|
-
return t38.cloneNode(exp);
|
|
4369
|
-
}
|
|
4370
|
-
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4371
|
-
if (sourcedRoot) {
|
|
4372
|
-
const rebuilt = rebuildMemberWithNewRoot(exp, sourcedRoot);
|
|
4373
|
-
if (rebuilt) {
|
|
4374
|
-
return rebuilt;
|
|
4375
|
-
}
|
|
4376
|
-
return t38.cloneNode(sourcedRoot, true);
|
|
4377
|
-
}
|
|
4378
|
-
}
|
|
4379
|
-
return null;
|
|
4380
|
-
}
|
|
4381
|
-
function rebuildMemberWithNewRoot(node2, nextRoot) {
|
|
4382
|
-
const replacedObject = (() => {
|
|
4383
|
-
if (t38.isIdentifier(node2.object)) {
|
|
4384
|
-
return t38.cloneNode(nextRoot, true);
|
|
4385
|
-
}
|
|
4386
|
-
if (t38.isMemberExpression(node2.object) || t38.isOptionalMemberExpression(node2.object)) {
|
|
4387
|
-
return rebuildMemberWithNewRoot(node2.object, nextRoot);
|
|
4388
|
-
}
|
|
4389
|
-
return null;
|
|
4390
|
-
})();
|
|
4391
|
-
if (!replacedObject) {
|
|
4392
|
-
return null;
|
|
4393
|
-
}
|
|
4394
|
-
const property = t38.cloneNode(node2.property, true);
|
|
4395
|
-
if (t38.isMemberExpression(node2)) {
|
|
4396
|
-
return t38.memberExpression(
|
|
4397
|
-
replacedObject,
|
|
4398
|
-
property,
|
|
4399
|
-
node2.computed
|
|
4400
|
-
);
|
|
4401
|
-
}
|
|
4402
|
-
return t38.optionalMemberExpression(
|
|
4403
|
-
replacedObject,
|
|
4404
|
-
property,
|
|
4405
|
-
node2.computed,
|
|
4406
|
-
node2.optional
|
|
4407
|
-
);
|
|
4408
|
-
}
|
|
4409
|
-
return t38.arrayExpression(Array.from(deps.values()));
|
|
4410
|
-
}
|
|
4411
|
-
function getDependencyKey(exp) {
|
|
4412
|
-
if (t38.isIdentifier(exp)) {
|
|
4413
|
-
return exp.name;
|
|
4414
|
-
}
|
|
4415
|
-
if (t38.isMemberExpression(exp) || t38.isOptionalMemberExpression(exp)) {
|
|
4416
|
-
const objectKey = getDependencyKey(exp.object);
|
|
4417
|
-
const opt = exp.optional ? "?" : "";
|
|
4418
|
-
if (!exp.computed && t38.isIdentifier(exp.property)) {
|
|
4419
|
-
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4420
|
-
}
|
|
4421
|
-
if (t38.isStringLiteral(exp.property) || t38.isNumericLiteral(exp.property)) {
|
|
4422
|
-
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4423
|
-
}
|
|
4424
|
-
return `${objectKey}${opt}[*]`;
|
|
4425
|
-
}
|
|
4426
|
-
return exp.type;
|
|
4427
|
-
}
|
|
4428
|
-
function isNestedMemberObject(path9) {
|
|
4429
|
-
const parent = path9.parentPath;
|
|
4430
|
-
if (!parent) return false;
|
|
4431
|
-
if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
|
|
4432
|
-
return parent.node.object === path9.node;
|
|
4433
|
-
}
|
|
4434
|
-
return false;
|
|
4435
|
-
}
|
|
4436
|
-
function isReactiveBinding(node) {
|
|
4437
|
-
if (!node) return false;
|
|
4438
|
-
return !!_optionalChain([getScriptNodeMeta, 'call', _124 => _124(node), 'optionalAccess', _125 => _125.is_reactive]);
|
|
4439
|
-
}
|
|
4440
|
-
|
|
4441
|
-
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4442
|
-
function resolveAnalysisOnlyAdapter(ctx) {
|
|
4443
|
-
return {
|
|
4444
|
-
"CallExpression|Identifier"(path9) {
|
|
4445
|
-
const node = path9.node;
|
|
4446
|
-
const apiName = getApiName(node);
|
|
4447
|
-
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
4448
|
-
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
4449
|
-
return;
|
|
4450
|
-
}
|
|
4451
|
-
if (!isVueApiReference(path9, apiName)) {
|
|
4452
|
-
return;
|
|
4453
|
-
}
|
|
4454
|
-
if (t39.isCallExpression(node)) {
|
|
4455
|
-
resolveCallNode(path9, adapter, ctx);
|
|
4456
|
-
} else {
|
|
4457
|
-
replaceIdName(node, adapter.target);
|
|
4458
|
-
}
|
|
4459
|
-
recordImport(ctx, adapter.package, adapter.target);
|
|
4460
|
-
}
|
|
4461
|
-
};
|
|
4462
|
-
}
|
|
4463
|
-
function getApiName(node) {
|
|
4464
|
-
const isCallNode = t39.isCallExpression(node);
|
|
4465
|
-
let apiName = "";
|
|
4466
|
-
if (t39.isIdentifier(node)) {
|
|
4467
|
-
apiName = node.name;
|
|
4468
|
-
} else if (isCallNode && t39.isIdentifier(node.callee)) {
|
|
4469
|
-
apiName = node.callee.name;
|
|
4470
|
-
}
|
|
4471
|
-
return apiName;
|
|
4472
|
-
}
|
|
4473
|
-
function resolveCallNode(path9, adapter, ctx) {
|
|
4474
|
-
const { node } = path9;
|
|
4475
|
-
const { arguments: args } = node;
|
|
4476
|
-
if (!args.length) return;
|
|
4477
|
-
const fn = args[0];
|
|
4478
|
-
if (!t39.isArrowFunctionExpression(fn) && !t39.isFunctionExpression(fn)) {
|
|
4479
|
-
return;
|
|
4480
|
-
}
|
|
4481
|
-
const fnPath = path9.get("arguments")[0];
|
|
4482
|
-
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
4483
|
-
args.push(deps);
|
|
4484
|
-
replaceCallName(node, adapter.target);
|
|
4485
|
-
recordImport(ctx, adapter.package, adapter.target);
|
|
4486
|
-
}
|
|
4487
|
-
function isVueApiReference(path9, apiName) {
|
|
4488
|
-
if (path9.isIdentifier()) {
|
|
4489
|
-
if (path9.parentPath.isCallExpression() && path9.parentPath.node.callee === path9.node) {
|
|
4490
|
-
return false;
|
|
4491
|
-
}
|
|
4492
|
-
if (!path9.isReferencedIdentifier()) {
|
|
4493
|
-
return false;
|
|
4494
|
-
}
|
|
4495
|
-
}
|
|
4496
|
-
if (path9.isCallExpression()) {
|
|
4497
|
-
const callee = path9.get("callee");
|
|
4762
|
+
if (path8.isCallExpression()) {
|
|
4763
|
+
const callee = path8.get("callee");
|
|
4498
4764
|
if (!callee.isIdentifier()) return false;
|
|
4499
4765
|
return isVueImportBinding(callee.scope.getBinding(apiName));
|
|
4500
4766
|
}
|
|
4501
|
-
return isVueImportBinding(
|
|
4767
|
+
return isVueImportBinding(path8.scope.getBinding(apiName));
|
|
4502
4768
|
}
|
|
4503
4769
|
function isVueImportBinding(binding) {
|
|
4504
4770
|
if (!binding) return false;
|
|
@@ -4506,8 +4772,8 @@ function isVueImportBinding(binding) {
|
|
|
4506
4772
|
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
4507
4773
|
return false;
|
|
4508
4774
|
}
|
|
4509
|
-
const parent = _optionalChain([bindingPath, 'access',
|
|
4510
|
-
if (!parent || !
|
|
4775
|
+
const parent = _optionalChain([bindingPath, 'access', _148 => _148.parentPath, 'optionalAccess', _149 => _149.node]);
|
|
4776
|
+
if (!parent || !t43.isImportDeclaration(parent)) {
|
|
4511
4777
|
return false;
|
|
4512
4778
|
}
|
|
4513
4779
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4523,24 +4789,24 @@ function isVueImportBinding(binding) {
|
|
|
4523
4789
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
|
|
4524
4790
|
function resolveArrowFnDeps(ctx, ast) {
|
|
4525
4791
|
return {
|
|
4526
|
-
ArrowFunctionExpression(
|
|
4527
|
-
const { node, parentPath } =
|
|
4528
|
-
if (isSkip(
|
|
4792
|
+
ArrowFunctionExpression(path8) {
|
|
4793
|
+
const { node, parentPath } = path8;
|
|
4794
|
+
if (isSkip(path8) || !atComponentOrHookRoot(parentPath, ast.program)) {
|
|
4529
4795
|
return;
|
|
4530
4796
|
}
|
|
4531
|
-
const deps = analyzeDeps(node, ctx,
|
|
4797
|
+
const deps = analyzeDeps(node, ctx, path8);
|
|
4532
4798
|
if (!deps.elements.length) return;
|
|
4533
4799
|
const newNode = createUseCallback(node, deps);
|
|
4534
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
4800
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
4535
4801
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
4536
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
4537
|
-
replaceNode(
|
|
4802
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _150 => _150.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
4803
|
+
replaceNode(path8, newNode, node);
|
|
4538
4804
|
}
|
|
4539
4805
|
};
|
|
4540
4806
|
}
|
|
4541
|
-
function isSkip(
|
|
4542
|
-
const { parentPath } =
|
|
4543
|
-
const isVariableDecl = () => getVariableDeclaratorPath(
|
|
4807
|
+
function isSkip(path8) {
|
|
4808
|
+
const { parentPath } = path8;
|
|
4809
|
+
const isVariableDecl = () => getVariableDeclaratorPath(path8) !== null;
|
|
4544
4810
|
const isReturnFunc = () => !isVariableDecl() && parentPath.isReturnStatement();
|
|
4545
4811
|
const isCallback = () => {
|
|
4546
4812
|
if (!parentPath) {
|
|
@@ -4549,12 +4815,12 @@ function isSkip(path9) {
|
|
|
4549
4815
|
if (parentPath.isCallExpression()) {
|
|
4550
4816
|
const callExpressionPath = parentPath;
|
|
4551
4817
|
const args = callExpressionPath.node.arguments;
|
|
4552
|
-
return args.some((arg) => arg ===
|
|
4818
|
+
return args.some((arg) => arg === path8.node);
|
|
4553
4819
|
}
|
|
4554
4820
|
if (parentPath.isArrayExpression()) {
|
|
4555
4821
|
const arrayExpressionPath = parentPath;
|
|
4556
4822
|
const elements = arrayExpressionPath.node.elements;
|
|
4557
|
-
return elements.some((element) => element ===
|
|
4823
|
+
return elements.some((element) => element === path8.node);
|
|
4558
4824
|
}
|
|
4559
4825
|
return false;
|
|
4560
4826
|
};
|
|
@@ -4578,13 +4844,13 @@ function isSkip(path9) {
|
|
|
4578
4844
|
|
|
4579
4845
|
function resolveElementRef(ctx) {
|
|
4580
4846
|
return {
|
|
4581
|
-
CallExpression(
|
|
4847
|
+
CallExpression(path8) {
|
|
4582
4848
|
const {
|
|
4583
4849
|
inputType,
|
|
4584
4850
|
templateData: { refBindings }
|
|
4585
4851
|
} = ctx;
|
|
4586
4852
|
if (inputType !== "sfc") return;
|
|
4587
|
-
const { node } =
|
|
4853
|
+
const { node } = path8;
|
|
4588
4854
|
const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
|
|
4589
4855
|
const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
|
|
4590
4856
|
const shouldProcess = isUseTemplateRef || isCompRefBindings;
|
|
@@ -4592,31 +4858,31 @@ function resolveElementRef(ctx) {
|
|
|
4592
4858
|
return;
|
|
4593
4859
|
}
|
|
4594
4860
|
if (isCompRefBindings) {
|
|
4595
|
-
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
4596
|
-
if (!
|
|
4861
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _151 => _151(path8), 'optionalAccess', _152 => _152.node]);
|
|
4862
|
+
if (!t44.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _153 => _153.id]))) {
|
|
4597
4863
|
return;
|
|
4598
4864
|
}
|
|
4599
4865
|
const varName = varDeclaratorPath.id.name;
|
|
4600
4866
|
const compRef = refBindings.componentRefs[varName];
|
|
4601
4867
|
if (!compRef) return;
|
|
4602
4868
|
}
|
|
4603
|
-
node.arguments[0] =
|
|
4604
|
-
resolveTypeParameters(ctx,
|
|
4869
|
+
node.arguments[0] = t44.identifier("null");
|
|
4870
|
+
resolveTypeParameters(ctx, path8);
|
|
4605
4871
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
4606
4872
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
4607
4873
|
},
|
|
4608
|
-
MemberExpression(
|
|
4609
|
-
resolveRefValueToCurrent(
|
|
4874
|
+
MemberExpression(path8) {
|
|
4875
|
+
resolveRefValueToCurrent(path8);
|
|
4610
4876
|
}
|
|
4611
4877
|
};
|
|
4612
4878
|
}
|
|
4613
|
-
function resolveTypeParameters(ctx,
|
|
4879
|
+
function resolveTypeParameters(ctx, path8) {
|
|
4614
4880
|
const {
|
|
4615
4881
|
templateData: { refBindings },
|
|
4616
4882
|
scriptData
|
|
4617
4883
|
} = ctx;
|
|
4618
|
-
const { node } =
|
|
4619
|
-
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
4884
|
+
const { node } = path8;
|
|
4885
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _154 => _154(path8), 'optionalAccess', _155 => _155.node]);
|
|
4620
4886
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
4621
4887
|
return;
|
|
4622
4888
|
}
|
|
@@ -4625,20 +4891,20 @@ function resolveTypeParameters(ctx, path9) {
|
|
|
4625
4891
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
4626
4892
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
4627
4893
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
4628
|
-
node.typeParameters =
|
|
4894
|
+
node.typeParameters = t44.tsTypeParameterInstantiation([t44.tsTypeReference(t44.identifier(type))]);
|
|
4629
4895
|
}
|
|
4630
4896
|
}
|
|
4631
|
-
function resolveRefValueToCurrent(
|
|
4632
|
-
const { node } =
|
|
4633
|
-
if (node.computed || !
|
|
4897
|
+
function resolveRefValueToCurrent(path8) {
|
|
4898
|
+
const { node } = path8;
|
|
4899
|
+
if (node.computed || !t44.isIdentifier(node.property) || node.property.name !== "value") {
|
|
4634
4900
|
return;
|
|
4635
4901
|
}
|
|
4636
|
-
const rootPath = findRootVariablePath(
|
|
4637
|
-
if (!_optionalChain([rootPath, 'optionalAccess',
|
|
4902
|
+
const rootPath = findRootVariablePath(path8);
|
|
4903
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _156 => _156.node]) || !t44.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
4638
4904
|
return;
|
|
4639
4905
|
}
|
|
4640
4906
|
const rootId = findRootIdentifier(node);
|
|
4641
|
-
if (!
|
|
4907
|
+
if (!t44.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _157 => _157.name])) {
|
|
4642
4908
|
return;
|
|
4643
4909
|
}
|
|
4644
4910
|
node.property.name = "current";
|
|
@@ -4649,31 +4915,32 @@ function resolveRefValueToCurrent(path9) {
|
|
|
4649
4915
|
function resolveExprMemo(ctx, ast) {
|
|
4650
4916
|
const isScriptFile = ctx.inputType !== "sfc";
|
|
4651
4917
|
return {
|
|
4652
|
-
VariableDeclarator(
|
|
4653
|
-
const { node } =
|
|
4918
|
+
VariableDeclarator(path8) {
|
|
4919
|
+
const { node } = path8;
|
|
4654
4920
|
const { init } = node;
|
|
4655
4921
|
const shouldMemo = () => {
|
|
4656
4922
|
if (!init) return false;
|
|
4657
|
-
if (!atComponentOrHookRoot(
|
|
4923
|
+
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
4658
4924
|
return false;
|
|
4659
4925
|
}
|
|
4660
|
-
if (!
|
|
4926
|
+
if (!t45.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
|
|
4661
4927
|
return false;
|
|
4662
4928
|
}
|
|
4663
|
-
if (
|
|
4664
|
-
if (
|
|
4929
|
+
if (t45.isFunction(init)) return false;
|
|
4930
|
+
if (t45.isCallExpression(init) && t45.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
4665
4931
|
return false;
|
|
4666
4932
|
}
|
|
4667
4933
|
return true;
|
|
4668
4934
|
};
|
|
4669
4935
|
if (!shouldMemo()) return;
|
|
4670
|
-
const initPath =
|
|
4936
|
+
const initPath = path8.get("init");
|
|
4671
4937
|
if (!initPath.isExpression()) return;
|
|
4672
4938
|
const deps = analyzeDeps(initPath.node, ctx, initPath);
|
|
4673
4939
|
if (!deps.elements.length) return;
|
|
4674
4940
|
const useMemoCall = createUseMemo(initPath.node, deps);
|
|
4675
4941
|
initPath.replaceWith(useMemoCall);
|
|
4676
4942
|
setScriptNodeMeta(node, { is_reactive: true, reactive_type: "indirect" });
|
|
4943
|
+
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useMemo);
|
|
4677
4944
|
}
|
|
4678
4945
|
};
|
|
4679
4946
|
}
|
|
@@ -4683,12 +4950,12 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4683
4950
|
function resolveLintRules(ctx, ast) {
|
|
4684
4951
|
const inScriptFile = ctx.inputType !== "sfc";
|
|
4685
4952
|
return {
|
|
4686
|
-
CallExpression(
|
|
4687
|
-
const { node, parentPath } =
|
|
4688
|
-
if (!
|
|
4953
|
+
CallExpression(path8) {
|
|
4954
|
+
const { node, parentPath } = path8;
|
|
4955
|
+
if (!t46.isIdentifier(node.callee)) return;
|
|
4689
4956
|
const { name: callName } = node.callee;
|
|
4690
|
-
const addLog = (
|
|
4691
|
-
logger.error(
|
|
4957
|
+
const addLog = (t52) => {
|
|
4958
|
+
logger.error(t52, {
|
|
4692
4959
|
file: ctx.filename,
|
|
4693
4960
|
source: ctx.scriptData.source,
|
|
4694
4961
|
loc: node.loc
|
|
@@ -4703,7 +4970,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
4703
4970
|
);
|
|
4704
4971
|
return;
|
|
4705
4972
|
}
|
|
4706
|
-
if (!atComponentOrHookRoot(
|
|
4973
|
+
if (!atComponentOrHookRoot(path8, ast.program)) {
|
|
4707
4974
|
addLog(
|
|
4708
4975
|
`The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
|
|
4709
4976
|
);
|
|
@@ -4719,7 +4986,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
4719
4986
|
};
|
|
4720
4987
|
const lintHooks = () => {
|
|
4721
4988
|
if (!callName.startsWith("use")) return;
|
|
4722
|
-
if (!atComponentOrHookRoot(
|
|
4989
|
+
if (!atComponentOrHookRoot(path8, ast.program, inScriptFile)) {
|
|
4723
4990
|
addLog(
|
|
4724
4991
|
`The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
|
|
4725
4992
|
);
|
|
@@ -4737,9 +5004,9 @@ function resolveLintRules(ctx, ast) {
|
|
|
4737
5004
|
function resolveProvide(ctx) {
|
|
4738
5005
|
if (ctx.inputType === "style") return {};
|
|
4739
5006
|
return {
|
|
4740
|
-
CallExpression(
|
|
4741
|
-
const { node } =
|
|
4742
|
-
const providerTarget = _optionalChain([ADAPTER_RULES, 'access',
|
|
5007
|
+
CallExpression(path8) {
|
|
5008
|
+
const { node } = path8;
|
|
5009
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _158 => _158.runtime, 'access', _159 => _159[VUE_API_MAP.provide], 'optionalAccess', _160 => _160.target]);
|
|
4743
5010
|
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
4744
5011
|
if (!isProvideCall) return;
|
|
4745
5012
|
const { provide } = ctx.scriptData;
|
|
@@ -4748,7 +5015,7 @@ function resolveProvide(ctx) {
|
|
|
4748
5015
|
const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
4749
5016
|
assignProviderValue(target, key, value);
|
|
4750
5017
|
recordImport(ctx, adapter.package, adapter.target);
|
|
4751
|
-
|
|
5018
|
+
path8.parentPath.remove();
|
|
4752
5019
|
}
|
|
4753
5020
|
};
|
|
4754
5021
|
}
|
|
@@ -4757,7 +5024,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
4757
5024
|
return root;
|
|
4758
5025
|
}
|
|
4759
5026
|
let cur = root.provide;
|
|
4760
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
5027
|
+
while (_optionalChain([cur, 'optionalAccess', _161 => _161.isOccupied])) {
|
|
4761
5028
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
4762
5029
|
}
|
|
4763
5030
|
return cur || (root.provide = {});
|
|
@@ -4765,18 +5032,18 @@ function findOrCreateCtxProvider(root) {
|
|
|
4765
5032
|
function assignProviderValue(target, key, value) {
|
|
4766
5033
|
const getRawExp = (exp) => {
|
|
4767
5034
|
if (!exp) return "''";
|
|
4768
|
-
if (
|
|
5035
|
+
if (t47.isStringLiteral(exp)) {
|
|
4769
5036
|
return JSON.stringify(exp.value);
|
|
4770
5037
|
}
|
|
4771
|
-
if (
|
|
5038
|
+
if (t47.isNumericLiteral(exp)) {
|
|
4772
5039
|
return exp.value.toString();
|
|
4773
5040
|
}
|
|
4774
|
-
if (
|
|
5041
|
+
if (t47.isIdentifier(exp)) {
|
|
4775
5042
|
return exp.name;
|
|
4776
5043
|
}
|
|
4777
5044
|
try {
|
|
4778
5045
|
return _generator.generate.call(void 0, exp).code;
|
|
4779
|
-
} catch (
|
|
5046
|
+
} catch (e6) {
|
|
4780
5047
|
return "null";
|
|
4781
5048
|
}
|
|
4782
5049
|
};
|
|
@@ -4790,13 +5057,13 @@ function assignProviderValue(target, key, value) {
|
|
|
4790
5057
|
|
|
4791
5058
|
function resolveRenameAdapter(ctx) {
|
|
4792
5059
|
return {
|
|
4793
|
-
"CallExpression|Identifier"(
|
|
4794
|
-
const node =
|
|
4795
|
-
const isCallNode =
|
|
5060
|
+
"CallExpression|Identifier"(path8) {
|
|
5061
|
+
const node = path8.node;
|
|
5062
|
+
const isCallNode = t48.isCallExpression(node);
|
|
4796
5063
|
let apiName = "";
|
|
4797
|
-
if (
|
|
5064
|
+
if (t48.isIdentifier(node)) {
|
|
4798
5065
|
apiName = node.name;
|
|
4799
|
-
} else if (isCallNode &&
|
|
5066
|
+
} else if (isCallNode && t48.isIdentifier(node.callee)) {
|
|
4800
5067
|
apiName = node.callee.name;
|
|
4801
5068
|
}
|
|
4802
5069
|
if (!apiName) {
|
|
@@ -4808,13 +5075,13 @@ function resolveRenameAdapter(ctx) {
|
|
|
4808
5075
|
if (!adapter || adapter.type !== "rename") {
|
|
4809
5076
|
return;
|
|
4810
5077
|
}
|
|
4811
|
-
if (!isVueApiReference2(
|
|
5078
|
+
if (!isVueApiReference2(path8, apiName)) {
|
|
4812
5079
|
return;
|
|
4813
5080
|
}
|
|
4814
5081
|
if (adapter.isTrackable) {
|
|
4815
5082
|
const reactiveType = getReactiveType(apiName);
|
|
4816
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
4817
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
5083
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
5084
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _162 => _162.node]), {
|
|
4818
5085
|
is_reactive: true,
|
|
4819
5086
|
reactive_type: reactiveType
|
|
4820
5087
|
});
|
|
@@ -4831,25 +5098,25 @@ function resolveRenameAdapter(ctx) {
|
|
|
4831
5098
|
}
|
|
4832
5099
|
};
|
|
4833
5100
|
}
|
|
4834
|
-
function isVueApiReference2(
|
|
5101
|
+
function isVueApiReference2(path8, apiName) {
|
|
4835
5102
|
const whitelist = [VUE_API_MAP.defineAsyncComponent];
|
|
4836
5103
|
if (whitelist.includes(apiName)) {
|
|
4837
5104
|
return true;
|
|
4838
5105
|
}
|
|
4839
|
-
if (
|
|
4840
|
-
if (
|
|
5106
|
+
if (path8.isIdentifier()) {
|
|
5107
|
+
if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
|
|
4841
5108
|
return false;
|
|
4842
5109
|
}
|
|
4843
|
-
if (!
|
|
5110
|
+
if (!path8.isReferencedIdentifier()) {
|
|
4844
5111
|
return false;
|
|
4845
5112
|
}
|
|
4846
5113
|
}
|
|
4847
|
-
if (
|
|
4848
|
-
const callee =
|
|
5114
|
+
if (path8.isCallExpression()) {
|
|
5115
|
+
const callee = path8.get("callee");
|
|
4849
5116
|
if (!callee.isIdentifier()) return false;
|
|
4850
5117
|
return isVueImportBinding2(callee.scope.getBinding(apiName));
|
|
4851
5118
|
}
|
|
4852
|
-
return isVueImportBinding2(
|
|
5119
|
+
return isVueImportBinding2(path8.scope.getBinding(apiName));
|
|
4853
5120
|
}
|
|
4854
5121
|
function isVueImportBinding2(binding) {
|
|
4855
5122
|
if (!binding) return false;
|
|
@@ -4857,8 +5124,8 @@ function isVueImportBinding2(binding) {
|
|
|
4857
5124
|
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
4858
5125
|
return false;
|
|
4859
5126
|
}
|
|
4860
|
-
const parent = _optionalChain([bindingPath, 'access',
|
|
4861
|
-
if (!parent || !
|
|
5127
|
+
const parent = _optionalChain([bindingPath, 'access', _163 => _163.parentPath, 'optionalAccess', _164 => _164.node]);
|
|
5128
|
+
if (!parent || !t48.isImportDeclaration(parent)) {
|
|
4862
5129
|
return false;
|
|
4863
5130
|
}
|
|
4864
5131
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4909,12 +5176,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
4909
5176
|
}
|
|
4910
5177
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
4911
5178
|
const runExcludeThenApply = (cfg) => {
|
|
4912
|
-
_optionalChain([cfg, 'access',
|
|
4913
|
-
_optionalChain([cfg, 'access',
|
|
5179
|
+
_optionalChain([cfg, 'access', _165 => _165.excludeBabel, 'optionalAccess', _166 => _166.forEach, 'call', _167 => _167((fn) => fn(ctx, ast))]);
|
|
5180
|
+
_optionalChain([cfg, 'access', _168 => _168.applyBabel, 'optionalAccess', _169 => _169.forEach, 'call', _170 => _170((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4914
5181
|
};
|
|
4915
5182
|
const runApplyThenExclude = (cfg) => {
|
|
4916
|
-
_optionalChain([cfg, 'access',
|
|
4917
|
-
_optionalChain([cfg, 'access',
|
|
5183
|
+
_optionalChain([cfg, 'access', _171 => _171.applyBabel, 'optionalAccess', _172 => _172.forEach, 'call', _173 => _173((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
5184
|
+
_optionalChain([cfg, 'access', _174 => _174.excludeBabel, 'optionalAccess', _175 => _175.forEach, 'call', _176 => _176((fn) => fn(ctx, ast))]);
|
|
4918
5185
|
};
|
|
4919
5186
|
runExcludeThenApply(options.preprocess);
|
|
4920
5187
|
runExcludeThenApply(options.process);
|
|
@@ -5001,50 +5268,50 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
5001
5268
|
|
|
5002
5269
|
|
|
5003
5270
|
var strCodeTypes = {
|
|
5004
|
-
isIdentifier:
|
|
5271
|
+
isIdentifier: isIdentifier28,
|
|
5005
5272
|
isSimpleExpression,
|
|
5006
|
-
isStringLiteral:
|
|
5273
|
+
isStringLiteral: isStringLiteral13
|
|
5007
5274
|
};
|
|
5008
5275
|
function isSimpleExpression(code, excludeVar = false) {
|
|
5009
5276
|
let node;
|
|
5010
5277
|
try {
|
|
5011
5278
|
node = _parser.parseExpression.call(void 0, code);
|
|
5012
|
-
} catch (
|
|
5279
|
+
} catch (e7) {
|
|
5013
5280
|
return false;
|
|
5014
5281
|
}
|
|
5015
|
-
if (
|
|
5282
|
+
if (t49.isLiteral(node)) {
|
|
5016
5283
|
return true;
|
|
5017
5284
|
}
|
|
5018
|
-
if (!excludeVar &&
|
|
5285
|
+
if (!excludeVar && t49.isIdentifier(node)) {
|
|
5019
5286
|
return true;
|
|
5020
5287
|
}
|
|
5021
|
-
if (
|
|
5022
|
-
return isSimpleExpression(node.object) &&
|
|
5288
|
+
if (t49.isMemberExpression(node)) {
|
|
5289
|
+
return isSimpleExpression(node.object) && t49.isIdentifier(node.property);
|
|
5023
5290
|
}
|
|
5024
|
-
if (
|
|
5291
|
+
if (t49.isObjectExpression(node) || t49.isArrayExpression(node)) {
|
|
5025
5292
|
return false;
|
|
5026
5293
|
}
|
|
5027
|
-
if (
|
|
5294
|
+
if (t49.isCallExpression(node) || t49.isAssignmentExpression(node)) {
|
|
5028
5295
|
return false;
|
|
5029
5296
|
}
|
|
5030
|
-
if (
|
|
5297
|
+
if (t49.isBinaryExpression(node) || t49.isUnaryExpression(node)) {
|
|
5031
5298
|
return true;
|
|
5032
5299
|
}
|
|
5033
5300
|
return false;
|
|
5034
5301
|
}
|
|
5035
|
-
function
|
|
5302
|
+
function isIdentifier28(code) {
|
|
5036
5303
|
try {
|
|
5037
5304
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5038
|
-
return
|
|
5039
|
-
} catch (
|
|
5305
|
+
return t49.isIdentifier(node);
|
|
5306
|
+
} catch (e8) {
|
|
5040
5307
|
return false;
|
|
5041
5308
|
}
|
|
5042
5309
|
}
|
|
5043
|
-
function
|
|
5310
|
+
function isStringLiteral13(code) {
|
|
5044
5311
|
try {
|
|
5045
5312
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5046
|
-
return
|
|
5047
|
-
} catch (
|
|
5313
|
+
return t49.isStringLiteral(node);
|
|
5314
|
+
} catch (e9) {
|
|
5048
5315
|
return false;
|
|
5049
5316
|
}
|
|
5050
5317
|
}
|
|
@@ -5153,12 +5420,12 @@ function wrapSingleQuotes(content, condition) {
|
|
|
5153
5420
|
return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
|
|
5154
5421
|
}
|
|
5155
5422
|
function checkPropIsDynamicKey(ctx, node) {
|
|
5156
|
-
const isKeyStatic = _optionalChain([node, 'access',
|
|
5423
|
+
const isKeyStatic = _optionalChain([node, 'access', _177 => _177.arg, 'optionalAccess', _178 => _178.isStatic]);
|
|
5157
5424
|
const { source, filename } = ctx;
|
|
5158
5425
|
if (node.rawName === "v-bind" && !node.name) {
|
|
5159
5426
|
logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
|
|
5160
5427
|
source,
|
|
5161
|
-
loc: _optionalChain([node, 'access',
|
|
5428
|
+
loc: _optionalChain([node, 'access', _179 => _179.arg, 'optionalAccess', _180 => _180.loc]),
|
|
5162
5429
|
file: filename
|
|
5163
5430
|
});
|
|
5164
5431
|
return;
|
|
@@ -5166,7 +5433,7 @@ function checkPropIsDynamicKey(ctx, node) {
|
|
|
5166
5433
|
if (isKeyStatic === false) {
|
|
5167
5434
|
logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
|
|
5168
5435
|
source,
|
|
5169
|
-
loc: _optionalChain([node, 'access',
|
|
5436
|
+
loc: _optionalChain([node, 'access', _181 => _181.arg, 'optionalAccess', _182 => _182.loc]),
|
|
5170
5437
|
file: filename
|
|
5171
5438
|
});
|
|
5172
5439
|
}
|
|
@@ -5185,23 +5452,23 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5185
5452
|
const mergedItems = value.merge;
|
|
5186
5453
|
const setNameIdentifier = (target, valueName) => {
|
|
5187
5454
|
target.content = valueName;
|
|
5188
|
-
target.ast =
|
|
5455
|
+
target.ast = t50.jsxIdentifier(valueName);
|
|
5189
5456
|
};
|
|
5190
|
-
const setValueExpression = (target, content,
|
|
5457
|
+
const setValueExpression = (target, content, isStringLiteral14) => {
|
|
5191
5458
|
target.content = content;
|
|
5192
|
-
target.ast = resolveStringExpr(content, ctx,
|
|
5459
|
+
target.ast = resolveStringExpr(content, ctx, isStringLiteral14);
|
|
5193
5460
|
};
|
|
5194
5461
|
const createRuntimeCall = (fnName, args) => {
|
|
5195
5462
|
const fnArgs = args.filter(Boolean).join(",");
|
|
5196
5463
|
return `${fnName}(${fnArgs})`;
|
|
5197
5464
|
};
|
|
5198
|
-
const applyRuntimeExpression = (expression, setName = false, nameIdentifier,
|
|
5465
|
+
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral14) => {
|
|
5199
5466
|
if (setName && nameIdentifier) {
|
|
5200
5467
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
5201
5468
|
}
|
|
5202
5469
|
const dir = ADAPTER_RULES.runtime.dir;
|
|
5203
5470
|
recordImport(ctx, dir.package, dir.target);
|
|
5204
|
-
setValueExpression(value.babelExp, expression,
|
|
5471
|
+
setValueExpression(value.babelExp, expression, isStringLiteral14);
|
|
5205
5472
|
};
|
|
5206
5473
|
if (ir.isKeyLessVBind) {
|
|
5207
5474
|
const dirKeyless = ADAPTER_RULES.runtime.dirKeyless;
|
|
@@ -5211,19 +5478,19 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5211
5478
|
}
|
|
5212
5479
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
5213
5480
|
const dirCls = ADAPTER_RULES.runtime.dirCls;
|
|
5214
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5481
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _183 => _183.join, 'call', _184 => _184(",")]) || wrapSingleQuotes(valueContent);
|
|
5215
5482
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
5216
5483
|
applyRuntimeExpression(expression, true, name);
|
|
5217
5484
|
return;
|
|
5218
5485
|
}
|
|
5219
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
5486
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _185 => _185.some, 'call', _186 => _186((item) => !isSimpleStyle(item))]))) {
|
|
5220
5487
|
const dirStyle = ADAPTER_RULES.runtime.dirStyle;
|
|
5221
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5488
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _187 => _187.join, 'call', _188 => _188(",")]) || valueContent;
|
|
5222
5489
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
5223
5490
|
applyRuntimeExpression(expression, true, name);
|
|
5224
5491
|
return;
|
|
5225
5492
|
}
|
|
5226
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
5493
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _189 => _189.modifiers, 'optionalAccess', _190 => _190.length])) {
|
|
5227
5494
|
const dirOn = ADAPTER_RULES.runtime.dirOn;
|
|
5228
5495
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
5229
5496
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
@@ -5278,7 +5545,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
5278
5545
|
continue;
|
|
5279
5546
|
}
|
|
5280
5547
|
const nodeIR = child;
|
|
5281
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
5548
|
+
if (_optionalChain([parentIR, 'optionalAccess', _191 => _191.isBuiltIn])) {
|
|
5282
5549
|
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
5283
5550
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
5284
5551
|
}
|
|
@@ -5319,7 +5586,7 @@ function walkElementNodes(node, onElement) {
|
|
|
5319
5586
|
}
|
|
5320
5587
|
function resolveDefaultStyleModuleName(node) {
|
|
5321
5588
|
const { exp } = node;
|
|
5322
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
5589
|
+
if (_optionalChain([exp, 'optionalAccess', _192 => _192.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
5323
5590
|
return;
|
|
5324
5591
|
}
|
|
5325
5592
|
if (exp.content.includes("$style")) {
|
|
@@ -5356,26 +5623,16 @@ function injectStyleScopeAttribute(node, ctx) {
|
|
|
5356
5623
|
return;
|
|
5357
5624
|
}
|
|
5358
5625
|
let hasScopeId = false;
|
|
5359
|
-
let hasClassOrId = false;
|
|
5360
5626
|
for (const prop of node.props) {
|
|
5361
|
-
if (prop.type
|
|
5362
|
-
|
|
5363
|
-
hasScopeId = true;
|
|
5364
|
-
break;
|
|
5365
|
-
}
|
|
5366
|
-
if (getHasClassOrId(prop.name)) {
|
|
5367
|
-
hasClassOrId = true;
|
|
5368
|
-
break;
|
|
5369
|
-
}
|
|
5627
|
+
if (prop.type !== _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5628
|
+
continue;
|
|
5370
5629
|
}
|
|
5371
|
-
if (prop.
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
break;
|
|
5375
|
-
}
|
|
5630
|
+
if (prop.name === scopeId) {
|
|
5631
|
+
hasScopeId = true;
|
|
5632
|
+
break;
|
|
5376
5633
|
}
|
|
5377
5634
|
}
|
|
5378
|
-
if (hasScopeId
|
|
5635
|
+
if (hasScopeId) return;
|
|
5379
5636
|
const attr = {
|
|
5380
5637
|
type: _compilercore.NodeTypes.ATTRIBUTE,
|
|
5381
5638
|
name: scopeId,
|
|
@@ -5385,9 +5642,6 @@ function injectStyleScopeAttribute(node, ctx) {
|
|
|
5385
5642
|
};
|
|
5386
5643
|
node.props.push(attr);
|
|
5387
5644
|
}
|
|
5388
|
-
function getHasClassOrId(ns) {
|
|
5389
|
-
return isClassAttr(ns) || ns === "id";
|
|
5390
|
-
}
|
|
5391
5645
|
|
|
5392
5646
|
// src/core/transform/sfc/template/shared/prop-merge-utils.ts
|
|
5393
5647
|
function mergePropsIR(ctx, oldAttr, newAttr) {
|
|
@@ -5428,7 +5682,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
5428
5682
|
const oldStyle = oldAttr.value.content;
|
|
5429
5683
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
5430
5684
|
let merged = oldAttr.value.merge;
|
|
5431
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
5685
|
+
if (!_optionalChain([merged, 'optionalAccess', _193 => _193.length])) {
|
|
5432
5686
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
5433
5687
|
} else {
|
|
5434
5688
|
merged.push(newStyle);
|
|
@@ -5458,7 +5712,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
5458
5712
|
const { source, filename } = ctx;
|
|
5459
5713
|
let value = "";
|
|
5460
5714
|
let loc;
|
|
5461
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
5715
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _194 => _194.exp, 'optionalAccess', _195 => _195.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
5462
5716
|
value = node.exp.content;
|
|
5463
5717
|
loc = node.exp.loc;
|
|
5464
5718
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -5512,11 +5766,11 @@ function resolveRefProp(prop, ctx, nodeIR) {
|
|
|
5512
5766
|
} = ctx;
|
|
5513
5767
|
let propIR;
|
|
5514
5768
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5515
|
-
const tag = _optionalChain([prop, 'access',
|
|
5769
|
+
const tag = _optionalChain([prop, 'access', _196 => _196.value, 'optionalAccess', _197 => _197.content]);
|
|
5516
5770
|
if (!tag) return;
|
|
5517
5771
|
collectComponentRef(tag, ctx);
|
|
5518
5772
|
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
5519
|
-
const refVar = _optionalChain([domRefBinding, 'optionalAccess',
|
|
5773
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _198 => _198.name]) || _optionalChain([refBindings, 'access', _199 => _199.componentRefs, 'access', _200 => _200[tag], 'optionalAccess', _201 => _201.name]);
|
|
5520
5774
|
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
5521
5775
|
} else {
|
|
5522
5776
|
const exp = prop.exp;
|
|
@@ -5568,7 +5822,7 @@ function resolveTemplateNodeKey(templNode, keyContent, ctx) {
|
|
|
5568
5822
|
return;
|
|
5569
5823
|
}
|
|
5570
5824
|
const [firstChild] = children;
|
|
5571
|
-
if (_optionalChain([firstChild, 'optionalAccess',
|
|
5825
|
+
if (_optionalChain([firstChild, 'optionalAccess', _202 => _202.type]) !== _compilercore.NodeTypes.ELEMENT || firstChild.tagType === _compilercore.ElementTypes.TEMPLATE || firstChild.tagType === _compilercore.ElementTypes.SLOT) {
|
|
5572
5826
|
return;
|
|
5573
5827
|
}
|
|
5574
5828
|
const hasKeyProp = firstChild.props.some(
|
|
@@ -5605,8 +5859,8 @@ function createSimpleVueBind(name, value) {
|
|
|
5605
5859
|
function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
5606
5860
|
const arg = directive.arg;
|
|
5607
5861
|
const exp = directive.exp;
|
|
5608
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5609
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
5862
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _203 => _203.content]), () => ( ""));
|
|
5863
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _204 => _204.content]), () => ( "true"));
|
|
5610
5864
|
warnUnsupportedVueDollarVar(ctx, directive);
|
|
5611
5865
|
if (name === "is") {
|
|
5612
5866
|
resolveDynamicIsProp(directive, ir, ctx, nodeIR);
|
|
@@ -5621,7 +5875,7 @@ function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
5621
5875
|
return;
|
|
5622
5876
|
}
|
|
5623
5877
|
const propIR = createPropsIR(directive.rawName, name, content);
|
|
5624
|
-
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5878
|
+
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _205 => _205.isStatic]), () => ( true));
|
|
5625
5879
|
checkPropIsDynamicKey(ctx, directive);
|
|
5626
5880
|
resolvePropertyIR(propIR, ir, ctx, nodeIR, true);
|
|
5627
5881
|
}
|
|
@@ -5635,12 +5889,12 @@ function resolvePropertyIR(propsIR, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
5635
5889
|
content = propsIR.value.content = parseStyleString(content);
|
|
5636
5890
|
}
|
|
5637
5891
|
if (isDynamic) {
|
|
5638
|
-
const
|
|
5639
|
-
if (
|
|
5892
|
+
const isStringLiteral14 = strCodeTypes.isStringLiteral(content);
|
|
5893
|
+
if (isStringLiteral14) {
|
|
5640
5894
|
content = normalizeString(content);
|
|
5641
5895
|
propsIR.value.content = content;
|
|
5642
5896
|
}
|
|
5643
|
-
propsIR.value.isStringLiteral =
|
|
5897
|
+
propsIR.value.isStringLiteral = isStringLiteral14;
|
|
5644
5898
|
}
|
|
5645
5899
|
const existing = findSameProp(nodeIR.props, propsIR);
|
|
5646
5900
|
if (existing) {
|
|
@@ -5660,7 +5914,7 @@ function normalizeString(s) {
|
|
|
5660
5914
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
5661
5915
|
function resolveAttributeProp(attribute, ir, ctx, nodeIR) {
|
|
5662
5916
|
const name = attribute.name;
|
|
5663
|
-
const content = _nullishCoalesce(_optionalChain([attribute, 'access',
|
|
5917
|
+
const content = _nullishCoalesce(_optionalChain([attribute, 'access', _206 => _206.value, 'optionalAccess', _207 => _207.content]), () => ( "true"));
|
|
5664
5918
|
if (name === "is") {
|
|
5665
5919
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
5666
5920
|
return;
|
|
@@ -5755,10 +6009,10 @@ function resolveRouterLinkVSlotProp(directive, nodeIR, ctx) {
|
|
|
5755
6009
|
type: 2 /* SLOT */,
|
|
5756
6010
|
name: "customRender",
|
|
5757
6011
|
rawName: _nullishCoalesce(directive.rawName, () => ( "v-slot")),
|
|
5758
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6012
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _208 => _208.isStatic]), () => ( true)),
|
|
5759
6013
|
isScoped: true,
|
|
5760
6014
|
callback: {
|
|
5761
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6015
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _209 => _209.content, 'optionalAccess', _210 => _210.trim, 'call', _211 => _211()]), () => ( "")),
|
|
5762
6016
|
exp: []
|
|
5763
6017
|
}
|
|
5764
6018
|
};
|
|
@@ -5774,10 +6028,10 @@ function resolveVFor(directive, ir, ctx, nodeIR) {
|
|
|
5774
6028
|
};
|
|
5775
6029
|
}
|
|
5776
6030
|
function resolveForResult(forParseResult) {
|
|
5777
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
5778
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
5779
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
5780
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
6031
|
+
const source = _optionalChain([forParseResult, 'access', _212 => _212.source, 'optionalAccess', _213 => _213.content]);
|
|
6032
|
+
const value = _optionalChain([forParseResult, 'access', _214 => _214.value, 'optionalAccess', _215 => _215.content]);
|
|
6033
|
+
const index = _optionalChain([forParseResult, 'access', _216 => _216.index, 'optionalAccess', _217 => _217.content]);
|
|
6034
|
+
const key = _optionalChain([forParseResult, 'access', _218 => _218.key, 'optionalAccess', _219 => _219.content]);
|
|
5781
6035
|
return {
|
|
5782
6036
|
source,
|
|
5783
6037
|
value,
|
|
@@ -5797,7 +6051,7 @@ function resolveVHtml(directive, ir, ctx, nodeIR) {
|
|
|
5797
6051
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
5798
6052
|
function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
5799
6053
|
const name = directive.name === "else-if" ? "elseIf" : directive.name;
|
|
5800
|
-
const value = _nullishCoalesce(_optionalChain([directive, 'access',
|
|
6054
|
+
const value = _nullishCoalesce(_optionalChain([directive, 'access', _220 => _220.exp, 'optionalAccess', _221 => _221.content]), () => ( "true"));
|
|
5801
6055
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
5802
6056
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
5803
6057
|
let hasError = false;
|
|
@@ -5836,7 +6090,7 @@ function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
5836
6090
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
5837
6091
|
function resolveVMemo(directive, _ir, ctx, nodeIR) {
|
|
5838
6092
|
const exp = directive.exp;
|
|
5839
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
6093
|
+
let value = _optionalChain([exp, 'optionalAccess', _222 => _222.content]);
|
|
5840
6094
|
if (value !== void 0) {
|
|
5841
6095
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
5842
6096
|
const { source, filename } = ctx;
|
|
@@ -5876,14 +6130,14 @@ function resolveVModel(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
5876
6130
|
const getterName = exp.content;
|
|
5877
6131
|
const isComponent = vueNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
5878
6132
|
const inputType = resolveHtmlInput(vueNode, isComponent);
|
|
5879
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6133
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _223 => _223.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
5880
6134
|
let valuePropIR;
|
|
5881
6135
|
let eventPropIR;
|
|
5882
6136
|
if (isComponent) {
|
|
5883
6137
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
5884
6138
|
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
5885
6139
|
const eventVueName = `update:${propName}`;
|
|
5886
|
-
const isTS = _optionalChain([ctx, 'access',
|
|
6140
|
+
const isTS = _optionalChain([ctx, 'access', _224 => _224.scriptData, 'optionalAccess', _225 => _225.lang, 'optionalAccess', _226 => _226.startsWith, 'call', _227 => _227("ts")]);
|
|
5887
6141
|
const valueArg = isTS ? "value: any" : "value";
|
|
5888
6142
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
5889
6143
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -5921,7 +6175,7 @@ function getRadioValue(vueNode) {
|
|
|
5921
6175
|
const valueAttr = vueNode.props.find(
|
|
5922
6176
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
5923
6177
|
);
|
|
5924
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
6178
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _228 => _228.value, 'optionalAccess', _229 => _229.content])) return '""';
|
|
5925
6179
|
const content = valueAttr.value.content;
|
|
5926
6180
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
5927
6181
|
}
|
|
@@ -5931,7 +6185,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
5931
6185
|
const typeProp = node.props.find(
|
|
5932
6186
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
5933
6187
|
);
|
|
5934
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
6188
|
+
return _optionalChain([typeProp, 'optionalAccess', _230 => _230.value, 'optionalAccess', _231 => _231.content, 'optionalAccess', _232 => _232.toLowerCase, 'call', _233 => _233()]);
|
|
5935
6189
|
}
|
|
5936
6190
|
function applyValueModifiers(valueExp, modifiers) {
|
|
5937
6191
|
let result = valueExp;
|
|
@@ -5950,22 +6204,10 @@ function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
|
5950
6204
|
const arg = directive.arg;
|
|
5951
6205
|
const exp = directive.exp;
|
|
5952
6206
|
const modifiers = directive.modifiers.map((item) => item.content);
|
|
5953
|
-
const captureIndex = modifiers
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
eventName = modifiers[captureIndex] ? `${eventName}Capture` : eventName;
|
|
5958
|
-
modifiers.splice(captureIndex, 1);
|
|
5959
|
-
}
|
|
5960
|
-
let originalVueEventName = "";
|
|
5961
|
-
if (modifiers.length) {
|
|
5962
|
-
originalVueEventName = `${arg.content}.${modifiers.join(".")}`;
|
|
5963
|
-
} else {
|
|
5964
|
-
const expr = stringToExpr(handler);
|
|
5965
|
-
if (!t47.isFunctionExpression(expr) && !t47.isArrowFunctionExpression(expr) && !t47.isIdentifier(expr)) {
|
|
5966
|
-
handler = `() => {${handler}}`;
|
|
5967
|
-
}
|
|
5968
|
-
}
|
|
6207
|
+
const captureIndex = resolveCaptureModifier(modifiers);
|
|
6208
|
+
const eventName = resolveEventName(arg.content, captureIndex);
|
|
6209
|
+
const handler = resolveHandler(exp.content.trim(), ctx, modifiers);
|
|
6210
|
+
const originalVueEventName = modifiers.length ? `${arg.content}.${modifiers.join(".")}` : "";
|
|
5969
6211
|
const eventIR = createPropsIR(directive.rawName, eventName, handler);
|
|
5970
6212
|
eventIR.type = 3 /* EVENT */;
|
|
5971
6213
|
eventIR.isStatic = arg.isStatic;
|
|
@@ -5980,11 +6222,45 @@ function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
|
5980
6222
|
}
|
|
5981
6223
|
nodeIR.props.push(eventIR);
|
|
5982
6224
|
}
|
|
6225
|
+
function resolveCaptureModifier(modifiers) {
|
|
6226
|
+
const captureIndex = modifiers.findIndex((modifier) => modifier === "capture");
|
|
6227
|
+
if (captureIndex > -1) {
|
|
6228
|
+
modifiers.splice(captureIndex, 1);
|
|
6229
|
+
}
|
|
6230
|
+
return captureIndex;
|
|
6231
|
+
}
|
|
6232
|
+
function resolveEventName(rawEventName, captureIndex) {
|
|
6233
|
+
let eventName = normalizeVOnEventName(rawEventName);
|
|
6234
|
+
if (captureIndex > -1) {
|
|
6235
|
+
eventName = `${eventName}Capture`;
|
|
6236
|
+
}
|
|
6237
|
+
return eventName;
|
|
6238
|
+
}
|
|
5983
6239
|
function normalizeVOnEventName(rawEventName) {
|
|
5984
6240
|
const segments = rawEventName.split(/[:-]/g).map((segment) => segment.trim()).filter(Boolean);
|
|
5985
6241
|
const normalized = segments.map((segment) => capitalize(camelCase(segment))).join("");
|
|
5986
6242
|
return `on${normalized}`;
|
|
5987
6243
|
}
|
|
6244
|
+
function resolveHandler(handlerContent, ctx, modifiers) {
|
|
6245
|
+
let handler = resolveSpecialExpression(handlerContent, ctx);
|
|
6246
|
+
if (modifiers.length) {
|
|
6247
|
+
return handler;
|
|
6248
|
+
}
|
|
6249
|
+
const expr = stringToExpr(handler);
|
|
6250
|
+
if (isConsoleCall(expr)) {
|
|
6251
|
+
return "() => {}";
|
|
6252
|
+
}
|
|
6253
|
+
if (!isFnReference(expr)) {
|
|
6254
|
+
handler = `() => {${handler}}`;
|
|
6255
|
+
}
|
|
6256
|
+
return handler;
|
|
6257
|
+
}
|
|
6258
|
+
function isConsoleCall(expr) {
|
|
6259
|
+
return t51.isCallExpression(expr) && t51.isMemberExpression(expr.callee) && t51.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
|
|
6260
|
+
}
|
|
6261
|
+
function isFnReference(expr) {
|
|
6262
|
+
return t51.isIdentifier(expr) || t51.isMemberExpression(expr) || t51.isFunction(expr);
|
|
6263
|
+
}
|
|
5988
6264
|
|
|
5989
6265
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
|
|
5990
6266
|
function resolveVShow(directive, ir, ctx, nodeIR) {
|
|
@@ -6016,7 +6292,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6016
6292
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
6017
6293
|
const content = !isScoped ? [] : void 0;
|
|
6018
6294
|
const callback = isScoped ? {
|
|
6019
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6295
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _234 => _234.content, 'optionalAccess', _235 => _235.trim, 'call', _236 => _236()]), () => ( "")),
|
|
6020
6296
|
exp: []
|
|
6021
6297
|
} : void 0;
|
|
6022
6298
|
checkPropIsDynamicKey(ctx, directive);
|
|
@@ -6024,7 +6300,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6024
6300
|
type: 2 /* SLOT */,
|
|
6025
6301
|
name,
|
|
6026
6302
|
rawName: _nullishCoalesce(directive.rawName, () => ( "default")),
|
|
6027
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6303
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _237 => _237.isStatic]), () => ( true)),
|
|
6028
6304
|
isScoped,
|
|
6029
6305
|
content,
|
|
6030
6306
|
callback
|
|
@@ -6087,7 +6363,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
6087
6363
|
if (routerAdapter) {
|
|
6088
6364
|
if (!ctx.route) ctx.route = true;
|
|
6089
6365
|
nodeIR.isRoute = true;
|
|
6090
|
-
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess',
|
|
6366
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _238 => _238.package]), routerAdapter.target);
|
|
6091
6367
|
}
|
|
6092
6368
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
6093
6369
|
return nodeIR;
|
|
@@ -6234,7 +6510,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6234
6510
|
for (const prop of node.props) {
|
|
6235
6511
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
6236
6512
|
const attr = prop.name;
|
|
6237
|
-
const value = _optionalChain([prop, 'access',
|
|
6513
|
+
const value = _optionalChain([prop, 'access', _239 => _239.value, 'optionalAccess', _240 => _240.content, 'access', _241 => _241.trim, 'call', _242 => _242()]);
|
|
6238
6514
|
if (attr === "name" && value) {
|
|
6239
6515
|
result.name = camelCase(value);
|
|
6240
6516
|
} else {
|
|
@@ -6324,32 +6600,23 @@ function resolveTemplate2(root, ctx) {
|
|
|
6324
6600
|
// src/core/transform/sfc/index.ts
|
|
6325
6601
|
function transform(ast, ctx, options) {
|
|
6326
6602
|
const { template, script, style } = ast;
|
|
6327
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
6328
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
6603
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _243 => _243.ast]), ctx);
|
|
6604
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _244 => _244.ast]), ctx);
|
|
6329
6605
|
const result = {
|
|
6330
6606
|
template: templateIR,
|
|
6331
6607
|
script: scriptIR,
|
|
6332
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
6608
|
+
style: _optionalChain([style, 'optionalAccess', _245 => _245.source, 'optionalAccess', _246 => _246.content])
|
|
6333
6609
|
};
|
|
6334
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
6610
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _247 => _247.plugins]), result, ctx);
|
|
6335
6611
|
return result;
|
|
6336
6612
|
}
|
|
6337
6613
|
|
|
6338
6614
|
// package.json
|
|
6339
|
-
var version = "1.
|
|
6615
|
+
var version = "1.8.0";
|
|
6340
6616
|
var bin = {
|
|
6341
6617
|
vureact: "./bin/vureact.js"
|
|
6342
6618
|
};
|
|
6343
6619
|
|
|
6344
|
-
// src/compiler/shared/types/cache-types.ts
|
|
6345
|
-
var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
|
|
6346
|
-
CacheKey2["SFC"] = "sfc";
|
|
6347
|
-
CacheKey2["SCRIPT"] = "script";
|
|
6348
|
-
CacheKey2["STYLE"] = "style";
|
|
6349
|
-
CacheKey2["ASSET"] = "copied";
|
|
6350
|
-
return CacheKey2;
|
|
6351
|
-
})(CacheKey || {});
|
|
6352
|
-
|
|
6353
6620
|
// src/plugins/prettier.ts
|
|
6354
6621
|
async function formatWithPrettier(code, lang, opts) {
|
|
6355
6622
|
try {
|
|
@@ -6369,7 +6636,7 @@ async function formatWithPrettier(code, lang, opts) {
|
|
|
6369
6636
|
...opts,
|
|
6370
6637
|
parser
|
|
6371
6638
|
});
|
|
6372
|
-
} catch (
|
|
6639
|
+
} catch (e10) {
|
|
6373
6640
|
logger.info("Prettier is unavailable; the built-in simple formatter is used.");
|
|
6374
6641
|
return simpleFormat(code);
|
|
6375
6642
|
}
|
|
@@ -6419,7 +6686,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
6419
6686
|
if (content.trim()) {
|
|
6420
6687
|
try {
|
|
6421
6688
|
current = JSON.parse(content);
|
|
6422
|
-
} catch (
|
|
6689
|
+
} catch (e11) {
|
|
6423
6690
|
current = content;
|
|
6424
6691
|
}
|
|
6425
6692
|
}
|
|
@@ -6452,7 +6719,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
6452
6719
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
6453
6720
|
try {
|
|
6454
6721
|
await _fs2.default.promises.access(filePath);
|
|
6455
|
-
} catch (
|
|
6722
|
+
} catch (e12) {
|
|
6456
6723
|
await this.writeFile(filePath, "");
|
|
6457
6724
|
}
|
|
6458
6725
|
const release = await _properlockfile2.default.lock(filePath, {
|
|
@@ -6477,7 +6744,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
6477
6744
|
const { stale = 1e4, realpath = true, lockfilePath } = options;
|
|
6478
6745
|
try {
|
|
6479
6746
|
return await _properlockfile2.default.check(filePath, { stale, realpath, lockfilePath });
|
|
6480
|
-
} catch (
|
|
6747
|
+
} catch (e13) {
|
|
6481
6748
|
return false;
|
|
6482
6749
|
}
|
|
6483
6750
|
}
|
|
@@ -6499,7 +6766,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
6499
6766
|
lockfilePath
|
|
6500
6767
|
});
|
|
6501
6768
|
return release;
|
|
6502
|
-
} catch (
|
|
6769
|
+
} catch (e14) {
|
|
6503
6770
|
return null;
|
|
6504
6771
|
}
|
|
6505
6772
|
}
|
|
@@ -6512,7 +6779,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
6512
6779
|
const { realpath = true, lockfilePath } = options;
|
|
6513
6780
|
try {
|
|
6514
6781
|
await _properlockfile2.default.unlock(filePath, { realpath, lockfilePath });
|
|
6515
|
-
} catch (
|
|
6782
|
+
} catch (e15) {
|
|
6516
6783
|
}
|
|
6517
6784
|
}
|
|
6518
6785
|
async writeFile(filePath, content) {
|
|
@@ -6530,7 +6797,7 @@ var Helper = (_class5 = class {
|
|
|
6530
6797
|
__init8() {this.outDir = "react-app"}
|
|
6531
6798
|
constructor(opts) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);
|
|
6532
6799
|
this.compilerOpts = opts;
|
|
6533
|
-
if (_optionalChain([opts, 'access',
|
|
6800
|
+
if (_optionalChain([opts, 'access', _248 => _248.output, 'optionalAccess', _249 => _249.workspace])) {
|
|
6534
6801
|
this.workspaceDir = opts.output.workspace;
|
|
6535
6802
|
}
|
|
6536
6803
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -6550,13 +6817,6 @@ var Helper = (_class5 = class {
|
|
|
6550
6817
|
const { input = "src" } = this.compilerOpts;
|
|
6551
6818
|
return _path2.default.resolve(this.getProjectRoot(), input);
|
|
6552
6819
|
}
|
|
6553
|
-
/**
|
|
6554
|
-
* 检查 input 路径是否是单个文件
|
|
6555
|
-
*/
|
|
6556
|
-
isSingleFile() {
|
|
6557
|
-
const inputPath = this.getInputPath();
|
|
6558
|
-
return _fs2.default.existsSync(inputPath) && _fs2.default.statSync(inputPath).isFile();
|
|
6559
|
-
}
|
|
6560
6820
|
/**
|
|
6561
6821
|
* 获取输出文件的路径。如:'[root]/.vureact/dist/'
|
|
6562
6822
|
* @param addInput 会输出如:'[root]/.vureact/dist/[input]/'
|
|
@@ -6567,7 +6827,7 @@ var Helper = (_class5 = class {
|
|
|
6567
6827
|
}
|
|
6568
6828
|
getOutDirName() {
|
|
6569
6829
|
const { output } = this.compilerOpts;
|
|
6570
|
-
return _optionalChain([output, 'optionalAccess',
|
|
6830
|
+
return _optionalChain([output, 'optionalAccess', _250 => _250.outDir]) || this.outDir;
|
|
6571
6831
|
}
|
|
6572
6832
|
getWorkspaceDir() {
|
|
6573
6833
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -6581,7 +6841,7 @@ var Helper = (_class5 = class {
|
|
|
6581
6841
|
}
|
|
6582
6842
|
getIgnoreAssets() {
|
|
6583
6843
|
const { output } = this.compilerOpts;
|
|
6584
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
6844
|
+
if (_optionalChain([output, 'optionalAccess', _251 => _251.ignoreAssets])) {
|
|
6585
6845
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
6586
6846
|
}
|
|
6587
6847
|
return /* @__PURE__ */ new Set([
|
|
@@ -6615,6 +6875,13 @@ var Helper = (_class5 = class {
|
|
|
6615
6875
|
getOutputPkgPath() {
|
|
6616
6876
|
return _path2.default.join(this.getOuputPath(), "package.json");
|
|
6617
6877
|
}
|
|
6878
|
+
/**
|
|
6879
|
+
* 获取缓存文件路径
|
|
6880
|
+
*/
|
|
6881
|
+
getCachePath() {
|
|
6882
|
+
const filename = "_metadata";
|
|
6883
|
+
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
|
|
6884
|
+
}
|
|
6618
6885
|
/**
|
|
6619
6886
|
* 返回文件相对工作区的路径
|
|
6620
6887
|
*/
|
|
@@ -6664,12 +6931,12 @@ var Helper = (_class5 = class {
|
|
|
6664
6931
|
*/
|
|
6665
6932
|
async formatCode({ code, fileInfo }) {
|
|
6666
6933
|
const { format } = this.compilerOpts;
|
|
6667
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
6668
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
6934
|
+
if (!_optionalChain([format, 'optionalAccess', _252 => _252.enabled])) return code;
|
|
6935
|
+
if (_optionalChain([format, 'optionalAccess', _253 => _253.formatter]) === "builtin") {
|
|
6669
6936
|
return simpleFormat(code);
|
|
6670
6937
|
}
|
|
6671
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
6672
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
6938
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _254 => _254.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _255 => _255.script])));
|
|
6939
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _256 => _256.prettierOptions]));
|
|
6673
6940
|
}
|
|
6674
6941
|
/**
|
|
6675
6942
|
* 通用的缓存校验工具函数
|
|
@@ -6703,7 +6970,7 @@ var Helper = (_class5 = class {
|
|
|
6703
6970
|
* @param options.lock - 是否启用文件锁(默认false)
|
|
6704
6971
|
*/
|
|
6705
6972
|
async writeFileWithDir(filePath, content, options) {
|
|
6706
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6973
|
+
if (_optionalChain([options, 'optionalAccess', _257 => _257.lock])) {
|
|
6707
6974
|
await fileLock.updateFile(filePath, async () => content, options);
|
|
6708
6975
|
} else {
|
|
6709
6976
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
@@ -6712,95 +6979,15 @@ var Helper = (_class5 = class {
|
|
|
6712
6979
|
}
|
|
6713
6980
|
async rmFile(filePath) {
|
|
6714
6981
|
try {
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
}
|
|
6718
|
-
}
|
|
6719
|
-
async loadCache(key) {
|
|
6720
|
-
const cacheFile = this.getCachePath();
|
|
6721
|
-
const defaultData = this.createCacheData(key);
|
|
6722
|
-
if (!_fs2.default.existsSync(cacheFile)) {
|
|
6723
|
-
return defaultData;
|
|
6724
|
-
}
|
|
6725
|
-
try {
|
|
6726
|
-
const content = await _fs2.default.promises.readFile(cacheFile, "utf-8");
|
|
6727
|
-
const data = JSON.parse(content);
|
|
6728
|
-
return {
|
|
6729
|
-
key,
|
|
6730
|
-
target: data[key] || [],
|
|
6731
|
-
source: data
|
|
6732
|
-
};
|
|
6733
|
-
} catch (e16) {
|
|
6734
|
-
return defaultData;
|
|
6735
|
-
}
|
|
6736
|
-
}
|
|
6737
|
-
createCacheData(key) {
|
|
6738
|
-
return {
|
|
6739
|
-
key,
|
|
6740
|
-
target: [],
|
|
6741
|
-
source: {
|
|
6742
|
-
["sfc" /* SFC */]: [],
|
|
6743
|
-
["script" /* SCRIPT */]: [],
|
|
6744
|
-
["style" /* STYLE */]: [],
|
|
6745
|
-
["copied" /* ASSET */]: []
|
|
6982
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
6983
|
+
await _fs2.default.promises.rm(filePath, { recursive: true, force: true });
|
|
6746
6984
|
}
|
|
6747
|
-
}
|
|
6748
|
-
}
|
|
6749
|
-
/**
|
|
6750
|
-
* 获取缓存文件路径
|
|
6751
|
-
*/
|
|
6752
|
-
getCachePath() {
|
|
6753
|
-
const filename = "_metadata";
|
|
6754
|
-
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
|
|
6755
|
-
}
|
|
6756
|
-
async saveCache(data) {
|
|
6757
|
-
if (!this.getIsCache() || !data) {
|
|
6758
|
-
return;
|
|
6985
|
+
} catch (e16) {
|
|
6759
6986
|
}
|
|
6760
|
-
const getDefaultValue = () => ({
|
|
6761
|
-
["sfc" /* SFC */]: [],
|
|
6762
|
-
["script" /* SCRIPT */]: [],
|
|
6763
|
-
["style" /* STYLE */]: [],
|
|
6764
|
-
["copied" /* ASSET */]: []
|
|
6765
|
-
});
|
|
6766
|
-
const cachePath = this.getCachePath();
|
|
6767
|
-
await fileLock.updateFile(cachePath, (currentData) => {
|
|
6768
|
-
const { key, target } = data;
|
|
6769
|
-
const mergedData = currentData || getDefaultValue();
|
|
6770
|
-
mergedData[key] = target;
|
|
6771
|
-
return mergedData;
|
|
6772
|
-
});
|
|
6773
6987
|
}
|
|
6774
6988
|
genHash(content) {
|
|
6775
6989
|
return genHashByXXH(content);
|
|
6776
6990
|
}
|
|
6777
|
-
/**
|
|
6778
|
-
* 扫描指定目录下的所有文件
|
|
6779
|
-
* @param dir 目标目录
|
|
6780
|
-
* @param filter 筛选指定的文件后缀名
|
|
6781
|
-
*/
|
|
6782
|
-
scanFiles(dir, filter) {
|
|
6783
|
-
const results = [];
|
|
6784
|
-
if (!_fs2.default.existsSync(dir)) {
|
|
6785
|
-
return results;
|
|
6786
|
-
}
|
|
6787
|
-
const stats = _fs2.default.statSync(dir);
|
|
6788
|
-
if (stats.isFile()) {
|
|
6789
|
-
return filter(dir) ? [dir] : [];
|
|
6790
|
-
}
|
|
6791
|
-
const list = _fs2.default.readdirSync(dir);
|
|
6792
|
-
for (const file of list) {
|
|
6793
|
-
const fullPath = _path2.default.resolve(dir, file);
|
|
6794
|
-
if (this.shouldSkipPath(fullPath)) continue;
|
|
6795
|
-
const stat = _fs2.default.statSync(fullPath);
|
|
6796
|
-
if (stat.isDirectory() && this.compilerOpts.recursive !== false) {
|
|
6797
|
-
results.push(...this.scanFiles(fullPath, filter));
|
|
6798
|
-
} else if (filter(fullPath)) {
|
|
6799
|
-
results.push(fullPath);
|
|
6800
|
-
}
|
|
6801
|
-
}
|
|
6802
|
-
return results;
|
|
6803
|
-
}
|
|
6804
6991
|
getAbsPath(filePath) {
|
|
6805
6992
|
return _path2.default.isAbsolute(filePath) ? filePath : _path2.default.resolve(this.getProjectRoot(), filePath);
|
|
6806
6993
|
}
|
|
@@ -6812,9 +6999,9 @@ var Helper = (_class5 = class {
|
|
|
6812
6999
|
};
|
|
6813
7000
|
}
|
|
6814
7001
|
async removeOutputFile(filePath, resolveOutputPath) {
|
|
6815
|
-
const
|
|
6816
|
-
if (!_fs2.default.existsSync(
|
|
6817
|
-
await _fs2.default.promises.unlink(
|
|
7002
|
+
const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
|
|
7003
|
+
if (!_fs2.default.existsSync(path8)) return;
|
|
7004
|
+
await _fs2.default.promises.unlink(path8);
|
|
6818
7005
|
}
|
|
6819
7006
|
updateCache(targetFile, newData, cache) {
|
|
6820
7007
|
const index = cache.target.findIndex((c) => c.file === targetFile);
|
|
@@ -6828,7 +7015,7 @@ var Helper = (_class5 = class {
|
|
|
6828
7015
|
* 获取需要排除编译的文件
|
|
6829
7016
|
*/
|
|
6830
7017
|
getExcludes() {
|
|
6831
|
-
if (!_optionalChain([this, 'access',
|
|
7018
|
+
if (!_optionalChain([this, 'access', _258 => _258.compilerOpts, 'access', _259 => _259.exclude, 'optionalAccess', _260 => _260.length])) {
|
|
6832
7019
|
return PathFilter.withDefaults();
|
|
6833
7020
|
}
|
|
6834
7021
|
return this.compilerOpts.exclude;
|
|
@@ -6867,18 +7054,18 @@ var Helper = (_class5 = class {
|
|
|
6867
7054
|
/**
|
|
6868
7055
|
* 读取 package.json 文件内容,并处理成对象返回
|
|
6869
7056
|
*/
|
|
6870
|
-
async resolvePackageFile(
|
|
6871
|
-
if (!_fs2.default.existsSync(
|
|
7057
|
+
async resolvePackageFile(path8) {
|
|
7058
|
+
if (!_fs2.default.existsSync(path8)) {
|
|
6872
7059
|
return {};
|
|
6873
7060
|
}
|
|
6874
7061
|
try {
|
|
6875
|
-
const content = await _fs2.default.promises.readFile(
|
|
7062
|
+
const content = await _fs2.default.promises.readFile(path8, "utf-8");
|
|
6876
7063
|
if (!content.trim()) {
|
|
6877
7064
|
return {};
|
|
6878
7065
|
}
|
|
6879
7066
|
return JSON.parse(content);
|
|
6880
7067
|
} catch (error) {
|
|
6881
|
-
console.error(_kleur2.default.red("\u274C"), `Failed to parse JSON file ${
|
|
7068
|
+
console.error(_kleur2.default.red("\u274C"), `Failed to parse JSON file ${path8}:
|
|
6882
7069
|
`, error);
|
|
6883
7070
|
return {};
|
|
6884
7071
|
}
|
|
@@ -6926,7 +7113,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
6926
7113
|
ast: void 0
|
|
6927
7114
|
}
|
|
6928
7115
|
};
|
|
6929
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
7116
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _261 => _261.plugins]), result, ctx);
|
|
6930
7117
|
return result;
|
|
6931
7118
|
}
|
|
6932
7119
|
|
|
@@ -6950,7 +7137,7 @@ var CompilationContext = (_class6 = class {constructor() { _class6.prototype.__i
|
|
|
6950
7137
|
}
|
|
6951
7138
|
create() {
|
|
6952
7139
|
return {
|
|
6953
|
-
fileId:
|
|
7140
|
+
fileId: Date.now().toString(),
|
|
6954
7141
|
source: "",
|
|
6955
7142
|
filename: "",
|
|
6956
7143
|
imports: /* @__PURE__ */ new Map(),
|
|
@@ -7060,16 +7247,16 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7060
7247
|
});
|
|
7061
7248
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
7062
7249
|
const resolveSFCAndScriptFile = () => {
|
|
7063
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7064
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7250
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _262 => _262.parser]) });
|
|
7251
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _263 => _263.transformer]) });
|
|
7065
7252
|
const gen = generate(ir, ctx.data, {
|
|
7066
7253
|
...genOptions,
|
|
7067
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7254
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _264 => _264.codegen])
|
|
7068
7255
|
});
|
|
7069
7256
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
7070
7257
|
};
|
|
7071
7258
|
const resolveStyleFile = () => {
|
|
7072
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7259
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _265 => _265.parser]) });
|
|
7073
7260
|
return this.resolveStyleResult(result, ctx.data);
|
|
7074
7261
|
};
|
|
7075
7262
|
try {
|
|
@@ -7108,9 +7295,9 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7108
7295
|
lang
|
|
7109
7296
|
},
|
|
7110
7297
|
css: {
|
|
7111
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
7112
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
7113
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
7298
|
+
file: _optionalChain([styleData, 'optionalAccess', _266 => _266.filePath]),
|
|
7299
|
+
hash: _optionalChain([styleData, 'optionalAccess', _267 => _267.scopeId]),
|
|
7300
|
+
code: _optionalChain([ir, 'optionalAccess', _268 => _268.style])
|
|
7114
7301
|
}
|
|
7115
7302
|
},
|
|
7116
7303
|
...base
|
|
@@ -7138,6 +7325,15 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7138
7325
|
}
|
|
7139
7326
|
}, _class7);
|
|
7140
7327
|
|
|
7328
|
+
// src/compiler/shared/types/cache-types.ts
|
|
7329
|
+
var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
|
|
7330
|
+
CacheKey2["SFC"] = "sfc";
|
|
7331
|
+
CacheKey2["SCRIPT"] = "script";
|
|
7332
|
+
CacheKey2["STYLE"] = "style";
|
|
7333
|
+
CacheKey2["ASSET"] = "copied";
|
|
7334
|
+
return CacheKey2;
|
|
7335
|
+
})(CacheKey || {});
|
|
7336
|
+
|
|
7141
7337
|
// src/utils/calc-elapsed-time.ts
|
|
7142
7338
|
function calcElapsedTime(start) {
|
|
7143
7339
|
const end = performance.now();
|
|
@@ -7160,9 +7356,10 @@ var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
|
7160
7356
|
|
|
7161
7357
|
|
|
7162
7358
|
var AssetManager = (_class8 = class {
|
|
7163
|
-
constructor(fileCompiler, cleanupManager) {;_class8.prototype.__init12.call(this);_class8.prototype.__init13.call(this);
|
|
7359
|
+
constructor(fileCompiler, cleanupManager, cacheManager) {;_class8.prototype.__init12.call(this);_class8.prototype.__init13.call(this);
|
|
7164
7360
|
this.fileCompiler = fileCompiler;
|
|
7165
7361
|
this.cleanupManager = cleanupManager;
|
|
7362
|
+
this.cacheManager = cacheManager;
|
|
7166
7363
|
}
|
|
7167
7364
|
// 需要经过管线编译处理的文件类型
|
|
7168
7365
|
__init12() {this.pipelineFiles = [".js", ".ts", ".less", ".scss", ".sass"]}
|
|
@@ -7170,70 +7367,40 @@ var AssetManager = (_class8 = class {
|
|
|
7170
7367
|
/**
|
|
7171
7368
|
* 运行资源文件处理管线
|
|
7172
7369
|
*/
|
|
7173
|
-
async
|
|
7174
|
-
const
|
|
7175
|
-
const
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
|
|
7181
|
-
const filename = _path2.default.basename(p).toLowerCase();
|
|
7182
|
-
const ext = _path2.default.extname(p).toLowerCase();
|
|
7183
|
-
if (!_optionalChain([options, 'access', _249 => _249.output, 'optionalAccess', _250 => _250.ignoreAssets])) {
|
|
7184
|
-
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
7185
|
-
if (pattern.endsWith(".")) {
|
|
7186
|
-
return filename.startsWith(pattern);
|
|
7187
|
-
}
|
|
7188
|
-
if (pattern.startsWith(".")) {
|
|
7189
|
-
return ext === pattern;
|
|
7190
|
-
}
|
|
7191
|
-
return relativeToRoot === pattern || filename === pattern;
|
|
7192
|
-
});
|
|
7193
|
-
if (shouldExclude) return false;
|
|
7194
|
-
} else if (exclusions.has(relativeToRoot) || exclusions.has(filename)) {
|
|
7195
|
-
return false;
|
|
7196
|
-
}
|
|
7197
|
-
if (ext === ".vue") return false;
|
|
7198
|
-
const isInsideSrc = p.startsWith(inputPath + _path2.default.sep);
|
|
7199
|
-
if (isInsideSrc && this.pipelineFiles.includes(ext)) {
|
|
7200
|
-
return false;
|
|
7201
|
-
}
|
|
7202
|
-
return true;
|
|
7203
|
-
});
|
|
7204
|
-
const absFiles = new Set(assetFiles.map((f) => this.fileCompiler.getAbsPath(f)));
|
|
7205
|
-
await this.cleanupManager.cleanupOldOutput("copied" /* ASSET */, (u) => !absFiles.has(u.file));
|
|
7206
|
-
if (!assetFiles.length) return 0;
|
|
7207
|
-
const cache = await this.fileCompiler.loadCache("copied" /* ASSET */);
|
|
7208
|
-
const copied = await Promise.all(
|
|
7209
|
-
assetFiles.map((file) => {
|
|
7210
|
-
return this.processAsset(file, cache);
|
|
7211
|
-
})
|
|
7370
|
+
async runAsset(files, cacheMap) {
|
|
7371
|
+
const absPaths = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
|
|
7372
|
+
const cache = cacheMap["copied" /* ASSET */];
|
|
7373
|
+
await this.cleanupManager.removeMatchedFromCache(
|
|
7374
|
+
"copied" /* ASSET */,
|
|
7375
|
+
cache,
|
|
7376
|
+
(u) => !absPaths.has(u.file)
|
|
7212
7377
|
);
|
|
7213
|
-
|
|
7378
|
+
if (!files.length) return 0;
|
|
7379
|
+
const copied = await Promise.all(files.map((file) => this.processAsset(file, cache)));
|
|
7214
7380
|
return copied.filter(Boolean).length;
|
|
7215
7381
|
}
|
|
7216
7382
|
/**
|
|
7217
7383
|
* Process single asset file, compare with cache and decide whether to copy.
|
|
7218
7384
|
*/
|
|
7219
7385
|
async processAsset(filePath, existingCache) {
|
|
7220
|
-
const
|
|
7386
|
+
const { fileCompiler, cacheManager } = this;
|
|
7387
|
+
const absPath = fileCompiler.getAbsPath(filePath);
|
|
7221
7388
|
const fileMeta = {
|
|
7222
7389
|
file: absPath,
|
|
7223
|
-
...await
|
|
7390
|
+
...await fileCompiler.getFileMeta(absPath)
|
|
7224
7391
|
};
|
|
7225
|
-
const cache = (
|
|
7392
|
+
const cache = (fileCompiler.getIsCache() ? existingCache : void 0) || await cacheManager.loadCache("copied" /* ASSET */);
|
|
7226
7393
|
const record = cache.target.find((f) => f.file === absPath);
|
|
7227
|
-
if (record &&
|
|
7394
|
+
if (record && fileCompiler.compareFileMeta(record, fileMeta)) {
|
|
7228
7395
|
this.skippedCount++;
|
|
7229
7396
|
return;
|
|
7230
7397
|
}
|
|
7231
|
-
const outputPath =
|
|
7398
|
+
const outputPath = fileCompiler.resolveOutputPath(absPath);
|
|
7232
7399
|
await _fs2.default.promises.mkdir(_path2.default.dirname(outputPath), { recursive: true });
|
|
7233
7400
|
await _fs2.default.promises.copyFile(absPath, outputPath);
|
|
7234
7401
|
this.updateCache(absPath, fileMeta, cache);
|
|
7235
|
-
if (
|
|
7236
|
-
await
|
|
7402
|
+
if (fileCompiler.getIsCache() && !existingCache) {
|
|
7403
|
+
await cacheManager.saveCache(cache);
|
|
7237
7404
|
}
|
|
7238
7405
|
return fileMeta;
|
|
7239
7406
|
}
|
|
@@ -7264,11 +7431,14 @@ var AssetManager = (_class8 = class {
|
|
|
7264
7431
|
}, _class8);
|
|
7265
7432
|
|
|
7266
7433
|
// src/compiler/shared/file-compiler/cache-manager.ts
|
|
7434
|
+
|
|
7267
7435
|
var CacheManager = (_class9 = class {
|
|
7268
|
-
constructor(fileCompiler) {;_class9.prototype.__init14.call(this);
|
|
7436
|
+
constructor(fileCompiler) {;_class9.prototype.__init14.call(this);_class9.prototype.__init15.call(this);
|
|
7269
7437
|
this.fileCompiler = fileCompiler;
|
|
7270
7438
|
}
|
|
7271
7439
|
__init14() {this.pendingUpdates = /* @__PURE__ */ new Map()}
|
|
7440
|
+
/** 缓存文件仅读取一次,之后复用此副本 */
|
|
7441
|
+
__init15() {this.cachedData = null}
|
|
7272
7442
|
/**
|
|
7273
7443
|
* 批量更新缓存记录
|
|
7274
7444
|
*/
|
|
@@ -7277,12 +7447,12 @@ var CacheManager = (_class9 = class {
|
|
|
7277
7447
|
const meta = { ...unit };
|
|
7278
7448
|
delete meta.source;
|
|
7279
7449
|
if (key === "sfc" /* SFC */) {
|
|
7280
|
-
_optionalChainDelete([meta, 'access',
|
|
7281
|
-
_optionalChainDelete([meta, 'access',
|
|
7450
|
+
_optionalChainDelete([meta, 'access', _269 => _269.output, 'optionalAccess', _270 => _270.jsx, 'access', _271 => delete _271.code]);
|
|
7451
|
+
_optionalChainDelete([meta, 'access', _272 => _272.output, 'optionalAccess', _273 => _273.css, 'access', _274 => delete _274.code]);
|
|
7282
7452
|
} else if (key === "script" /* SCRIPT */) {
|
|
7283
|
-
_optionalChainDelete([meta, 'access',
|
|
7453
|
+
_optionalChainDelete([meta, 'access', _275 => _275.output, 'optionalAccess', _276 => _276.script, 'access', _277 => delete _277.code]);
|
|
7284
7454
|
} else if (key === "style" /* STYLE */) {
|
|
7285
|
-
_optionalChainDelete([meta, 'access',
|
|
7455
|
+
_optionalChainDelete([meta, 'access', _278 => _278.output, 'optionalAccess', _279 => _279.style, 'access', _280 => delete _280.code]);
|
|
7286
7456
|
}
|
|
7287
7457
|
if (!this.pendingUpdates.has(key)) {
|
|
7288
7458
|
this.pendingUpdates.set(key, []);
|
|
@@ -7290,94 +7460,203 @@ var CacheManager = (_class9 = class {
|
|
|
7290
7460
|
this.pendingUpdates.get(key).push({ unit, meta });
|
|
7291
7461
|
}
|
|
7292
7462
|
/**
|
|
7293
|
-
*
|
|
7463
|
+
* 一次性刷新所有缓存(只写一次文件)
|
|
7294
7464
|
*/
|
|
7295
|
-
async
|
|
7296
|
-
if (!this.fileCompiler.getIsCache()
|
|
7465
|
+
async flushAllCache() {
|
|
7466
|
+
if (!this.fileCompiler.getIsCache()) {
|
|
7297
7467
|
return;
|
|
7298
7468
|
}
|
|
7469
|
+
const keys = Object.values(CacheKey);
|
|
7470
|
+
if (!this.cachedData) {
|
|
7471
|
+
await this.loadAllCache();
|
|
7472
|
+
}
|
|
7473
|
+
for (const key of keys) {
|
|
7474
|
+
const updates = this.pendingUpdates.get(key);
|
|
7475
|
+
if (!_optionalChain([updates, 'optionalAccess', _281 => _281.length])) continue;
|
|
7476
|
+
const activeFiles = new Set(updates.map((u) => u.unit.file));
|
|
7477
|
+
const entries = (this.cachedData[key] || []).filter((c) => activeFiles.has(c.file));
|
|
7478
|
+
updates.forEach(({ unit, meta }) => {
|
|
7479
|
+
const idx = entries.findIndex((c) => c.file === unit.file);
|
|
7480
|
+
if (idx > -1) {
|
|
7481
|
+
entries[idx] = meta;
|
|
7482
|
+
} else {
|
|
7483
|
+
entries.push(meta);
|
|
7484
|
+
}
|
|
7485
|
+
});
|
|
7486
|
+
this.cachedData[key] = entries;
|
|
7487
|
+
this.pendingUpdates.set(key, []);
|
|
7488
|
+
}
|
|
7489
|
+
await fileLock.updateFile(this.fileCompiler.getCachePath(), () => this.cachedData);
|
|
7490
|
+
}
|
|
7491
|
+
/**
|
|
7492
|
+
* 一次性加载所有缓存(只读一次文件)
|
|
7493
|
+
*/
|
|
7494
|
+
async loadAllCache() {
|
|
7495
|
+
const filePath = this.fileCompiler.getCachePath();
|
|
7496
|
+
const result = {};
|
|
7497
|
+
let raw = null;
|
|
7498
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
7499
|
+
try {
|
|
7500
|
+
const content = await _fs2.default.promises.readFile(filePath, "utf-8");
|
|
7501
|
+
raw = JSON.parse(content);
|
|
7502
|
+
} catch (e17) {
|
|
7503
|
+
}
|
|
7504
|
+
}
|
|
7505
|
+
this.cachedData = raw || this.getEmptyList();
|
|
7506
|
+
const keys = Object.values(CacheKey);
|
|
7507
|
+
for (const key of keys) {
|
|
7508
|
+
result[key] = this.buildLoadedCache(key, raw);
|
|
7509
|
+
}
|
|
7510
|
+
return result;
|
|
7511
|
+
}
|
|
7512
|
+
/**
|
|
7513
|
+
* 加载指定类型的缓存(watch 等场景使用)
|
|
7514
|
+
*/
|
|
7515
|
+
async loadCache(key) {
|
|
7516
|
+
if (this.cachedData) {
|
|
7517
|
+
return this.buildLoadedCache(key, this.cachedData);
|
|
7518
|
+
}
|
|
7519
|
+
const filePath = this.fileCompiler.getCachePath();
|
|
7520
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
7521
|
+
try {
|
|
7522
|
+
const content = await _fs2.default.promises.readFile(filePath, "utf-8");
|
|
7523
|
+
const data = JSON.parse(content);
|
|
7524
|
+
return this.buildLoadedCache(key, data);
|
|
7525
|
+
} catch (e18) {
|
|
7526
|
+
}
|
|
7527
|
+
}
|
|
7528
|
+
return this.buildLoadedCache(key, null);
|
|
7529
|
+
}
|
|
7530
|
+
/**
|
|
7531
|
+
* 刷新指定 key 的缓存(统一由 flushAllCache 写入,此方法仅用于外部兼容调用)
|
|
7532
|
+
*/
|
|
7533
|
+
async flushCache(key) {
|
|
7534
|
+
if (!this.fileCompiler.getIsCache()) return;
|
|
7535
|
+
if (!this.pendingUpdates.has(key)) return;
|
|
7299
7536
|
const updates = this.pendingUpdates.get(key);
|
|
7300
|
-
if (updates.length
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7537
|
+
if (!updates.length) return;
|
|
7538
|
+
if (!this.cachedData) {
|
|
7539
|
+
const filePath = this.fileCompiler.getCachePath();
|
|
7540
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
7541
|
+
try {
|
|
7542
|
+
const content = await _fs2.default.promises.readFile(filePath, "utf-8");
|
|
7543
|
+
this.cachedData = JSON.parse(content);
|
|
7544
|
+
} catch (e19) {
|
|
7545
|
+
}
|
|
7546
|
+
}
|
|
7304
7547
|
}
|
|
7305
|
-
|
|
7548
|
+
const activeFiles = new Set(updates.map((u) => u.unit.file));
|
|
7549
|
+
let entries = (this.cachedData || this.getEmptyList())[key] || [];
|
|
7550
|
+
entries = entries.filter((c) => activeFiles.has(c.file));
|
|
7551
|
+
updates.forEach(({ unit, meta }) => {
|
|
7552
|
+
const idx = entries.findIndex((c) => c.file === unit.file);
|
|
7553
|
+
if (idx > -1) {
|
|
7554
|
+
entries[idx] = meta;
|
|
7555
|
+
} else {
|
|
7556
|
+
entries.push(meta);
|
|
7557
|
+
}
|
|
7558
|
+
});
|
|
7559
|
+
(this.cachedData || this.getEmptyList())[key] = entries;
|
|
7306
7560
|
this.pendingUpdates.set(key, []);
|
|
7561
|
+
await this.saveCache(this.buildLoadedCache(key, this.cachedData));
|
|
7562
|
+
}
|
|
7563
|
+
getEmptyList() {
|
|
7564
|
+
return {
|
|
7565
|
+
["sfc" /* SFC */]: [],
|
|
7566
|
+
["script" /* SCRIPT */]: [],
|
|
7567
|
+
["style" /* STYLE */]: [],
|
|
7568
|
+
["copied" /* ASSET */]: []
|
|
7569
|
+
};
|
|
7307
7570
|
}
|
|
7308
7571
|
/**
|
|
7309
|
-
*
|
|
7572
|
+
* 保存缓存数据到文件(watch 等场景使用)
|
|
7310
7573
|
*/
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
if (
|
|
7314
|
-
|
|
7315
|
-
}
|
|
7316
|
-
|
|
7317
|
-
|
|
7574
|
+
async saveCache(data) {
|
|
7575
|
+
if (!this.fileCompiler.getIsCache() || !data) return;
|
|
7576
|
+
if (this.cachedData) {
|
|
7577
|
+
this.cachedData[data.key] = data.target;
|
|
7578
|
+
}
|
|
7579
|
+
await fileLock.updateFile(this.fileCompiler.getCachePath(), (currentData) => {
|
|
7580
|
+
const merged = currentData || this.getEmptyList();
|
|
7581
|
+
merged[data.key] = data.target;
|
|
7582
|
+
return merged;
|
|
7583
|
+
});
|
|
7584
|
+
}
|
|
7585
|
+
buildLoadedCache(key, raw) {
|
|
7586
|
+
const emptySource = {
|
|
7587
|
+
["sfc" /* SFC */]: [],
|
|
7588
|
+
["script" /* SCRIPT */]: [],
|
|
7589
|
+
["style" /* STYLE */]: [],
|
|
7590
|
+
["copied" /* ASSET */]: []
|
|
7591
|
+
};
|
|
7592
|
+
const source = raw || emptySource;
|
|
7593
|
+
return {
|
|
7594
|
+
key,
|
|
7595
|
+
target: source[key] || [],
|
|
7596
|
+
source
|
|
7597
|
+
};
|
|
7318
7598
|
}
|
|
7319
7599
|
}, _class9);
|
|
7320
7600
|
|
|
7321
7601
|
// src/compiler/shared/file-compiler/cleanup-manager.ts
|
|
7322
7602
|
|
|
7323
7603
|
var CleanupManager = class {
|
|
7324
|
-
constructor(fileCompiler) {
|
|
7604
|
+
constructor(fileCompiler, cacheManager) {
|
|
7325
7605
|
this.fileCompiler = fileCompiler;
|
|
7606
|
+
this.cacheManager = cacheManager;
|
|
7326
7607
|
}
|
|
7327
7608
|
/**
|
|
7328
|
-
*
|
|
7609
|
+
* 删除指定路径对应的构建产物和缓存
|
|
7329
7610
|
*/
|
|
7330
7611
|
async removeOutputPath(targetPath, type) {
|
|
7331
7612
|
const absPath = this.fileCompiler.getAbsPath(targetPath);
|
|
7332
|
-
await this.
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
u.file.startsWith(absPath + _path2.default.sep)
|
|
7338
|
-
);
|
|
7613
|
+
const cache = await this.cacheManager.loadCache(type);
|
|
7614
|
+
await this.removeMatchedFromCache(type, cache, (m) => {
|
|
7615
|
+
return m.file === absPath || m.file.startsWith(absPath + _path2.default.sep);
|
|
7616
|
+
});
|
|
7617
|
+
await this.cacheManager.saveCache(cache);
|
|
7339
7618
|
}
|
|
7340
7619
|
/**
|
|
7341
|
-
*
|
|
7620
|
+
* 删除匹配的输出文件,并从内存缓存中移除对应条目(不写磁盘)
|
|
7342
7621
|
*/
|
|
7343
|
-
async
|
|
7344
|
-
const cache = await this.fileCompiler.loadCache(key);
|
|
7622
|
+
async removeMatchedFromCache(key, cache, filter) {
|
|
7345
7623
|
if (!cache.target.length) return;
|
|
7346
7624
|
const toRemove = cache.target.filter(filter);
|
|
7347
7625
|
if (!toRemove.length) return;
|
|
7348
|
-
|
|
7349
|
-
let meta;
|
|
7350
|
-
switch (key) {
|
|
7351
|
-
case "sfc" /* SFC */: {
|
|
7352
|
-
meta = m;
|
|
7353
|
-
const { jsx, css } = meta.output;
|
|
7354
|
-
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
7355
|
-
if (_optionalChain([css, 'optionalAccess', _263 => _263.file])) {
|
|
7356
|
-
await this.fileCompiler.removeOutputFile(css.file);
|
|
7357
|
-
}
|
|
7358
|
-
break;
|
|
7359
|
-
}
|
|
7360
|
-
case "script" /* SCRIPT */: {
|
|
7361
|
-
meta = m;
|
|
7362
|
-
await this.fileCompiler.removeOutputFile(meta.output.script.file);
|
|
7363
|
-
break;
|
|
7364
|
-
}
|
|
7365
|
-
case "style" /* STYLE */: {
|
|
7366
|
-
meta = m;
|
|
7367
|
-
await this.fileCompiler.removeOutputFile(meta.output.style.file);
|
|
7368
|
-
break;
|
|
7369
|
-
}
|
|
7370
|
-
// 静态资产缓存直接删除对应文件
|
|
7371
|
-
default: {
|
|
7372
|
-
await this.fileCompiler.removeOutputFile(m.file, true);
|
|
7373
|
-
break;
|
|
7374
|
-
}
|
|
7375
|
-
}
|
|
7376
|
-
};
|
|
7377
|
-
await Promise.all(toRemove.map(removeFn));
|
|
7626
|
+
await Promise.all(toRemove.map((m) => this.removeCacheMeta(key, m)));
|
|
7378
7627
|
const removedFiles = new Set(toRemove.map((m) => m.file));
|
|
7379
7628
|
cache.target = cache.target.filter((m) => !removedFiles.has(m.file));
|
|
7380
|
-
|
|
7629
|
+
}
|
|
7630
|
+
/**
|
|
7631
|
+
* 删除单个缓存元数据对应的输出文件(不操作缓存)
|
|
7632
|
+
*/
|
|
7633
|
+
async removeCacheMeta(key, meta) {
|
|
7634
|
+
switch (key) {
|
|
7635
|
+
case "sfc" /* SFC */: {
|
|
7636
|
+
const sfcMeta = meta;
|
|
7637
|
+
const { jsx, css } = sfcMeta.output;
|
|
7638
|
+
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
7639
|
+
if (_optionalChain([css, 'optionalAccess', _282 => _282.file])) {
|
|
7640
|
+
await this.fileCompiler.removeOutputFile(css.file);
|
|
7641
|
+
}
|
|
7642
|
+
break;
|
|
7643
|
+
}
|
|
7644
|
+
case "script" /* SCRIPT */: {
|
|
7645
|
+
const scriptMeta = meta;
|
|
7646
|
+
await this.fileCompiler.removeOutputFile(scriptMeta.output.script.file);
|
|
7647
|
+
break;
|
|
7648
|
+
}
|
|
7649
|
+
case "style" /* STYLE */: {
|
|
7650
|
+
const styleMeta = meta;
|
|
7651
|
+
await this.fileCompiler.removeOutputFile(styleMeta.output.style.file);
|
|
7652
|
+
break;
|
|
7653
|
+
}
|
|
7654
|
+
// 静态资产缓存直接删除对应文件
|
|
7655
|
+
default: {
|
|
7656
|
+
await this.fileCompiler.removeOutputFile(meta.file, true);
|
|
7657
|
+
break;
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7381
7660
|
}
|
|
7382
7661
|
};
|
|
7383
7662
|
|
|
@@ -7413,7 +7692,7 @@ var CompilationUnitProcessor = class {
|
|
|
7413
7692
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
7414
7693
|
const isStyleFile = key === "style" /* STYLE */;
|
|
7415
7694
|
if (isSFC || isScriptFile) {
|
|
7416
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
7695
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _283 => _283.hasRoute]);
|
|
7417
7696
|
}
|
|
7418
7697
|
const resolveFileInfo = () => {
|
|
7419
7698
|
if (isSFC) {
|
|
@@ -7433,7 +7712,7 @@ var CompilationUnitProcessor = class {
|
|
|
7433
7712
|
const { script } = result.fileInfo;
|
|
7434
7713
|
unit.output = {
|
|
7435
7714
|
script: {
|
|
7436
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
7715
|
+
file: _optionalChain([script, 'optionalAccess', _284 => _284.file]),
|
|
7437
7716
|
code
|
|
7438
7717
|
}
|
|
7439
7718
|
};
|
|
@@ -7482,12 +7761,12 @@ var CompilationUnitProcessor = class {
|
|
|
7482
7761
|
|
|
7483
7762
|
|
|
7484
7763
|
var FileProcessor = (_class10 = class {
|
|
7485
|
-
constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class10.prototype.
|
|
7764
|
+
constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class10.prototype.__init16.call(this);
|
|
7486
7765
|
this.fileCompiler = fileCompiler;
|
|
7487
7766
|
this.compilationUnitProcessor = compilationUnitProcessor;
|
|
7488
7767
|
this.cacheManager = cacheManager;
|
|
7489
7768
|
}
|
|
7490
|
-
|
|
7769
|
+
__init16() {this.skippedCount = 0}
|
|
7491
7770
|
/**
|
|
7492
7771
|
* Process a single Vue file (this method is called directly in CLI Watch mode)
|
|
7493
7772
|
*/
|
|
@@ -7509,8 +7788,8 @@ var FileProcessor = (_class10 = class {
|
|
|
7509
7788
|
async processFile(key, filePath, existingCache) {
|
|
7510
7789
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
7511
7790
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
7512
|
-
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.
|
|
7513
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
7791
|
+
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.cacheManager.loadCache(key);
|
|
7792
|
+
const record = _optionalChain([cache, 'optionalAccess', _285 => _285.target, 'access', _286 => _286.find, 'call', _287 => _287((c) => c.file === absPath)]);
|
|
7514
7793
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
7515
7794
|
fileMeta,
|
|
7516
7795
|
record,
|
|
@@ -7532,10 +7811,10 @@ var FileProcessor = (_class10 = class {
|
|
|
7532
7811
|
hash: hash || this.fileCompiler.genHash(source)
|
|
7533
7812
|
};
|
|
7534
7813
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
7535
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
7814
|
+
if (_optionalChain([processed, 'optionalAccess', _288 => _288.output])) {
|
|
7536
7815
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
7537
7816
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
7538
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
7817
|
+
if (_optionalChain([processed, 'optionalAccess', _289 => _289.hasRoute])) {
|
|
7539
7818
|
await this.addRouterToPackageJson();
|
|
7540
7819
|
await this.updateEntryWithRouterProvider();
|
|
7541
7820
|
}
|
|
@@ -7549,13 +7828,13 @@ var FileProcessor = (_class10 = class {
|
|
|
7549
7828
|
*/
|
|
7550
7829
|
async addRouterToPackageJson() {
|
|
7551
7830
|
const { output } = this.fileCompiler.options;
|
|
7552
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7831
|
+
if (_optionalChain([output, 'optionalAccess', _290 => _290.bootstrapVite]) === false) {
|
|
7553
7832
|
return;
|
|
7554
7833
|
}
|
|
7555
7834
|
const { router } = RUNTIME_PACKAGES;
|
|
7556
7835
|
const filePath = this.fileCompiler.getOutputPkgPath();
|
|
7557
7836
|
const packageJson = await this.fileCompiler.resolvePackageFile(filePath);
|
|
7558
|
-
if (_optionalChain([packageJson, 'optionalAccess',
|
|
7837
|
+
if (_optionalChain([packageJson, 'optionalAccess', _291 => _291.dependencies, 'optionalAccess', _292 => _292[router.name]])) {
|
|
7559
7838
|
return;
|
|
7560
7839
|
}
|
|
7561
7840
|
if (!packageJson.dependencies) {
|
|
@@ -7574,14 +7853,14 @@ var FileProcessor = (_class10 = class {
|
|
|
7574
7853
|
const { exclude, output, router } = this.fileCompiler.options;
|
|
7575
7854
|
const inputPath = this.fileCompiler.getInputPath();
|
|
7576
7855
|
const outputPath = this.fileCompiler.getOuputPath(true);
|
|
7577
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7856
|
+
if (_optionalChain([output, 'optionalAccess', _293 => _293.bootstrapVite]) === false || _optionalChain([router, 'optionalAccess', _294 => _294.autoUpdateEntry]) === false || !_optionalChain([router, 'optionalAccess', _295 => _295.configFile])) {
|
|
7578
7857
|
return;
|
|
7579
7858
|
}
|
|
7580
7859
|
const getMainFile = async (filename) => {
|
|
7581
7860
|
const filePath = _path2.default.resolve(outputPath, filename);
|
|
7582
7861
|
try {
|
|
7583
7862
|
return { filePath, content: await _fs2.default.promises.readFile(filePath, "utf-8") };
|
|
7584
|
-
} catch (
|
|
7863
|
+
} catch (e20) {
|
|
7585
7864
|
return;
|
|
7586
7865
|
}
|
|
7587
7866
|
};
|
|
@@ -7595,7 +7874,7 @@ var FileProcessor = (_class10 = class {
|
|
|
7595
7874
|
const prepareRouterEntry = () => {
|
|
7596
7875
|
const importPath = this.fileCompiler.resolveRelativePath(inputPath, router.configFile);
|
|
7597
7876
|
let content = fileData.content;
|
|
7598
|
-
if (_optionalChain([exclude, 'optionalAccess',
|
|
7877
|
+
if (_optionalChain([exclude, 'optionalAccess', _296 => _296.includes, 'call', _297 => _297(router.configFile)]) || _optionalChain([exclude, 'optionalAccess', _298 => _298.includes, 'call', _299 => _299(importPath)])) {
|
|
7599
7878
|
return content;
|
|
7600
7879
|
}
|
|
7601
7880
|
const routerModule = "RouterInstance";
|
|
@@ -7634,64 +7913,160 @@ ${routerImport}`);
|
|
|
7634
7913
|
resetSkippedCount() {
|
|
7635
7914
|
this.skippedCount = 0;
|
|
7636
7915
|
}
|
|
7916
|
+
/**
|
|
7917
|
+
* 扫描项目中的编译文件和资产文件
|
|
7918
|
+
* @param recursive 是否递归扫描子目录
|
|
7919
|
+
* @param ignoreAssets 需要忽略的资产文件列表
|
|
7920
|
+
*/
|
|
7921
|
+
scanFiles() {
|
|
7922
|
+
const { fileCompiler } = this;
|
|
7923
|
+
const rootPath = fileCompiler.getProjectRoot();
|
|
7924
|
+
const inputPath = fileCompiler.getInputPath();
|
|
7925
|
+
const scriptExt = /\.(js|ts|jsx|tsx)$/i;
|
|
7926
|
+
const styleExt = /\.(css|less|sass|scss)$/i;
|
|
7927
|
+
const result = {
|
|
7928
|
+
assets: [],
|
|
7929
|
+
script: [],
|
|
7930
|
+
style: [],
|
|
7931
|
+
vue: []
|
|
7932
|
+
};
|
|
7933
|
+
const getInputStat = (path8) => {
|
|
7934
|
+
if (!_fs2.default.existsSync(path8)) return;
|
|
7935
|
+
return _fs2.default.statSync(path8);
|
|
7936
|
+
};
|
|
7937
|
+
const resolveDirectory = (file, walk, fallback) => {
|
|
7938
|
+
const directory = _fs2.default.readdirSync(file);
|
|
7939
|
+
directory.forEach((p) => {
|
|
7940
|
+
const fullPath = _path2.default.resolve(file, p);
|
|
7941
|
+
if (fileCompiler.shouldSkipPath(fullPath)) {
|
|
7942
|
+
return;
|
|
7943
|
+
}
|
|
7944
|
+
const stat = _fs2.default.statSync(fullPath);
|
|
7945
|
+
if (stat.isDirectory() && fileCompiler.options.recursive !== false) {
|
|
7946
|
+
walk(fullPath);
|
|
7947
|
+
return;
|
|
7948
|
+
}
|
|
7949
|
+
fallback(fullPath);
|
|
7950
|
+
});
|
|
7951
|
+
};
|
|
7952
|
+
const scanCompilationFiles = (file, res) => {
|
|
7953
|
+
const stat = getInputStat(file);
|
|
7954
|
+
if (!stat) return;
|
|
7955
|
+
const classifyFile = (filePath) => {
|
|
7956
|
+
const fileExt = _path2.default.extname(filePath);
|
|
7957
|
+
if (fileExt === ".vue") {
|
|
7958
|
+
res.vue.push(filePath);
|
|
7959
|
+
return;
|
|
7960
|
+
}
|
|
7961
|
+
if (scriptExt.test(fileExt)) {
|
|
7962
|
+
res.script.push(filePath);
|
|
7963
|
+
return;
|
|
7964
|
+
}
|
|
7965
|
+
if (styleExt.test(fileExt)) {
|
|
7966
|
+
res.style.push(filePath);
|
|
7967
|
+
}
|
|
7968
|
+
};
|
|
7969
|
+
if (stat.isFile()) {
|
|
7970
|
+
classifyFile(file);
|
|
7971
|
+
return;
|
|
7972
|
+
}
|
|
7973
|
+
resolveDirectory(
|
|
7974
|
+
file,
|
|
7975
|
+
(path8) => scanCompilationFiles(path8, res),
|
|
7976
|
+
(path8) => classifyFile(path8)
|
|
7977
|
+
);
|
|
7978
|
+
};
|
|
7979
|
+
const isAssetFile = (input) => {
|
|
7980
|
+
const fileExt = _path2.default.extname(input).toLowerCase();
|
|
7981
|
+
const resolvedPath = normalizePath(fileCompiler.relativePath(input));
|
|
7982
|
+
const baseName = _path2.default.basename(input).toLowerCase();
|
|
7983
|
+
const exclusions = fileCompiler.getIgnoreAssets();
|
|
7984
|
+
if (!_optionalChain([fileCompiler, 'access', _300 => _300.options, 'access', _301 => _301.output, 'optionalAccess', _302 => _302.ignoreAssets])) {
|
|
7985
|
+
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
7986
|
+
if (pattern.endsWith(".")) {
|
|
7987
|
+
return baseName.startsWith(pattern);
|
|
7988
|
+
}
|
|
7989
|
+
if (pattern.startsWith(".")) {
|
|
7990
|
+
return fileExt === pattern;
|
|
7991
|
+
}
|
|
7992
|
+
return resolvedPath === pattern || baseName === pattern;
|
|
7993
|
+
});
|
|
7994
|
+
if (shouldExclude) return false;
|
|
7995
|
+
} else {
|
|
7996
|
+
if (exclusions.has(resolvedPath) || exclusions.has(baseName) || fileExt === ".vue") {
|
|
7997
|
+
return false;
|
|
7998
|
+
}
|
|
7999
|
+
}
|
|
8000
|
+
const isInsideSrc = input.startsWith(inputPath + _path2.default.sep);
|
|
8001
|
+
if (isInsideSrc && (scriptExt.test(fileExt) || styleExt.test(fileExt))) {
|
|
8002
|
+
return false;
|
|
8003
|
+
}
|
|
8004
|
+
return true;
|
|
8005
|
+
};
|
|
8006
|
+
const scanAssetFiles = (input, res) => {
|
|
8007
|
+
const stat = getInputStat(input);
|
|
8008
|
+
if (!stat || fileCompiler.shouldSkipPath(input)) {
|
|
8009
|
+
return;
|
|
8010
|
+
}
|
|
8011
|
+
if (stat.isFile()) {
|
|
8012
|
+
if (isAssetFile(input)) {
|
|
8013
|
+
res.assets.push(input);
|
|
8014
|
+
}
|
|
8015
|
+
return;
|
|
8016
|
+
}
|
|
8017
|
+
resolveDirectory(
|
|
8018
|
+
input,
|
|
8019
|
+
(path8) => scanAssetFiles(path8, res),
|
|
8020
|
+
(path8) => {
|
|
8021
|
+
if (isAssetFile(path8)) {
|
|
8022
|
+
res.assets.push(path8);
|
|
8023
|
+
}
|
|
8024
|
+
}
|
|
8025
|
+
);
|
|
8026
|
+
};
|
|
8027
|
+
scanCompilationFiles(inputPath, result);
|
|
8028
|
+
scanAssetFiles(rootPath, result);
|
|
8029
|
+
return result;
|
|
8030
|
+
}
|
|
7637
8031
|
}, _class10);
|
|
7638
8032
|
|
|
7639
8033
|
// src/compiler/shared/file-compiler/pipeline-manager.ts
|
|
7640
|
-
|
|
7641
8034
|
var PipelineManager = (_class11 = class {
|
|
7642
|
-
constructor(fileCompiler, fileProcessor) {;_class11.prototype.
|
|
8035
|
+
constructor(fileCompiler, fileProcessor, cleanupManager) {;_class11.prototype.__init17.call(this);
|
|
7643
8036
|
this.fileCompiler = fileCompiler;
|
|
7644
8037
|
this.fileProcessor = fileProcessor;
|
|
7645
|
-
this.cleanupManager =
|
|
8038
|
+
this.cleanupManager = cleanupManager;
|
|
7646
8039
|
}
|
|
7647
|
-
|
|
7648
|
-
|
|
8040
|
+
__init17() {this.skippedCount = 0}
|
|
7649
8041
|
/**
|
|
7650
8042
|
* 运行 SFC 编译管线
|
|
7651
8043
|
*/
|
|
7652
|
-
async
|
|
7653
|
-
return this.
|
|
8044
|
+
async runSFC(files, cacheMap) {
|
|
8045
|
+
return this.runCore(files, "sfc" /* SFC */, cacheMap);
|
|
7654
8046
|
}
|
|
7655
8047
|
/**
|
|
7656
8048
|
* 运行 Script 编译管线
|
|
7657
8049
|
*/
|
|
7658
|
-
async
|
|
7659
|
-
return this.
|
|
8050
|
+
async runScript(files, cacheMap) {
|
|
8051
|
+
return this.runCore(files, "script" /* SCRIPT */, cacheMap);
|
|
7660
8052
|
}
|
|
7661
8053
|
/**
|
|
7662
8054
|
* 运行 Style 编译管线
|
|
7663
8055
|
*/
|
|
7664
|
-
async
|
|
7665
|
-
return this.
|
|
8056
|
+
async runStyle(files, cacheMap) {
|
|
8057
|
+
return this.runCore(files, "style" /* STYLE */, cacheMap);
|
|
7666
8058
|
}
|
|
7667
8059
|
/**
|
|
7668
8060
|
* 核心编译管线
|
|
7669
8061
|
*/
|
|
7670
|
-
async
|
|
7671
|
-
const
|
|
7672
|
-
const
|
|
7673
|
-
|
|
7674
|
-
const files = this.fileCompiler.scanFiles(inputPath, (p) => {
|
|
7675
|
-
const ext = _path2.default.extname(p);
|
|
7676
|
-
if (key === "sfc" /* SFC */) {
|
|
7677
|
-
return ext === ".vue";
|
|
7678
|
-
}
|
|
7679
|
-
if (key === "script" /* SCRIPT */) {
|
|
7680
|
-
return scriptExtRegex.test(ext);
|
|
7681
|
-
}
|
|
7682
|
-
if (key === "style" /* STYLE */) {
|
|
7683
|
-
return styleExtRegex.test(ext);
|
|
7684
|
-
}
|
|
7685
|
-
return false;
|
|
7686
|
-
});
|
|
7687
|
-
const absFiles = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
|
|
7688
|
-
await this.cleanupManager.cleanupOldOutput(key, (c) => !absFiles.has(c.file));
|
|
8062
|
+
async runCore(files, key, cacheMap) {
|
|
8063
|
+
const absPaths = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
|
|
8064
|
+
const cache = cacheMap[key];
|
|
8065
|
+
await this.cleanupManager.removeMatchedFromCache(key, cache, (c) => !absPaths.has(c.file));
|
|
7689
8066
|
if (!files.length) return 0;
|
|
7690
|
-
const cache = await this.fileCompiler.loadCache(key);
|
|
7691
8067
|
const compiled = await Promise.all(
|
|
7692
|
-
files.map(
|
|
8068
|
+
files.map((f) => this.fileProcessor.processFile(key, f, cache))
|
|
7693
8069
|
);
|
|
7694
|
-
await this.fileCompiler.flushCache(key);
|
|
7695
8070
|
return compiled.filter(Boolean).length;
|
|
7696
8071
|
}
|
|
7697
8072
|
/**
|
|
@@ -7714,12 +8089,12 @@ var _child_process = require('child_process');
|
|
|
7714
8089
|
|
|
7715
8090
|
|
|
7716
8091
|
var ViteBootstrapper = (_class12 = class {
|
|
7717
|
-
constructor(fileCompiler, options) {;_class12.prototype.
|
|
8092
|
+
constructor(fileCompiler, options) {;_class12.prototype.__init18.call(this);_class12.prototype.__init19.call(this);
|
|
7718
8093
|
this.fileCompiler = fileCompiler;
|
|
7719
8094
|
this.options = options;
|
|
7720
8095
|
}
|
|
7721
|
-
|
|
7722
|
-
|
|
8096
|
+
__init18() {this.spinner = _ora2.default.call(void 0, )}
|
|
8097
|
+
__init19() {this.defaultConfig = {
|
|
7723
8098
|
template: "react-ts",
|
|
7724
8099
|
viteVersion: "@latest"
|
|
7725
8100
|
}}
|
|
@@ -7741,29 +8116,19 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7741
8116
|
const { output } = this.options;
|
|
7742
8117
|
const workspaceDir = this.fileCompiler.getWorkspaceDir();
|
|
7743
8118
|
await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
|
|
7744
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
8119
|
+
if (_optionalChain([output, 'optionalAccess', _303 => _303.bootstrapVite]) === false) {
|
|
7745
8120
|
return false;
|
|
7746
8121
|
}
|
|
7747
8122
|
if (this.isSingleFile()) {
|
|
7748
|
-
console.info("
|
|
8123
|
+
console.info(_kleur2.default.dim("Skip Vite init for single file"));
|
|
8124
|
+
console.info();
|
|
7749
8125
|
return;
|
|
7750
8126
|
}
|
|
7751
8127
|
const outputPkgPath = this.fileCompiler.getOutputPkgPath();
|
|
7752
8128
|
if (_fs2.default.existsSync(outputPkgPath)) {
|
|
7753
8129
|
return;
|
|
7754
8130
|
}
|
|
7755
|
-
|
|
7756
|
-
this.spinner.start("Bootstrapping Vite React environment...");
|
|
7757
|
-
await this.resolveViteCreateApp();
|
|
7758
|
-
} catch (err) {
|
|
7759
|
-
console.error(
|
|
7760
|
-
_kleur2.default.red("\u2716"),
|
|
7761
|
-
"Failed to bootstrap Vite environment. Please check npm/network.\n",
|
|
7762
|
-
err
|
|
7763
|
-
);
|
|
7764
|
-
this.spinner.stop();
|
|
7765
|
-
return;
|
|
7766
|
-
}
|
|
8131
|
+
await this.resolveViteCreateApp();
|
|
7767
8132
|
const removeVuePackages = (deps) => {
|
|
7768
8133
|
for (const name in deps) {
|
|
7769
8134
|
const isVueLike = VUE_PACKAGES.some((n) => name.includes(n));
|
|
@@ -7791,9 +8156,9 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7791
8156
|
const newDevDeps = resolveDeps(sourcePkg.devDependencies, newPkg.devDependencies, true);
|
|
7792
8157
|
newPkg.dependencies = newDeps;
|
|
7793
8158
|
newPkg.devDependencies = newDevDeps;
|
|
7794
|
-
newPkg = _optionalChain([output, 'optionalAccess',
|
|
8159
|
+
newPkg = _optionalChain([output, 'optionalAccess', _304 => _304.packageJson, 'optionalCall', _305 => _305(newPkg)]) || newPkg;
|
|
7795
8160
|
await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
|
|
7796
|
-
this.spinner.succeed("
|
|
8161
|
+
this.spinner.succeed("Initialized Vite React environment");
|
|
7797
8162
|
return true;
|
|
7798
8163
|
}
|
|
7799
8164
|
/**
|
|
@@ -7802,12 +8167,12 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7802
8167
|
async resolveViteCreateApp() {
|
|
7803
8168
|
const { output } = this.options;
|
|
7804
8169
|
const { viteVersion, template: tmpl } = this.defaultConfig;
|
|
7805
|
-
const bootstrapVite = _optionalChain([output, 'optionalAccess',
|
|
8170
|
+
const bootstrapVite = _optionalChain([output, 'optionalAccess', _306 => _306.bootstrapVite]);
|
|
7806
8171
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
7807
8172
|
const configObject = typeof bootstrapVite === "object" ? bootstrapVite : null;
|
|
7808
|
-
const viteVer = _optionalChain([configObject, 'optionalAccess',
|
|
7809
|
-
const reactVer = _optionalChain([configObject, 'optionalAccess',
|
|
7810
|
-
const template = _optionalChain([configObject, 'optionalAccess',
|
|
8173
|
+
const viteVer = _optionalChain([configObject, 'optionalAccess', _307 => _307.vite]) || viteVersion;
|
|
8174
|
+
const reactVer = _optionalChain([configObject, 'optionalAccess', _308 => _308.react]);
|
|
8175
|
+
const template = _optionalChain([configObject, 'optionalAccess', _309 => _309.template]) || tmpl;
|
|
7811
8176
|
const cmd = `npm create vite${viteVer} ${outDirName} -- --template ${template}`;
|
|
7812
8177
|
_child_process.execSync.call(void 0, cmd, {
|
|
7813
8178
|
cwd: this.fileCompiler.getWorkspaceDir(),
|
|
@@ -7863,13 +8228,13 @@ var SetupManager = class {
|
|
|
7863
8228
|
fileCompiler.manager = {};
|
|
7864
8229
|
const manager = fileCompiler.manager;
|
|
7865
8230
|
manager.cacheManager = new CacheManager(fileCompiler);
|
|
7866
|
-
manager.cleanupManager = new CleanupManager(fileCompiler);
|
|
7867
8231
|
}
|
|
7868
8232
|
/**
|
|
7869
8233
|
* 创建依赖基础管理器的管理器
|
|
7870
8234
|
*/
|
|
7871
8235
|
setupManagedByBase(fileCompiler) {
|
|
7872
8236
|
const manager = fileCompiler.manager;
|
|
8237
|
+
manager.cleanupManager = new CleanupManager(fileCompiler, manager.cacheManager);
|
|
7873
8238
|
manager.fileProcessor = new FileProcessor(
|
|
7874
8239
|
fileCompiler,
|
|
7875
8240
|
new CompilationUnitProcessor(fileCompiler),
|
|
@@ -7882,47 +8247,78 @@ var SetupManager = class {
|
|
|
7882
8247
|
setupCompositeManager(fileCompiler) {
|
|
7883
8248
|
const manager = fileCompiler.manager;
|
|
7884
8249
|
manager.viteBootstrapper = new ViteBootstrapper(fileCompiler, fileCompiler.options);
|
|
7885
|
-
manager.pipelineManager = new PipelineManager(
|
|
7886
|
-
|
|
8250
|
+
manager.pipelineManager = new PipelineManager(
|
|
8251
|
+
fileCompiler,
|
|
8252
|
+
manager.fileProcessor,
|
|
8253
|
+
manager.cleanupManager
|
|
8254
|
+
);
|
|
8255
|
+
manager.assetManager = new AssetManager(
|
|
8256
|
+
fileCompiler,
|
|
8257
|
+
manager.cleanupManager,
|
|
8258
|
+
manager.cacheManager
|
|
8259
|
+
);
|
|
7887
8260
|
}
|
|
7888
8261
|
};
|
|
7889
8262
|
|
|
7890
8263
|
// src/compiler/shared/file-compiler/index.ts
|
|
7891
8264
|
var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
7892
8265
|
|
|
7893
|
-
|
|
8266
|
+
__init20() {this.spinner = _ora2.default.call(void 0, )}
|
|
7894
8267
|
constructor(options = {}) {
|
|
7895
|
-
super(options);_class13.prototype.
|
|
8268
|
+
super(options);_class13.prototype.__init20.call(this);;
|
|
7896
8269
|
new SetupManager(() => this);
|
|
7897
8270
|
}
|
|
8271
|
+
printTitle() {
|
|
8272
|
+
const purple = "\x1B[38;2;153;50;204m";
|
|
8273
|
+
const reset = "\x1B[0m";
|
|
8274
|
+
console.info();
|
|
8275
|
+
console.info();
|
|
8276
|
+
console.info(`${purple}${_kleur2.default.bold("VUREACT")} v${this.version}${reset}`);
|
|
8277
|
+
console.info();
|
|
8278
|
+
}
|
|
8279
|
+
updateSpinner(text) {
|
|
8280
|
+
this.spinner.stop();
|
|
8281
|
+
this.spinner.start(text);
|
|
8282
|
+
}
|
|
7898
8283
|
/** 执行完整的编译流程 */
|
|
7899
8284
|
async execute() {
|
|
7900
|
-
|
|
7901
|
-
const startTime = performance.now();
|
|
7902
|
-
const rmWorkspace = async () => {
|
|
7903
|
-
await this.rmFile(this.getWorkspaceDir());
|
|
7904
|
-
};
|
|
8285
|
+
this.printTitle();
|
|
7905
8286
|
try {
|
|
7906
8287
|
if (!this.getIsCache()) {
|
|
7907
|
-
await
|
|
8288
|
+
await this.rmFile(this.getCachePath());
|
|
7908
8289
|
}
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
8290
|
+
} catch (err) {
|
|
8291
|
+
console.warn(_kleur2.default.yellow("\u26A0"), "Failed to clear cache");
|
|
8292
|
+
console.info();
|
|
8293
|
+
}
|
|
8294
|
+
const { viteBootstrapper, fileProcessor, cacheManager, pipelineManager, assetManager } = this.manager;
|
|
8295
|
+
let startTime = 0;
|
|
8296
|
+
try {
|
|
8297
|
+
this.updateSpinner("Initializing Vite React env...");
|
|
8298
|
+
await viteBootstrapper.bootstrapIfNeeded();
|
|
8299
|
+
const cacheMap = await cacheManager.loadAllCache();
|
|
8300
|
+
startTime = performance.now();
|
|
8301
|
+
this.updateSpinner("Scanning files...");
|
|
8302
|
+
const scanFiles = fileProcessor.scanFiles();
|
|
8303
|
+
this.updateSpinner("Compiling Vue to React...");
|
|
8304
|
+
const sfcCount = await pipelineManager.runSFC(scanFiles.vue, cacheMap);
|
|
8305
|
+
const scriptCount = await pipelineManager.runScript(scanFiles.script, cacheMap);
|
|
8306
|
+
const styleCount = await pipelineManager.runStyle(scanFiles.style, cacheMap);
|
|
8307
|
+
this.updateSpinner("Copying assets...");
|
|
8308
|
+
const assetCount = await assetManager.runAsset(scanFiles.assets, cacheMap);
|
|
8309
|
+
this.updateSpinner("Almost done...");
|
|
8310
|
+
await cacheManager.flushAllCache();
|
|
8311
|
+
await _optionalChain([this, 'access', _310 => _310.options, 'access', _311 => _311.onSuccess, 'optionalCall', _312 => _312()]);
|
|
7915
8312
|
const endTime = calcElapsedTime(startTime);
|
|
7916
8313
|
this.printCoreLogs();
|
|
7917
8314
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|
|
7918
8315
|
} catch (error) {
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}`);
|
|
8316
|
+
this.spinner.stop();
|
|
8317
|
+
console.error(_kleur2.default.red("\u2716"), `Build failed in ${calcElapsedTime(startTime)}`);
|
|
7922
8318
|
console.error(error);
|
|
8319
|
+
await this.rmFile(this.getWorkspaceDir());
|
|
7923
8320
|
process.exit(-1);
|
|
7924
8321
|
} finally {
|
|
7925
|
-
this.spinner.stop();
|
|
7926
8322
|
this.resetSkippedCount();
|
|
7927
8323
|
}
|
|
7928
8324
|
}
|
|
@@ -7959,62 +8355,40 @@ var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
|
7959
8355
|
async processAsset(filePath, existingCache) {
|
|
7960
8356
|
return this.manager.assetManager.processAsset(filePath, existingCache);
|
|
7961
8357
|
}
|
|
7962
|
-
/** 批量保存缓存 */
|
|
7963
|
-
async flushCache(key) {
|
|
7964
|
-
await this.manager.cacheManager.flushCache(key);
|
|
7965
|
-
}
|
|
7966
8358
|
/** 删除指定路径对应的输出文件和缓存 */
|
|
7967
8359
|
async removeOutputPath(targetPath, type) {
|
|
7968
8360
|
return await this.manager.cleanupManager.removeOutputPath(targetPath, type);
|
|
7969
8361
|
}
|
|
7970
|
-
async runPipelineWithSpinner(name) {
|
|
7971
|
-
const options = {
|
|
7972
|
-
["sfc" /* SFC */]: {
|
|
7973
|
-
text: "Compiling Vue files...",
|
|
7974
|
-
pipeline: () => this.manager.pipelineManager.runSfcPipeline()
|
|
7975
|
-
},
|
|
7976
|
-
["script" /* SCRIPT */]: {
|
|
7977
|
-
text: "Compiling script files...",
|
|
7978
|
-
pipeline: () => this.manager.pipelineManager.runScriptPipeline()
|
|
7979
|
-
},
|
|
7980
|
-
["style" /* STYLE */]: {
|
|
7981
|
-
text: "Compiling style files...",
|
|
7982
|
-
pipeline: () => this.manager.pipelineManager.runStylePipeline()
|
|
7983
|
-
},
|
|
7984
|
-
["copied" /* ASSET */]: {
|
|
7985
|
-
text: "Copying assets...",
|
|
7986
|
-
pipeline: () => this.manager.assetManager.runAssetPipeline()
|
|
7987
|
-
}
|
|
7988
|
-
};
|
|
7989
|
-
const { text, pipeline } = options[name];
|
|
7990
|
-
try {
|
|
7991
|
-
this.spinner.start(text);
|
|
7992
|
-
return await pipeline();
|
|
7993
|
-
} catch (err) {
|
|
7994
|
-
throw err;
|
|
7995
|
-
} finally {
|
|
7996
|
-
this.spinner.stop();
|
|
7997
|
-
}
|
|
7998
|
-
}
|
|
7999
8362
|
showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount) {
|
|
8000
8363
|
this.spinner.succeed(`Build completed in ${endTime}`);
|
|
8001
|
-
console.info();
|
|
8002
8364
|
if (sfcCount || scriptCount || styleCount || assetCount) {
|
|
8003
8365
|
const stats = [];
|
|
8004
|
-
if (sfcCount) stats.push(`${sfcCount} SFC(s)`);
|
|
8005
|
-
if (scriptCount) stats.push(`${scriptCount} script(s)`);
|
|
8006
|
-
if (styleCount) stats.push(`${styleCount} style(s)`);
|
|
8007
|
-
if (assetCount) stats.push(`${assetCount} asset(s)`);
|
|
8008
|
-
this.spinner.succeed(
|
|
8366
|
+
if (sfcCount) stats.push(`${sfcCount} ${_kleur2.default.dim("SFC(s)")}`);
|
|
8367
|
+
if (scriptCount) stats.push(`${scriptCount} ${_kleur2.default.dim("script(s)")}`);
|
|
8368
|
+
if (styleCount) stats.push(`${styleCount} ${_kleur2.default.dim("style(s)")}`);
|
|
8369
|
+
if (assetCount) stats.push(`${assetCount} ${_kleur2.default.dim("asset(s)")}`);
|
|
8370
|
+
this.spinner.succeed(`${_kleur2.default.bold("Processed")}: ${stats.join(", ")}`);
|
|
8009
8371
|
}
|
|
8010
8372
|
const skippedCount = this.manager.pipelineManager.getSkippedCount() + this.manager.assetManager.getSkippedCount();
|
|
8011
8373
|
if (skippedCount) {
|
|
8012
|
-
console.info(
|
|
8374
|
+
console.info();
|
|
8375
|
+
console.info(
|
|
8376
|
+
_kleur2.default.gray(`\u21B7 ${_kleur2.default.bold("Cached")}: ${_kleur2.default.white(skippedCount)} unchanged file(s)`)
|
|
8377
|
+
);
|
|
8013
8378
|
this.resetSkippedCount();
|
|
8014
8379
|
}
|
|
8015
8380
|
const dir = normalizePath(this.relativePath(this.getOuputPath()));
|
|
8016
8381
|
console.info();
|
|
8017
|
-
console.info(`\u{1F4E6} Output: ${dir}`);
|
|
8382
|
+
console.info(`\u{1F4E6} ${_kleur2.default.bold("Output")}: ${_kleur2.default.cyan(dir)}`);
|
|
8383
|
+
console.info();
|
|
8384
|
+
console.info(` > cd ${dir}`);
|
|
8385
|
+
console.info(` > npm install`);
|
|
8386
|
+
console.info(` > npm run dev`);
|
|
8387
|
+
console.info();
|
|
8388
|
+
console.info(
|
|
8389
|
+
_kleur2.default.dim("\u2B50 If you like VuReact, give us a star on GitHub:"),
|
|
8390
|
+
_kleur2.default.gray(_kleur2.default.underline("https://github.com/vureact-js/core"))
|
|
8391
|
+
);
|
|
8018
8392
|
console.info();
|
|
8019
8393
|
}
|
|
8020
8394
|
resetSkippedCount() {
|
|
@@ -8051,4 +8425,4 @@ var VuReact = class extends FileCompiler {
|
|
|
8051
8425
|
|
|
8052
8426
|
|
|
8053
8427
|
|
|
8054
|
-
exports.getDirname = getDirname; exports.normalizePath = normalizePath; exports.calcElapsedTime = calcElapsedTime; exports.generateComponent = generateComponent; exports.generateOnlyScript = generateOnlyScript; exports.generate = generate; exports.parseOnlyScript = parseOnlyScript; exports.parseSFC = parseSFC; exports.parse = parse; exports.transform = transform; exports.version = version; exports.bin = bin; exports.
|
|
8428
|
+
exports.getDirname = getDirname; exports.normalizePath = normalizePath; exports.calcElapsedTime = calcElapsedTime; exports.generateComponent = generateComponent; exports.generateOnlyScript = generateOnlyScript; exports.generate = generate; exports.parseOnlyScript = parseOnlyScript; exports.parseSFC = parseSFC; exports.parse = parse; exports.transform = transform; exports.version = version; exports.bin = bin; exports.Helper = Helper; exports.BaseCompiler = BaseCompiler; exports.CacheKey = CacheKey; exports.FileCompiler = FileCompiler; exports.defineConfig = defineConfig; exports.VuReact = VuReact;
|