@vureact/compiler-core 1.5.0 → 1.5.2
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 +16 -16
- package/README.md +15 -13
- package/lib/{chunk-TSGO73AO.js → chunk-37GGS4UW.js} +826 -867
- package/lib/{chunk-IGLKQRRZ.esm.js → chunk-UYTNAOAJ.esm.js} +719 -760
- package/lib/cli.esm.js +2 -2
- package/lib/cli.js +10 -10
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;/**
|
|
2
|
-
* @vureact/compiler-core v1.5.
|
|
2
|
+
* @vureact/compiler-core v1.5.2
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,7 +24,7 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var
|
|
27
|
+
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -624,7 +624,7 @@ function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
|
624
624
|
const newContent = resolveSpecialExpressions(input, ctx);
|
|
625
625
|
try {
|
|
626
626
|
return stringToExpr(newContent, scriptData.lang, filename);
|
|
627
|
-
} catch (
|
|
627
|
+
} catch (e) {
|
|
628
628
|
return t5.identifier(newContent);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
@@ -780,7 +780,7 @@ function normalizePath(filePath) {
|
|
|
780
780
|
if (fp.startsWith("file:")) {
|
|
781
781
|
fp = _url.fileURLToPath.call(void 0, fp);
|
|
782
782
|
}
|
|
783
|
-
} catch (
|
|
783
|
+
} catch (e2) {
|
|
784
784
|
}
|
|
785
785
|
fp = fp.replace(/\\/g, "/").replace(/\/\/+/, "/");
|
|
786
786
|
return fp;
|
|
@@ -995,7 +995,7 @@ function buildSlotCallbackParams(nodeIR, ctx) {
|
|
|
995
995
|
return [];
|
|
996
996
|
}
|
|
997
997
|
return expression.params;
|
|
998
|
-
} catch (
|
|
998
|
+
} catch (e3) {
|
|
999
999
|
logger.warn(`Failed to parse slot params "${rawArg}". Falling back to no-arg slot function.`, {
|
|
1000
1000
|
file: ctx.filename
|
|
1001
1001
|
});
|
|
@@ -1029,7 +1029,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1029
1029
|
babelExp: { ast: keyAST },
|
|
1030
1030
|
value: {
|
|
1031
1031
|
content,
|
|
1032
|
-
isStringLiteral:
|
|
1032
|
+
isStringLiteral: isStringLiteral12,
|
|
1033
1033
|
babelExp: { ast: valueAST }
|
|
1034
1034
|
}
|
|
1035
1035
|
} = nodeIR;
|
|
@@ -1038,7 +1038,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
let value;
|
|
1040
1040
|
if (content !== "true") {
|
|
1041
|
-
value =
|
|
1041
|
+
value = isStringLiteral12 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
1042
1042
|
}
|
|
1043
1043
|
return t9.jsxAttribute(keyAST, value);
|
|
1044
1044
|
}
|
|
@@ -1110,7 +1110,7 @@ function buildCtxProviderNode(nodeIR, ctx, children) {
|
|
|
1110
1110
|
if (!raw) return t11.stringLiteral("");
|
|
1111
1111
|
try {
|
|
1112
1112
|
return stringToExpr(raw, ctx.scriptData.lang, ctx.filename);
|
|
1113
|
-
} catch (
|
|
1113
|
+
} catch (e4) {
|
|
1114
1114
|
return t11.stringLiteral(raw);
|
|
1115
1115
|
}
|
|
1116
1116
|
};
|
|
@@ -1385,7 +1385,12 @@ function generateComponent(ir, ctx, options) {
|
|
|
1385
1385
|
quotes: "single"
|
|
1386
1386
|
// 使用单引号
|
|
1387
1387
|
},
|
|
1388
|
-
minified:
|
|
1388
|
+
minified: false,
|
|
1389
|
+
// 不压缩输出内容
|
|
1390
|
+
retainLines: false,
|
|
1391
|
+
// 不保留行号
|
|
1392
|
+
retainFunctionParens: true,
|
|
1393
|
+
// 保留函数括号
|
|
1389
1394
|
...options
|
|
1390
1395
|
});
|
|
1391
1396
|
const result = {
|
|
@@ -1451,107 +1456,39 @@ var _compilersfc = require('@vue/compiler-sfc');
|
|
|
1451
1456
|
|
|
1452
1457
|
// src/core/parse/sfc/process/resolve-script.ts
|
|
1453
1458
|
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
function resolveScript(descriptor, ctx, pResult) {
|
|
1457
|
-
const scriptBlock = descriptor.scriptSetup || descriptor.script;
|
|
1458
|
-
if (!scriptBlock) return null;
|
|
1459
|
-
const result = {
|
|
1460
|
-
ast: {},
|
|
1461
|
-
source: scriptBlock
|
|
1462
|
-
};
|
|
1463
|
-
const options = getBabelParseOptions(scriptBlock.lang, "script", ctx.filename);
|
|
1459
|
+
function resolveScript(descriptor, ctx, parseResult) {
|
|
1464
1460
|
if (descriptor.script) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
result.ast = ast;
|
|
1469
|
-
ctx.compName = name;
|
|
1470
|
-
}
|
|
1471
|
-
logger.warn(
|
|
1472
|
-
"Using traditional script (instead of <script setup>) may result in unstable or non-functional React code. It is recommended to use <script setup> instead.",
|
|
1473
|
-
{ file: ctx.filename }
|
|
1461
|
+
throw new Error(
|
|
1462
|
+
`Traditional Vue <script> syntax is not supported. Please migrate to <script setup>.
|
|
1463
|
+
at <anonymous> (${ctx.filename})`
|
|
1474
1464
|
);
|
|
1475
|
-
} else {
|
|
1476
|
-
result.ast = _parser.parse.call(void 0, result.source.content, options);
|
|
1477
1465
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1466
|
+
const { scriptSetup } = descriptor;
|
|
1467
|
+
if (!scriptSetup) return null;
|
|
1468
|
+
if (_optionalChain([scriptSetup, 'optionalAccess', _41 => _41.warnings])) {
|
|
1469
|
+
_optionalChain([scriptSetup, 'optionalAccess', _42 => _42.warnings, 'access', _43 => _43.forEach, 'call', _44 => _44((msg) => {
|
|
1480
1470
|
logger.warn(msg, { file: ctx.filename });
|
|
1481
1471
|
})]);
|
|
1482
1472
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
}
|
|
1489
|
-
function extractSetupBodyToTopLevel(content, options) {
|
|
1490
|
-
let name = "";
|
|
1491
|
-
try {
|
|
1492
|
-
const ast = _parser.parse.call(void 0, content, options);
|
|
1493
|
-
const importNodes = [];
|
|
1494
|
-
const otherTopLevel = [];
|
|
1495
|
-
let setupStatements = [];
|
|
1496
|
-
for (const node of ast.program.body) {
|
|
1497
|
-
if (t15.isImportDeclaration(node)) {
|
|
1498
|
-
importNodes.push(node);
|
|
1499
|
-
continue;
|
|
1500
|
-
}
|
|
1501
|
-
if (t15.isExportDefaultDeclaration(node)) {
|
|
1502
|
-
const decl = node.declaration;
|
|
1503
|
-
if (decl && t15.isObjectExpression(decl)) {
|
|
1504
|
-
const nameProp = decl.properties.find((p) => {
|
|
1505
|
-
if (t15.isObjectProperty(p)) {
|
|
1506
|
-
const key = p.key;
|
|
1507
|
-
return t15.isIdentifier(key) && key.name === "name" || t15.isStringLiteral(key) && key.value === "name";
|
|
1508
|
-
}
|
|
1509
|
-
return false;
|
|
1510
|
-
});
|
|
1511
|
-
if (nameProp && t15.isObjectProperty(nameProp)) {
|
|
1512
|
-
if (t15.isStringLiteral(nameProp.value)) {
|
|
1513
|
-
name = nameProp.value.value;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
const setupProp = decl.properties.find((p) => {
|
|
1517
|
-
if (t15.isObjectMethod(p)) {
|
|
1518
|
-
return p.key && p.key.name === "setup";
|
|
1519
|
-
}
|
|
1520
|
-
if (t15.isObjectProperty(p)) {
|
|
1521
|
-
const key = p.key;
|
|
1522
|
-
return t15.isIdentifier(key) && key.name === "setup" || t15.isStringLiteral(key) && key.value === "setup";
|
|
1523
|
-
}
|
|
1524
|
-
return false;
|
|
1525
|
-
});
|
|
1526
|
-
if (setupProp) {
|
|
1527
|
-
const value = t15.isObjectMethod(setupProp) ? setupProp : t15.isObjectProperty(setupProp) ? setupProp.value : null;
|
|
1528
|
-
if (value && (t15.isFunction(value) || t15.isObjectMethod(value))) {
|
|
1529
|
-
const fnBody = t15.isBlockStatement(value.body) ? value.body.body : [];
|
|
1530
|
-
for (const stmt of fnBody) {
|
|
1531
|
-
if (t15.isReturnStatement(stmt)) continue;
|
|
1532
|
-
setupStatements.push(stmt);
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
continue;
|
|
1538
|
-
}
|
|
1539
|
-
otherTopLevel.push(node);
|
|
1540
|
-
}
|
|
1541
|
-
const parts = [];
|
|
1542
|
-
const stmts = importNodes.concat(otherTopLevel, setupStatements);
|
|
1543
|
-
for (const n of stmts) {
|
|
1544
|
-
parts.push(_generator.generate.call(void 0, n).code);
|
|
1545
|
-
}
|
|
1546
|
-
return { name, ast, code: parts.join("\n\n") };
|
|
1547
|
-
} catch (e) {
|
|
1548
|
-
console.error(e);
|
|
1549
|
-
return { name, code: content };
|
|
1550
|
-
}
|
|
1473
|
+
resolveContext(scriptSetup, ctx);
|
|
1474
|
+
const parseOpts = getBabelParseOptions(scriptSetup.lang, "script", ctx.filename);
|
|
1475
|
+
parseResult.script = {
|
|
1476
|
+
ast: _parser.parse.call(void 0, scriptSetup.content, parseOpts),
|
|
1477
|
+
source: scriptSetup
|
|
1478
|
+
};
|
|
1551
1479
|
}
|
|
1552
|
-
function
|
|
1553
|
-
|
|
1554
|
-
|
|
1480
|
+
function resolveContext(scriptSetup, ctx) {
|
|
1481
|
+
let { content, lang } = scriptSetup;
|
|
1482
|
+
const resolveVRComment = (source) => {
|
|
1483
|
+
const regx = /\/\/\s*@vr-name:\s*(\w+)/;
|
|
1484
|
+
const nameMatch = source.match(regx);
|
|
1485
|
+
content = content.replace(regx, "");
|
|
1486
|
+
return _optionalChain([nameMatch, 'optionalAccess', _45 => _45[1], 'optionalAccess', _46 => _46.trim, 'call', _47 => _47()]) || "";
|
|
1487
|
+
};
|
|
1488
|
+
ctx.compName = resolveVRComment(content);
|
|
1489
|
+
ctx.scriptData.source = content;
|
|
1490
|
+
ctx.scriptData.lang = lang || "js";
|
|
1491
|
+
scriptSetup.content = content;
|
|
1555
1492
|
}
|
|
1556
1493
|
|
|
1557
1494
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
@@ -1662,10 +1599,10 @@ function resolveScriptMeta(result, ctx) {
|
|
|
1662
1599
|
_core.traverse.call(void 0, scriptAST, {
|
|
1663
1600
|
VariableDeclarator(path9) {
|
|
1664
1601
|
const { node } = path9;
|
|
1665
|
-
if (!atComponentOrHookRoot(path9, scriptAST.program) || !
|
|
1602
|
+
if (!atComponentOrHookRoot(path9, scriptAST.program) || !t15.isIdentifier(node.id)) {
|
|
1666
1603
|
return;
|
|
1667
1604
|
}
|
|
1668
|
-
if (node.init &&
|
|
1605
|
+
if (node.init && t15.isCallExpression(node.init) && t15.isIdentifier(node.init.callee)) {
|
|
1669
1606
|
collectReactiveBindings(node, ctx);
|
|
1670
1607
|
collectRefBindings(node, ctx);
|
|
1671
1608
|
}
|
|
@@ -1936,268 +1873,11 @@ function parse(source, ctx, options) {
|
|
|
1936
1873
|
// src/core/transform/sfc/script/syntax-processor/index.ts
|
|
1937
1874
|
|
|
1938
1875
|
|
|
1939
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/insert-css-import.ts
|
|
1940
|
-
|
|
1941
|
-
function insertCSSImport(ctx) {
|
|
1942
|
-
const { inputType } = ctx;
|
|
1943
|
-
if (inputType !== "sfc") return;
|
|
1944
|
-
const { filePath, moduleName } = ctx.styleData;
|
|
1945
|
-
if (!filePath) return;
|
|
1946
|
-
const scriptIR = getScriptIR(ctx);
|
|
1947
|
-
const filename = normalizePath(filePath).split("/").pop();
|
|
1948
|
-
const importPath = `./${filename}`;
|
|
1949
|
-
const importDecl = t17.importDeclaration(
|
|
1950
|
-
!moduleName ? [] : [t17.importDefaultSpecifier(t17.identifier(moduleName))],
|
|
1951
|
-
t17.stringLiteral(importPath)
|
|
1952
|
-
);
|
|
1953
|
-
scriptIR.imports.push(importDecl);
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-required-imports/index.ts
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
// src/core/transform/shared.ts
|
|
1960
|
-
function recordImport(ctx, pkg, name, onDemand = true) {
|
|
1961
|
-
const { imports } = ctx;
|
|
1962
|
-
if (isTypeOnlyImport(name)) {
|
|
1963
|
-
name = `type ${name}`;
|
|
1964
|
-
}
|
|
1965
|
-
if (imports.has(pkg)) {
|
|
1966
|
-
const list = imports.get(pkg);
|
|
1967
|
-
const foundItem = list.find((item) => item.name === name);
|
|
1968
|
-
if (!foundItem) {
|
|
1969
|
-
list.push({ name, onDemand });
|
|
1970
|
-
}
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
imports.set(pkg, [{ name, onDemand }]);
|
|
1974
|
-
}
|
|
1975
|
-
function isTypeOnlyImport(name) {
|
|
1976
|
-
const arr = [REACT_API_MAP.ReactNode];
|
|
1977
|
-
return arr.includes(name);
|
|
1978
|
-
}
|
|
1979
|
-
|
|
1980
|
-
// src/core/transform/sfc/script/shared/replace-vue-suffix.ts
|
|
1981
|
-
function replaceVueSuffix(ctx, node) {
|
|
1982
|
-
if (!node.value.endsWith(".vue")) return;
|
|
1983
|
-
const jsxFile = node.value.replace(/.vue$/, "");
|
|
1984
|
-
node.value = jsxFile;
|
|
1985
|
-
node.extra = { rawValue: jsxFile, raw: jsxFile };
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-required-imports/import-strategies.ts
|
|
1989
|
-
var VueRouterStrategy = class {
|
|
1990
|
-
matches(moduleName) {
|
|
1991
|
-
return moduleName === "vue-router" || moduleName.startsWith("vue-router/");
|
|
1992
|
-
}
|
|
1993
|
-
process() {
|
|
1994
|
-
return {
|
|
1995
|
-
shouldReplaceSource: true,
|
|
1996
|
-
newSource: PACKAGE_NAME.router,
|
|
1997
|
-
shouldRemove: false,
|
|
1998
|
-
shouldInjectRuntimeImports: false
|
|
1999
|
-
};
|
|
2000
|
-
}
|
|
2001
|
-
};
|
|
2002
|
-
var VueEcosystemStrategy = class {
|
|
2003
|
-
matches(moduleName) {
|
|
2004
|
-
if (moduleName.startsWith(".") || moduleName.startsWith("/") || moduleName.startsWith("file:")) {
|
|
2005
|
-
return false;
|
|
2006
|
-
}
|
|
2007
|
-
if (moduleName === "vue-router" || moduleName.startsWith("vue-router/")) {
|
|
2008
|
-
return false;
|
|
2009
|
-
}
|
|
2010
|
-
if (moduleName.startsWith("@vue/")) {
|
|
2011
|
-
return true;
|
|
2012
|
-
}
|
|
2013
|
-
for (const pkg of VUE_PACKAGES) {
|
|
2014
|
-
if (moduleName === pkg || moduleName.startsWith(`${pkg}/`)) {
|
|
2015
|
-
return true;
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
return false;
|
|
2019
|
-
}
|
|
2020
|
-
process() {
|
|
2021
|
-
return {
|
|
2022
|
-
shouldReplaceSource: false,
|
|
2023
|
-
shouldRemove: true,
|
|
2024
|
-
shouldInjectRuntimeImports: true
|
|
2025
|
-
};
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
var StyleFileStrategy = (_class3 = class {constructor() { _class3.prototype.__init5.call(this); }
|
|
2029
|
-
__init5() {this.regExp = /\.(less|sass|scss)$/i}
|
|
2030
|
-
matches(moduleName) {
|
|
2031
|
-
return this.regExp.test(moduleName);
|
|
2032
|
-
}
|
|
2033
|
-
process(path9, ctx) {
|
|
2034
|
-
if (!ctx.preprocessStyles) {
|
|
2035
|
-
return {};
|
|
2036
|
-
}
|
|
2037
|
-
const importSource = path9.node.source.value;
|
|
2038
|
-
if (typeof importSource !== "string") {
|
|
2039
|
-
return {};
|
|
2040
|
-
}
|
|
2041
|
-
return {
|
|
2042
|
-
shouldReplaceSource: true,
|
|
2043
|
-
newSource: importSource.replace(this.regExp, ".css"),
|
|
2044
|
-
shouldRemove: false,
|
|
2045
|
-
shouldInjectRuntimeImports: false
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
}, _class3);
|
|
2049
|
-
|
|
2050
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-required-imports/import-strategy-manager.ts
|
|
2051
|
-
var ImportStrategyManager = (_class4 = class {
|
|
2052
|
-
__init6() {this.strategies = []}
|
|
2053
|
-
constructor() {;_class4.prototype.__init6.call(this);
|
|
2054
|
-
this.strategies.push(new VueRouterStrategy());
|
|
2055
|
-
this.strategies.push(new VueEcosystemStrategy());
|
|
2056
|
-
this.strategies.push(new StyleFileStrategy());
|
|
2057
|
-
}
|
|
2058
|
-
/** 添加自定义策略 */
|
|
2059
|
-
addStrategy(strategy) {
|
|
2060
|
-
this.strategies.push(strategy);
|
|
2061
|
-
}
|
|
2062
|
-
/** 查找匹配的策略 */
|
|
2063
|
-
findStrategy(moduleName) {
|
|
2064
|
-
for (const strategy of this.strategies) {
|
|
2065
|
-
if (strategy.matches(moduleName)) {
|
|
2066
|
-
return strategy;
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
return null;
|
|
2070
|
-
}
|
|
2071
|
-
}, _class4);
|
|
2072
|
-
|
|
2073
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-required-imports/index.ts
|
|
2074
|
-
function resolveRequiredImports(ctx) {
|
|
2075
|
-
const processedModules = /* @__PURE__ */ new Set();
|
|
2076
|
-
let hasProcessedImports = false;
|
|
2077
|
-
const strategyManager = new ImportStrategyManager();
|
|
2078
|
-
if (ctx.inputType === "sfc") {
|
|
2079
|
-
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
|
|
2080
|
-
}
|
|
2081
|
-
function resolveRequiredImport(path9) {
|
|
2082
|
-
const { node } = path9;
|
|
2083
|
-
const originalModuleName = node.source.value.toLowerCase();
|
|
2084
|
-
const strategy = strategyManager.findStrategy(originalModuleName);
|
|
2085
|
-
if (strategy) {
|
|
2086
|
-
const result = strategy.process(path9, ctx, originalModuleName);
|
|
2087
|
-
if (result.shouldReplaceSource && result.newSource) {
|
|
2088
|
-
node.source.value = result.newSource;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
const normalizedModuleName = node.source.value.toLowerCase();
|
|
2092
|
-
mergeImports(node, ctx, normalizedModuleName);
|
|
2093
|
-
if (processedModules.has(normalizedModuleName) && !path9.removed) {
|
|
2094
|
-
path9.remove();
|
|
2095
|
-
return;
|
|
2096
|
-
}
|
|
2097
|
-
processedModules.add(normalizedModuleName);
|
|
2098
|
-
if (!hasProcessedImports) {
|
|
2099
|
-
const required = createRequiredImports(ctx);
|
|
2100
|
-
if (strategy) {
|
|
2101
|
-
const result = strategy.process(path9, ctx, originalModuleName);
|
|
2102
|
-
if (result.shouldRemove) {
|
|
2103
|
-
path9.replaceWithMultiple(required);
|
|
2104
|
-
} else if (normalizedModuleName === PACKAGE_NAME.react) {
|
|
2105
|
-
path9.insertAfter(required);
|
|
2106
|
-
} else {
|
|
2107
|
-
path9.insertBefore(required);
|
|
2108
|
-
}
|
|
2109
|
-
} else {
|
|
2110
|
-
if (normalizedModuleName === PACKAGE_NAME.react) {
|
|
2111
|
-
path9.insertAfter(required);
|
|
2112
|
-
} else {
|
|
2113
|
-
path9.insertBefore(required);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
hasProcessedImports = true;
|
|
2117
|
-
}
|
|
2118
|
-
if (strategy) {
|
|
2119
|
-
const result = strategy.process(path9, ctx, originalModuleName);
|
|
2120
|
-
if (result.shouldRemove && !path9.removed) {
|
|
2121
|
-
path9.remove();
|
|
2122
|
-
return;
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
replaceVueSuffix(ctx, node.source);
|
|
2126
|
-
}
|
|
2127
|
-
return {
|
|
2128
|
-
// 兜底:无 ImportDeclaration 的文件也要能注入必需依赖。
|
|
2129
|
-
Program: {
|
|
2130
|
-
exit(path9) {
|
|
2131
|
-
if (hasProcessedImports) return;
|
|
2132
|
-
const required = createRequiredImports(ctx);
|
|
2133
|
-
path9.unshiftContainer("body", required);
|
|
2134
|
-
hasProcessedImports = true;
|
|
2135
|
-
}
|
|
2136
|
-
},
|
|
2137
|
-
ImportDeclaration(path9) {
|
|
2138
|
-
resolveRequiredImport(path9);
|
|
2139
|
-
}
|
|
2140
|
-
};
|
|
2141
|
-
}
|
|
2142
|
-
function mergeImports(currentNode, ctx, moduleName) {
|
|
2143
|
-
const ctxImportItems = ctx.imports.get(moduleName);
|
|
2144
|
-
if (!_optionalChain([ctxImportItems, 'optionalAccess', _58 => _58.length])) {
|
|
2145
|
-
return;
|
|
2146
|
-
}
|
|
2147
|
-
const currentImports = /* @__PURE__ */ new Set();
|
|
2148
|
-
for (const spec of currentNode.specifiers) {
|
|
2149
|
-
if (t18.isImportSpecifier(spec) && t18.isIdentifier(spec.imported)) {
|
|
2150
|
-
currentImports.add(spec.imported.name);
|
|
2151
|
-
}
|
|
2152
|
-
if (t18.isImportDefaultSpecifier(spec) && t18.isIdentifier(spec.local)) {
|
|
2153
|
-
currentImports.add(spec.local.name);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
for (const item of ctxImportItems) {
|
|
2157
|
-
if (currentImports.has(item.name)) {
|
|
2158
|
-
continue;
|
|
2159
|
-
}
|
|
2160
|
-
const local = t18.identifier(item.name);
|
|
2161
|
-
const newNode = !item.onDemand ? t18.importDefaultSpecifier(local) : t18.importSpecifier(local, local);
|
|
2162
|
-
currentNode.specifiers.push(newNode);
|
|
2163
|
-
}
|
|
2164
|
-
ctx.imports.delete(moduleName);
|
|
2165
|
-
}
|
|
2166
|
-
function createRequiredImports(ctx) {
|
|
2167
|
-
const result = [];
|
|
2168
|
-
const importMap = {};
|
|
2169
|
-
ctx.imports.forEach((items, moduleName) => {
|
|
2170
|
-
const specifier = [];
|
|
2171
|
-
for (const item of items) {
|
|
2172
|
-
const local = t18.identifier(item.name);
|
|
2173
|
-
if (!item.onDemand) {
|
|
2174
|
-
specifier.push(t18.importDefaultSpecifier(local));
|
|
2175
|
-
} else {
|
|
2176
|
-
specifier.push(t18.importSpecifier(local, local));
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
importMap[moduleName] = specifier;
|
|
2180
|
-
});
|
|
2181
|
-
for (const name in importMap) {
|
|
2182
|
-
const specifiers = importMap[name];
|
|
2183
|
-
const importDecl = t18.importDeclaration(specifiers, t18.stringLiteral(name));
|
|
2184
|
-
if (name === PACKAGE_NAME.react) {
|
|
2185
|
-
result.unshift(importDecl);
|
|
2186
|
-
} else {
|
|
2187
|
-
result.push(importDecl);
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
return result;
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-static-hoisting.ts
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
1876
|
// src/core/transform/sfc/script/shared/babel-utils.ts
|
|
2197
1877
|
|
|
2198
1878
|
function findRootVariablePath(path9) {
|
|
2199
1879
|
const rootId = findRootIdentifier(path9.node);
|
|
2200
|
-
if (!_optionalChain([rootId, 'optionalAccess',
|
|
1880
|
+
if (!_optionalChain([rootId, 'optionalAccess', _58 => _58.name])) return null;
|
|
2201
1881
|
const binding = path9.scope.getBinding(rootId.name);
|
|
2202
1882
|
if (!binding) return null;
|
|
2203
1883
|
const rootPath = getVariableDeclaratorPath(binding.path);
|
|
@@ -2205,10 +1885,10 @@ function findRootVariablePath(path9) {
|
|
|
2205
1885
|
}
|
|
2206
1886
|
function findRootIdentifier(node) {
|
|
2207
1887
|
let current = node.object;
|
|
2208
|
-
while (
|
|
1888
|
+
while (t16.isMemberExpression(current) || t16.isOptionalMemberExpression(current)) {
|
|
2209
1889
|
current = current.object;
|
|
2210
1890
|
}
|
|
2211
|
-
return
|
|
1891
|
+
return t16.isIdentifier(current) ? current : null;
|
|
2212
1892
|
}
|
|
2213
1893
|
function getVariableDeclaratorPath(path9) {
|
|
2214
1894
|
if (path9.isVariableDeclarator()) {
|
|
@@ -2292,14 +1972,14 @@ function isPropertyName(path9) {
|
|
|
2292
1972
|
}
|
|
2293
1973
|
function replaceCallName(callExp, identifierName) {
|
|
2294
1974
|
const { callee } = callExp;
|
|
2295
|
-
if (!
|
|
1975
|
+
if (!t16.isIdentifier(callee)) return;
|
|
2296
1976
|
callee.name = identifierName;
|
|
2297
1977
|
if (callee.loc) {
|
|
2298
1978
|
callee.loc.identifierName = identifierName;
|
|
2299
1979
|
}
|
|
2300
1980
|
}
|
|
2301
1981
|
function replaceIdName(id, newName) {
|
|
2302
|
-
if (!
|
|
1982
|
+
if (!t16.isIdentifier(id)) return;
|
|
2303
1983
|
id.name = newName;
|
|
2304
1984
|
if (id.loc) {
|
|
2305
1985
|
id.loc.identifierName = newName;
|
|
@@ -2309,69 +1989,110 @@ function stringValueToTSType(ctx, input, tsTypeAnnotation7) {
|
|
|
2309
1989
|
const { filename, scriptData } = ctx;
|
|
2310
1990
|
const exp = stringToExpr(input, scriptData.lang, filename);
|
|
2311
1991
|
const ts = expressionToTSType(exp);
|
|
2312
|
-
return tsTypeAnnotation7 ?
|
|
1992
|
+
return tsTypeAnnotation7 ? t16.tsTypeAnnotation(ts) : ts;
|
|
2313
1993
|
}
|
|
2314
1994
|
function expressionToTSType(exp) {
|
|
2315
|
-
if (
|
|
2316
|
-
if (
|
|
2317
|
-
if (
|
|
2318
|
-
if (
|
|
2319
|
-
if (
|
|
1995
|
+
if (t16.isStringLiteral(exp)) return t16.tsStringKeyword();
|
|
1996
|
+
if (t16.isNumericLiteral(exp)) return t16.tsNumberKeyword();
|
|
1997
|
+
if (t16.isBooleanLiteral(exp)) return t16.tsBooleanKeyword();
|
|
1998
|
+
if (t16.isArrayExpression(exp)) return t16.tsArrayType(t16.tsAnyKeyword());
|
|
1999
|
+
if (t16.isObjectExpression(exp)) {
|
|
2320
2000
|
const members = [];
|
|
2321
2001
|
for (const p of exp.properties) {
|
|
2322
|
-
if (!
|
|
2002
|
+
if (!t16.isObjectProperty(p)) continue;
|
|
2323
2003
|
let key;
|
|
2324
|
-
if (
|
|
2325
|
-
else if (
|
|
2004
|
+
if (t16.isIdentifier(p.key)) key = p.key.name;
|
|
2005
|
+
else if (t16.isStringLiteral(p.key)) key = p.key.value;
|
|
2326
2006
|
if (!key) continue;
|
|
2327
|
-
if (
|
|
2007
|
+
if (t16.isExpression(p.value)) {
|
|
2328
2008
|
members.push(
|
|
2329
|
-
|
|
2009
|
+
t16.tsPropertySignature(t16.identifier(key), t16.tsTypeAnnotation(expressionToTSType(p.value)))
|
|
2330
2010
|
);
|
|
2331
2011
|
} else {
|
|
2332
2012
|
members.push(
|
|
2333
|
-
|
|
2013
|
+
t16.tsPropertySignature(t16.identifier(key), t16.tsTypeAnnotation(t16.tsAnyKeyword()))
|
|
2334
2014
|
);
|
|
2335
2015
|
}
|
|
2336
2016
|
}
|
|
2337
|
-
return
|
|
2017
|
+
return t16.tsTypeLiteral(members);
|
|
2338
2018
|
}
|
|
2339
|
-
if (
|
|
2019
|
+
if (t16.isArrowFunctionExpression(exp) || t16.isFunctionExpression(exp)) {
|
|
2340
2020
|
const params = exp.params.map((p, i) => {
|
|
2341
|
-
const id =
|
|
2342
|
-
id.typeAnnotation =
|
|
2021
|
+
const id = t16.isIdentifier(p) ? t16.identifier(p.name) : t16.identifier(`arg${i}`);
|
|
2022
|
+
id.typeAnnotation = t16.tsTypeAnnotation(t16.tsAnyKeyword());
|
|
2343
2023
|
return id;
|
|
2344
2024
|
});
|
|
2345
|
-
let returnType =
|
|
2346
|
-
if (
|
|
2025
|
+
let returnType = t16.tsAnyKeyword();
|
|
2026
|
+
if (t16.isBlockStatement(exp.body)) {
|
|
2347
2027
|
for (const stmt of exp.body.body) {
|
|
2348
|
-
if (
|
|
2349
|
-
if (
|
|
2028
|
+
if (t16.isReturnStatement(stmt) && stmt.argument) {
|
|
2029
|
+
if (t16.isExpression(stmt.argument)) {
|
|
2350
2030
|
returnType = expressionToTSType(stmt.argument);
|
|
2351
2031
|
break;
|
|
2352
2032
|
}
|
|
2353
2033
|
}
|
|
2354
2034
|
}
|
|
2355
|
-
} else if (
|
|
2035
|
+
} else if (t16.isExpression(exp.body)) {
|
|
2356
2036
|
returnType = expressionToTSType(exp.body);
|
|
2357
2037
|
}
|
|
2358
|
-
return
|
|
2038
|
+
return t16.tsFunctionType(null, params, t16.tsTypeAnnotation(returnType));
|
|
2359
2039
|
}
|
|
2360
|
-
return
|
|
2040
|
+
return t16.tsAnyKeyword();
|
|
2361
2041
|
}
|
|
2362
2042
|
function isCalleeNamed(node, name) {
|
|
2363
|
-
if (!
|
|
2043
|
+
if (!t16.isIdentifier(node.callee)) {
|
|
2364
2044
|
return false;
|
|
2365
2045
|
}
|
|
2366
2046
|
return node.callee.name === name;
|
|
2367
2047
|
}
|
|
2368
2048
|
function isSimpleLiteral(node) {
|
|
2369
2049
|
if (!node) return false;
|
|
2370
|
-
if (
|
|
2050
|
+
if (t16.isStringLiteral(node) || t16.isNumericLiteral(node) || t16.isBooleanLiteral(node) || t16.isNullLiteral(node) || t16.isRegExpLiteral(node) || t16.isBigIntLiteral(node) || t16.isDecimalLiteral(node)) {
|
|
2371
2051
|
return true;
|
|
2372
2052
|
}
|
|
2373
2053
|
return false;
|
|
2374
2054
|
}
|
|
2055
|
+
function forkNode(node, deep = true) {
|
|
2056
|
+
const newNode = t16.cloneNode(node, deep);
|
|
2057
|
+
newNode.leadingComments = node.leadingComments;
|
|
2058
|
+
newNode.innerComments = node.innerComments;
|
|
2059
|
+
newNode.trailingComments = null;
|
|
2060
|
+
cleanNodeLoc(node);
|
|
2061
|
+
cleanNodeComments(node);
|
|
2062
|
+
return newNode;
|
|
2063
|
+
}
|
|
2064
|
+
function cleanNodeLoc(node) {
|
|
2065
|
+
node.start = null;
|
|
2066
|
+
node.end = null;
|
|
2067
|
+
node.loc = null;
|
|
2068
|
+
}
|
|
2069
|
+
function cleanNodeComments(node) {
|
|
2070
|
+
node.leadingComments = null;
|
|
2071
|
+
node.innerComments = null;
|
|
2072
|
+
node.trailingComments = null;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-global-type-chunk.ts
|
|
2076
|
+
function resolveGlobalTypeChunks(path9, ir) {
|
|
2077
|
+
if (!_optionalChain([path9, 'access', _59 => _59.parentPath, 'optionalAccess', _60 => _60.isProgram, 'call', _61 => _61()])) {
|
|
2078
|
+
return;
|
|
2079
|
+
}
|
|
2080
|
+
const forked = forkNode(path9.node);
|
|
2081
|
+
ir.tsTypes.push(forked);
|
|
2082
|
+
path9.remove();
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-module-chunk.ts
|
|
2086
|
+
|
|
2087
|
+
function resolveModuleChunks(path9, ir) {
|
|
2088
|
+
const forked = forkNode(path9.node);
|
|
2089
|
+
if (t17.isImportDeclaration(forked)) {
|
|
2090
|
+
ir.imports.push(forked);
|
|
2091
|
+
} else if (t17.isExportDeclaration(forked)) {
|
|
2092
|
+
ir.exports.push(forked);
|
|
2093
|
+
}
|
|
2094
|
+
path9.remove();
|
|
2095
|
+
}
|
|
2375
2096
|
|
|
2376
2097
|
// src/core/transform/sfc/script/shared/metadata-utils.ts
|
|
2377
2098
|
var META_KEY = "__vureact_metadata";
|
|
@@ -2389,43 +2110,289 @@ function setScriptNodeMeta(node, opts) {
|
|
|
2389
2110
|
node[META_KEY] = opts;
|
|
2390
2111
|
}
|
|
2391
2112
|
|
|
2392
|
-
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-static-
|
|
2393
|
-
function
|
|
2113
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-static-const-chunk.ts
|
|
2114
|
+
function resolveStaticConstChunks(path9, ir) {
|
|
2115
|
+
const { node, parentPath } = path9;
|
|
2116
|
+
const parent = parentPath.node;
|
|
2117
|
+
if (!isVariableDeclTopLevel(path9) || !parentPath.isVariableDeclaration() || parent.kind !== "const" || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
const forked = forkNode(parent);
|
|
2121
|
+
ir.statement.global.push(forked);
|
|
2122
|
+
parentPath.remove();
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/index.ts
|
|
2126
|
+
function resolveASTChunks(ctx, ast) {
|
|
2394
2127
|
const scriptIR = getScriptIR(ctx);
|
|
2395
2128
|
if (ctx.inputType !== "sfc") {
|
|
2396
2129
|
return {};
|
|
2397
2130
|
}
|
|
2131
|
+
scriptIR.statement.local = ast;
|
|
2398
2132
|
return {
|
|
2133
|
+
// 提取 import/export
|
|
2399
2134
|
"ImportDeclaration|ExportDeclaration"(path9) {
|
|
2400
|
-
|
|
2401
|
-
scriptIR.imports.push(path9.node);
|
|
2402
|
-
} else if (t20.isExportDeclaration(path9.node)) {
|
|
2403
|
-
scriptIR.exports.push(path9.node);
|
|
2404
|
-
}
|
|
2405
|
-
path9.remove();
|
|
2135
|
+
resolveModuleChunks(path9, scriptIR);
|
|
2406
2136
|
},
|
|
2137
|
+
// 提取全局类型声明
|
|
2407
2138
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path9) {
|
|
2408
|
-
|
|
2409
|
-
scriptIR.tsTypes.push(path9.node);
|
|
2410
|
-
path9.remove();
|
|
2411
|
-
}
|
|
2139
|
+
resolveGlobalTypeChunks(path9, scriptIR);
|
|
2412
2140
|
},
|
|
2141
|
+
// 提升顶层常量声明
|
|
2413
2142
|
VariableDeclarator(path9) {
|
|
2143
|
+
resolveStaticConstChunks(path9, scriptIR);
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-runtime-imports/index.ts
|
|
2149
|
+
|
|
2150
|
+
|
|
2151
|
+
// src/core/transform/shared.ts
|
|
2152
|
+
function recordImport(ctx, pkg, name, onDemand = true) {
|
|
2153
|
+
const { imports } = ctx;
|
|
2154
|
+
if (isTypeOnlyImport(name)) {
|
|
2155
|
+
name = `type ${name}`;
|
|
2156
|
+
}
|
|
2157
|
+
if (imports.has(pkg)) {
|
|
2158
|
+
const list = imports.get(pkg);
|
|
2159
|
+
const foundItem = list.find((item) => item.name === name);
|
|
2160
|
+
if (!foundItem) {
|
|
2161
|
+
list.push({ name, onDemand });
|
|
2162
|
+
}
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
imports.set(pkg, [{ name, onDemand }]);
|
|
2166
|
+
}
|
|
2167
|
+
function isTypeOnlyImport(name) {
|
|
2168
|
+
const arr = [REACT_API_MAP.ReactNode];
|
|
2169
|
+
return arr.includes(name);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
// src/core/transform/sfc/script/shared/replace-vue-suffix.ts
|
|
2173
|
+
function replaceVueSuffix(node) {
|
|
2174
|
+
if (!node.value.endsWith(".vue")) return;
|
|
2175
|
+
const replaced = node.value.replace(/.vue$/, "");
|
|
2176
|
+
node.value = replaced;
|
|
2177
|
+
node.extra = {
|
|
2178
|
+
rawValue: replaced,
|
|
2179
|
+
// fix: 当 minified: true 的情况下,输出内容丢失引号
|
|
2180
|
+
raw: `'${replaced}'`
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-runtime-imports/import-strategies.ts
|
|
2185
|
+
var VueRouterStrategy = class {
|
|
2186
|
+
matches(moduleName) {
|
|
2187
|
+
return moduleName === "vue-router" || moduleName.startsWith("vue-router/");
|
|
2188
|
+
}
|
|
2189
|
+
process() {
|
|
2190
|
+
return {
|
|
2191
|
+
shouldReplaceSource: true,
|
|
2192
|
+
newSource: PACKAGE_NAME.router,
|
|
2193
|
+
shouldRemove: false,
|
|
2194
|
+
shouldInjectRuntimeImports: false
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
var VueEcosystemStrategy = class {
|
|
2199
|
+
matches(moduleName) {
|
|
2200
|
+
if (moduleName.startsWith(".") || moduleName.startsWith("/") || moduleName.startsWith("file:")) {
|
|
2201
|
+
return false;
|
|
2202
|
+
}
|
|
2203
|
+
if (moduleName === "vue-router" || moduleName.startsWith("vue-router/")) {
|
|
2204
|
+
return false;
|
|
2205
|
+
}
|
|
2206
|
+
if (moduleName.startsWith("@vue/")) {
|
|
2207
|
+
return true;
|
|
2208
|
+
}
|
|
2209
|
+
for (const pkg of VUE_PACKAGES) {
|
|
2210
|
+
if (moduleName === pkg || moduleName.startsWith(`${pkg}/`)) {
|
|
2211
|
+
return true;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
return false;
|
|
2215
|
+
}
|
|
2216
|
+
process() {
|
|
2217
|
+
return {
|
|
2218
|
+
shouldReplaceSource: false,
|
|
2219
|
+
shouldRemove: true,
|
|
2220
|
+
shouldInjectRuntimeImports: true
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
var StyleFileStrategy = (_class3 = class {constructor() { _class3.prototype.__init5.call(this); }
|
|
2225
|
+
__init5() {this.regExp = /\.(less|sass|scss)$/i}
|
|
2226
|
+
matches(moduleName) {
|
|
2227
|
+
return this.regExp.test(moduleName);
|
|
2228
|
+
}
|
|
2229
|
+
process(path9, ctx) {
|
|
2230
|
+
if (!ctx.preprocessStyles) {
|
|
2231
|
+
return {};
|
|
2232
|
+
}
|
|
2233
|
+
const importSource = path9.node.source.value;
|
|
2234
|
+
if (typeof importSource !== "string") {
|
|
2235
|
+
return {};
|
|
2236
|
+
}
|
|
2237
|
+
return {
|
|
2238
|
+
shouldReplaceSource: true,
|
|
2239
|
+
newSource: importSource.replace(this.regExp, ".css"),
|
|
2240
|
+
shouldRemove: false,
|
|
2241
|
+
shouldInjectRuntimeImports: false
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
}, _class3);
|
|
2245
|
+
|
|
2246
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-runtime-imports/import-strategy-manager.ts
|
|
2247
|
+
var ImportStrategyManager = (_class4 = class {
|
|
2248
|
+
__init6() {this.strategies = []}
|
|
2249
|
+
constructor() {;_class4.prototype.__init6.call(this);
|
|
2250
|
+
this.strategies.push(new VueRouterStrategy());
|
|
2251
|
+
this.strategies.push(new VueEcosystemStrategy());
|
|
2252
|
+
this.strategies.push(new StyleFileStrategy());
|
|
2253
|
+
}
|
|
2254
|
+
/** 添加自定义策略 */
|
|
2255
|
+
addStrategy(strategy) {
|
|
2256
|
+
this.strategies.push(strategy);
|
|
2257
|
+
}
|
|
2258
|
+
/** 查找匹配的策略 */
|
|
2259
|
+
findStrategy(moduleName) {
|
|
2260
|
+
for (const strategy of this.strategies) {
|
|
2261
|
+
if (strategy.matches(moduleName)) {
|
|
2262
|
+
return strategy;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
}, _class4);
|
|
2268
|
+
|
|
2269
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-runtime-imports/index.ts
|
|
2270
|
+
function resolveRuntimeImports(ctx) {
|
|
2271
|
+
if (ctx.inputType === "sfc") {
|
|
2272
|
+
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
|
|
2273
|
+
}
|
|
2274
|
+
const strategyManager = new ImportStrategyManager();
|
|
2275
|
+
const processedModules = /* @__PURE__ */ new Set();
|
|
2276
|
+
let hasImports = false;
|
|
2277
|
+
return {
|
|
2278
|
+
ImportDeclaration(path9) {
|
|
2414
2279
|
const { node } = path9;
|
|
2415
|
-
|
|
2280
|
+
const originalModuleName = node.source.value.toLowerCase();
|
|
2281
|
+
const strategy = strategyManager.findStrategy(originalModuleName);
|
|
2282
|
+
let strategyResult = null;
|
|
2283
|
+
if (strategy) {
|
|
2284
|
+
strategyResult = strategy.process(path9, ctx, originalModuleName);
|
|
2285
|
+
if (strategyResult.shouldReplaceSource && strategyResult.newSource) {
|
|
2286
|
+
node.source.value = strategyResult.newSource;
|
|
2287
|
+
}
|
|
2288
|
+
if (strategyResult.shouldRemove && !path9.removed) {
|
|
2289
|
+
path9.remove();
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
replaceVueSuffix(node.source);
|
|
2294
|
+
const finalModuleName = node.source.value.toLowerCase();
|
|
2295
|
+
if (processedModules.has(finalModuleName) && !path9.removed) {
|
|
2296
|
+
path9.remove();
|
|
2416
2297
|
return;
|
|
2417
2298
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2299
|
+
processedModules.add(finalModuleName);
|
|
2300
|
+
mergeImports(node, ctx, finalModuleName);
|
|
2301
|
+
if (!hasImports) {
|
|
2302
|
+
const importNodes = createImportNodes(ctx);
|
|
2303
|
+
if (importNodes.length) {
|
|
2304
|
+
if (_optionalChain([strategyResult, 'optionalAccess', _62 => _62.shouldInjectRuntimeImports])) {
|
|
2305
|
+
path9.insertAfter(importNodes);
|
|
2306
|
+
} else if (finalModuleName === PACKAGE_NAME.react) {
|
|
2307
|
+
path9.insertAfter(importNodes);
|
|
2308
|
+
} else {
|
|
2309
|
+
forkLeadingComments(importNodes[0], node);
|
|
2310
|
+
path9.insertBefore(importNodes);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
hasImports = true;
|
|
2314
|
+
}
|
|
2315
|
+
},
|
|
2316
|
+
// 兜底:无 ImportDeclaration 的文件也要能注入必需依赖。
|
|
2317
|
+
Program: {
|
|
2318
|
+
exit(path9) {
|
|
2319
|
+
if (hasImports) return;
|
|
2320
|
+
hasImports = true;
|
|
2321
|
+
const { node } = path9;
|
|
2322
|
+
const importNodes = createImportNodes(ctx);
|
|
2323
|
+
if (!importNodes.length) return;
|
|
2324
|
+
forkLeadingComments(importNodes[0], node);
|
|
2325
|
+
path9.unshiftContainer("body", importNodes);
|
|
2326
|
+
}
|
|
2422
2327
|
}
|
|
2423
2328
|
};
|
|
2424
2329
|
}
|
|
2425
|
-
function
|
|
2330
|
+
function mergeImports(currentNode, ctx, moduleName) {
|
|
2331
|
+
const ctxImportItems = ctx.imports.get(moduleName);
|
|
2332
|
+
if (!_optionalChain([ctxImportItems, 'optionalAccess', _63 => _63.length])) {
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
const currentImports = /* @__PURE__ */ new Set();
|
|
2336
|
+
for (const spec of currentNode.specifiers) {
|
|
2337
|
+
if (t18.isImportSpecifier(spec) && t18.isIdentifier(spec.imported)) {
|
|
2338
|
+
currentImports.add(spec.imported.name);
|
|
2339
|
+
}
|
|
2340
|
+
if (t18.isImportDefaultSpecifier(spec) && t18.isIdentifier(spec.local)) {
|
|
2341
|
+
currentImports.add(spec.local.name);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
for (const item of ctxImportItems) {
|
|
2345
|
+
if (currentImports.has(item.name)) {
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
const local = t18.identifier(item.name);
|
|
2349
|
+
const newNode = !item.onDemand ? t18.importDefaultSpecifier(local) : t18.importSpecifier(local, local);
|
|
2350
|
+
currentNode.specifiers.push(newNode);
|
|
2351
|
+
}
|
|
2352
|
+
ctx.imports.delete(moduleName);
|
|
2353
|
+
}
|
|
2354
|
+
function createImportNodes(ctx) {
|
|
2355
|
+
const result = [];
|
|
2356
|
+
const importDeclarations = Array.from(ctx.imports).map(([moduleName, items]) => {
|
|
2357
|
+
const specifiers = items.map((item) => {
|
|
2358
|
+
const local = t18.identifier(item.name);
|
|
2359
|
+
return item.onDemand ? t18.importSpecifier(local, local) : t18.importDefaultSpecifier(local);
|
|
2360
|
+
});
|
|
2361
|
+
return t18.importDeclaration(specifiers, t18.stringLiteral(moduleName));
|
|
2362
|
+
});
|
|
2363
|
+
for (const decl of importDeclarations) {
|
|
2364
|
+
const name = decl.source.value;
|
|
2365
|
+
if (name === PACKAGE_NAME.react) {
|
|
2366
|
+
result.unshift(decl);
|
|
2367
|
+
} else {
|
|
2368
|
+
result.push(decl);
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
return result;
|
|
2372
|
+
}
|
|
2373
|
+
function forkLeadingComments(target, source) {
|
|
2374
|
+
const { leadingComments } = source;
|
|
2375
|
+
if (!_optionalChain([leadingComments, 'optionalAccess', _64 => _64.length])) {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
const newComments = [...leadingComments];
|
|
2379
|
+
source.leadingComments = null;
|
|
2380
|
+
target.leadingComments = newComments;
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-sfc-css-import.ts
|
|
2384
|
+
|
|
2385
|
+
function resolveSfcCssImport(ctx) {
|
|
2426
2386
|
if (ctx.inputType !== "sfc") return;
|
|
2427
2387
|
const scriptIR = getScriptIR(ctx);
|
|
2428
|
-
|
|
2388
|
+
const { filePath, moduleName } = ctx.styleData;
|
|
2389
|
+
if (!filePath) return;
|
|
2390
|
+
const styleFilename = normalizePath(filePath).split("/").pop();
|
|
2391
|
+
const importDecl = t19.importDeclaration(
|
|
2392
|
+
!moduleName ? [] : [t19.importDefaultSpecifier(t19.identifier(moduleName))],
|
|
2393
|
+
t19.stringLiteral(`./${styleFilename}`)
|
|
2394
|
+
);
|
|
2395
|
+
scriptIR.imports.push(importDecl);
|
|
2429
2396
|
}
|
|
2430
2397
|
|
|
2431
2398
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-async-component.ts
|
|
@@ -2445,11 +2412,11 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
2445
2412
|
};
|
|
2446
2413
|
}
|
|
2447
2414
|
function checkIsUnsupported(ctx, arg) {
|
|
2448
|
-
if (
|
|
2415
|
+
if (t20.isFunction(arg)) {
|
|
2449
2416
|
checkIsDynamicImport(ctx, arg);
|
|
2450
|
-
} else if (
|
|
2417
|
+
} else if (t20.isObjectExpression(arg)) {
|
|
2451
2418
|
const { value } = arg.properties.find(
|
|
2452
|
-
(p) =>
|
|
2419
|
+
(p) => t20.isObjectProperty(p) && t20.isIdentifier(p.key) && p.key.name === "loader"
|
|
2453
2420
|
);
|
|
2454
2421
|
checkIsDynamicImport(ctx, value);
|
|
2455
2422
|
if (arg.properties.length > 1) {
|
|
@@ -2460,32 +2427,32 @@ function checkIsUnsupported(ctx, arg) {
|
|
|
2460
2427
|
function checkIsDynamicImport(ctx, node) {
|
|
2461
2428
|
const { scriptData, filename } = ctx;
|
|
2462
2429
|
const warnIsNotImport = (target) => {
|
|
2463
|
-
if (!target || !
|
|
2430
|
+
if (!target || !t20.isImport(target)) {
|
|
2464
2431
|
logger.error(
|
|
2465
2432
|
`Only ES module dynamic imports are supported. You must use and return import('...').`,
|
|
2466
2433
|
{
|
|
2467
2434
|
source: scriptData.source,
|
|
2468
2435
|
file: filename,
|
|
2469
|
-
loc: _optionalChain([target, 'optionalAccess',
|
|
2436
|
+
loc: _optionalChain([target, 'optionalAccess', _65 => _65.loc]) || {}
|
|
2470
2437
|
}
|
|
2471
2438
|
);
|
|
2472
2439
|
}
|
|
2473
2440
|
};
|
|
2474
|
-
if (
|
|
2441
|
+
if (t20.isFunction(node)) {
|
|
2475
2442
|
checkIsDynamicImport(ctx, node.body);
|
|
2476
2443
|
return;
|
|
2477
2444
|
}
|
|
2478
|
-
if (
|
|
2445
|
+
if (t20.isBlockStatement(node)) {
|
|
2479
2446
|
const [returnSmt] = node.body;
|
|
2480
|
-
if (
|
|
2447
|
+
if (t20.isReturnStatement(returnSmt)) {
|
|
2481
2448
|
warnIsNotImport(returnSmt.argument);
|
|
2482
2449
|
}
|
|
2483
2450
|
return;
|
|
2484
2451
|
}
|
|
2485
|
-
if (
|
|
2452
|
+
if (t20.isCallExpression(node)) {
|
|
2486
2453
|
warnIsNotImport(node.callee);
|
|
2487
|
-
if (
|
|
2488
|
-
replaceVueSuffix(
|
|
2454
|
+
if (t20.isStringLiteral(node.arguments[0])) {
|
|
2455
|
+
replaceVueSuffix(node.arguments[0]);
|
|
2489
2456
|
}
|
|
2490
2457
|
return;
|
|
2491
2458
|
}
|
|
@@ -2518,7 +2485,7 @@ function pushToGlobalScope(path9, ctx) {
|
|
|
2518
2485
|
declarationPath = declarationPath.parentPath;
|
|
2519
2486
|
}
|
|
2520
2487
|
let fullNode;
|
|
2521
|
-
if (_optionalChain([declarationPath, 'optionalAccess',
|
|
2488
|
+
if (_optionalChain([declarationPath, 'optionalAccess', _66 => _66.isVariableDeclaration, 'call', _67 => _67()])) {
|
|
2522
2489
|
fullNode = declarationPath.node;
|
|
2523
2490
|
declarationPath.remove();
|
|
2524
2491
|
} else if (path9.parentPath.isVariableDeclarator()) {
|
|
@@ -2538,19 +2505,19 @@ function pushToGlobalScope(path9, ctx) {
|
|
|
2538
2505
|
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
2539
2506
|
|
|
2540
2507
|
function createUseCallback(body, deps) {
|
|
2541
|
-
return
|
|
2508
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useCallback), [
|
|
2542
2509
|
body,
|
|
2543
|
-
_nullishCoalesce(deps, () => (
|
|
2510
|
+
_nullishCoalesce(deps, () => ( t21.arrayExpression([])))
|
|
2544
2511
|
]);
|
|
2545
2512
|
}
|
|
2546
2513
|
function createUseMemo(body, deps) {
|
|
2547
|
-
return
|
|
2548
|
-
|
|
2549
|
-
_nullishCoalesce(deps, () => (
|
|
2514
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useMemo), [
|
|
2515
|
+
t21.arrowFunctionExpression([], body),
|
|
2516
|
+
_nullishCoalesce(deps, () => ( t21.arrayExpression([])))
|
|
2550
2517
|
]);
|
|
2551
2518
|
}
|
|
2552
2519
|
function createUseImperativeHandle(refId, init) {
|
|
2553
|
-
return
|
|
2520
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
2554
2521
|
}
|
|
2555
2522
|
|
|
2556
2523
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
@@ -2571,16 +2538,16 @@ function resolveDefineExpose(ctx) {
|
|
|
2571
2538
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
2572
2539
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
2573
2540
|
recordImport(ctx, adapter.package, adapter.target);
|
|
2574
|
-
if (!
|
|
2541
|
+
if (!t22.isObjectExpression(expose) && !t22.isFunction(expose)) {
|
|
2575
2542
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
2576
2543
|
file: filename,
|
|
2577
2544
|
loc: expose.loc,
|
|
2578
2545
|
source: scriptData.source
|
|
2579
2546
|
});
|
|
2580
2547
|
}
|
|
2581
|
-
const init = !
|
|
2548
|
+
const init = !t22.isFunction(expose) ? t22.arrowFunctionExpression([], expose) : expose;
|
|
2582
2549
|
const { forwardRef } = scriptData;
|
|
2583
|
-
const newNode = createUseImperativeHandle(
|
|
2550
|
+
const newNode = createUseImperativeHandle(t22.identifier(forwardRef.refField), init);
|
|
2584
2551
|
forwardRef.enabled = true;
|
|
2585
2552
|
path9.replaceWith(newNode);
|
|
2586
2553
|
}
|
|
@@ -2602,20 +2569,20 @@ function resolveDefineOptions(ctx) {
|
|
|
2602
2569
|
logger.warn("defineOptions was found, but no options were provided.", {
|
|
2603
2570
|
source: scriptData.source,
|
|
2604
2571
|
file: filename,
|
|
2605
|
-
loc: _optionalChain([node, 'optionalAccess',
|
|
2572
|
+
loc: _optionalChain([node, 'optionalAccess', _68 => _68.loc])
|
|
2606
2573
|
});
|
|
2607
2574
|
path9.remove();
|
|
2608
2575
|
return;
|
|
2609
2576
|
}
|
|
2610
|
-
if (!
|
|
2577
|
+
if (!t23.isObjectExpression(options)) {
|
|
2611
2578
|
logger.warn("Argument for defineOptions must be an object expression.", {
|
|
2612
2579
|
source: scriptData.source,
|
|
2613
2580
|
file: filename,
|
|
2614
|
-
loc: _optionalChain([options, 'optionalAccess',
|
|
2581
|
+
loc: _optionalChain([options, 'optionalAccess', _69 => _69.loc])
|
|
2615
2582
|
});
|
|
2616
2583
|
} else {
|
|
2617
2584
|
for (const prop of options.properties) {
|
|
2618
|
-
if (!
|
|
2585
|
+
if (!t23.isObjectProperty(prop) || !t23.isIdentifier(prop.key)) {
|
|
2619
2586
|
continue;
|
|
2620
2587
|
}
|
|
2621
2588
|
extractName(prop, ctx);
|
|
@@ -2629,14 +2596,14 @@ function extractName(prop, ctx) {
|
|
|
2629
2596
|
if (ctx.compName) return;
|
|
2630
2597
|
const { filename, scriptData } = ctx;
|
|
2631
2598
|
if (!prop.computed && prop.key.name === "name") {
|
|
2632
|
-
if (
|
|
2599
|
+
if (t23.isStringLiteral(prop.value)) {
|
|
2633
2600
|
ctx.compName = prop.value.value;
|
|
2634
2601
|
return;
|
|
2635
2602
|
}
|
|
2636
2603
|
logger.error(`name must be a string type, but got ${prop.value.type}`, {
|
|
2637
2604
|
source: scriptData.source,
|
|
2638
2605
|
file: filename,
|
|
2639
|
-
loc: _optionalChain([prop, 'access',
|
|
2606
|
+
loc: _optionalChain([prop, 'access', _70 => _70.key, 'optionalAccess', _71 => _71.loc])
|
|
2640
2607
|
});
|
|
2641
2608
|
}
|
|
2642
2609
|
}
|
|
@@ -2656,7 +2623,7 @@ function resolveEmitCalls(ctx) {
|
|
|
2656
2623
|
CallExpression(path9) {
|
|
2657
2624
|
const { node } = path9;
|
|
2658
2625
|
const { filename, templateData, scriptData } = ctx;
|
|
2659
|
-
if (!
|
|
2626
|
+
if (!t24.isIdentifier(node.callee)) return;
|
|
2660
2627
|
const { name } = node.callee;
|
|
2661
2628
|
const checkIfFromDefineEmits = () => {
|
|
2662
2629
|
let result = false;
|
|
@@ -2668,7 +2635,7 @@ function resolveEmitCalls(ctx) {
|
|
|
2668
2635
|
const binding = path9.scope.getBinding(name);
|
|
2669
2636
|
if (binding) {
|
|
2670
2637
|
const parent = binding.path.node;
|
|
2671
|
-
if (
|
|
2638
|
+
if (t24.isVariableDeclarator(parent) && t24.isCallExpression(parent.init) && t24.isIdentifier(parent.init.callee)) {
|
|
2672
2639
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
2673
2640
|
}
|
|
2674
2641
|
}
|
|
@@ -2677,20 +2644,20 @@ function resolveEmitCalls(ctx) {
|
|
|
2677
2644
|
};
|
|
2678
2645
|
if (!checkIfFromDefineEmits()) return;
|
|
2679
2646
|
const [callee, ...args] = node.arguments;
|
|
2680
|
-
const eventName =
|
|
2647
|
+
const eventName = t24.isStringLiteral(callee) ? formatEmitEventName(callee.value) : void 0;
|
|
2681
2648
|
if (!eventName) {
|
|
2682
|
-
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess',
|
|
2649
|
+
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess', _72 => _72.type])}, expression will be removed`, {
|
|
2683
2650
|
file: filename,
|
|
2684
2651
|
source: scriptData.source,
|
|
2685
|
-
loc: _optionalChain([callee, 'optionalAccess',
|
|
2652
|
+
loc: _optionalChain([callee, 'optionalAccess', _73 => _73.loc])
|
|
2686
2653
|
});
|
|
2687
2654
|
path9.remove();
|
|
2688
2655
|
return;
|
|
2689
2656
|
}
|
|
2690
|
-
const propCall =
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2657
|
+
const propCall = t24.optionalCallExpression(
|
|
2658
|
+
t24.optionalMemberExpression(
|
|
2659
|
+
t24.identifier(ctx.propField),
|
|
2660
|
+
t24.identifier(eventName),
|
|
2694
2661
|
false,
|
|
2695
2662
|
true
|
|
2696
2663
|
),
|
|
@@ -2712,21 +2679,21 @@ function resolveEmitCalls(ctx) {
|
|
|
2712
2679
|
|
|
2713
2680
|
function cloneCallableParams(params) {
|
|
2714
2681
|
const cloneCallableParam = (param, index) => {
|
|
2715
|
-
if (
|
|
2682
|
+
if (t25.isRestElement(param)) {
|
|
2716
2683
|
const arg = param.argument;
|
|
2717
|
-
const name =
|
|
2718
|
-
const rest =
|
|
2719
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
2684
|
+
const name = t25.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
2685
|
+
const rest = t25.restElement(t25.identifier(name));
|
|
2686
|
+
rest.typeAnnotation = param.typeAnnotation || (t25.isIdentifier(arg) ? arg.typeAnnotation : null) || t25.tsTypeAnnotation(t25.tsArrayType(t25.tsAnyKeyword()));
|
|
2720
2687
|
return rest;
|
|
2721
2688
|
}
|
|
2722
|
-
if (
|
|
2723
|
-
const id =
|
|
2689
|
+
if (t25.isIdentifier(param)) {
|
|
2690
|
+
const id = t25.identifier(param.name || `arg${index}`);
|
|
2724
2691
|
id.optional = param.optional;
|
|
2725
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
2692
|
+
id.typeAnnotation = param.typeAnnotation || t25.tsTypeAnnotation(t25.tsAnyKeyword());
|
|
2726
2693
|
return id;
|
|
2727
2694
|
}
|
|
2728
|
-
const fallback =
|
|
2729
|
-
fallback.typeAnnotation =
|
|
2695
|
+
const fallback = t25.identifier(`arg${index}`);
|
|
2696
|
+
fallback.typeAnnotation = t25.tsTypeAnnotation(t25.tsAnyKeyword());
|
|
2730
2697
|
return fallback;
|
|
2731
2698
|
};
|
|
2732
2699
|
return params.map(cloneCallableParam);
|
|
@@ -2736,18 +2703,18 @@ function cloneCallableParams(params) {
|
|
|
2736
2703
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
2737
2704
|
return {
|
|
2738
2705
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path9) {
|
|
2739
|
-
if (!
|
|
2706
|
+
if (!t26.isProgram(path9.parent)) return;
|
|
2740
2707
|
const { node } = path9;
|
|
2741
|
-
if (
|
|
2742
|
-
const typeLiteral =
|
|
2708
|
+
if (t26.isTSInterfaceDeclaration(node)) {
|
|
2709
|
+
const typeLiteral = t26.tsTypeLiteral(node.body.body);
|
|
2743
2710
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
2744
2711
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
2745
|
-
if (resolved &&
|
|
2712
|
+
if (resolved && t26.isTSTypeLiteral(resolved)) {
|
|
2746
2713
|
node.body.body = resolved.members;
|
|
2747
2714
|
}
|
|
2748
2715
|
return;
|
|
2749
2716
|
}
|
|
2750
|
-
if (
|
|
2717
|
+
if (t26.isTSTypeAliasDeclaration(node)) {
|
|
2751
2718
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
2752
2719
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
2753
2720
|
if (resolved) {
|
|
@@ -2758,55 +2725,55 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
2758
2725
|
};
|
|
2759
2726
|
}
|
|
2760
2727
|
function resolveTopLevelEmitType(tsType) {
|
|
2761
|
-
if (
|
|
2728
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2762
2729
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
2763
2730
|
}
|
|
2764
|
-
if (
|
|
2731
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2765
2732
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2766
2733
|
return tsType;
|
|
2767
2734
|
}
|
|
2768
2735
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
2769
|
-
return
|
|
2736
|
+
return t26.tsTypeReference(
|
|
2770
2737
|
tsType.typeName,
|
|
2771
|
-
|
|
2738
|
+
t26.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2772
2739
|
);
|
|
2773
2740
|
}
|
|
2774
|
-
if (
|
|
2741
|
+
if (t26.isTSIntersectionType(tsType)) {
|
|
2775
2742
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2776
2743
|
if (!types.length) return null;
|
|
2777
2744
|
if (types.length === 1) return types[0];
|
|
2778
|
-
return
|
|
2745
|
+
return t26.tsIntersectionType(types);
|
|
2779
2746
|
}
|
|
2780
|
-
if (
|
|
2747
|
+
if (t26.isTSUnionType(tsType)) {
|
|
2781
2748
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2782
2749
|
if (!types.length) return null;
|
|
2783
2750
|
if (types.length === 1) return types[0];
|
|
2784
|
-
return
|
|
2751
|
+
return t26.tsUnionType(types);
|
|
2785
2752
|
}
|
|
2786
|
-
if (
|
|
2753
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2787
2754
|
const members = [];
|
|
2788
2755
|
for (const member of tsType.members) {
|
|
2789
|
-
if (
|
|
2756
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2790
2757
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2791
2758
|
continue;
|
|
2792
2759
|
}
|
|
2793
2760
|
members.push(member);
|
|
2794
2761
|
}
|
|
2795
2762
|
if (!members.length) return null;
|
|
2796
|
-
return
|
|
2763
|
+
return t26.tsTypeLiteral(members);
|
|
2797
2764
|
}
|
|
2798
|
-
if (
|
|
2765
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2799
2766
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2800
2767
|
if (!props.length) return null;
|
|
2801
|
-
return
|
|
2768
|
+
return t26.tsTypeLiteral(props);
|
|
2802
2769
|
}
|
|
2803
2770
|
return tsType;
|
|
2804
2771
|
}
|
|
2805
2772
|
function resolveDefineEmitsIface(path9, ctx) {
|
|
2806
2773
|
const { node } = path9;
|
|
2807
2774
|
const [runtimeArg] = node.arguments;
|
|
2808
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2809
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
2775
|
+
const tsParams = _optionalChain([node, 'access', _74 => _74.typeParameters, 'optionalAccess', _75 => _75.params]);
|
|
2776
|
+
if (_optionalChain([tsParams, 'optionalAccess', _76 => _76.length])) {
|
|
2810
2777
|
processExplicitType(ctx, tsParams);
|
|
2811
2778
|
return;
|
|
2812
2779
|
}
|
|
@@ -2819,41 +2786,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
2819
2786
|
propsTSIface: { emitTypes }
|
|
2820
2787
|
} = ctx.scriptData;
|
|
2821
2788
|
const members = [];
|
|
2822
|
-
if (
|
|
2789
|
+
if (t26.isArrayExpression(runtimeArg)) {
|
|
2823
2790
|
for (const element of runtimeArg.elements) {
|
|
2824
|
-
if (!element || !
|
|
2791
|
+
if (!element || !t26.isStringLiteral(element)) continue;
|
|
2825
2792
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
2826
2793
|
const key = buildKey(handlerName);
|
|
2827
|
-
const fnType =
|
|
2794
|
+
const fnType = t26.tsFunctionType(
|
|
2828
2795
|
null,
|
|
2829
2796
|
[createRestAnyParam("args")],
|
|
2830
|
-
|
|
2797
|
+
t26.tsTypeAnnotation(t26.tsAnyKeyword())
|
|
2831
2798
|
);
|
|
2832
|
-
const prop =
|
|
2799
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2833
2800
|
prop.optional = true;
|
|
2834
2801
|
members.push(prop);
|
|
2835
2802
|
}
|
|
2836
2803
|
if (members.length) {
|
|
2837
|
-
emitTypes.push(
|
|
2804
|
+
emitTypes.push(t26.tsTypeLiteral(members));
|
|
2838
2805
|
}
|
|
2839
2806
|
return;
|
|
2840
2807
|
}
|
|
2841
|
-
if (
|
|
2808
|
+
if (t26.isObjectExpression(runtimeArg)) {
|
|
2842
2809
|
for (const prop of runtimeArg.properties) {
|
|
2843
|
-
if (!
|
|
2844
|
-
if (
|
|
2810
|
+
if (!t26.isObjectProperty(prop)) continue;
|
|
2811
|
+
if (t26.isSpreadElement(prop)) continue;
|
|
2845
2812
|
const rawName = resolvePropName(prop.key);
|
|
2846
2813
|
if (!rawName) continue;
|
|
2847
2814
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2848
2815
|
const key = buildKey(handlerName);
|
|
2849
|
-
const params =
|
|
2850
|
-
const fnType =
|
|
2851
|
-
const propSig =
|
|
2816
|
+
const params = t26.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
2817
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(t26.tsAnyKeyword()));
|
|
2818
|
+
const propSig = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2852
2819
|
propSig.optional = true;
|
|
2853
2820
|
members.push(propSig);
|
|
2854
2821
|
}
|
|
2855
2822
|
if (members.length) {
|
|
2856
|
-
emitTypes.push(
|
|
2823
|
+
emitTypes.push(t26.tsTypeLiteral(members));
|
|
2857
2824
|
}
|
|
2858
2825
|
}
|
|
2859
2826
|
}
|
|
@@ -2874,129 +2841,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
2874
2841
|
return `on${name}`;
|
|
2875
2842
|
}
|
|
2876
2843
|
function resolvePropName(key) {
|
|
2877
|
-
if (
|
|
2878
|
-
if (
|
|
2879
|
-
if (
|
|
2844
|
+
if (t26.isIdentifier(key)) return key.name;
|
|
2845
|
+
if (t26.isStringLiteral(key)) return key.value;
|
|
2846
|
+
if (t26.isNumericLiteral(key)) return String(key.value);
|
|
2880
2847
|
return null;
|
|
2881
2848
|
}
|
|
2882
2849
|
function buildKey(name) {
|
|
2883
|
-
return
|
|
2850
|
+
return t26.isValidIdentifier(name) ? t26.identifier(name) : t26.stringLiteral(name);
|
|
2884
2851
|
}
|
|
2885
2852
|
function createRestAnyParam(name) {
|
|
2886
|
-
const id =
|
|
2887
|
-
const rest =
|
|
2888
|
-
rest.typeAnnotation =
|
|
2853
|
+
const id = t26.identifier(name);
|
|
2854
|
+
const rest = t26.restElement(id);
|
|
2855
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(t26.tsArrayType(t26.tsAnyKeyword()));
|
|
2889
2856
|
return rest;
|
|
2890
2857
|
}
|
|
2891
2858
|
function resolveRuntimeTupleParams(value) {
|
|
2892
2859
|
const params = [];
|
|
2893
2860
|
value.elements.forEach((element, index) => {
|
|
2894
2861
|
if (!element) return;
|
|
2895
|
-
if (
|
|
2862
|
+
if (t26.isSpreadElement(element)) {
|
|
2896
2863
|
params.push(createRestAnyParam(`args${index}`));
|
|
2897
2864
|
return;
|
|
2898
2865
|
}
|
|
2899
|
-
if (
|
|
2900
|
-
const id =
|
|
2901
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
2866
|
+
if (t26.isIdentifier(element)) {
|
|
2867
|
+
const id = t26.identifier(element.name);
|
|
2868
|
+
id.typeAnnotation = element.typeAnnotation || t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2902
2869
|
params.push(id);
|
|
2903
2870
|
return;
|
|
2904
2871
|
}
|
|
2905
|
-
if (
|
|
2906
|
-
const id =
|
|
2907
|
-
id.typeAnnotation =
|
|
2872
|
+
if (t26.isTSAsExpression(element)) {
|
|
2873
|
+
const id = t26.identifier(`arg${index}`);
|
|
2874
|
+
id.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
2908
2875
|
params.push(id);
|
|
2909
2876
|
return;
|
|
2910
2877
|
}
|
|
2911
|
-
const fallback =
|
|
2912
|
-
fallback.typeAnnotation =
|
|
2878
|
+
const fallback = t26.identifier(`arg${index}`);
|
|
2879
|
+
fallback.typeAnnotation = t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2913
2880
|
params.push(fallback);
|
|
2914
2881
|
});
|
|
2915
2882
|
return params;
|
|
2916
2883
|
}
|
|
2917
2884
|
function resolveExplicitEmitType(tsType) {
|
|
2918
|
-
if (
|
|
2885
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2919
2886
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
2920
2887
|
}
|
|
2921
|
-
if (
|
|
2888
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2922
2889
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2923
2890
|
return tsType;
|
|
2924
2891
|
}
|
|
2925
2892
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
2926
|
-
return
|
|
2893
|
+
return t26.tsTypeReference(
|
|
2927
2894
|
tsType.typeName,
|
|
2928
|
-
|
|
2895
|
+
t26.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2929
2896
|
);
|
|
2930
2897
|
}
|
|
2931
|
-
if (
|
|
2898
|
+
if (t26.isTSIntersectionType(tsType)) {
|
|
2932
2899
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2933
2900
|
if (!types.length) return null;
|
|
2934
2901
|
if (types.length === 1) return types[0];
|
|
2935
|
-
return
|
|
2902
|
+
return t26.tsIntersectionType(types);
|
|
2936
2903
|
}
|
|
2937
|
-
if (
|
|
2904
|
+
if (t26.isTSUnionType(tsType)) {
|
|
2938
2905
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2939
2906
|
if (!types.length) return null;
|
|
2940
2907
|
if (types.length === 1) return types[0];
|
|
2941
|
-
return
|
|
2908
|
+
return t26.tsUnionType(types);
|
|
2942
2909
|
}
|
|
2943
|
-
if (
|
|
2910
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2944
2911
|
const members = [];
|
|
2945
2912
|
for (const member of tsType.members) {
|
|
2946
|
-
if (
|
|
2913
|
+
if (t26.isTSPropertySignature(member)) {
|
|
2947
2914
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
2948
2915
|
if (prop) members.push(prop);
|
|
2949
2916
|
continue;
|
|
2950
2917
|
}
|
|
2951
|
-
if (
|
|
2918
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2952
2919
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2953
2920
|
continue;
|
|
2954
2921
|
}
|
|
2955
2922
|
}
|
|
2956
2923
|
if (!members.length) return null;
|
|
2957
|
-
return
|
|
2924
|
+
return t26.tsTypeLiteral(members);
|
|
2958
2925
|
}
|
|
2959
|
-
if (
|
|
2926
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2960
2927
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2961
2928
|
if (!props.length) return null;
|
|
2962
|
-
return
|
|
2929
|
+
return t26.tsTypeLiteral(props);
|
|
2963
2930
|
}
|
|
2964
2931
|
return tsType;
|
|
2965
2932
|
}
|
|
2966
2933
|
function hasEmitsSignatureInType(tsType) {
|
|
2967
|
-
if (
|
|
2934
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2968
2935
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
2969
2936
|
}
|
|
2970
|
-
if (
|
|
2937
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2971
2938
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2972
2939
|
return false;
|
|
2973
2940
|
}
|
|
2974
2941
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
2975
2942
|
}
|
|
2976
|
-
if (
|
|
2943
|
+
if (t26.isTSIntersectionType(tsType) || t26.isTSUnionType(tsType)) {
|
|
2977
2944
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
2978
2945
|
}
|
|
2979
|
-
if (
|
|
2946
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2980
2947
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
2981
2948
|
}
|
|
2982
|
-
if (
|
|
2949
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2983
2950
|
return isEmitsCallable(tsType.parameters);
|
|
2984
2951
|
}
|
|
2985
2952
|
return false;
|
|
2986
2953
|
}
|
|
2987
2954
|
function hasEmitsSignatureInMember(member) {
|
|
2988
|
-
if (
|
|
2955
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2989
2956
|
return isEmitsCallable(member.parameters);
|
|
2990
2957
|
}
|
|
2991
2958
|
return false;
|
|
2992
2959
|
}
|
|
2993
2960
|
function isEmitsCallable(parameters) {
|
|
2994
2961
|
const [eventParam] = parameters;
|
|
2995
|
-
if (!eventParam || !
|
|
2962
|
+
if (!eventParam || !t26.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2996
2963
|
return false;
|
|
2997
2964
|
}
|
|
2998
2965
|
const { typeAnnotation } = eventParam;
|
|
2999
|
-
if (
|
|
2966
|
+
if (t26.isNoop(typeAnnotation)) return false;
|
|
3000
2967
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
3001
2968
|
}
|
|
3002
2969
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -3004,21 +2971,21 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3004
2971
|
if (!rawName) return null;
|
|
3005
2972
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3006
2973
|
const key = buildKey(handlerName);
|
|
3007
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
2974
|
+
const typeAnnotation = _optionalChain([member, 'access', _77 => _77.typeAnnotation, 'optionalAccess', _78 => _78.typeAnnotation]);
|
|
3008
2975
|
let params = [];
|
|
3009
|
-
let returnType =
|
|
3010
|
-
if (typeAnnotation &&
|
|
2976
|
+
let returnType = t26.tsAnyKeyword();
|
|
2977
|
+
if (typeAnnotation && t26.isTSFunctionType(typeAnnotation)) {
|
|
3011
2978
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3012
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
3013
|
-
} else if (typeAnnotation &&
|
|
2979
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _79 => _79.typeAnnotation, 'optionalAccess', _80 => _80.typeAnnotation]), () => ( returnType));
|
|
2980
|
+
} else if (typeAnnotation && t26.isTSTupleType(typeAnnotation)) {
|
|
3014
2981
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
3015
2982
|
} else if (typeAnnotation) {
|
|
3016
|
-
const id =
|
|
3017
|
-
id.typeAnnotation =
|
|
2983
|
+
const id = t26.identifier("value");
|
|
2984
|
+
id.typeAnnotation = t26.tsTypeAnnotation(typeAnnotation);
|
|
3018
2985
|
params = [id];
|
|
3019
2986
|
}
|
|
3020
|
-
const fnType =
|
|
3021
|
-
const prop =
|
|
2987
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(returnType));
|
|
2988
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
3022
2989
|
prop.optional = !!member.optional;
|
|
3023
2990
|
return prop;
|
|
3024
2991
|
}
|
|
@@ -3027,32 +2994,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
3027
2994
|
}
|
|
3028
2995
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
3029
2996
|
const [eventParam, ...restParams] = parameters;
|
|
3030
|
-
if (!eventParam || !
|
|
2997
|
+
if (!eventParam || !t26.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3031
2998
|
return [];
|
|
3032
2999
|
}
|
|
3033
3000
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
3034
|
-
if (
|
|
3001
|
+
if (t26.isNoop(paramTypeAnnotation)) return [];
|
|
3035
3002
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
3036
3003
|
if (!eventNames.length) return [];
|
|
3037
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
3004
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _81 => _81.typeAnnotation]), () => ( t26.tsAnyKeyword()));
|
|
3038
3005
|
return eventNames.map((eventName) => {
|
|
3039
3006
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
3040
3007
|
const key = buildKey(handlerName);
|
|
3041
3008
|
const params = cloneCallableParams(restParams);
|
|
3042
|
-
const fnType =
|
|
3043
|
-
const prop =
|
|
3009
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(returnType));
|
|
3010
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
3044
3011
|
prop.optional = true;
|
|
3045
3012
|
return prop;
|
|
3046
3013
|
});
|
|
3047
3014
|
}
|
|
3048
3015
|
function resolveEventNames(type) {
|
|
3049
|
-
if (
|
|
3016
|
+
if (t26.isTSLiteralType(type) && t26.isStringLiteral(type.literal)) {
|
|
3050
3017
|
return [type.literal.value];
|
|
3051
3018
|
}
|
|
3052
|
-
if (
|
|
3019
|
+
if (t26.isTSUnionType(type)) {
|
|
3053
3020
|
return type.types.flatMap(resolveEventNames);
|
|
3054
3021
|
}
|
|
3055
|
-
if (
|
|
3022
|
+
if (t26.isTSParenthesizedType(type)) {
|
|
3056
3023
|
return resolveEventNames(type.typeAnnotation);
|
|
3057
3024
|
}
|
|
3058
3025
|
return [];
|
|
@@ -3065,39 +3032,39 @@ function resolveTupleTypeParams(tuple) {
|
|
|
3065
3032
|
return params;
|
|
3066
3033
|
}
|
|
3067
3034
|
function resolveTupleElementParam(element, index) {
|
|
3068
|
-
const isNamedTuple = typeof
|
|
3035
|
+
const isNamedTuple = typeof t26.isTSNamedTupleMember === "function" && t26.isTSNamedTupleMember(element);
|
|
3069
3036
|
if (isNamedTuple) {
|
|
3070
3037
|
const tupleMember = element;
|
|
3071
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
3038
|
+
const name = _optionalChain([tupleMember, 'access', _82 => _82.label, 'optionalAccess', _83 => _83.name]) || `arg${index}`;
|
|
3072
3039
|
let innerType = tupleMember.elementType;
|
|
3073
3040
|
let optional = tupleMember.optional;
|
|
3074
|
-
if (
|
|
3041
|
+
if (t26.isTSOptionalType(innerType)) {
|
|
3075
3042
|
optional = true;
|
|
3076
3043
|
innerType = innerType.typeAnnotation;
|
|
3077
3044
|
}
|
|
3078
|
-
if (
|
|
3079
|
-
const rest =
|
|
3080
|
-
rest.typeAnnotation =
|
|
3045
|
+
if (t26.isTSRestType(innerType)) {
|
|
3046
|
+
const rest = t26.restElement(t26.identifier(name));
|
|
3047
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(innerType.typeAnnotation);
|
|
3081
3048
|
return rest;
|
|
3082
3049
|
}
|
|
3083
|
-
const id2 =
|
|
3050
|
+
const id2 = t26.identifier(name);
|
|
3084
3051
|
id2.optional = optional;
|
|
3085
|
-
id2.typeAnnotation =
|
|
3052
|
+
id2.typeAnnotation = t26.tsTypeAnnotation(innerType);
|
|
3086
3053
|
return id2;
|
|
3087
3054
|
}
|
|
3088
|
-
if (
|
|
3089
|
-
const rest =
|
|
3090
|
-
rest.typeAnnotation =
|
|
3055
|
+
if (t26.isTSRestType(element)) {
|
|
3056
|
+
const rest = t26.restElement(t26.identifier(`args${index}`));
|
|
3057
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
3091
3058
|
return rest;
|
|
3092
3059
|
}
|
|
3093
|
-
if (
|
|
3094
|
-
const id2 =
|
|
3060
|
+
if (t26.isTSOptionalType(element)) {
|
|
3061
|
+
const id2 = t26.identifier(`arg${index}`);
|
|
3095
3062
|
id2.optional = true;
|
|
3096
|
-
id2.typeAnnotation =
|
|
3063
|
+
id2.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
3097
3064
|
return id2;
|
|
3098
3065
|
}
|
|
3099
|
-
const id =
|
|
3100
|
-
id.typeAnnotation =
|
|
3066
|
+
const id = t26.identifier(`arg${index}`);
|
|
3067
|
+
id.typeAnnotation = t26.tsTypeAnnotation(element);
|
|
3101
3068
|
return id;
|
|
3102
3069
|
}
|
|
3103
3070
|
|
|
@@ -3106,8 +3073,8 @@ function resolveTupleElementParam(element, index) {
|
|
|
3106
3073
|
function resolveDefinePropsIface(path9, ctx) {
|
|
3107
3074
|
const { node } = path9;
|
|
3108
3075
|
const [runtimeArg] = node.arguments;
|
|
3109
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3110
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
3076
|
+
const tsParams = _optionalChain([node, 'access', _84 => _84.typeParameters, 'optionalAccess', _85 => _85.params]);
|
|
3077
|
+
if (_optionalChain([tsParams, 'optionalAccess', _86 => _86.length])) {
|
|
3111
3078
|
const { propsTSIface } = ctx.scriptData;
|
|
3112
3079
|
propsTSIface.propsTypes = tsParams;
|
|
3113
3080
|
return;
|
|
@@ -3122,38 +3089,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3122
3089
|
} = scriptData;
|
|
3123
3090
|
if (!runtimeArg) return;
|
|
3124
3091
|
const members = [];
|
|
3125
|
-
if (
|
|
3092
|
+
if (t27.isArrayExpression(runtimeArg)) {
|
|
3126
3093
|
for (const element of runtimeArg.elements) {
|
|
3127
|
-
if (!element || !
|
|
3128
|
-
const key =
|
|
3129
|
-
const prop =
|
|
3094
|
+
if (!element || !t27.isStringLiteral(element)) continue;
|
|
3095
|
+
const key = t27.isValidIdentifier(element.value) ? t27.identifier(element.value) : t27.stringLiteral(element.value);
|
|
3096
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
3130
3097
|
prop.optional = true;
|
|
3131
3098
|
members.push(prop);
|
|
3132
3099
|
}
|
|
3133
3100
|
if (members.length) {
|
|
3134
|
-
propsTypes.push(
|
|
3101
|
+
propsTypes.push(t27.tsTypeLiteral(members));
|
|
3135
3102
|
}
|
|
3136
3103
|
return;
|
|
3137
3104
|
}
|
|
3138
|
-
if (
|
|
3105
|
+
if (t27.isObjectExpression(runtimeArg)) {
|
|
3139
3106
|
for (const prop of runtimeArg.properties) {
|
|
3140
|
-
if (!
|
|
3141
|
-
if (
|
|
3107
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
3108
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
3142
3109
|
const key = prop.key;
|
|
3143
3110
|
let propName = null;
|
|
3144
|
-
if (
|
|
3145
|
-
if (
|
|
3146
|
-
if (
|
|
3111
|
+
if (t27.isIdentifier(key)) propName = key.name;
|
|
3112
|
+
if (t27.isStringLiteral(key)) propName = key.value;
|
|
3113
|
+
if (t27.isNumericLiteral(key)) propName = String(key.value);
|
|
3147
3114
|
if (!propName) continue;
|
|
3148
3115
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
3149
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
3150
|
-
const tsKey =
|
|
3151
|
-
const tsProp =
|
|
3116
|
+
const tsType = _nullishCoalesce(type, () => ( t27.tsAnyKeyword()));
|
|
3117
|
+
const tsKey = t27.isValidIdentifier(propName) ? t27.identifier(propName) : t27.stringLiteral(propName);
|
|
3118
|
+
const tsProp = t27.tsPropertySignature(tsKey, t27.tsTypeAnnotation(tsType));
|
|
3152
3119
|
tsProp.optional = !required;
|
|
3153
3120
|
members.push(tsProp);
|
|
3154
3121
|
}
|
|
3155
3122
|
if (members.length) {
|
|
3156
|
-
propsTypes.push(
|
|
3123
|
+
propsTypes.push(t27.tsTypeLiteral(members));
|
|
3157
3124
|
}
|
|
3158
3125
|
return;
|
|
3159
3126
|
}
|
|
@@ -3162,47 +3129,47 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3162
3129
|
{
|
|
3163
3130
|
source,
|
|
3164
3131
|
file: filename,
|
|
3165
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
3132
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _87 => _87.loc])
|
|
3166
3133
|
}
|
|
3167
3134
|
);
|
|
3168
3135
|
}
|
|
3169
3136
|
function resolveRuntimePropMeta(value) {
|
|
3170
|
-
if (
|
|
3137
|
+
if (t27.isIdentifier(value)) {
|
|
3171
3138
|
return {
|
|
3172
3139
|
type: mapRuntimeTypeToTSType(value),
|
|
3173
3140
|
required: false
|
|
3174
3141
|
};
|
|
3175
3142
|
}
|
|
3176
|
-
if (
|
|
3143
|
+
if (t27.isArrayExpression(value)) {
|
|
3177
3144
|
return {
|
|
3178
3145
|
type: resolveRuntimeUnionType(value),
|
|
3179
3146
|
required: false
|
|
3180
3147
|
};
|
|
3181
3148
|
}
|
|
3182
|
-
if (!
|
|
3149
|
+
if (!t27.isObjectExpression(value)) {
|
|
3183
3150
|
return { required: false };
|
|
3184
3151
|
}
|
|
3185
3152
|
let type;
|
|
3186
3153
|
let required = false;
|
|
3187
3154
|
for (const prop of value.properties) {
|
|
3188
|
-
if (!
|
|
3189
|
-
if (
|
|
3155
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
3156
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
3190
3157
|
const key = prop.key;
|
|
3191
|
-
const propName =
|
|
3158
|
+
const propName = t27.isIdentifier(key) ? key.name : t27.isStringLiteral(key) ? key.value : null;
|
|
3192
3159
|
if (!propName) continue;
|
|
3193
3160
|
if (propName === "type") {
|
|
3194
3161
|
const valueNode = prop.value;
|
|
3195
|
-
if (
|
|
3162
|
+
if (t27.isArrayExpression(valueNode)) {
|
|
3196
3163
|
type = resolveRuntimeUnionType(valueNode);
|
|
3197
3164
|
continue;
|
|
3198
3165
|
}
|
|
3199
|
-
if (
|
|
3166
|
+
if (t27.isIdentifier(valueNode)) {
|
|
3200
3167
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3201
3168
|
continue;
|
|
3202
3169
|
}
|
|
3203
3170
|
}
|
|
3204
3171
|
if (propName === "required") {
|
|
3205
|
-
if (
|
|
3172
|
+
if (t27.isBooleanLiteral(prop.value)) {
|
|
3206
3173
|
required = prop.value.value;
|
|
3207
3174
|
}
|
|
3208
3175
|
}
|
|
@@ -3212,34 +3179,34 @@ function resolveRuntimePropMeta(value) {
|
|
|
3212
3179
|
function resolveRuntimeUnionType(value) {
|
|
3213
3180
|
const types = [];
|
|
3214
3181
|
for (const element of value.elements) {
|
|
3215
|
-
if (!element || !
|
|
3182
|
+
if (!element || !t27.isIdentifier(element)) continue;
|
|
3216
3183
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3217
3184
|
if (resolved) types.push(resolved);
|
|
3218
3185
|
}
|
|
3219
|
-
if (!types.length) return
|
|
3186
|
+
if (!types.length) return t27.tsAnyKeyword();
|
|
3220
3187
|
if (types.length === 1) return types[0];
|
|
3221
|
-
return
|
|
3188
|
+
return t27.tsUnionType(types);
|
|
3222
3189
|
}
|
|
3223
3190
|
function mapRuntimeTypeToTSType(value) {
|
|
3224
3191
|
switch (value.name) {
|
|
3225
3192
|
case "String":
|
|
3226
|
-
return
|
|
3193
|
+
return t27.tsStringKeyword();
|
|
3227
3194
|
case "Number":
|
|
3228
|
-
return
|
|
3195
|
+
return t27.tsNumberKeyword();
|
|
3229
3196
|
case "Boolean":
|
|
3230
|
-
return
|
|
3197
|
+
return t27.tsBooleanKeyword();
|
|
3231
3198
|
case "Object":
|
|
3232
|
-
return
|
|
3199
|
+
return t27.tsTypeLiteral([]);
|
|
3233
3200
|
case "Array":
|
|
3234
|
-
return
|
|
3201
|
+
return t27.tsArrayType(t27.tsAnyKeyword());
|
|
3235
3202
|
case "Function":
|
|
3236
|
-
return
|
|
3203
|
+
return t27.tsFunctionType(null, [], t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
3237
3204
|
case "Symbol":
|
|
3238
|
-
return
|
|
3205
|
+
return t27.tsSymbolKeyword();
|
|
3239
3206
|
case "BigInt":
|
|
3240
|
-
return
|
|
3207
|
+
return t27.tsBigIntKeyword();
|
|
3241
3208
|
default:
|
|
3242
|
-
return
|
|
3209
|
+
return t27.tsAnyKeyword();
|
|
3243
3210
|
}
|
|
3244
3211
|
}
|
|
3245
3212
|
|
|
@@ -3254,19 +3221,19 @@ function resolveSlotsTopLevelTypes(ctx) {
|
|
|
3254
3221
|
}
|
|
3255
3222
|
return {
|
|
3256
3223
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path9) {
|
|
3257
|
-
if (!
|
|
3224
|
+
if (!t28.isProgram(path9.parent)) return;
|
|
3258
3225
|
const { node } = path9;
|
|
3259
|
-
if (
|
|
3260
|
-
const typeLiteral =
|
|
3226
|
+
if (t28.isTSInterfaceDeclaration(node)) {
|
|
3227
|
+
const typeLiteral = t28.tsTypeLiteral(node.body.body);
|
|
3261
3228
|
if (!hasSlotsSignatureInType(typeLiteral)) return;
|
|
3262
3229
|
const resolved = resolveSlotType(typeLiteral);
|
|
3263
|
-
if (resolved &&
|
|
3230
|
+
if (resolved && t28.isTSTypeLiteral(resolved)) {
|
|
3264
3231
|
node.body.body = resolved.members;
|
|
3265
3232
|
recordReactNode(ctx);
|
|
3266
3233
|
}
|
|
3267
3234
|
return;
|
|
3268
3235
|
}
|
|
3269
|
-
if (
|
|
3236
|
+
if (t28.isTSTypeAliasDeclaration(node)) {
|
|
3270
3237
|
if (!hasSlotsSignatureInType(node.typeAnnotation)) return;
|
|
3271
3238
|
const resolved = resolveSlotType(node.typeAnnotation);
|
|
3272
3239
|
if (resolved) {
|
|
@@ -3279,8 +3246,8 @@ function resolveSlotsTopLevelTypes(ctx) {
|
|
|
3279
3246
|
}
|
|
3280
3247
|
function resolveDefineSlotsIface(path9, ctx) {
|
|
3281
3248
|
const { node } = path9;
|
|
3282
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3283
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
3249
|
+
const tsParams = _optionalChain([node, 'access', _88 => _88.typeParameters, 'optionalAccess', _89 => _89.params]);
|
|
3250
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _90 => _90.length])) return;
|
|
3284
3251
|
const {
|
|
3285
3252
|
propsTSIface: { slotTypes }
|
|
3286
3253
|
} = ctx.scriptData;
|
|
@@ -3311,7 +3278,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
3311
3278
|
}
|
|
3312
3279
|
if (tsMembers.length) {
|
|
3313
3280
|
recordReactNode(ctx);
|
|
3314
|
-
slotTypes.push(
|
|
3281
|
+
slotTypes.push(t28.tsTypeLiteral(tsMembers));
|
|
3315
3282
|
}
|
|
3316
3283
|
}
|
|
3317
3284
|
function recordReactNode(ctx) {
|
|
@@ -3321,32 +3288,32 @@ function recordReactNode(ctx) {
|
|
|
3321
3288
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
|
|
3322
3289
|
}
|
|
3323
3290
|
function resolveSlotType(tsType) {
|
|
3324
|
-
if (
|
|
3291
|
+
if (t28.isTSParenthesizedType(tsType)) {
|
|
3325
3292
|
return resolveSlotType(tsType.typeAnnotation);
|
|
3326
3293
|
}
|
|
3327
|
-
if (
|
|
3294
|
+
if (t28.isTSTypeReference(tsType)) {
|
|
3328
3295
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3329
3296
|
return tsType;
|
|
3330
3297
|
}
|
|
3331
3298
|
const params = tsType.typeParameters.params.map((param) => resolveSlotType(param)).filter(Boolean);
|
|
3332
|
-
return
|
|
3299
|
+
return t28.tsTypeReference(
|
|
3333
3300
|
tsType.typeName,
|
|
3334
|
-
|
|
3301
|
+
t28.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3335
3302
|
);
|
|
3336
3303
|
}
|
|
3337
|
-
if (
|
|
3304
|
+
if (t28.isTSIntersectionType(tsType)) {
|
|
3338
3305
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3339
3306
|
if (!types.length) return null;
|
|
3340
3307
|
if (types.length === 1) return types[0];
|
|
3341
|
-
return
|
|
3308
|
+
return t28.tsIntersectionType(types);
|
|
3342
3309
|
}
|
|
3343
|
-
if (
|
|
3310
|
+
if (t28.isTSUnionType(tsType)) {
|
|
3344
3311
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3345
3312
|
if (!types.length) return null;
|
|
3346
3313
|
if (types.length === 1) return types[0];
|
|
3347
|
-
return
|
|
3314
|
+
return t28.tsUnionType(types);
|
|
3348
3315
|
}
|
|
3349
|
-
if (
|
|
3316
|
+
if (t28.isTSTypeLiteral(tsType)) {
|
|
3350
3317
|
const members = [];
|
|
3351
3318
|
for (const member of tsType.members) {
|
|
3352
3319
|
const resolved = resolveSlotPropFromMember(member);
|
|
@@ -3357,111 +3324,111 @@ function resolveSlotType(tsType) {
|
|
|
3357
3324
|
members.push(member);
|
|
3358
3325
|
}
|
|
3359
3326
|
if (!members.length) return null;
|
|
3360
|
-
return
|
|
3327
|
+
return t28.tsTypeLiteral(members);
|
|
3361
3328
|
}
|
|
3362
|
-
if (
|
|
3329
|
+
if (t28.isTSFunctionType(tsType)) {
|
|
3363
3330
|
const props = buildSlotPropSignature(
|
|
3364
3331
|
SLOT_DEFAULT_NAME,
|
|
3365
3332
|
cloneCallableParams(tsType.parameters),
|
|
3366
3333
|
false
|
|
3367
3334
|
);
|
|
3368
|
-
return
|
|
3335
|
+
return t28.tsTypeLiteral([props]);
|
|
3369
3336
|
}
|
|
3370
3337
|
return tsType;
|
|
3371
3338
|
}
|
|
3372
3339
|
function hasSlotsSignatureInType(tsType) {
|
|
3373
|
-
if (
|
|
3340
|
+
if (t28.isTSParenthesizedType(tsType)) {
|
|
3374
3341
|
return hasSlotsSignatureInType(tsType.typeAnnotation);
|
|
3375
3342
|
}
|
|
3376
|
-
if (
|
|
3343
|
+
if (t28.isTSTypeReference(tsType)) {
|
|
3377
3344
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3378
3345
|
return false;
|
|
3379
3346
|
}
|
|
3380
3347
|
return tsType.typeParameters.params.some(hasSlotsSignatureInType);
|
|
3381
3348
|
}
|
|
3382
|
-
if (
|
|
3349
|
+
if (t28.isTSIntersectionType(tsType) || t28.isTSUnionType(tsType)) {
|
|
3383
3350
|
return tsType.types.some(hasSlotsSignatureInType);
|
|
3384
3351
|
}
|
|
3385
|
-
if (
|
|
3352
|
+
if (t28.isTSTypeLiteral(tsType)) {
|
|
3386
3353
|
return tsType.members.some(hasSlotsSignatureInMember);
|
|
3387
3354
|
}
|
|
3388
|
-
if (
|
|
3355
|
+
if (t28.isTSFunctionType(tsType)) {
|
|
3389
3356
|
return true;
|
|
3390
3357
|
}
|
|
3391
3358
|
return false;
|
|
3392
3359
|
}
|
|
3393
3360
|
function hasSlotsSignatureInMember(member) {
|
|
3394
|
-
if (
|
|
3395
|
-
if (
|
|
3396
|
-
if (
|
|
3397
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3361
|
+
if (t28.isTSMethodSignature(member)) return true;
|
|
3362
|
+
if (t28.isTSCallSignatureDeclaration(member)) return true;
|
|
3363
|
+
if (t28.isTSPropertySignature(member)) {
|
|
3364
|
+
const typeAnnotation = _optionalChain([member, 'access', _91 => _91.typeAnnotation, 'optionalAccess', _92 => _92.typeAnnotation]);
|
|
3398
3365
|
return !!(typeAnnotation && resolveCallableType(typeAnnotation));
|
|
3399
3366
|
}
|
|
3400
3367
|
return false;
|
|
3401
3368
|
}
|
|
3402
3369
|
function resolveSlotPropFromMember(member) {
|
|
3403
|
-
if (
|
|
3370
|
+
if (t28.isTSMethodSignature(member)) {
|
|
3404
3371
|
const rawName = resolvePropName2(member.key);
|
|
3405
3372
|
if (!rawName) return null;
|
|
3406
3373
|
const params = cloneCallableParams(member.parameters);
|
|
3407
3374
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3408
3375
|
}
|
|
3409
|
-
if (
|
|
3376
|
+
if (t28.isTSPropertySignature(member)) {
|
|
3410
3377
|
const rawName = resolvePropName2(member.key);
|
|
3411
3378
|
if (!rawName) return null;
|
|
3412
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3379
|
+
const typeAnnotation = _optionalChain([member, 'access', _93 => _93.typeAnnotation, 'optionalAccess', _94 => _94.typeAnnotation]);
|
|
3413
3380
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
3414
3381
|
if (!callable) return null;
|
|
3415
3382
|
const params = cloneCallableParams(callable.parameters);
|
|
3416
3383
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3417
3384
|
}
|
|
3418
|
-
if (
|
|
3385
|
+
if (t28.isTSCallSignatureDeclaration(member)) {
|
|
3419
3386
|
const params = cloneCallableParams(member.parameters);
|
|
3420
3387
|
return buildSlotPropSignature(SLOT_DEFAULT_NAME, params, true);
|
|
3421
3388
|
}
|
|
3422
3389
|
return null;
|
|
3423
3390
|
}
|
|
3424
3391
|
function resolveCallableType(tsType) {
|
|
3425
|
-
if (
|
|
3426
|
-
if (
|
|
3392
|
+
if (t28.isTSFunctionType(tsType)) return tsType;
|
|
3393
|
+
if (t28.isTSParenthesizedType(tsType)) return resolveCallableType(tsType.typeAnnotation);
|
|
3427
3394
|
return null;
|
|
3428
3395
|
}
|
|
3429
3396
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3430
3397
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3431
|
-
const key =
|
|
3432
|
-
const reactNodeType =
|
|
3433
|
-
|
|
3398
|
+
const key = t28.isValidIdentifier(propName) ? t28.identifier(propName) : t28.stringLiteral(propName);
|
|
3399
|
+
const reactNodeType = t28.tsTypeAnnotation(
|
|
3400
|
+
t28.tsTypeReference(t28.identifier(REACT_API_MAP.ReactNode))
|
|
3434
3401
|
);
|
|
3435
3402
|
let typeAnnotation;
|
|
3436
3403
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3437
3404
|
typeAnnotation = reactNodeType;
|
|
3438
3405
|
} else {
|
|
3439
|
-
const fnType =
|
|
3440
|
-
typeAnnotation =
|
|
3406
|
+
const fnType = t28.tsFunctionType(null, params, reactNodeType);
|
|
3407
|
+
typeAnnotation = t28.tsTypeAnnotation(fnType);
|
|
3441
3408
|
}
|
|
3442
|
-
const prop =
|
|
3409
|
+
const prop = t28.tsPropertySignature(key, typeAnnotation);
|
|
3443
3410
|
prop.optional = optional;
|
|
3444
3411
|
return prop;
|
|
3445
3412
|
}
|
|
3446
3413
|
function createSlotScopeParam(props, ctx) {
|
|
3447
|
-
const paramId =
|
|
3414
|
+
const paramId = t28.identifier(SLOT_FN_PARAM_NAME);
|
|
3448
3415
|
const propsSigns = [];
|
|
3449
3416
|
const { reactiveBindings } = ctx.templateData;
|
|
3450
3417
|
props.forEach(({ prop, tsType }) => {
|
|
3451
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
3418
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _95 => _95[prop], 'optionalAccess', _96 => _96.value]);
|
|
3452
3419
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3453
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3454
|
-
const key =
|
|
3455
|
-
const propSign =
|
|
3420
|
+
const typeAnnotation = foundBindingTypes ? t28.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
3421
|
+
const key = t28.isValidIdentifier(prop) ? t28.identifier(prop) : t28.stringLiteral(prop);
|
|
3422
|
+
const propSign = t28.tsPropertySignature(key, typeAnnotation);
|
|
3456
3423
|
propsSigns.push(propSign);
|
|
3457
3424
|
});
|
|
3458
|
-
paramId.typeAnnotation =
|
|
3425
|
+
paramId.typeAnnotation = t28.tsTypeAnnotation(t28.tsTypeLiteral(propsSigns));
|
|
3459
3426
|
return paramId;
|
|
3460
3427
|
}
|
|
3461
3428
|
function resolvePropName2(key) {
|
|
3462
|
-
if (
|
|
3463
|
-
if (
|
|
3464
|
-
if (
|
|
3429
|
+
if (t28.isIdentifier(key)) return key.name;
|
|
3430
|
+
if (t28.isStringLiteral(key)) return key.value;
|
|
3431
|
+
if (t28.isNumericLiteral(key)) return String(key.value);
|
|
3465
3432
|
return null;
|
|
3466
3433
|
}
|
|
3467
3434
|
|
|
@@ -3513,9 +3480,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3513
3480
|
}
|
|
3514
3481
|
const n = ctx.compName || "Comp";
|
|
3515
3482
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
3516
|
-
const typeNode =
|
|
3517
|
-
const typeAliasDecl =
|
|
3518
|
-
const exportDecl =
|
|
3483
|
+
const typeNode = t29.tsIntersectionType(tsTypes);
|
|
3484
|
+
const typeAliasDecl = t29.tsTypeAliasDeclaration(t29.identifier(ns), null, typeNode);
|
|
3485
|
+
const exportDecl = t29.exportNamedDeclaration(typeAliasDecl);
|
|
3519
3486
|
propsTSIface.name = ns;
|
|
3520
3487
|
const scriptIR = getScriptIR(ctx);
|
|
3521
3488
|
scriptIR.exports.push(exportDecl);
|
|
@@ -3531,9 +3498,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3531
3498
|
var TRACE_MAX_DEPTH = 20;
|
|
3532
3499
|
function analyzeDeps(node, ctx, parentPath) {
|
|
3533
3500
|
if (!parentPath) {
|
|
3534
|
-
return
|
|
3501
|
+
return t30.arrayExpression([]);
|
|
3535
3502
|
}
|
|
3536
|
-
const isFnExpr =
|
|
3503
|
+
const isFnExpr = t30.isArrowFunctionExpression(node) || t30.isFunctionExpression(node);
|
|
3537
3504
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
3538
3505
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
3539
3506
|
const reactiveStateApis = getReactiveStateApis();
|
|
@@ -3544,13 +3511,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3544
3511
|
}
|
|
3545
3512
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
3546
3513
|
if (analyzeTargetPath) {
|
|
3547
|
-
if (
|
|
3514
|
+
if (t30.isMemberExpression(analyzeTarget) || t30.isOptionalMemberExpression(analyzeTarget)) {
|
|
3548
3515
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
3549
3516
|
if (rootId) {
|
|
3550
3517
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
3551
3518
|
processedIdentifiers.add(rootId);
|
|
3552
3519
|
}
|
|
3553
|
-
} else if (
|
|
3520
|
+
} else if (t30.isIdentifier(analyzeTarget)) {
|
|
3554
3521
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
3555
3522
|
}
|
|
3556
3523
|
}
|
|
@@ -3601,55 +3568,55 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3601
3568
|
}
|
|
3602
3569
|
}
|
|
3603
3570
|
function normalizeDependencyExpr(path9, rootName) {
|
|
3604
|
-
if (
|
|
3605
|
-
return
|
|
3571
|
+
if (t30.isIdentifier(path9.node)) {
|
|
3572
|
+
return t30.identifier(path9.node.name);
|
|
3606
3573
|
}
|
|
3607
|
-
if (
|
|
3574
|
+
if (t30.isMemberExpression(path9.node) || t30.isOptionalMemberExpression(path9.node)) {
|
|
3608
3575
|
const normalizedExp = normalizeMemberForCallSite(path9, path9.node);
|
|
3609
|
-
const safeExp =
|
|
3576
|
+
const safeExp = t30.isMemberExpression(normalizedExp) || t30.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
3610
3577
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
3611
|
-
return
|
|
3578
|
+
return t30.cloneNode(safeExp, true);
|
|
3612
3579
|
}
|
|
3613
|
-
return
|
|
3580
|
+
return t30.identifier(rootName);
|
|
3614
3581
|
}
|
|
3615
3582
|
return null;
|
|
3616
3583
|
}
|
|
3617
3584
|
function normalizeSourcedDependency(exp) {
|
|
3618
|
-
if (
|
|
3619
|
-
return
|
|
3585
|
+
if (t30.isIdentifier(exp)) {
|
|
3586
|
+
return t30.identifier(exp.name);
|
|
3620
3587
|
}
|
|
3621
|
-
if (
|
|
3588
|
+
if (t30.isMemberExpression(exp) || t30.isOptionalMemberExpression(exp)) {
|
|
3622
3589
|
const root = findRootIdentifier(exp);
|
|
3623
3590
|
if (!root) return null;
|
|
3624
|
-
const safeExp =
|
|
3591
|
+
const safeExp = t30.isMemberExpression(exp) || t30.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
3625
3592
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
3626
|
-
return
|
|
3593
|
+
return t30.cloneNode(safeExp, true);
|
|
3627
3594
|
}
|
|
3628
|
-
return
|
|
3595
|
+
return t30.identifier(root.name);
|
|
3629
3596
|
}
|
|
3630
3597
|
return null;
|
|
3631
3598
|
}
|
|
3632
3599
|
function isReactValidDependencyExpr(node2) {
|
|
3633
|
-
if (
|
|
3600
|
+
if (t30.isIdentifier(node2)) {
|
|
3634
3601
|
return true;
|
|
3635
3602
|
}
|
|
3636
|
-
if (
|
|
3603
|
+
if (t30.isMemberExpression(node2) || t30.isOptionalMemberExpression(node2)) {
|
|
3637
3604
|
return isStaticMemberChain(node2);
|
|
3638
3605
|
}
|
|
3639
3606
|
return false;
|
|
3640
3607
|
}
|
|
3641
3608
|
function isStaticMemberChain(node2) {
|
|
3642
3609
|
let current = node2;
|
|
3643
|
-
while (
|
|
3644
|
-
if (!current.computed && !
|
|
3610
|
+
while (t30.isMemberExpression(current) || t30.isOptionalMemberExpression(current)) {
|
|
3611
|
+
if (!current.computed && !t30.isIdentifier(current.property)) {
|
|
3645
3612
|
return false;
|
|
3646
3613
|
}
|
|
3647
|
-
if (current.computed && !
|
|
3614
|
+
if (current.computed && !t30.isStringLiteral(current.property) && !t30.isNumericLiteral(current.property)) {
|
|
3648
3615
|
return false;
|
|
3649
3616
|
}
|
|
3650
3617
|
current = current.object;
|
|
3651
3618
|
}
|
|
3652
|
-
return
|
|
3619
|
+
return t30.isIdentifier(current);
|
|
3653
3620
|
}
|
|
3654
3621
|
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
3655
3622
|
let current = binding.path;
|
|
@@ -3667,7 +3634,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3667
3634
|
if (!isDirectCallee) {
|
|
3668
3635
|
return node2;
|
|
3669
3636
|
}
|
|
3670
|
-
if (!
|
|
3637
|
+
if (!t30.isExpression(node2.object)) {
|
|
3671
3638
|
return node2;
|
|
3672
3639
|
}
|
|
3673
3640
|
return node2.object;
|
|
@@ -3676,15 +3643,15 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3676
3643
|
if (!hasTrailingMemberAccess(node2)) {
|
|
3677
3644
|
return node2;
|
|
3678
3645
|
}
|
|
3679
|
-
if (
|
|
3646
|
+
if (t30.isOptionalMemberExpression(node2) && node2.optional) {
|
|
3680
3647
|
return node2;
|
|
3681
3648
|
}
|
|
3682
|
-
const object =
|
|
3683
|
-
const property =
|
|
3684
|
-
return
|
|
3649
|
+
const object = t30.cloneNode(node2.object, true);
|
|
3650
|
+
const property = t30.cloneNode(node2.property, true);
|
|
3651
|
+
return t30.optionalMemberExpression(object, property, node2.computed, true);
|
|
3685
3652
|
}
|
|
3686
3653
|
function hasTrailingMemberAccess(node2) {
|
|
3687
|
-
return
|
|
3654
|
+
return t30.isMemberExpression(node2.object) || t30.isOptionalMemberExpression(node2.object);
|
|
3688
3655
|
}
|
|
3689
3656
|
function isEligibleBindingSource(binding) {
|
|
3690
3657
|
if (binding.kind === "param") {
|
|
@@ -3693,18 +3660,18 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3693
3660
|
const bindingPath = binding.path;
|
|
3694
3661
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
3695
3662
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
3696
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess',
|
|
3697
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
3698
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
3699
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
3700
|
-
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess',
|
|
3663
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _97 => _97.node, 'access', _98 => _98.init]);
|
|
3664
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t30.isCallExpression(nodeInit) && t30.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
3665
|
+
const isHookCallVarBinding = !!declaratorPath && t30.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
3666
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t30.isArrowFunctionExpression(nodeInit) || t30.isFunctionExpression(nodeInit));
|
|
3667
|
+
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _99 => _99.node])) || isReactiveBinding(bindingPath.node));
|
|
3701
3668
|
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
3702
3669
|
}
|
|
3703
3670
|
function isHookLikeCallee(callee) {
|
|
3704
|
-
if (
|
|
3671
|
+
if (t30.isIdentifier(callee)) {
|
|
3705
3672
|
return callee.name.startsWith("use");
|
|
3706
3673
|
}
|
|
3707
|
-
if (
|
|
3674
|
+
if (t30.isMemberExpression(callee) && !callee.computed && t30.isIdentifier(callee.property)) {
|
|
3708
3675
|
return callee.property.name.startsWith("use");
|
|
3709
3676
|
}
|
|
3710
3677
|
return false;
|
|
@@ -3720,7 +3687,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3720
3687
|
}
|
|
3721
3688
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
3722
3689
|
if (depth <= 0) return null;
|
|
3723
|
-
if (
|
|
3690
|
+
if (t30.isIdentifier(exp)) {
|
|
3724
3691
|
const sourceBinding = scope.getBinding(exp.name);
|
|
3725
3692
|
if (!sourceBinding) return null;
|
|
3726
3693
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -3728,13 +3695,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3728
3695
|
}
|
|
3729
3696
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3730
3697
|
}
|
|
3731
|
-
if (
|
|
3698
|
+
if (t30.isMemberExpression(exp) || t30.isOptionalMemberExpression(exp)) {
|
|
3732
3699
|
const root = findRootIdentifier(exp);
|
|
3733
3700
|
if (!root) return null;
|
|
3734
3701
|
const sourceBinding = scope.getBinding(root.name);
|
|
3735
3702
|
if (!sourceBinding) return null;
|
|
3736
3703
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
3737
|
-
return
|
|
3704
|
+
return t30.cloneNode(exp);
|
|
3738
3705
|
}
|
|
3739
3706
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3740
3707
|
if (sourcedRoot) {
|
|
@@ -3742,17 +3709,17 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3742
3709
|
if (rebuilt) {
|
|
3743
3710
|
return rebuilt;
|
|
3744
3711
|
}
|
|
3745
|
-
return
|
|
3712
|
+
return t30.cloneNode(sourcedRoot, true);
|
|
3746
3713
|
}
|
|
3747
3714
|
}
|
|
3748
3715
|
return null;
|
|
3749
3716
|
}
|
|
3750
3717
|
function rebuildMemberWithNewRoot(node2, nextRoot) {
|
|
3751
3718
|
const replacedObject = (() => {
|
|
3752
|
-
if (
|
|
3753
|
-
return
|
|
3719
|
+
if (t30.isIdentifier(node2.object)) {
|
|
3720
|
+
return t30.cloneNode(nextRoot, true);
|
|
3754
3721
|
}
|
|
3755
|
-
if (
|
|
3722
|
+
if (t30.isMemberExpression(node2.object) || t30.isOptionalMemberExpression(node2.object)) {
|
|
3756
3723
|
return rebuildMemberWithNewRoot(node2.object, nextRoot);
|
|
3757
3724
|
}
|
|
3758
3725
|
return null;
|
|
@@ -3760,34 +3727,34 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3760
3727
|
if (!replacedObject) {
|
|
3761
3728
|
return null;
|
|
3762
3729
|
}
|
|
3763
|
-
const property =
|
|
3764
|
-
if (
|
|
3765
|
-
return
|
|
3730
|
+
const property = t30.cloneNode(node2.property, true);
|
|
3731
|
+
if (t30.isMemberExpression(node2)) {
|
|
3732
|
+
return t30.memberExpression(
|
|
3766
3733
|
replacedObject,
|
|
3767
3734
|
property,
|
|
3768
3735
|
node2.computed
|
|
3769
3736
|
);
|
|
3770
3737
|
}
|
|
3771
|
-
return
|
|
3738
|
+
return t30.optionalMemberExpression(
|
|
3772
3739
|
replacedObject,
|
|
3773
3740
|
property,
|
|
3774
3741
|
node2.computed,
|
|
3775
3742
|
node2.optional
|
|
3776
3743
|
);
|
|
3777
3744
|
}
|
|
3778
|
-
return
|
|
3745
|
+
return t30.arrayExpression(Array.from(deps.values()));
|
|
3779
3746
|
}
|
|
3780
3747
|
function getDependencyKey(exp) {
|
|
3781
|
-
if (
|
|
3748
|
+
if (t30.isIdentifier(exp)) {
|
|
3782
3749
|
return exp.name;
|
|
3783
3750
|
}
|
|
3784
|
-
if (
|
|
3751
|
+
if (t30.isMemberExpression(exp) || t30.isOptionalMemberExpression(exp)) {
|
|
3785
3752
|
const objectKey = getDependencyKey(exp.object);
|
|
3786
3753
|
const opt = exp.optional ? "?" : "";
|
|
3787
|
-
if (!exp.computed &&
|
|
3754
|
+
if (!exp.computed && t30.isIdentifier(exp.property)) {
|
|
3788
3755
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
3789
3756
|
}
|
|
3790
|
-
if (
|
|
3757
|
+
if (t30.isStringLiteral(exp.property) || t30.isNumericLiteral(exp.property)) {
|
|
3791
3758
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
3792
3759
|
}
|
|
3793
3760
|
return `${objectKey}${opt}[*]`;
|
|
@@ -3804,7 +3771,7 @@ function isNestedMemberObject(path9) {
|
|
|
3804
3771
|
}
|
|
3805
3772
|
function isReactiveBinding(node) {
|
|
3806
3773
|
if (!node) return false;
|
|
3807
|
-
return !!_optionalChain([getScriptNodeMeta, 'call',
|
|
3774
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _100 => _100(node), 'optionalAccess', _101 => _101.is_reactive]);
|
|
3808
3775
|
}
|
|
3809
3776
|
|
|
3810
3777
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -3820,7 +3787,7 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
3820
3787
|
if (!isVueApiReference(path9, apiName)) {
|
|
3821
3788
|
return;
|
|
3822
3789
|
}
|
|
3823
|
-
if (
|
|
3790
|
+
if (t31.isCallExpression(node)) {
|
|
3824
3791
|
resolveCallNode(path9, adapter, ctx);
|
|
3825
3792
|
} else {
|
|
3826
3793
|
replaceIdName(node, adapter.target);
|
|
@@ -3830,11 +3797,11 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
3830
3797
|
};
|
|
3831
3798
|
}
|
|
3832
3799
|
function getApiName(node) {
|
|
3833
|
-
const isCallNode =
|
|
3800
|
+
const isCallNode = t31.isCallExpression(node);
|
|
3834
3801
|
let apiName = "";
|
|
3835
|
-
if (
|
|
3802
|
+
if (t31.isIdentifier(node)) {
|
|
3836
3803
|
apiName = node.name;
|
|
3837
|
-
} else if (isCallNode &&
|
|
3804
|
+
} else if (isCallNode && t31.isIdentifier(node.callee)) {
|
|
3838
3805
|
apiName = node.callee.name;
|
|
3839
3806
|
}
|
|
3840
3807
|
return apiName;
|
|
@@ -3844,7 +3811,7 @@ function resolveCallNode(path9, adapter, ctx) {
|
|
|
3844
3811
|
const { arguments: args } = node;
|
|
3845
3812
|
if (!args.length) return;
|
|
3846
3813
|
const fn = args[0];
|
|
3847
|
-
if (!
|
|
3814
|
+
if (!t31.isArrowFunctionExpression(fn) && !t31.isFunctionExpression(fn)) {
|
|
3848
3815
|
return;
|
|
3849
3816
|
}
|
|
3850
3817
|
const fnPath = path9.get("arguments")[0];
|
|
@@ -3875,8 +3842,8 @@ function isVueImportBinding(binding) {
|
|
|
3875
3842
|
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
3876
3843
|
return false;
|
|
3877
3844
|
}
|
|
3878
|
-
const parent = _optionalChain([bindingPath, 'access',
|
|
3879
|
-
if (!parent || !
|
|
3845
|
+
const parent = _optionalChain([bindingPath, 'access', _102 => _102.parentPath, 'optionalAccess', _103 => _103.node]);
|
|
3846
|
+
if (!parent || !t31.isImportDeclaration(parent)) {
|
|
3880
3847
|
return false;
|
|
3881
3848
|
}
|
|
3882
3849
|
const source = parent.source.value.toLowerCase();
|
|
@@ -3902,7 +3869,7 @@ function resolveArrowFnDeps(ctx, ast) {
|
|
|
3902
3869
|
const newNode = createUseCallback(node, deps);
|
|
3903
3870
|
const declaratorPath = getVariableDeclaratorPath(path9);
|
|
3904
3871
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
3905
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
3872
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _104 => _104.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
3906
3873
|
path9.replaceWith(newNode);
|
|
3907
3874
|
}
|
|
3908
3875
|
};
|
|
@@ -3961,15 +3928,15 @@ function resolveElementRef(ctx) {
|
|
|
3961
3928
|
return;
|
|
3962
3929
|
}
|
|
3963
3930
|
if (isCompRefBindings) {
|
|
3964
|
-
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3965
|
-
if (!
|
|
3931
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _105 => _105(path9), 'optionalAccess', _106 => _106.node]);
|
|
3932
|
+
if (!t32.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _107 => _107.id]))) {
|
|
3966
3933
|
return;
|
|
3967
3934
|
}
|
|
3968
3935
|
const varName = varDeclaratorPath.id.name;
|
|
3969
3936
|
const compRef = refBindings.componentRefs[varName];
|
|
3970
3937
|
if (!compRef) return;
|
|
3971
3938
|
}
|
|
3972
|
-
node.arguments[0] =
|
|
3939
|
+
node.arguments[0] = t32.identifier("null");
|
|
3973
3940
|
resolveTypeParameters(ctx, path9);
|
|
3974
3941
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
3975
3942
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
@@ -3985,7 +3952,7 @@ function resolveTypeParameters(ctx, path9) {
|
|
|
3985
3952
|
scriptData
|
|
3986
3953
|
} = ctx;
|
|
3987
3954
|
const { node } = path9;
|
|
3988
|
-
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3955
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _108 => _108(path9), 'optionalAccess', _109 => _109.node]);
|
|
3989
3956
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
3990
3957
|
return;
|
|
3991
3958
|
}
|
|
@@ -3994,20 +3961,20 @@ function resolveTypeParameters(ctx, path9) {
|
|
|
3994
3961
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
3995
3962
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
3996
3963
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
3997
|
-
node.typeParameters =
|
|
3964
|
+
node.typeParameters = t32.tsTypeParameterInstantiation([t32.tsTypeReference(t32.identifier(type))]);
|
|
3998
3965
|
}
|
|
3999
3966
|
}
|
|
4000
3967
|
function resolveRefValueToCurrent(path9) {
|
|
4001
3968
|
const { node } = path9;
|
|
4002
|
-
if (node.computed || !
|
|
3969
|
+
if (node.computed || !t32.isIdentifier(node.property) || node.property.name !== "value") {
|
|
4003
3970
|
return;
|
|
4004
3971
|
}
|
|
4005
3972
|
const rootPath = findRootVariablePath(path9);
|
|
4006
|
-
if (!_optionalChain([rootPath, 'optionalAccess',
|
|
3973
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _110 => _110.node]) || !t32.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
4007
3974
|
return;
|
|
4008
3975
|
}
|
|
4009
3976
|
const rootId = findRootIdentifier(node);
|
|
4010
|
-
if (!
|
|
3977
|
+
if (!t32.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _111 => _111.name])) {
|
|
4011
3978
|
return;
|
|
4012
3979
|
}
|
|
4013
3980
|
node.property.name = "current";
|
|
@@ -4026,11 +3993,11 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4026
3993
|
if (!atComponentOrHookRoot(path9, ast.program, isScriptFile)) {
|
|
4027
3994
|
return false;
|
|
4028
3995
|
}
|
|
4029
|
-
if (!
|
|
3996
|
+
if (!t33.isVariableDeclaration(path9.parent) || path9.parent.kind !== "const") {
|
|
4030
3997
|
return false;
|
|
4031
3998
|
}
|
|
4032
|
-
if (
|
|
4033
|
-
if (
|
|
3999
|
+
if (t33.isFunction(init)) return false;
|
|
4000
|
+
if (t33.isCallExpression(init) && t33.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
4034
4001
|
return false;
|
|
4035
4002
|
}
|
|
4036
4003
|
return true;
|
|
@@ -4054,10 +4021,10 @@ function resolveLintRules(ctx, ast) {
|
|
|
4054
4021
|
return {
|
|
4055
4022
|
CallExpression(path9) {
|
|
4056
4023
|
const { node, parentPath } = path9;
|
|
4057
|
-
if (!
|
|
4024
|
+
if (!t34.isIdentifier(node.callee)) return;
|
|
4058
4025
|
const { name: callName } = node.callee;
|
|
4059
|
-
const addLog = (
|
|
4060
|
-
logger.error(
|
|
4026
|
+
const addLog = (t40) => {
|
|
4027
|
+
logger.error(t40, {
|
|
4061
4028
|
file: ctx.filename,
|
|
4062
4029
|
source: ctx.scriptData.source,
|
|
4063
4030
|
loc: node.loc
|
|
@@ -4108,7 +4075,7 @@ function resolveProvide(ctx) {
|
|
|
4108
4075
|
return {
|
|
4109
4076
|
CallExpression(path9) {
|
|
4110
4077
|
const { node } = path9;
|
|
4111
|
-
const providerTarget = _optionalChain([ADAPTER_RULES, 'access',
|
|
4078
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _112 => _112.runtime, 'access', _113 => _113[VUE_API_MAP.provide], 'optionalAccess', _114 => _114.target]);
|
|
4112
4079
|
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
4113
4080
|
if (!isProvideCall) return;
|
|
4114
4081
|
const { provide } = ctx.scriptData;
|
|
@@ -4126,7 +4093,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
4126
4093
|
return root;
|
|
4127
4094
|
}
|
|
4128
4095
|
let cur = root.provide;
|
|
4129
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
4096
|
+
while (_optionalChain([cur, 'optionalAccess', _115 => _115.isOccupied])) {
|
|
4130
4097
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
4131
4098
|
}
|
|
4132
4099
|
return cur || (root.provide = {});
|
|
@@ -4134,18 +4101,18 @@ function findOrCreateCtxProvider(root) {
|
|
|
4134
4101
|
function assignProviderValue(target, key, value) {
|
|
4135
4102
|
const getRawExp = (exp) => {
|
|
4136
4103
|
if (!exp) return "''";
|
|
4137
|
-
if (
|
|
4104
|
+
if (t35.isStringLiteral(exp)) {
|
|
4138
4105
|
return JSON.stringify(exp.value);
|
|
4139
4106
|
}
|
|
4140
|
-
if (
|
|
4107
|
+
if (t35.isNumericLiteral(exp)) {
|
|
4141
4108
|
return exp.value.toString();
|
|
4142
4109
|
}
|
|
4143
|
-
if (
|
|
4110
|
+
if (t35.isIdentifier(exp)) {
|
|
4144
4111
|
return exp.name;
|
|
4145
4112
|
}
|
|
4146
4113
|
try {
|
|
4147
4114
|
return _generator.generate.call(void 0, exp).code;
|
|
4148
|
-
} catch (
|
|
4115
|
+
} catch (e5) {
|
|
4149
4116
|
return "null";
|
|
4150
4117
|
}
|
|
4151
4118
|
};
|
|
@@ -4161,11 +4128,11 @@ function resolveRenameAdapter(ctx) {
|
|
|
4161
4128
|
return {
|
|
4162
4129
|
"CallExpression|Identifier"(path9) {
|
|
4163
4130
|
const node = path9.node;
|
|
4164
|
-
const isCallNode =
|
|
4131
|
+
const isCallNode = t36.isCallExpression(node);
|
|
4165
4132
|
let apiName = "";
|
|
4166
|
-
if (
|
|
4133
|
+
if (t36.isIdentifier(node)) {
|
|
4167
4134
|
apiName = node.name;
|
|
4168
|
-
} else if (isCallNode &&
|
|
4135
|
+
} else if (isCallNode && t36.isIdentifier(node.callee)) {
|
|
4169
4136
|
apiName = node.callee.name;
|
|
4170
4137
|
}
|
|
4171
4138
|
if (!apiName) {
|
|
@@ -4183,7 +4150,7 @@ function resolveRenameAdapter(ctx) {
|
|
|
4183
4150
|
if (adapter.isTrackable) {
|
|
4184
4151
|
const reactiveType = getReactiveType(apiName);
|
|
4185
4152
|
const declaratorPath = getVariableDeclaratorPath(path9);
|
|
4186
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
4153
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _116 => _116.node]), {
|
|
4187
4154
|
is_reactive: true,
|
|
4188
4155
|
reactive_type: reactiveType
|
|
4189
4156
|
});
|
|
@@ -4222,8 +4189,8 @@ function isVueImportBinding2(binding) {
|
|
|
4222
4189
|
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
4223
4190
|
return false;
|
|
4224
4191
|
}
|
|
4225
|
-
const parent = _optionalChain([bindingPath, 'access',
|
|
4226
|
-
if (!parent || !
|
|
4192
|
+
const parent = _optionalChain([bindingPath, 'access', _117 => _117.parentPath, 'optionalAccess', _118 => _118.node]);
|
|
4193
|
+
if (!parent || !t36.isImportDeclaration(parent)) {
|
|
4227
4194
|
return false;
|
|
4228
4195
|
}
|
|
4229
4196
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4266,19 +4233,19 @@ function processVueSyntax2(ast, ctx) {
|
|
|
4266
4233
|
excludeBabel: [resolveTemplateSlotIface, resolveCompIProps]
|
|
4267
4234
|
},
|
|
4268
4235
|
postprocess: {
|
|
4269
|
-
applyBabel: [
|
|
4270
|
-
excludeBabel: [
|
|
4236
|
+
applyBabel: [resolveRuntimeImports, resolveASTChunks],
|
|
4237
|
+
excludeBabel: [resolveSfcCssImport]
|
|
4271
4238
|
}
|
|
4272
4239
|
});
|
|
4273
4240
|
}
|
|
4274
4241
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
4275
4242
|
const runExcludeThenApply = (cfg) => {
|
|
4276
|
-
_optionalChain([cfg, 'access',
|
|
4277
|
-
_optionalChain([cfg, 'access',
|
|
4243
|
+
_optionalChain([cfg, 'access', _119 => _119.excludeBabel, 'optionalAccess', _120 => _120.forEach, 'call', _121 => _121((fn) => fn(ctx, ast))]);
|
|
4244
|
+
_optionalChain([cfg, 'access', _122 => _122.applyBabel, 'optionalAccess', _123 => _123.forEach, 'call', _124 => _124((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4278
4245
|
};
|
|
4279
4246
|
const runApplyThenExclude = (cfg) => {
|
|
4280
|
-
_optionalChain([cfg, 'access',
|
|
4281
|
-
_optionalChain([cfg, 'access',
|
|
4247
|
+
_optionalChain([cfg, 'access', _125 => _125.applyBabel, 'optionalAccess', _126 => _126.forEach, 'call', _127 => _127((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4248
|
+
_optionalChain([cfg, 'access', _128 => _128.excludeBabel, 'optionalAccess', _129 => _129.forEach, 'call', _130 => _130((fn) => fn(ctx, ast))]);
|
|
4282
4249
|
};
|
|
4283
4250
|
runExcludeThenApply(options.preprocess);
|
|
4284
4251
|
runExcludeThenApply(options.process);
|
|
@@ -4365,50 +4332,50 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
4365
4332
|
|
|
4366
4333
|
|
|
4367
4334
|
var strCodeTypes = {
|
|
4368
|
-
isIdentifier:
|
|
4335
|
+
isIdentifier: isIdentifier19,
|
|
4369
4336
|
isSimpleExpression,
|
|
4370
|
-
isStringLiteral:
|
|
4337
|
+
isStringLiteral: isStringLiteral11
|
|
4371
4338
|
};
|
|
4372
4339
|
function isSimpleExpression(code, excludeVar = false) {
|
|
4373
4340
|
let node;
|
|
4374
4341
|
try {
|
|
4375
4342
|
node = _parser.parseExpression.call(void 0, code);
|
|
4376
|
-
} catch (
|
|
4343
|
+
} catch (e6) {
|
|
4377
4344
|
return false;
|
|
4378
4345
|
}
|
|
4379
|
-
if (
|
|
4346
|
+
if (t37.isLiteral(node)) {
|
|
4380
4347
|
return true;
|
|
4381
4348
|
}
|
|
4382
|
-
if (!excludeVar &&
|
|
4349
|
+
if (!excludeVar && t37.isIdentifier(node)) {
|
|
4383
4350
|
return true;
|
|
4384
4351
|
}
|
|
4385
|
-
if (
|
|
4386
|
-
return isSimpleExpression(node.object) &&
|
|
4352
|
+
if (t37.isMemberExpression(node)) {
|
|
4353
|
+
return isSimpleExpression(node.object) && t37.isIdentifier(node.property);
|
|
4387
4354
|
}
|
|
4388
|
-
if (
|
|
4355
|
+
if (t37.isObjectExpression(node) || t37.isArrayExpression(node)) {
|
|
4389
4356
|
return false;
|
|
4390
4357
|
}
|
|
4391
|
-
if (
|
|
4358
|
+
if (t37.isCallExpression(node) || t37.isAssignmentExpression(node)) {
|
|
4392
4359
|
return false;
|
|
4393
4360
|
}
|
|
4394
|
-
if (
|
|
4361
|
+
if (t37.isBinaryExpression(node) || t37.isUnaryExpression(node)) {
|
|
4395
4362
|
return true;
|
|
4396
4363
|
}
|
|
4397
4364
|
return false;
|
|
4398
4365
|
}
|
|
4399
|
-
function
|
|
4366
|
+
function isIdentifier19(code) {
|
|
4400
4367
|
try {
|
|
4401
4368
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4402
|
-
return
|
|
4403
|
-
} catch (
|
|
4369
|
+
return t37.isIdentifier(node);
|
|
4370
|
+
} catch (e7) {
|
|
4404
4371
|
return false;
|
|
4405
4372
|
}
|
|
4406
4373
|
}
|
|
4407
|
-
function
|
|
4374
|
+
function isStringLiteral11(code) {
|
|
4408
4375
|
try {
|
|
4409
4376
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4410
|
-
return
|
|
4411
|
-
} catch (
|
|
4377
|
+
return t37.isStringLiteral(node);
|
|
4378
|
+
} catch (e8) {
|
|
4412
4379
|
return false;
|
|
4413
4380
|
}
|
|
4414
4381
|
}
|
|
@@ -4517,12 +4484,12 @@ function wrapSingleQuotes(content, condition) {
|
|
|
4517
4484
|
return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
|
|
4518
4485
|
}
|
|
4519
4486
|
function checkPropIsDynamicKey(ctx, node) {
|
|
4520
|
-
const isKeyStatic = _optionalChain([node, 'access',
|
|
4487
|
+
const isKeyStatic = _optionalChain([node, 'access', _131 => _131.arg, 'optionalAccess', _132 => _132.isStatic]);
|
|
4521
4488
|
const { source, filename } = ctx;
|
|
4522
4489
|
if (node.rawName === "v-bind" && !node.name) {
|
|
4523
4490
|
logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
|
|
4524
4491
|
source,
|
|
4525
|
-
loc: _optionalChain([node, 'access',
|
|
4492
|
+
loc: _optionalChain([node, 'access', _133 => _133.arg, 'optionalAccess', _134 => _134.loc]),
|
|
4526
4493
|
file: filename
|
|
4527
4494
|
});
|
|
4528
4495
|
return;
|
|
@@ -4530,7 +4497,7 @@ function checkPropIsDynamicKey(ctx, node) {
|
|
|
4530
4497
|
if (isKeyStatic === false) {
|
|
4531
4498
|
logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
|
|
4532
4499
|
source,
|
|
4533
|
-
loc: _optionalChain([node, 'access',
|
|
4500
|
+
loc: _optionalChain([node, 'access', _135 => _135.arg, 'optionalAccess', _136 => _136.loc]),
|
|
4534
4501
|
file: filename
|
|
4535
4502
|
});
|
|
4536
4503
|
}
|
|
@@ -4549,23 +4516,23 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
4549
4516
|
const mergedItems = value.merge;
|
|
4550
4517
|
const setNameIdentifier = (target, valueName) => {
|
|
4551
4518
|
target.content = valueName;
|
|
4552
|
-
target.ast =
|
|
4519
|
+
target.ast = t38.jsxIdentifier(valueName);
|
|
4553
4520
|
};
|
|
4554
|
-
const setValueExpression = (target, content,
|
|
4521
|
+
const setValueExpression = (target, content, isStringLiteral12) => {
|
|
4555
4522
|
target.content = content;
|
|
4556
|
-
target.ast = resolveStringExpr(content, ctx,
|
|
4523
|
+
target.ast = resolveStringExpr(content, ctx, isStringLiteral12);
|
|
4557
4524
|
};
|
|
4558
4525
|
const createRuntimeCall = (fnName, args) => {
|
|
4559
4526
|
const fnArgs = args.filter(Boolean).join(",");
|
|
4560
4527
|
return `${fnName}(${fnArgs})`;
|
|
4561
4528
|
};
|
|
4562
|
-
const applyRuntimeExpression = (expression, setName = false, nameIdentifier,
|
|
4529
|
+
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral12) => {
|
|
4563
4530
|
if (setName && nameIdentifier) {
|
|
4564
4531
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
4565
4532
|
}
|
|
4566
4533
|
const dir = ADAPTER_RULES.runtime.dir;
|
|
4567
4534
|
recordImport(ctx, dir.package, dir.target);
|
|
4568
|
-
setValueExpression(value.babelExp, expression,
|
|
4535
|
+
setValueExpression(value.babelExp, expression, isStringLiteral12);
|
|
4569
4536
|
};
|
|
4570
4537
|
if (ir.isKeyLessVBind) {
|
|
4571
4538
|
const dirKeyless = ADAPTER_RULES.runtime.dirKeyless;
|
|
@@ -4575,19 +4542,19 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
4575
4542
|
}
|
|
4576
4543
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
4577
4544
|
const dirCls = ADAPTER_RULES.runtime.dirCls;
|
|
4578
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
4545
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _137 => _137.join, 'call', _138 => _138(",")]) || wrapSingleQuotes(valueContent);
|
|
4579
4546
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
4580
4547
|
applyRuntimeExpression(expression, true, name);
|
|
4581
4548
|
return;
|
|
4582
4549
|
}
|
|
4583
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
4550
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _139 => _139.some, 'call', _140 => _140((item) => !isSimpleStyle(item))]))) {
|
|
4584
4551
|
const dirStyle = ADAPTER_RULES.runtime.dirStyle;
|
|
4585
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
4552
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _141 => _141.join, 'call', _142 => _142(",")]) || valueContent;
|
|
4586
4553
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
4587
4554
|
applyRuntimeExpression(expression, true, name);
|
|
4588
4555
|
return;
|
|
4589
4556
|
}
|
|
4590
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
4557
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _143 => _143.modifiers, 'optionalAccess', _144 => _144.length])) {
|
|
4591
4558
|
const dirOn = ADAPTER_RULES.runtime.dirOn;
|
|
4592
4559
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
4593
4560
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
@@ -4642,7 +4609,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
4642
4609
|
continue;
|
|
4643
4610
|
}
|
|
4644
4611
|
const nodeIR = child;
|
|
4645
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
4612
|
+
if (_optionalChain([parentIR, 'optionalAccess', _145 => _145.isBuiltIn])) {
|
|
4646
4613
|
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
4647
4614
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
4648
4615
|
}
|
|
@@ -4683,7 +4650,7 @@ function walkElementNodes(node, onElement) {
|
|
|
4683
4650
|
}
|
|
4684
4651
|
function resolveDefaultStyleModuleName(node) {
|
|
4685
4652
|
const { exp } = node;
|
|
4686
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
4653
|
+
if (_optionalChain([exp, 'optionalAccess', _146 => _146.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4687
4654
|
return;
|
|
4688
4655
|
}
|
|
4689
4656
|
if (exp.content.includes("$style")) {
|
|
@@ -4732,7 +4699,7 @@ function injectStyleScopeAttribute(node, ctx) {
|
|
|
4732
4699
|
break;
|
|
4733
4700
|
}
|
|
4734
4701
|
}
|
|
4735
|
-
if (prop.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([prop, 'access',
|
|
4702
|
+
if (prop.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([prop, 'access', _147 => _147.arg, 'optionalAccess', _148 => _148.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4736
4703
|
if (getHasClassOrId(prop.arg.content)) {
|
|
4737
4704
|
hasClassOrId = true;
|
|
4738
4705
|
break;
|
|
@@ -4792,7 +4759,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
4792
4759
|
const oldStyle = oldAttr.value.content;
|
|
4793
4760
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
4794
4761
|
let merged = oldAttr.value.merge;
|
|
4795
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
4762
|
+
if (!_optionalChain([merged, 'optionalAccess', _149 => _149.length])) {
|
|
4796
4763
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
4797
4764
|
} else {
|
|
4798
4765
|
merged.push(newStyle);
|
|
@@ -4822,7 +4789,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
4822
4789
|
const { source, filename } = ctx;
|
|
4823
4790
|
let value = "";
|
|
4824
4791
|
let loc;
|
|
4825
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
4792
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _150 => _150.exp, 'optionalAccess', _151 => _151.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4826
4793
|
value = node.exp.content;
|
|
4827
4794
|
loc = node.exp.loc;
|
|
4828
4795
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -4876,11 +4843,11 @@ function resolveRefProp(node, ctx, nodeIR) {
|
|
|
4876
4843
|
} = ctx;
|
|
4877
4844
|
let propIR;
|
|
4878
4845
|
if (node.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
4879
|
-
const tag = _optionalChain([node, 'access',
|
|
4846
|
+
const tag = _optionalChain([node, 'access', _152 => _152.value, 'optionalAccess', _153 => _153.content]);
|
|
4880
4847
|
if (!tag) return;
|
|
4881
4848
|
collectComponentRef(tag, ctx);
|
|
4882
4849
|
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
4883
|
-
const refVar = _optionalChain([domRefBinding, 'optionalAccess',
|
|
4850
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _154 => _154.name]) || _optionalChain([refBindings, 'access', _155 => _155.componentRefs, 'access', _156 => _156[tag], 'optionalAccess', _157 => _157.name]);
|
|
4884
4851
|
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
4885
4852
|
} else {
|
|
4886
4853
|
const exp = node.exp;
|
|
@@ -4915,8 +4882,8 @@ function collectComponentRef(tag, ctx) {
|
|
|
4915
4882
|
function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
4916
4883
|
const arg = node.arg;
|
|
4917
4884
|
const exp = node.exp;
|
|
4918
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4919
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4885
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _158 => _158.content]), () => ( ""));
|
|
4886
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _159 => _159.content]), () => ( "true"));
|
|
4920
4887
|
warnUnsupportedVueDollarVar(ctx, node);
|
|
4921
4888
|
if (name === "is") {
|
|
4922
4889
|
resolveDynamicIsProp(node, ir, ctx, nodeIR);
|
|
@@ -4927,7 +4894,7 @@ function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
|
4927
4894
|
return;
|
|
4928
4895
|
}
|
|
4929
4896
|
const dynamicPropIR = createPropsIR(node.rawName, name, content);
|
|
4930
|
-
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4897
|
+
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _160 => _160.isStatic]), () => ( true));
|
|
4931
4898
|
checkPropIsDynamicKey(ctx, node);
|
|
4932
4899
|
resolvePropertyIR(dynamicPropIR, ir, ctx, nodeIR, true);
|
|
4933
4900
|
}
|
|
@@ -4941,12 +4908,12 @@ function resolvePropertyIR(node, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
4941
4908
|
content = node.value.content = parseStyleString(content);
|
|
4942
4909
|
}
|
|
4943
4910
|
if (isDynamic) {
|
|
4944
|
-
const
|
|
4945
|
-
if (
|
|
4911
|
+
const isStringLiteral12 = strCodeTypes.isStringLiteral(content);
|
|
4912
|
+
if (isStringLiteral12) {
|
|
4946
4913
|
content = normalizeString(content);
|
|
4947
4914
|
node.value.content = content;
|
|
4948
4915
|
}
|
|
4949
|
-
node.value.isStringLiteral =
|
|
4916
|
+
node.value.isStringLiteral = isStringLiteral12;
|
|
4950
4917
|
}
|
|
4951
4918
|
const existing = findSameProp(nodeIR.props, node);
|
|
4952
4919
|
if (existing) {
|
|
@@ -4966,7 +4933,7 @@ function normalizeString(s) {
|
|
|
4966
4933
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
4967
4934
|
function resolveAttributeProp(node, ir, ctx, nodeIR) {
|
|
4968
4935
|
const name = node.name;
|
|
4969
|
-
const content = _nullishCoalesce(_optionalChain([node, 'access',
|
|
4936
|
+
const content = _nullishCoalesce(_optionalChain([node, 'access', _161 => _161.value, 'optionalAccess', _162 => _162.content]), () => ( "true"));
|
|
4970
4937
|
if (name === "is") {
|
|
4971
4938
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
4972
4939
|
return;
|
|
@@ -4990,10 +4957,10 @@ function resolveRouterLinkVSlotProp(node, nodeIR, ctx) {
|
|
|
4990
4957
|
type: 2 /* SLOT */,
|
|
4991
4958
|
name: "customRender",
|
|
4992
4959
|
rawName: _nullishCoalesce(node.rawName, () => ( "v-slot")),
|
|
4993
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4960
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _163 => _163.isStatic]), () => ( true)),
|
|
4994
4961
|
isScoped: true,
|
|
4995
4962
|
callback: {
|
|
4996
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4963
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _164 => _164.content, 'optionalAccess', _165 => _165.trim, 'call', _166 => _166()]), () => ( "")),
|
|
4997
4964
|
exp: []
|
|
4998
4965
|
}
|
|
4999
4966
|
};
|
|
@@ -5009,10 +4976,10 @@ function resolveVFor(node, _ir, _ctx, nodeIR) {
|
|
|
5009
4976
|
};
|
|
5010
4977
|
}
|
|
5011
4978
|
function resolveForResult(forParseResult) {
|
|
5012
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
5013
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
5014
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
5015
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
4979
|
+
const source = _optionalChain([forParseResult, 'access', _167 => _167.source, 'optionalAccess', _168 => _168.content]);
|
|
4980
|
+
const value = _optionalChain([forParseResult, 'access', _169 => _169.value, 'optionalAccess', _170 => _170.content]);
|
|
4981
|
+
const index = _optionalChain([forParseResult, 'access', _171 => _171.index, 'optionalAccess', _172 => _172.content]);
|
|
4982
|
+
const key = _optionalChain([forParseResult, 'access', _173 => _173.key, 'optionalAccess', _174 => _174.content]);
|
|
5016
4983
|
return {
|
|
5017
4984
|
source,
|
|
5018
4985
|
value,
|
|
@@ -5032,7 +4999,7 @@ function resolveVHtml(node, ir, ctx, nodeIR) {
|
|
|
5032
4999
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
5033
5000
|
function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
5034
5001
|
const name = node.name === "else-if" ? "elseIf" : node.name;
|
|
5035
|
-
const value = _nullishCoalesce(_optionalChain([node, 'access',
|
|
5002
|
+
const value = _nullishCoalesce(_optionalChain([node, 'access', _175 => _175.exp, 'optionalAccess', _176 => _176.content]), () => ( "true"));
|
|
5036
5003
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
5037
5004
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
5038
5005
|
let hasError = false;
|
|
@@ -5071,7 +5038,7 @@ function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
5071
5038
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
5072
5039
|
function resolveVMemo(node, _ir, ctx, nodeIR) {
|
|
5073
5040
|
const exp = node.exp;
|
|
5074
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
5041
|
+
let value = _optionalChain([exp, 'optionalAccess', _177 => _177.content]);
|
|
5075
5042
|
if (value !== void 0) {
|
|
5076
5043
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
5077
5044
|
const { source, filename } = ctx;
|
|
@@ -5111,14 +5078,14 @@ function resolveVModel(node, _ir, ctx, elementNode, nodeIR) {
|
|
|
5111
5078
|
const getterName = exp.content;
|
|
5112
5079
|
const isComponent = elementNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
5113
5080
|
const inputType = resolveHtmlInput(elementNode, isComponent);
|
|
5114
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5081
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _178 => _178.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
5115
5082
|
let valuePropIR;
|
|
5116
5083
|
let eventPropIR;
|
|
5117
5084
|
if (isComponent) {
|
|
5118
5085
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
5119
5086
|
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
5120
5087
|
const eventVueName = `update:${propName}`;
|
|
5121
|
-
const isTS = _optionalChain([ctx, 'access',
|
|
5088
|
+
const isTS = _optionalChain([ctx, 'access', _179 => _179.scriptData, 'optionalAccess', _180 => _180.lang, 'optionalAccess', _181 => _181.startsWith, 'call', _182 => _182("ts")]);
|
|
5122
5089
|
const valueArg = isTS ? "value: any" : "value";
|
|
5123
5090
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
5124
5091
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -5156,7 +5123,7 @@ function getRadioValue(elementNode) {
|
|
|
5156
5123
|
const valueAttr = elementNode.props.find(
|
|
5157
5124
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
5158
5125
|
);
|
|
5159
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
5126
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _183 => _183.value, 'optionalAccess', _184 => _184.content])) return '""';
|
|
5160
5127
|
const content = valueAttr.value.content;
|
|
5161
5128
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
5162
5129
|
}
|
|
@@ -5166,7 +5133,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
5166
5133
|
const typeProp = node.props.find(
|
|
5167
5134
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
5168
5135
|
);
|
|
5169
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
5136
|
+
return _optionalChain([typeProp, 'optionalAccess', _185 => _185.value, 'optionalAccess', _186 => _186.content, 'optionalAccess', _187 => _187.toLowerCase, 'call', _188 => _188()]);
|
|
5170
5137
|
}
|
|
5171
5138
|
function applyValueModifiers(valueExp, modifiers) {
|
|
5172
5139
|
let result = valueExp;
|
|
@@ -5197,7 +5164,7 @@ function resolveVOn(node, _ir, ctx, nodeIR) {
|
|
|
5197
5164
|
originalVueEventName = `${arg.content}.${modifiers.join(".")}`;
|
|
5198
5165
|
} else {
|
|
5199
5166
|
const expr = stringToExpr(handler);
|
|
5200
|
-
if (!
|
|
5167
|
+
if (!t39.isFunctionExpression(expr) && !t39.isArrowFunctionExpression(expr) && !t39.isIdentifier(expr)) {
|
|
5201
5168
|
handler = `() => {${handler}}`;
|
|
5202
5169
|
}
|
|
5203
5170
|
}
|
|
@@ -5370,7 +5337,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
5370
5337
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
5371
5338
|
const content = !isScoped ? [] : void 0;
|
|
5372
5339
|
const callback = isScoped ? {
|
|
5373
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
5340
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _189 => _189.content, 'optionalAccess', _190 => _190.trim, 'call', _191 => _191()]), () => ( "")),
|
|
5374
5341
|
exp: []
|
|
5375
5342
|
} : void 0;
|
|
5376
5343
|
checkPropIsDynamicKey(ctx, node);
|
|
@@ -5378,7 +5345,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
5378
5345
|
type: 2 /* SLOT */,
|
|
5379
5346
|
name,
|
|
5380
5347
|
rawName: _nullishCoalesce(node.rawName, () => ( "default")),
|
|
5381
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5348
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _192 => _192.isStatic]), () => ( true)),
|
|
5382
5349
|
isScoped,
|
|
5383
5350
|
content,
|
|
5384
5351
|
callback
|
|
@@ -5412,7 +5379,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
5412
5379
|
if (routerAdapter) {
|
|
5413
5380
|
if (!ctx.route) ctx.route = true;
|
|
5414
5381
|
nodeIR.isRoute = true;
|
|
5415
|
-
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess',
|
|
5382
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _193 => _193.package]), routerAdapter.target);
|
|
5416
5383
|
}
|
|
5417
5384
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
5418
5385
|
return nodeIR;
|
|
@@ -5548,7 +5515,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
5548
5515
|
for (const prop of node.props) {
|
|
5549
5516
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5550
5517
|
const attr = prop.name;
|
|
5551
|
-
const value = _optionalChain([prop, 'access',
|
|
5518
|
+
const value = _optionalChain([prop, 'access', _194 => _194.value, 'optionalAccess', _195 => _195.content, 'access', _196 => _196.trim, 'call', _197 => _197()]);
|
|
5552
5519
|
if (attr === "name" && value) {
|
|
5553
5520
|
result.name = camelCase(value);
|
|
5554
5521
|
} else {
|
|
@@ -5638,19 +5605,19 @@ function resolveTemplate2(root, ctx) {
|
|
|
5638
5605
|
// src/core/transform/sfc/index.ts
|
|
5639
5606
|
function transform(ast, ctx, options) {
|
|
5640
5607
|
const { template, script, style } = ast;
|
|
5641
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
5642
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
5608
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _198 => _198.ast]), ctx);
|
|
5609
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _199 => _199.ast]), ctx);
|
|
5643
5610
|
const result = {
|
|
5644
5611
|
template: templateIR,
|
|
5645
5612
|
script: scriptIR,
|
|
5646
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
5613
|
+
style: _optionalChain([style, 'optionalAccess', _200 => _200.source, 'optionalAccess', _201 => _201.content])
|
|
5647
5614
|
};
|
|
5648
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
5615
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _202 => _202.plugins]), result, ctx);
|
|
5649
5616
|
return result;
|
|
5650
5617
|
}
|
|
5651
5618
|
|
|
5652
5619
|
// package.json
|
|
5653
|
-
var version = "1.5.
|
|
5620
|
+
var version = "1.5.2";
|
|
5654
5621
|
var bin = {
|
|
5655
5622
|
vureact: "./bin/vureact.js"
|
|
5656
5623
|
};
|
|
@@ -5683,7 +5650,7 @@ async function formatWithPrettier(code, lang, opts) {
|
|
|
5683
5650
|
...opts,
|
|
5684
5651
|
parser
|
|
5685
5652
|
});
|
|
5686
|
-
} catch (
|
|
5653
|
+
} catch (e9) {
|
|
5687
5654
|
logger.info("Prettier is unavailable; the built-in simple formatter is used.");
|
|
5688
5655
|
return simpleFormat(code);
|
|
5689
5656
|
}
|
|
@@ -5733,7 +5700,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
5733
5700
|
if (content.trim()) {
|
|
5734
5701
|
try {
|
|
5735
5702
|
current = JSON.parse(content);
|
|
5736
|
-
} catch (
|
|
5703
|
+
} catch (e10) {
|
|
5737
5704
|
current = content;
|
|
5738
5705
|
}
|
|
5739
5706
|
}
|
|
@@ -5766,7 +5733,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
5766
5733
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
5767
5734
|
try {
|
|
5768
5735
|
await _fs2.default.promises.access(filePath);
|
|
5769
|
-
} catch (
|
|
5736
|
+
} catch (e11) {
|
|
5770
5737
|
await this.writeFile(filePath, "");
|
|
5771
5738
|
}
|
|
5772
5739
|
const release = await _properlockfile2.default.lock(filePath, {
|
|
@@ -5791,7 +5758,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
5791
5758
|
const { stale = 1e4, realpath = true, lockfilePath } = options;
|
|
5792
5759
|
try {
|
|
5793
5760
|
return await _properlockfile2.default.check(filePath, { stale, realpath, lockfilePath });
|
|
5794
|
-
} catch (
|
|
5761
|
+
} catch (e12) {
|
|
5795
5762
|
return false;
|
|
5796
5763
|
}
|
|
5797
5764
|
}
|
|
@@ -5813,7 +5780,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
5813
5780
|
lockfilePath
|
|
5814
5781
|
});
|
|
5815
5782
|
return release;
|
|
5816
|
-
} catch (
|
|
5783
|
+
} catch (e13) {
|
|
5817
5784
|
return null;
|
|
5818
5785
|
}
|
|
5819
5786
|
}
|
|
@@ -5826,7 +5793,7 @@ var FileLockManager = class _FileLockManager {
|
|
|
5826
5793
|
const { realpath = true, lockfilePath } = options;
|
|
5827
5794
|
try {
|
|
5828
5795
|
await _properlockfile2.default.unlock(filePath, { realpath, lockfilePath });
|
|
5829
|
-
} catch (
|
|
5796
|
+
} catch (e14) {
|
|
5830
5797
|
}
|
|
5831
5798
|
}
|
|
5832
5799
|
async writeFile(filePath, content) {
|
|
@@ -5844,7 +5811,7 @@ var Helper = (_class5 = class {
|
|
|
5844
5811
|
__init8() {this.outDir = "react-app"}
|
|
5845
5812
|
constructor(opts) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);
|
|
5846
5813
|
this.compilerOpts = opts;
|
|
5847
|
-
if (_optionalChain([opts, 'access',
|
|
5814
|
+
if (_optionalChain([opts, 'access', _203 => _203.output, 'optionalAccess', _204 => _204.workspace])) {
|
|
5848
5815
|
this.workspaceDir = opts.output.workspace;
|
|
5849
5816
|
}
|
|
5850
5817
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -5881,7 +5848,7 @@ var Helper = (_class5 = class {
|
|
|
5881
5848
|
}
|
|
5882
5849
|
getOutDirName() {
|
|
5883
5850
|
const { output } = this.compilerOpts;
|
|
5884
|
-
return _optionalChain([output, 'optionalAccess',
|
|
5851
|
+
return _optionalChain([output, 'optionalAccess', _205 => _205.outDir]) || this.outDir;
|
|
5885
5852
|
}
|
|
5886
5853
|
getWorkspaceDir() {
|
|
5887
5854
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -5895,7 +5862,7 @@ var Helper = (_class5 = class {
|
|
|
5895
5862
|
}
|
|
5896
5863
|
getIgnoreAssets() {
|
|
5897
5864
|
const { output } = this.compilerOpts;
|
|
5898
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
5865
|
+
if (_optionalChain([output, 'optionalAccess', _206 => _206.ignoreAssets])) {
|
|
5899
5866
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
5900
5867
|
}
|
|
5901
5868
|
return /* @__PURE__ */ new Set([
|
|
@@ -5978,12 +5945,12 @@ var Helper = (_class5 = class {
|
|
|
5978
5945
|
*/
|
|
5979
5946
|
async formatCode({ code, fileInfo }) {
|
|
5980
5947
|
const { format } = this.compilerOpts;
|
|
5981
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
5982
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
5948
|
+
if (!_optionalChain([format, 'optionalAccess', _207 => _207.enabled])) return code;
|
|
5949
|
+
if (_optionalChain([format, 'optionalAccess', _208 => _208.formatter]) === "builtin") {
|
|
5983
5950
|
return simpleFormat(code);
|
|
5984
5951
|
}
|
|
5985
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
5986
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
5952
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _209 => _209.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _210 => _210.script])));
|
|
5953
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _211 => _211.prettierOptions]));
|
|
5987
5954
|
}
|
|
5988
5955
|
/**
|
|
5989
5956
|
* 通用的缓存校验工具函数
|
|
@@ -6017,7 +5984,7 @@ var Helper = (_class5 = class {
|
|
|
6017
5984
|
* @param options.lock - 是否启用文件锁(默认false)
|
|
6018
5985
|
*/
|
|
6019
5986
|
async writeFileWithDir(filePath, content, options) {
|
|
6020
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5987
|
+
if (_optionalChain([options, 'optionalAccess', _212 => _212.lock])) {
|
|
6021
5988
|
await fileLock.updateFile(filePath, async () => content, options);
|
|
6022
5989
|
} else {
|
|
6023
5990
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
@@ -6027,7 +5994,7 @@ var Helper = (_class5 = class {
|
|
|
6027
5994
|
async rmFile(filePath) {
|
|
6028
5995
|
try {
|
|
6029
5996
|
await _fs2.default.promises.rm(filePath, { recursive: true, force: true });
|
|
6030
|
-
} catch (
|
|
5997
|
+
} catch (e15) {
|
|
6031
5998
|
}
|
|
6032
5999
|
}
|
|
6033
6000
|
async loadCache(key) {
|
|
@@ -6044,7 +6011,7 @@ var Helper = (_class5 = class {
|
|
|
6044
6011
|
target: data[key] || [],
|
|
6045
6012
|
source: data
|
|
6046
6013
|
};
|
|
6047
|
-
} catch (
|
|
6014
|
+
} catch (e16) {
|
|
6048
6015
|
return defaultData;
|
|
6049
6016
|
}
|
|
6050
6017
|
}
|
|
@@ -6142,7 +6109,7 @@ var Helper = (_class5 = class {
|
|
|
6142
6109
|
* 获取需要排除编译的文件
|
|
6143
6110
|
*/
|
|
6144
6111
|
getExcludes() {
|
|
6145
|
-
if (!_optionalChain([this, 'access',
|
|
6112
|
+
if (!_optionalChain([this, 'access', _213 => _213.compilerOpts, 'access', _214 => _214.exclude, 'optionalAccess', _215 => _215.length])) {
|
|
6146
6113
|
return PathFilter.withDefaults();
|
|
6147
6114
|
}
|
|
6148
6115
|
return this.compilerOpts.exclude;
|
|
@@ -6240,7 +6207,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
6240
6207
|
ast: void 0
|
|
6241
6208
|
}
|
|
6242
6209
|
};
|
|
6243
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
6210
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _216 => _216.plugins]), result, ctx);
|
|
6244
6211
|
return result;
|
|
6245
6212
|
}
|
|
6246
6213
|
|
|
@@ -6372,16 +6339,16 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
6372
6339
|
});
|
|
6373
6340
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
6374
6341
|
const resolveSFCAndScriptFile = () => {
|
|
6375
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6376
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6342
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _217 => _217.parser]) });
|
|
6343
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _218 => _218.transformer]) });
|
|
6377
6344
|
const gen = generate(ir, ctx.data, {
|
|
6378
6345
|
...genOptions,
|
|
6379
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6346
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _219 => _219.codegen])
|
|
6380
6347
|
});
|
|
6381
6348
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
6382
6349
|
};
|
|
6383
6350
|
const resolveStyleFile = () => {
|
|
6384
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6351
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _220 => _220.parser]) });
|
|
6385
6352
|
return this.resolveStyleResult(result, ctx.data);
|
|
6386
6353
|
};
|
|
6387
6354
|
try {
|
|
@@ -6398,18 +6365,10 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
6398
6365
|
}
|
|
6399
6366
|
prepareGenerateOptions(filename) {
|
|
6400
6367
|
const userOptions = this.options.generate || {};
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
minimal: true,
|
|
6404
|
-
quotes: "single"
|
|
6405
|
-
},
|
|
6406
|
-
minified: true,
|
|
6407
|
-
...userOptions
|
|
6408
|
-
};
|
|
6409
|
-
if (mergedOptions.sourceMaps && filename) {
|
|
6410
|
-
mergedOptions.sourceFileName = mergedOptions.sourceFileName || filename;
|
|
6368
|
+
if (userOptions.sourceMaps && filename) {
|
|
6369
|
+
userOptions.sourceFileName = userOptions.sourceFileName || filename;
|
|
6411
6370
|
}
|
|
6412
|
-
return
|
|
6371
|
+
return userOptions;
|
|
6413
6372
|
}
|
|
6414
6373
|
resolveMainResult(ir, gen, ctxData) {
|
|
6415
6374
|
const { fileId, filename, scriptData, styleData, inputType } = ctxData;
|
|
@@ -6428,9 +6387,9 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
6428
6387
|
lang
|
|
6429
6388
|
},
|
|
6430
6389
|
css: {
|
|
6431
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
6432
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
6433
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
6390
|
+
file: _optionalChain([styleData, 'optionalAccess', _221 => _221.filePath]),
|
|
6391
|
+
hash: _optionalChain([styleData, 'optionalAccess', _222 => _222.scopeId]),
|
|
6392
|
+
code: _optionalChain([ir, 'optionalAccess', _223 => _223.style])
|
|
6434
6393
|
}
|
|
6435
6394
|
},
|
|
6436
6395
|
...base
|
|
@@ -6500,7 +6459,7 @@ var AssetManager = (_class8 = class {
|
|
|
6500
6459
|
const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
|
|
6501
6460
|
const filename = _path2.default.basename(p).toLowerCase();
|
|
6502
6461
|
const ext = _path2.default.extname(p).toLowerCase();
|
|
6503
|
-
if (!_optionalChain([options, 'access',
|
|
6462
|
+
if (!_optionalChain([options, 'access', _224 => _224.output, 'optionalAccess', _225 => _225.ignoreAssets])) {
|
|
6504
6463
|
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
6505
6464
|
if (pattern.endsWith(".")) {
|
|
6506
6465
|
return filename.startsWith(pattern);
|
|
@@ -6597,12 +6556,12 @@ var CacheManager = (_class9 = class {
|
|
|
6597
6556
|
const meta = { ...unit };
|
|
6598
6557
|
delete meta.source;
|
|
6599
6558
|
if (key === "sfc" /* SFC */) {
|
|
6600
|
-
_optionalChainDelete([meta, 'access',
|
|
6601
|
-
_optionalChainDelete([meta, 'access',
|
|
6559
|
+
_optionalChainDelete([meta, 'access', _226 => _226.output, 'optionalAccess', _227 => _227.jsx, 'access', _228 => delete _228.code]);
|
|
6560
|
+
_optionalChainDelete([meta, 'access', _229 => _229.output, 'optionalAccess', _230 => _230.css, 'access', _231 => delete _231.code]);
|
|
6602
6561
|
} else if (key === "script" /* SCRIPT */) {
|
|
6603
|
-
_optionalChainDelete([meta, 'access',
|
|
6562
|
+
_optionalChainDelete([meta, 'access', _232 => _232.output, 'optionalAccess', _233 => _233.script, 'access', _234 => delete _234.code]);
|
|
6604
6563
|
} else if (key === "style" /* STYLE */) {
|
|
6605
|
-
_optionalChainDelete([meta, 'access',
|
|
6564
|
+
_optionalChainDelete([meta, 'access', _235 => _235.output, 'optionalAccess', _236 => _236.style, 'access', _237 => delete _237.code]);
|
|
6606
6565
|
}
|
|
6607
6566
|
if (!this.pendingUpdates.has(key)) {
|
|
6608
6567
|
this.pendingUpdates.set(key, []);
|
|
@@ -6672,7 +6631,7 @@ var CleanupManager = class {
|
|
|
6672
6631
|
meta = m;
|
|
6673
6632
|
const { jsx, css } = meta.output;
|
|
6674
6633
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
6675
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
6634
|
+
if (_optionalChain([css, 'optionalAccess', _238 => _238.file])) {
|
|
6676
6635
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
6677
6636
|
}
|
|
6678
6637
|
break;
|
|
@@ -6733,7 +6692,7 @@ var CompilationUnitProcessor = class {
|
|
|
6733
6692
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
6734
6693
|
const isStyleFile = key === "style" /* STYLE */;
|
|
6735
6694
|
if (isSFC || isScriptFile) {
|
|
6736
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
6695
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _239 => _239.hasRoute]);
|
|
6737
6696
|
}
|
|
6738
6697
|
const resolveFileInfo = () => {
|
|
6739
6698
|
if (isSFC) {
|
|
@@ -6753,7 +6712,7 @@ var CompilationUnitProcessor = class {
|
|
|
6753
6712
|
const { script } = result.fileInfo;
|
|
6754
6713
|
unit.output = {
|
|
6755
6714
|
script: {
|
|
6756
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
6715
|
+
file: _optionalChain([script, 'optionalAccess', _240 => _240.file]),
|
|
6757
6716
|
code
|
|
6758
6717
|
}
|
|
6759
6718
|
};
|
|
@@ -6830,7 +6789,7 @@ var FileProcessor = (_class10 = class {
|
|
|
6830
6789
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
6831
6790
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
6832
6791
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
|
|
6833
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
6792
|
+
const record = _optionalChain([cache, 'optionalAccess', _241 => _241.target, 'access', _242 => _242.find, 'call', _243 => _243((c) => c.file === absPath)]);
|
|
6834
6793
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
6835
6794
|
fileMeta,
|
|
6836
6795
|
record,
|
|
@@ -6852,10 +6811,10 @@ var FileProcessor = (_class10 = class {
|
|
|
6852
6811
|
hash: hash || this.fileCompiler.genHash(source)
|
|
6853
6812
|
};
|
|
6854
6813
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
6855
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6814
|
+
if (_optionalChain([processed, 'optionalAccess', _244 => _244.output])) {
|
|
6856
6815
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
6857
6816
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
6858
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6817
|
+
if (_optionalChain([processed, 'optionalAccess', _245 => _245.hasRoute])) {
|
|
6859
6818
|
await this.addRouterToPackageJson();
|
|
6860
6819
|
await this.updateEntryWithRouterProvider();
|
|
6861
6820
|
}
|
|
@@ -6869,13 +6828,13 @@ var FileProcessor = (_class10 = class {
|
|
|
6869
6828
|
*/
|
|
6870
6829
|
async addRouterToPackageJson() {
|
|
6871
6830
|
const { output } = this.fileCompiler.options;
|
|
6872
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
6831
|
+
if (_optionalChain([output, 'optionalAccess', _246 => _246.bootstrapVite]) === false) {
|
|
6873
6832
|
return;
|
|
6874
6833
|
}
|
|
6875
6834
|
const { router } = RUNTIME_PACKAGES;
|
|
6876
6835
|
const filePath = this.fileCompiler.getOutputPkgPath();
|
|
6877
6836
|
const packageJson = await this.fileCompiler.resolvePackageFile(filePath);
|
|
6878
|
-
if (_optionalChain([packageJson, 'optionalAccess',
|
|
6837
|
+
if (_optionalChain([packageJson, 'optionalAccess', _247 => _247.dependencies, 'optionalAccess', _248 => _248[router.name]])) {
|
|
6879
6838
|
return;
|
|
6880
6839
|
}
|
|
6881
6840
|
if (!packageJson.dependencies) {
|
|
@@ -6894,14 +6853,14 @@ var FileProcessor = (_class10 = class {
|
|
|
6894
6853
|
const { exclude, output, router } = this.fileCompiler.options;
|
|
6895
6854
|
const inputPath = this.fileCompiler.getInputPath();
|
|
6896
6855
|
const outputPath = this.fileCompiler.getOuputPath(true);
|
|
6897
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
6856
|
+
if (_optionalChain([output, 'optionalAccess', _249 => _249.bootstrapVite]) === false || _optionalChain([router, 'optionalAccess', _250 => _250.autoUpdateEntry]) === false || !_optionalChain([router, 'optionalAccess', _251 => _251.configFile])) {
|
|
6898
6857
|
return;
|
|
6899
6858
|
}
|
|
6900
6859
|
const getMainFile = async (filename) => {
|
|
6901
6860
|
const filePath = _path2.default.resolve(outputPath, filename);
|
|
6902
6861
|
try {
|
|
6903
6862
|
return { filePath, content: await _fs2.default.promises.readFile(filePath, "utf-8") };
|
|
6904
|
-
} catch (
|
|
6863
|
+
} catch (e17) {
|
|
6905
6864
|
return;
|
|
6906
6865
|
}
|
|
6907
6866
|
};
|
|
@@ -6915,7 +6874,7 @@ var FileProcessor = (_class10 = class {
|
|
|
6915
6874
|
const prepareRouterEntry = () => {
|
|
6916
6875
|
const importPath = this.fileCompiler.resolveRelativePath(inputPath, router.configFile);
|
|
6917
6876
|
let content = fileData.content;
|
|
6918
|
-
if (_optionalChain([exclude, 'optionalAccess',
|
|
6877
|
+
if (_optionalChain([exclude, 'optionalAccess', _252 => _252.includes, 'call', _253 => _253(router.configFile)]) || _optionalChain([exclude, 'optionalAccess', _254 => _254.includes, 'call', _255 => _255(importPath)])) {
|
|
6919
6878
|
return content;
|
|
6920
6879
|
}
|
|
6921
6880
|
const routerModule = "RouterInstance";
|
|
@@ -7061,7 +7020,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7061
7020
|
const { output } = this.options;
|
|
7062
7021
|
const workspaceDir = this.fileCompiler.getWorkspaceDir();
|
|
7063
7022
|
await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
|
|
7064
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7023
|
+
if (_optionalChain([output, 'optionalAccess', _256 => _256.bootstrapVite]) === false) {
|
|
7065
7024
|
return false;
|
|
7066
7025
|
}
|
|
7067
7026
|
if (this.isSingleFile()) {
|
|
@@ -7111,7 +7070,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7111
7070
|
const newDevDeps = resolveDeps(sourcePkg.devDependencies, newPkg.devDependencies, true);
|
|
7112
7071
|
newPkg.dependencies = newDeps;
|
|
7113
7072
|
newPkg.devDependencies = newDevDeps;
|
|
7114
|
-
newPkg = _optionalChain([output, 'optionalAccess',
|
|
7073
|
+
newPkg = _optionalChain([output, 'optionalAccess', _257 => _257.packageJson, 'optionalCall', _258 => _258(newPkg)]) || newPkg;
|
|
7115
7074
|
await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
|
|
7116
7075
|
this.spinner.succeed("Standard Vite React environment initialized");
|
|
7117
7076
|
return true;
|
|
@@ -7122,12 +7081,12 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
7122
7081
|
async resolveViteCreateApp() {
|
|
7123
7082
|
const { output } = this.options;
|
|
7124
7083
|
const { viteVersion, template: tmpl } = this.defaultConfig;
|
|
7125
|
-
const bootstrapVite = _optionalChain([output, 'optionalAccess',
|
|
7084
|
+
const bootstrapVite = _optionalChain([output, 'optionalAccess', _259 => _259.bootstrapVite]);
|
|
7126
7085
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
7127
7086
|
const configObject = typeof bootstrapVite === "object" ? bootstrapVite : null;
|
|
7128
|
-
const viteVer = _optionalChain([configObject, 'optionalAccess',
|
|
7129
|
-
const reactVer = _optionalChain([configObject, 'optionalAccess',
|
|
7130
|
-
const template = _optionalChain([configObject, 'optionalAccess',
|
|
7087
|
+
const viteVer = _optionalChain([configObject, 'optionalAccess', _260 => _260.vite]) || viteVersion;
|
|
7088
|
+
const reactVer = _optionalChain([configObject, 'optionalAccess', _261 => _261.react]);
|
|
7089
|
+
const template = _optionalChain([configObject, 'optionalAccess', _262 => _262.template]) || tmpl;
|
|
7131
7090
|
const cmd = `npm create vite${viteVer} ${outDirName} -- --template ${template}`;
|
|
7132
7091
|
_child_process.execSync.call(void 0, cmd, {
|
|
7133
7092
|
cwd: this.fileCompiler.getWorkspaceDir(),
|
|
@@ -7231,7 +7190,7 @@ var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
|
7231
7190
|
const scriptCount = await this.runPipelineWithSpinner("script" /* SCRIPT */);
|
|
7232
7191
|
const styleCount = await this.runPipelineWithSpinner("style" /* STYLE */);
|
|
7233
7192
|
const assetCount = await this.runPipelineWithSpinner("copied" /* ASSET */);
|
|
7234
|
-
await _optionalChain([this, 'access',
|
|
7193
|
+
await _optionalChain([this, 'access', _263 => _263.options, 'access', _264 => _264.onSuccess, 'optionalCall', _265 => _265()]);
|
|
7235
7194
|
const endTime = calcElapsedTime(startTime);
|
|
7236
7195
|
this.printCoreLogs();
|
|
7237
7196
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|