@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
|
/**
|
|
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
|
*/
|
|
@@ -451,8 +451,8 @@ function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
|
451
451
|
function stringToExpr(input, lang, filename = "") {
|
|
452
452
|
return parseExpression(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) {
|
|
@@ -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
|
}
|
|
@@ -1521,10 +1521,10 @@ import * as t16 from "@babel/types";
|
|
|
1521
1521
|
|
|
1522
1522
|
// src/core/transform/sfc/script/shared/babel-utils.ts
|
|
1523
1523
|
import * as t15 from "@babel/types";
|
|
1524
|
-
function findRootVariablePath(
|
|
1525
|
-
const rootId = findRootIdentifier(
|
|
1524
|
+
function findRootVariablePath(path8) {
|
|
1525
|
+
const rootId = findRootIdentifier(path8.node);
|
|
1526
1526
|
if (!rootId?.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 (!programPath?.isProgram()) {
|
|
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 = tsType.typeParameters?.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
|
import * as t19 from "@babel/types";
|
|
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 = tsType.typeParameters?.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
|
import * as t20 from "@babel/types";
|
|
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 =
|
|
2194
|
+
const parent = path8.parentPath?.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
|
traverse(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
|
import postcss from "postcss";
|
|
2413
|
+
|
|
2414
|
+
// src/plugins/postcss/deep.ts
|
|
2415
|
+
import selectorParser2 from "postcss-selector-parser";
|
|
2416
|
+
|
|
2417
|
+
// src/plugins/postcss/standard.ts
|
|
2418
|
+
import selectorParser from "postcss-selector-parser";
|
|
2419
|
+
|
|
2420
|
+
// src/plugins/postcss/utils.ts
|
|
2421
|
+
function findFirstPseudoIndex(nodes, start, end) {
|
|
2422
|
+
for (let i = start; i <= end; i++) {
|
|
2423
|
+
if (nodes[i]?.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 (node?.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 (nodes[i]?.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 (node?.type === "nesting") {
|
|
2461
|
+
nestingFallback = i;
|
|
2462
|
+
continue;
|
|
2463
|
+
}
|
|
2464
|
+
if (node?.type === "tag" || node?.type === "class" || node?.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" && rule.parent?.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 selectorParser((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 (selector.nodes[i]?.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
|
+
selectorParser.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 = selectorParser2().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 (deepNode?.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 = deepNode.nodes?.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 (node?.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 = selectorParser2().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 && nodes[compoundEnd]?.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 (nodes[i]?.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
|
+
selectorParser2.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, options?.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 = postcss([
|
|
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);
|
|
@@ -2640,25 +2877,25 @@ import { parse as babelParse3 } from "@babel/parser";
|
|
|
2640
2877
|
import { traverse as traverse3 } from "@babel/core";
|
|
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 (!
|
|
2880
|
+
function resolveGlobalTypeChunks(path8, ir) {
|
|
2881
|
+
if (!path8.parentPath?.isProgram()) {
|
|
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
|
import * as t22 from "@babel/types";
|
|
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 = class {
|
|
|
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);
|
|
@@ -2869,12 +3106,12 @@ function resolveRuntimeImports(ctx) {
|
|
|
2869
3106
|
const importNodes = createImportNodes(ctx);
|
|
2870
3107
|
if (importNodes.length) {
|
|
2871
3108
|
if (strategyResult?.shouldInjectRuntimeImports) {
|
|
2872
|
-
|
|
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,14 +3119,14 @@ 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
|
};
|
|
@@ -2990,8 +3227,8 @@ function resolveSfcCssImport(ctx) {
|
|
|
2990
3227
|
import * as t25 from "@babel/types";
|
|
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: callee?.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
|
import * as t36 from "@babel/types";
|
|
@@ -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,8 +3482,8 @@ 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
3488
|
const tsParams = node.typeParameters?.params;
|
|
3250
3489
|
if (tsParams?.length) {
|
|
@@ -3544,8 +3783,8 @@ function resolveTupleElementParam(element, index) {
|
|
|
3544
3783
|
|
|
3545
3784
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
3546
3785
|
import * as t31 from "@babel/types";
|
|
3547
|
-
function resolveDefinePropsIface(
|
|
3548
|
-
const { node } =
|
|
3786
|
+
function resolveDefinePropsIface(path8, ctx) {
|
|
3787
|
+
const { node } = path8;
|
|
3549
3788
|
const [runtimeArg] = node.arguments;
|
|
3550
3789
|
const tsParams = node.typeParameters?.params;
|
|
3551
3790
|
if (tsParams?.length) {
|
|
@@ -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) {
|
|
@@ -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 } =
|
|
4247
|
+
function resolveDefineSlotsIface(path8, ctx) {
|
|
4248
|
+
const { node } = path8;
|
|
4010
4249
|
const tsParams = node.typeParameters?.params;
|
|
4011
4250
|
if (!tsParams?.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
|
import * as t37 from "@babel/types";
|
|
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);
|
|
@@ -4154,20 +4393,249 @@ function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
|
4154
4393
|
}
|
|
4155
4394
|
|
|
4156
4395
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4157
|
-
import * as
|
|
4396
|
+
import * as t43 from "@babel/types";
|
|
4158
4397
|
|
|
4159
|
-
// src/core/transform/sfc/script/shared/dependency-analyzer.ts
|
|
4398
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4160
4399
|
import { traverse as traverse2 } from "@babel/core";
|
|
4400
|
+
import * as t42 from "@babel/types";
|
|
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 !!getScriptNodeMeta(node)?.is_reactive;
|
|
4416
|
+
}
|
|
4417
|
+
|
|
4418
|
+
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
|
|
4161
4419
|
import * as t38 from "@babel/types";
|
|
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 = declaratorPath?.node.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(declaratorPath?.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
|
+
import * as t39 from "@babel/types";
|
|
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
|
|
4488
|
+
import * as t40 from "@babel/types";
|
|
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
|
+
}
|
|
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
|
+
import * as t41 from "@babel/types";
|
|
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
|
-
|
|
4275
|
-
|
|
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);
|
|
4762
|
+
if (path8.isCallExpression()) {
|
|
4763
|
+
const callee = path8.get("callee");
|
|
4764
|
+
if (!callee.isIdentifier()) return false;
|
|
4765
|
+
return isVueImportBinding(callee.scope.getBinding(apiName));
|
|
4284
4766
|
}
|
|
4285
|
-
|
|
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 = declaratorPath?.node.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(declaratorPath?.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 !!getScriptNodeMeta(node)?.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");
|
|
4498
|
-
if (!callee.isIdentifier()) return false;
|
|
4499
|
-
return isVueImportBinding(callee.scope.getBinding(apiName));
|
|
4500
|
-
}
|
|
4501
|
-
return isVueImportBinding(path9.scope.getBinding(apiName));
|
|
4767
|
+
return isVueImportBinding(path8.scope.getBinding(apiName));
|
|
4502
4768
|
}
|
|
4503
4769
|
function isVueImportBinding(binding) {
|
|
4504
4770
|
if (!binding) return false;
|
|
@@ -4507,7 +4773,7 @@ function isVueImportBinding(binding) {
|
|
|
4507
4773
|
return false;
|
|
4508
4774
|
}
|
|
4509
4775
|
const parent = bindingPath.parentPath?.node;
|
|
4510
|
-
if (!parent || !
|
|
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
4802
|
setScriptNodeMeta(declaratorPath?.node, { is_reactive: true, reactive_type: "indirect" });
|
|
4537
|
-
replaceNode(
|
|
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
|
};
|
|
@@ -4575,16 +4841,16 @@ function isSkip(path9) {
|
|
|
4575
4841
|
}
|
|
4576
4842
|
|
|
4577
4843
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-element-ref.ts
|
|
4578
|
-
import * as
|
|
4844
|
+
import * as t44 from "@babel/types";
|
|
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 = getVariableDeclaratorPath(
|
|
4596
|
-
if (!
|
|
4861
|
+
const varDeclaratorPath = getVariableDeclaratorPath(path8)?.node;
|
|
4862
|
+
if (!t44.isIdentifier(varDeclaratorPath?.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 = getVariableDeclaratorPath(
|
|
4884
|
+
const { node } = path8;
|
|
4885
|
+
const varDeclaratorNode = getVariableDeclaratorPath(path8)?.node;
|
|
4620
4886
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
4621
4887
|
return;
|
|
4622
4888
|
}
|
|
@@ -4625,70 +4891,71 @@ 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 (!rootPath?.node || !
|
|
4902
|
+
const rootPath = findRootVariablePath(path8);
|
|
4903
|
+
if (!rootPath?.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 !== rootId?.name) {
|
|
4642
4908
|
return;
|
|
4643
4909
|
}
|
|
4644
4910
|
node.property.name = "current";
|
|
4645
4911
|
}
|
|
4646
4912
|
|
|
4647
4913
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-expression-memo.ts
|
|
4648
|
-
import * as
|
|
4914
|
+
import * as t45 from "@babel/types";
|
|
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
|
}
|
|
4680
4947
|
|
|
4681
4948
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-lint-rules.ts
|
|
4682
|
-
import * as
|
|
4949
|
+
import * as t46 from "@babel/types";
|
|
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
|
);
|
|
@@ -4733,12 +5000,12 @@ function resolveLintRules(ctx, ast) {
|
|
|
4733
5000
|
|
|
4734
5001
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-provide.ts
|
|
4735
5002
|
import { generate as generate2 } from "@babel/generator";
|
|
4736
|
-
import * as
|
|
5003
|
+
import * as t47 from "@babel/types";
|
|
4737
5004
|
function resolveProvide(ctx) {
|
|
4738
5005
|
if (ctx.inputType === "style") return {};
|
|
4739
5006
|
return {
|
|
4740
|
-
CallExpression(
|
|
4741
|
-
const { node } =
|
|
5007
|
+
CallExpression(path8) {
|
|
5008
|
+
const { node } = path8;
|
|
4742
5009
|
const providerTarget = ADAPTER_RULES.runtime[VUE_API_MAP.provide]?.target;
|
|
4743
5010
|
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
4744
5011
|
if (!isProvideCall) return;
|
|
@@ -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
|
}
|
|
@@ -4765,13 +5032,13 @@ 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 {
|
|
@@ -4787,16 +5054,16 @@ function assignProviderValue(target, key, value) {
|
|
|
4787
5054
|
}
|
|
4788
5055
|
|
|
4789
5056
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
4790
|
-
import * as
|
|
5057
|
+
import * as t48 from "@babel/types";
|
|
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,12 +5075,12 @@ 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(
|
|
5083
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
4817
5084
|
setScriptNodeMeta(declaratorPath?.node, {
|
|
4818
5085
|
is_reactive: true,
|
|
4819
5086
|
reactive_type: reactiveType
|
|
@@ -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;
|
|
@@ -4858,7 +5125,7 @@ function isVueImportBinding2(binding) {
|
|
|
4858
5125
|
return false;
|
|
4859
5126
|
}
|
|
4860
5127
|
const parent = bindingPath.parentPath?.node;
|
|
4861
|
-
if (!parent || !
|
|
5128
|
+
if (!parent || !t48.isImportDeclaration(parent)) {
|
|
4862
5129
|
return false;
|
|
4863
5130
|
}
|
|
4864
5131
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4995,15 +5262,15 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
4995
5262
|
}
|
|
4996
5263
|
|
|
4997
5264
|
// src/core/transform/sfc/template/shared/prop-ir-utils.ts
|
|
4998
|
-
import * as
|
|
5265
|
+
import * as t50 from "@babel/types";
|
|
4999
5266
|
|
|
5000
5267
|
// src/shared/string-code-types.ts
|
|
5001
5268
|
import { parseExpression as parseExpression3 } from "@babel/parser";
|
|
5002
|
-
import * as
|
|
5269
|
+
import * as t49 from "@babel/types";
|
|
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;
|
|
@@ -5012,38 +5279,38 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
5012
5279
|
} catch {
|
|
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 = parseExpression3(code);
|
|
5038
|
-
return
|
|
5305
|
+
return t49.isIdentifier(node);
|
|
5039
5306
|
} catch {
|
|
5040
5307
|
return false;
|
|
5041
5308
|
}
|
|
5042
5309
|
}
|
|
5043
|
-
function
|
|
5310
|
+
function isStringLiteral13(code) {
|
|
5044
5311
|
try {
|
|
5045
5312
|
const node = parseExpression3(code);
|
|
5046
|
-
return
|
|
5313
|
+
return t49.isStringLiteral(node);
|
|
5047
5314
|
} catch {
|
|
5048
5315
|
return false;
|
|
5049
5316
|
}
|
|
@@ -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;
|
|
@@ -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 !== NodeTypes3.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: NodeTypes3.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) {
|
|
@@ -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) {
|
|
@@ -5945,27 +6199,15 @@ function applyValueModifiers(valueExp, modifiers) {
|
|
|
5945
6199
|
}
|
|
5946
6200
|
|
|
5947
6201
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
|
|
5948
|
-
import * as
|
|
6202
|
+
import * as t51 from "@babel/types";
|
|
5949
6203
|
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) {
|
|
@@ -6336,20 +6612,11 @@ function transform(ast, ctx, options) {
|
|
|
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 {
|
|
@@ -6550,13 +6817,6 @@ var Helper = class {
|
|
|
6550
6817
|
const { input = "src" } = this.compilerOpts;
|
|
6551
6818
|
return path3.resolve(this.getProjectRoot(), input);
|
|
6552
6819
|
}
|
|
6553
|
-
/**
|
|
6554
|
-
* 检查 input 路径是否是单个文件
|
|
6555
|
-
*/
|
|
6556
|
-
isSingleFile() {
|
|
6557
|
-
const inputPath = this.getInputPath();
|
|
6558
|
-
return fs2.existsSync(inputPath) && fs2.statSync(inputPath).isFile();
|
|
6559
|
-
}
|
|
6560
6820
|
/**
|
|
6561
6821
|
* 获取输出文件的路径。如:'[root]/.vureact/dist/'
|
|
6562
6822
|
* @param addInput 会输出如:'[root]/.vureact/dist/[input]/'
|
|
@@ -6615,6 +6875,13 @@ var Helper = class {
|
|
|
6615
6875
|
getOutputPkgPath() {
|
|
6616
6876
|
return path3.join(this.getOuputPath(), "package.json");
|
|
6617
6877
|
}
|
|
6878
|
+
/**
|
|
6879
|
+
* 获取缓存文件路径
|
|
6880
|
+
*/
|
|
6881
|
+
getCachePath() {
|
|
6882
|
+
const filename = "_metadata";
|
|
6883
|
+
return path3.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
|
|
6884
|
+
}
|
|
6618
6885
|
/**
|
|
6619
6886
|
* 返回文件相对工作区的路径
|
|
6620
6887
|
*/
|
|
@@ -6712,95 +6979,15 @@ var Helper = 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.existsSync(cacheFile)) {
|
|
6723
|
-
return defaultData;
|
|
6724
|
-
}
|
|
6725
|
-
try {
|
|
6726
|
-
const content = await fs2.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 {
|
|
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.existsSync(filePath)) {
|
|
6983
|
+
await fs2.promises.rm(filePath, { recursive: true, force: true });
|
|
6746
6984
|
}
|
|
6747
|
-
}
|
|
6748
|
-
}
|
|
6749
|
-
/**
|
|
6750
|
-
* 获取缓存文件路径
|
|
6751
|
-
*/
|
|
6752
|
-
getCachePath() {
|
|
6753
|
-
const filename = "_metadata";
|
|
6754
|
-
return path3.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
|
|
6755
|
-
}
|
|
6756
|
-
async saveCache(data) {
|
|
6757
|
-
if (!this.getIsCache() || !data) {
|
|
6758
|
-
return;
|
|
6985
|
+
} catch {
|
|
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.existsSync(dir)) {
|
|
6785
|
-
return results;
|
|
6786
|
-
}
|
|
6787
|
-
const stats = fs2.statSync(dir);
|
|
6788
|
-
if (stats.isFile()) {
|
|
6789
|
-
return filter(dir) ? [dir] : [];
|
|
6790
|
-
}
|
|
6791
|
-
const list = fs2.readdirSync(dir);
|
|
6792
|
-
for (const file of list) {
|
|
6793
|
-
const fullPath = path3.resolve(dir, file);
|
|
6794
|
-
if (this.shouldSkipPath(fullPath)) continue;
|
|
6795
|
-
const stat = fs2.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 path3.isAbsolute(filePath) ? filePath : path3.resolve(this.getProjectRoot(), filePath);
|
|
6806
6993
|
}
|
|
@@ -6812,9 +6999,9 @@ var Helper = class {
|
|
|
6812
6999
|
};
|
|
6813
7000
|
}
|
|
6814
7001
|
async removeOutputFile(filePath, resolveOutputPath) {
|
|
6815
|
-
const
|
|
6816
|
-
if (!fs2.existsSync(
|
|
6817
|
-
await fs2.promises.unlink(
|
|
7002
|
+
const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
|
|
7003
|
+
if (!fs2.existsSync(path8)) return;
|
|
7004
|
+
await fs2.promises.unlink(path8);
|
|
6818
7005
|
}
|
|
6819
7006
|
updateCache(targetFile, newData, cache) {
|
|
6820
7007
|
const index = cache.target.findIndex((c) => c.file === targetFile);
|
|
@@ -6867,18 +7054,18 @@ var Helper = class {
|
|
|
6867
7054
|
/**
|
|
6868
7055
|
* 读取 package.json 文件内容,并处理成对象返回
|
|
6869
7056
|
*/
|
|
6870
|
-
async resolvePackageFile(
|
|
6871
|
-
if (!fs2.existsSync(
|
|
7057
|
+
async resolvePackageFile(path8) {
|
|
7058
|
+
if (!fs2.existsSync(path8)) {
|
|
6872
7059
|
return {};
|
|
6873
7060
|
}
|
|
6874
7061
|
try {
|
|
6875
|
-
const content = await fs2.promises.readFile(
|
|
7062
|
+
const content = await fs2.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(kleur4.red("\u274C"), `Failed to parse JSON file ${
|
|
7068
|
+
console.error(kleur4.red("\u274C"), `Failed to parse JSON file ${path8}:
|
|
6882
7069
|
`, error);
|
|
6883
7070
|
return {};
|
|
6884
7071
|
}
|
|
@@ -6950,7 +7137,7 @@ var CompilationContext = class {
|
|
|
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(),
|
|
@@ -7138,6 +7325,15 @@ var BaseCompiler = class extends Helper {
|
|
|
7138
7325
|
}
|
|
7139
7326
|
};
|
|
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 @@ import ora2 from "ora";
|
|
|
7160
7356
|
import fs3 from "fs";
|
|
7161
7357
|
import path5 from "path";
|
|
7162
7358
|
var AssetManager = class {
|
|
7163
|
-
constructor(fileCompiler, cleanupManager) {
|
|
7359
|
+
constructor(fileCompiler, cleanupManager, cacheManager) {
|
|
7164
7360
|
this.fileCompiler = fileCompiler;
|
|
7165
7361
|
this.cleanupManager = cleanupManager;
|
|
7362
|
+
this.cacheManager = cacheManager;
|
|
7166
7363
|
}
|
|
7167
7364
|
// 需要经过管线编译处理的文件类型
|
|
7168
7365
|
pipelineFiles = [".js", ".ts", ".less", ".scss", ".sass"];
|
|
@@ -7170,70 +7367,40 @@ var AssetManager = 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 = path5.basename(p).toLowerCase();
|
|
7182
|
-
const ext = path5.extname(p).toLowerCase();
|
|
7183
|
-
if (!options.output?.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 + path5.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 fs3.promises.mkdir(path5.dirname(outputPath), { recursive: true });
|
|
7233
7400
|
await fs3.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 = class {
|
|
|
7264
7431
|
};
|
|
7265
7432
|
|
|
7266
7433
|
// src/compiler/shared/file-compiler/cache-manager.ts
|
|
7434
|
+
import fs4 from "fs";
|
|
7267
7435
|
var CacheManager = class {
|
|
7268
7436
|
constructor(fileCompiler) {
|
|
7269
7437
|
this.fileCompiler = fileCompiler;
|
|
7270
7438
|
}
|
|
7271
7439
|
pendingUpdates = /* @__PURE__ */ new Map();
|
|
7440
|
+
/** 缓存文件仅读取一次,之后复用此副本 */
|
|
7441
|
+
cachedData = null;
|
|
7272
7442
|
/**
|
|
7273
7443
|
* 批量更新缓存记录
|
|
7274
7444
|
*/
|
|
@@ -7290,94 +7460,203 @@ var CacheManager = 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 (!updates?.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 (fs4.existsSync(filePath)) {
|
|
7499
|
+
try {
|
|
7500
|
+
const content = await fs4.promises.readFile(filePath, "utf-8");
|
|
7501
|
+
raw = JSON.parse(content);
|
|
7502
|
+
} catch {
|
|
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 (fs4.existsSync(filePath)) {
|
|
7521
|
+
try {
|
|
7522
|
+
const content = await fs4.promises.readFile(filePath, "utf-8");
|
|
7523
|
+
const data = JSON.parse(content);
|
|
7524
|
+
return this.buildLoadedCache(key, data);
|
|
7525
|
+
} catch {
|
|
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 (fs4.existsSync(filePath)) {
|
|
7541
|
+
try {
|
|
7542
|
+
const content = await fs4.promises.readFile(filePath, "utf-8");
|
|
7543
|
+
this.cachedData = JSON.parse(content);
|
|
7544
|
+
} catch {
|
|
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
|
};
|
|
7320
7600
|
|
|
7321
7601
|
// src/compiler/shared/file-compiler/cleanup-manager.ts
|
|
7322
7602
|
import path6 from "path";
|
|
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 + path6.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 + path6.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 (css?.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 (css?.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
|
|
|
@@ -7478,7 +7757,7 @@ var CompilationUnitProcessor = class {
|
|
|
7478
7757
|
};
|
|
7479
7758
|
|
|
7480
7759
|
// src/compiler/shared/file-compiler/file-processor.ts
|
|
7481
|
-
import
|
|
7760
|
+
import fs5 from "fs";
|
|
7482
7761
|
import kleur6 from "kleur";
|
|
7483
7762
|
import path7 from "path";
|
|
7484
7763
|
var FileProcessor = class {
|
|
@@ -7509,18 +7788,18 @@ var FileProcessor = 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.
|
|
7791
|
+
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.cacheManager.loadCache(key);
|
|
7513
7792
|
const record = cache?.target.find((c) => c.file === absPath);
|
|
7514
7793
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
7515
7794
|
fileMeta,
|
|
7516
7795
|
record,
|
|
7517
|
-
() =>
|
|
7796
|
+
() => fs5.promises.readFile(absPath, "utf-8")
|
|
7518
7797
|
);
|
|
7519
7798
|
if (!shouldCompile) {
|
|
7520
7799
|
this.skippedCount++;
|
|
7521
7800
|
return;
|
|
7522
7801
|
}
|
|
7523
|
-
const source = await
|
|
7802
|
+
const source = await fs5.promises.readFile(absPath, "utf-8");
|
|
7524
7803
|
if (!source.trim()) return;
|
|
7525
7804
|
const initUnit = {
|
|
7526
7805
|
...fileMeta,
|
|
@@ -7580,7 +7859,7 @@ var FileProcessor = class {
|
|
|
7580
7859
|
const getMainFile = async (filename) => {
|
|
7581
7860
|
const filePath = path7.resolve(outputPath, filename);
|
|
7582
7861
|
try {
|
|
7583
|
-
return { filePath, content: await
|
|
7862
|
+
return { filePath, content: await fs5.promises.readFile(filePath, "utf-8") };
|
|
7584
7863
|
} catch {
|
|
7585
7864
|
return;
|
|
7586
7865
|
}
|
|
@@ -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 (!fs5.existsSync(path8)) return;
|
|
7935
|
+
return fs5.statSync(path8);
|
|
7936
|
+
};
|
|
7937
|
+
const resolveDirectory = (file, walk, fallback) => {
|
|
7938
|
+
const directory = fs5.readdirSync(file);
|
|
7939
|
+
directory.forEach((p) => {
|
|
7940
|
+
const fullPath = path7.resolve(file, p);
|
|
7941
|
+
if (fileCompiler.shouldSkipPath(fullPath)) {
|
|
7942
|
+
return;
|
|
7943
|
+
}
|
|
7944
|
+
const stat = fs5.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 = path7.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 = path7.extname(input).toLowerCase();
|
|
7981
|
+
const resolvedPath = normalizePath(fileCompiler.relativePath(input));
|
|
7982
|
+
const baseName = path7.basename(input).toLowerCase();
|
|
7983
|
+
const exclusions = fileCompiler.getIgnoreAssets();
|
|
7984
|
+
if (!fileCompiler.options.output?.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 + path7.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
|
};
|
|
7638
8032
|
|
|
7639
8033
|
// src/compiler/shared/file-compiler/pipeline-manager.ts
|
|
7640
|
-
import path8 from "path";
|
|
7641
8034
|
var PipelineManager = class {
|
|
7642
|
-
constructor(fileCompiler, fileProcessor) {
|
|
8035
|
+
constructor(fileCompiler, fileProcessor, cleanupManager) {
|
|
7643
8036
|
this.fileCompiler = fileCompiler;
|
|
7644
8037
|
this.fileProcessor = fileProcessor;
|
|
7645
|
-
this.cleanupManager =
|
|
8038
|
+
this.cleanupManager = cleanupManager;
|
|
7646
8039
|
}
|
|
7647
8040
|
skippedCount = 0;
|
|
7648
|
-
cleanupManager;
|
|
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 = path8.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
|
/**
|
|
@@ -7710,7 +8085,7 @@ var PipelineManager = class {
|
|
|
7710
8085
|
|
|
7711
8086
|
// src/compiler/shared/file-compiler/vite-bootstrapper.ts
|
|
7712
8087
|
import { execSync } from "child_process";
|
|
7713
|
-
import
|
|
8088
|
+
import fs6 from "fs";
|
|
7714
8089
|
import kleur7 from "kleur";
|
|
7715
8090
|
import ora from "ora";
|
|
7716
8091
|
var ViteBootstrapper = class {
|
|
@@ -7728,10 +8103,10 @@ var ViteBootstrapper = class {
|
|
|
7728
8103
|
*/
|
|
7729
8104
|
isSingleFile() {
|
|
7730
8105
|
const inputPath = this.fileCompiler.getInputPath();
|
|
7731
|
-
if (!
|
|
8106
|
+
if (!fs6.existsSync(inputPath)) {
|
|
7732
8107
|
return false;
|
|
7733
8108
|
}
|
|
7734
|
-
const stat =
|
|
8109
|
+
const stat = fs6.statSync(inputPath);
|
|
7735
8110
|
return stat.isFile();
|
|
7736
8111
|
}
|
|
7737
8112
|
/**
|
|
@@ -7740,30 +8115,20 @@ var ViteBootstrapper = class {
|
|
|
7740
8115
|
async bootstrapIfNeeded() {
|
|
7741
8116
|
const { output } = this.options;
|
|
7742
8117
|
const workspaceDir = this.fileCompiler.getWorkspaceDir();
|
|
7743
|
-
await
|
|
8118
|
+
await fs6.promises.mkdir(workspaceDir, { recursive: true });
|
|
7744
8119
|
if (output?.bootstrapVite === false) {
|
|
7745
8120
|
return false;
|
|
7746
8121
|
}
|
|
7747
8122
|
if (this.isSingleFile()) {
|
|
7748
|
-
console.info("
|
|
8123
|
+
console.info(kleur7.dim("Skip Vite init for single file"));
|
|
8124
|
+
console.info();
|
|
7749
8125
|
return;
|
|
7750
8126
|
}
|
|
7751
8127
|
const outputPkgPath = this.fileCompiler.getOutputPkgPath();
|
|
7752
|
-
if (
|
|
7753
|
-
return;
|
|
7754
|
-
}
|
|
7755
|
-
try {
|
|
7756
|
-
this.spinner.start("Bootstrapping Vite React environment...");
|
|
7757
|
-
await this.resolveViteCreateApp();
|
|
7758
|
-
} catch (err) {
|
|
7759
|
-
console.error(
|
|
7760
|
-
kleur7.red("\u2716"),
|
|
7761
|
-
"Failed to bootstrap Vite environment. Please check npm/network.\n",
|
|
7762
|
-
err
|
|
7763
|
-
);
|
|
7764
|
-
this.spinner.stop();
|
|
8128
|
+
if (fs6.existsSync(outputPkgPath)) {
|
|
7765
8129
|
return;
|
|
7766
8130
|
}
|
|
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));
|
|
@@ -7793,7 +8158,7 @@ var ViteBootstrapper = class {
|
|
|
7793
8158
|
newPkg.devDependencies = newDevDeps;
|
|
7794
8159
|
newPkg = output?.packageJson?.(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
|
/**
|
|
@@ -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,8 +8247,16 @@ 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
|
|
|
@@ -7895,34 +8268,57 @@ var FileCompiler = class extends BaseCompiler {
|
|
|
7895
8268
|
super(options);
|
|
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}${kleur8.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
|
-
|
|
8290
|
+
} catch (err) {
|
|
8291
|
+
console.warn(kleur8.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();
|
|
7914
8311
|
await this.options.onSuccess?.();
|
|
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(kleur8.red("\u2716"), `Build failed in ${endTime}`);
|
|
8316
|
+
this.spinner.stop();
|
|
8317
|
+
console.error(kleur8.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 = 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} ${kleur8.dim("SFC(s)")}`);
|
|
8367
|
+
if (scriptCount) stats.push(`${scriptCount} ${kleur8.dim("script(s)")}`);
|
|
8368
|
+
if (styleCount) stats.push(`${styleCount} ${kleur8.dim("style(s)")}`);
|
|
8369
|
+
if (assetCount) stats.push(`${assetCount} ${kleur8.dim("asset(s)")}`);
|
|
8370
|
+
this.spinner.succeed(`${kleur8.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
|
+
kleur8.gray(`\u21B7 ${kleur8.bold("Cached")}: ${kleur8.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} ${kleur8.bold("Output")}: ${kleur8.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
|
+
kleur8.dim("\u2B50 If you like VuReact, give us a star on GitHub:"),
|
|
8390
|
+
kleur8.gray(kleur8.underline("https://github.com/vureact-js/core"))
|
|
8391
|
+
);
|
|
8018
8392
|
console.info();
|
|
8019
8393
|
}
|
|
8020
8394
|
resetSkippedCount() {
|
|
@@ -8045,9 +8419,9 @@ export {
|
|
|
8045
8419
|
transform,
|
|
8046
8420
|
version,
|
|
8047
8421
|
bin,
|
|
8048
|
-
CacheKey,
|
|
8049
8422
|
Helper,
|
|
8050
8423
|
BaseCompiler,
|
|
8424
|
+
CacheKey,
|
|
8051
8425
|
FileCompiler,
|
|
8052
8426
|
defineConfig,
|
|
8053
8427
|
VuReact
|