@vureact/compiler-core 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{chunk-SQRJUILR.js → chunk-7LBUUA24.js} +829 -740
- package/lib/{chunk-7FIMRVQS.esm.js → chunk-CUCUXW56.esm.js} +782 -693
- package/lib/cli.d.cts +1 -2
- package/lib/cli.d.ts +1 -2
- package/lib/cli.esm.js +47 -2
- package/lib/cli.js +54 -9
- package/lib/compiler-core.d.cts +9 -0
- package/lib/compiler-core.d.ts +9 -0
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +13 -5
- package/templates/route-setup-notes.md +192 -0
- package/templates/route-setup-notes.zh.md +192 -0
|
@@ -1,5 +1,5 @@
|
|
|
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; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
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;/**
|
|
2
|
+
* @vureact/compiler-core v1.3.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,7 +24,7 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var
|
|
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 t20 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -418,8 +418,8 @@ function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
|
418
418
|
function stringToExpr(input, lang, filename = "") {
|
|
419
419
|
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
420
420
|
}
|
|
421
|
-
function atComponentOrHookRoot(
|
|
422
|
-
const { parentPath, scope } =
|
|
421
|
+
function atComponentOrHookRoot(path8, rootScope, inScriptFile = false) {
|
|
422
|
+
const { parentPath, scope } = path8;
|
|
423
423
|
const parentBlock = scope.block;
|
|
424
424
|
if (!parentPath) return !inScriptFile;
|
|
425
425
|
if (parentBlock === rootScope) {
|
|
@@ -545,6 +545,81 @@ function buildJsxChildren(children, ctx) {
|
|
|
545
545
|
|
|
546
546
|
// src/core/codegen/component/jsx/syntax-processor/process/build-loop-node.ts
|
|
547
547
|
|
|
548
|
+
|
|
549
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
// src/utils/camelCase.ts
|
|
553
|
+
var camelCase = (str) => {
|
|
554
|
+
if (str.includes("-")) {
|
|
555
|
+
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
556
|
+
}
|
|
557
|
+
return str;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/utils/capitalize.ts
|
|
561
|
+
var capitalize = (str) => {
|
|
562
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/special-expressions.ts
|
|
566
|
+
function resolveSpecialExpressions(input, ctx) {
|
|
567
|
+
input = resolveEmitsCalls(input, ctx);
|
|
568
|
+
input = resolveRefVariable(input, ctx);
|
|
569
|
+
return input;
|
|
570
|
+
}
|
|
571
|
+
function resolveEmitsCalls(input, ctx) {
|
|
572
|
+
const result = matchEmitCalls(input, ctx);
|
|
573
|
+
if (!result) return input;
|
|
574
|
+
const [, , eventName, args] = result;
|
|
575
|
+
const callee = eventName.split(/[:\-]/).map((part) => capitalize(camelCase(part))).join("");
|
|
576
|
+
const event = args ? `on${callee}?.(${args})` : `on${callee}?.()`;
|
|
577
|
+
return `${ctx.propField}?.${event}`;
|
|
578
|
+
}
|
|
579
|
+
function matchEmitCalls(input, ctx) {
|
|
580
|
+
const { reactiveBindings } = ctx.templateData;
|
|
581
|
+
const macroBinding = Object.values(reactiveBindings).find((b) => b.source === "defineEmits");
|
|
582
|
+
if (!macroBinding) return null;
|
|
583
|
+
const escapedName = macroBinding.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
584
|
+
const regex = new RegExp(
|
|
585
|
+
`${escapedName}\\s*\\(\\s*(['"\`])([^\\1]*?)\\1\\s*(?:,\\s*(.*?))?\\s*\\)$`,
|
|
586
|
+
// 可选的第二个参数
|
|
587
|
+
"s"
|
|
588
|
+
// s 标志让 . 匹配换行符
|
|
589
|
+
);
|
|
590
|
+
return input.trim().match(regex);
|
|
591
|
+
}
|
|
592
|
+
function resolveRefVariable(input, ctx) {
|
|
593
|
+
const { reactiveBindings } = ctx.templateData;
|
|
594
|
+
const addValueProperty = (input2, varName) => {
|
|
595
|
+
const escapedVarName = varName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
596
|
+
const regex = new RegExp(
|
|
597
|
+
`(?<![a-zA-Z0-9_\\.])${escapedVarName}(?![a-zA-Z0-9_])(?!\\.value)`,
|
|
598
|
+
"g"
|
|
599
|
+
);
|
|
600
|
+
return input2.replace(regex, `${varName}.value`);
|
|
601
|
+
};
|
|
602
|
+
for (const name in reactiveBindings) {
|
|
603
|
+
const binding = reactiveBindings[name];
|
|
604
|
+
if (_optionalChain([binding, 'optionalAccess', _6 => _6.reactiveType]) !== "ref") continue;
|
|
605
|
+
input = addValueProperty(input, name);
|
|
606
|
+
}
|
|
607
|
+
return input;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
611
|
+
function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
612
|
+
if (toStrLiteral) return t5.stringLiteral(input);
|
|
613
|
+
const { filename, scriptData } = ctx;
|
|
614
|
+
const newContent = resolveSpecialExpressions(input, ctx);
|
|
615
|
+
try {
|
|
616
|
+
return stringToExpr(newContent, scriptData.lang, filename);
|
|
617
|
+
} catch (e2) {
|
|
618
|
+
return t5.identifier(newContent);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/core/codegen/component/jsx/syntax-processor/process/build-loop-node.ts
|
|
548
623
|
function buildLoopNode(nodeIR, ctx) {
|
|
549
624
|
const loop = nodeIR.meta.loop;
|
|
550
625
|
loop.isHandled = true;
|
|
@@ -554,15 +629,15 @@ function buildLoopNode(nodeIR, ctx) {
|
|
|
554
629
|
function buildArrayLoopNode(nodeIR, ctx) {
|
|
555
630
|
const loop = nodeIR.meta.loop;
|
|
556
631
|
const { source, value, index, key } = loop.value;
|
|
557
|
-
const
|
|
558
|
-
const params = [
|
|
632
|
+
const sourceExpression = resolveStringExpr(source, ctx);
|
|
633
|
+
const params = [t6.identifier(value)];
|
|
559
634
|
if (_nullishCoalesce(index, () => ( key))) {
|
|
560
|
-
params.push(
|
|
635
|
+
params.push(t6.identifier(_nullishCoalesce(index, () => ( key))));
|
|
561
636
|
}
|
|
562
|
-
const mapCallExpression =
|
|
563
|
-
|
|
637
|
+
const mapCallExpression = t6.callExpression(
|
|
638
|
+
t6.memberExpression(sourceExpression, t6.identifier("map")),
|
|
564
639
|
[
|
|
565
|
-
|
|
640
|
+
t6.arrowFunctionExpression(
|
|
566
641
|
params,
|
|
567
642
|
convertJsxChildToExpression(buildElementNode(nodeIR, ctx))
|
|
568
643
|
)
|
|
@@ -573,21 +648,21 @@ function buildArrayLoopNode(nodeIR, ctx) {
|
|
|
573
648
|
function buildObjectLoopNode(nodeIR, ctx) {
|
|
574
649
|
const loop = nodeIR.meta.loop;
|
|
575
650
|
const { source, value, key, index } = loop.value;
|
|
576
|
-
const
|
|
577
|
-
const objectEntriesCallExpression =
|
|
578
|
-
|
|
579
|
-
[
|
|
651
|
+
const sourceExpression = resolveStringExpr(source, ctx);
|
|
652
|
+
const objectEntriesCallExpression = t6.callExpression(
|
|
653
|
+
t6.memberExpression(t6.identifier("Object"), t6.identifier("entries")),
|
|
654
|
+
[sourceExpression]
|
|
580
655
|
);
|
|
581
656
|
const params = [
|
|
582
|
-
|
|
657
|
+
t6.arrayPattern([t6.identifier(key || "key"), t6.identifier(value)])
|
|
583
658
|
];
|
|
584
659
|
if (index) {
|
|
585
|
-
params.push(
|
|
660
|
+
params.push(t6.identifier(index));
|
|
586
661
|
}
|
|
587
|
-
const mapCallExpression =
|
|
588
|
-
|
|
662
|
+
const mapCallExpression = t6.callExpression(
|
|
663
|
+
t6.memberExpression(objectEntriesCallExpression, t6.identifier("map")),
|
|
589
664
|
[
|
|
590
|
-
|
|
665
|
+
t6.arrowFunctionExpression(
|
|
591
666
|
params,
|
|
592
667
|
convertJsxChildToExpression(buildElementNode(nodeIR, ctx))
|
|
593
668
|
)
|
|
@@ -603,8 +678,8 @@ function buildMemoNode(nodeIR, ctx) {
|
|
|
603
678
|
memo.isHandled = true;
|
|
604
679
|
const depsExpression = memo.babelExp.ast;
|
|
605
680
|
const bodyExpression = convertJsxChildToExpression(buildElementNode(nodeIR, ctx));
|
|
606
|
-
const useMemoCallExpression =
|
|
607
|
-
|
|
681
|
+
const useMemoCallExpression = t7.callExpression(t7.identifier("useMemo"), [
|
|
682
|
+
t7.arrowFunctionExpression([], bodyExpression),
|
|
608
683
|
depsExpression
|
|
609
684
|
]);
|
|
610
685
|
return buildJsxExpressionNode(useMemoCallExpression);
|
|
@@ -624,6 +699,9 @@ function buildMemoNode(nodeIR, ctx) {
|
|
|
624
699
|
var _minimatch = require('minimatch');
|
|
625
700
|
var _url = require('url');
|
|
626
701
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
702
|
+
function getDirname(metaUrl) {
|
|
703
|
+
return _path2.default.dirname(_url.fileURLToPath.call(void 0, metaUrl));
|
|
704
|
+
}
|
|
627
705
|
var PathFilter = (_class = class {
|
|
628
706
|
__init() {this.patterns = []}
|
|
629
707
|
|
|
@@ -692,7 +770,7 @@ function normalizePath(filePath) {
|
|
|
692
770
|
if (fp.startsWith("file:")) {
|
|
693
771
|
fp = _url.fileURLToPath.call(void 0, fp);
|
|
694
772
|
}
|
|
695
|
-
} catch (
|
|
773
|
+
} catch (e3) {
|
|
696
774
|
}
|
|
697
775
|
fp = fp.replace(/\\/g, "/").replace(/\/\/+/, "/");
|
|
698
776
|
return fp;
|
|
@@ -725,8 +803,8 @@ var Logger = (_class2 = class {constructor() { _class2.prototype.__init2.call(th
|
|
|
725
803
|
level,
|
|
726
804
|
message,
|
|
727
805
|
file: file ? normalizePath(relativePath(file)) : void 0,
|
|
728
|
-
line: _optionalChain([loc, 'optionalAccess',
|
|
729
|
-
column: _optionalChain([loc, 'optionalAccess',
|
|
806
|
+
line: _optionalChain([loc, 'optionalAccess', _7 => _7.start, 'optionalAccess', _8 => _8.line]),
|
|
807
|
+
column: _optionalChain([loc, 'optionalAccess', _9 => _9.start, 'optionalAccess', _10 => _10.column]),
|
|
730
808
|
source,
|
|
731
809
|
contextLines
|
|
732
810
|
};
|
|
@@ -812,9 +890,9 @@ var Logger = (_class2 = class {constructor() { _class2.prototype.__init2.call(th
|
|
|
812
890
|
return result.join("\n");
|
|
813
891
|
}
|
|
814
892
|
getOrderedLogs(opts) {
|
|
815
|
-
const errorLogs = _optionalChain([opts, 'optionalAccess',
|
|
816
|
-
const warnLogs = _optionalChain([opts, 'optionalAccess',
|
|
817
|
-
const infoLogs = _optionalChain([opts, 'optionalAccess',
|
|
893
|
+
const errorLogs = _optionalChain([opts, 'optionalAccess', _11 => _11.errors]) === false ? [] : this.logs.filter((l) => l.level === "error");
|
|
894
|
+
const warnLogs = _optionalChain([opts, 'optionalAccess', _12 => _12.warnings]) === false ? [] : this.logs.filter((l) => l.level === "warning");
|
|
895
|
+
const infoLogs = _optionalChain([opts, 'optionalAccess', _13 => _13.info]) === false ? [] : this.logs.filter((l) => l.level === "info");
|
|
818
896
|
return [...errorLogs, ...warnLogs, ...infoLogs];
|
|
819
897
|
}
|
|
820
898
|
printSummary() {
|
|
@@ -864,16 +942,16 @@ var logger = new Logger();
|
|
|
864
942
|
|
|
865
943
|
// src/core/codegen/component/jsx/syntax-processor/process/build-slot-prop.ts
|
|
866
944
|
function buildSlotProp(nodeIR, ctx) {
|
|
867
|
-
const slotKey =
|
|
868
|
-
const childrenNodeIR = !nodeIR.isScoped ? nodeIR.content : _optionalChain([nodeIR, 'access',
|
|
869
|
-
if (!_optionalChain([childrenNodeIR, 'optionalAccess',
|
|
945
|
+
const slotKey = t8.jsxIdentifier(nodeIR.name);
|
|
946
|
+
const childrenNodeIR = !nodeIR.isScoped ? nodeIR.content : _optionalChain([nodeIR, 'access', _14 => _14.callback, 'optionalAccess', _15 => _15.exp]);
|
|
947
|
+
if (!_optionalChain([childrenNodeIR, 'optionalAccess', _16 => _16.length])) {
|
|
870
948
|
return null;
|
|
871
949
|
}
|
|
872
950
|
const jsxChild = childrenNodeIR.length > 1 ? buildFragmentNode(buildJsxChildren(childrenNodeIR, ctx)) : buildJsxNode(childrenNodeIR[0], ctx);
|
|
873
951
|
if (!jsxChild) {
|
|
874
952
|
return null;
|
|
875
953
|
}
|
|
876
|
-
const slotValue = nodeIR.isScoped ?
|
|
954
|
+
const slotValue = nodeIR.isScoped ? t8.arrowFunctionExpression(
|
|
877
955
|
buildSlotCallbackParams(nodeIR, ctx),
|
|
878
956
|
convertJsxChildToExpression(jsxChild)
|
|
879
957
|
) : jsxChild;
|
|
@@ -882,32 +960,32 @@ function buildSlotProp(nodeIR, ctx) {
|
|
|
882
960
|
}
|
|
883
961
|
if (!nodeIR.isStatic) {
|
|
884
962
|
const dynamicSlotKey = _parser.parseExpression.call(void 0, nodeIR.name);
|
|
885
|
-
const spreadObject =
|
|
886
|
-
|
|
963
|
+
const spreadObject = t8.objectExpression([
|
|
964
|
+
t8.objectProperty(dynamicSlotKey, convertSlotValueToExpression(slotValue), true)
|
|
887
965
|
]);
|
|
888
|
-
return
|
|
966
|
+
return t8.jsxSpreadAttribute(spreadObject);
|
|
889
967
|
}
|
|
890
|
-
return
|
|
968
|
+
return t8.jsxAttribute(slotKey, buildJsxExpressionNode(convertSlotValueToExpression(slotValue)));
|
|
891
969
|
}
|
|
892
970
|
function convertSlotValueToExpression(nodeIR) {
|
|
893
|
-
if (
|
|
971
|
+
if (t8.isArrowFunctionExpression(nodeIR)) {
|
|
894
972
|
return nodeIR;
|
|
895
973
|
}
|
|
896
974
|
return convertJsxChildToExpression(nodeIR);
|
|
897
975
|
}
|
|
898
976
|
function buildSlotCallbackParams(nodeIR, ctx) {
|
|
899
|
-
const rawArg = _optionalChain([nodeIR, 'access',
|
|
977
|
+
const rawArg = _optionalChain([nodeIR, 'access', _17 => _17.callback, 'optionalAccess', _18 => _18.arg, 'optionalAccess', _19 => _19.trim, 'call', _20 => _20()]);
|
|
900
978
|
if (!rawArg) {
|
|
901
979
|
return [];
|
|
902
980
|
}
|
|
903
981
|
const source = rawArg.startsWith("(") ? `${rawArg} => null` : `(${rawArg}) => null`;
|
|
904
982
|
try {
|
|
905
983
|
const expression = _parser.parseExpression.call(void 0, source);
|
|
906
|
-
if (!
|
|
984
|
+
if (!t8.isArrowFunctionExpression(expression)) {
|
|
907
985
|
return [];
|
|
908
986
|
}
|
|
909
987
|
return expression.params;
|
|
910
|
-
} catch (
|
|
988
|
+
} catch (e4) {
|
|
911
989
|
logger.warn(`Failed to parse slot params "${rawArg}". Falling back to no-arg slot function.`, {
|
|
912
990
|
file: ctx.filename
|
|
913
991
|
});
|
|
@@ -946,13 +1024,13 @@ function buildStandardProp(nodeIR) {
|
|
|
946
1024
|
}
|
|
947
1025
|
} = nodeIR;
|
|
948
1026
|
if (!isStatic || isKeyLessVBind) {
|
|
949
|
-
return
|
|
1027
|
+
return t9.jsxSpreadAttribute(valueAST);
|
|
950
1028
|
}
|
|
951
1029
|
let value;
|
|
952
1030
|
if (content !== "true") {
|
|
953
|
-
value = isStringLiteral13 ?
|
|
1031
|
+
value = isStringLiteral13 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
954
1032
|
}
|
|
955
|
-
return
|
|
1033
|
+
return t9.jsxAttribute(keyAST, value);
|
|
956
1034
|
}
|
|
957
1035
|
|
|
958
1036
|
// src/core/codegen/component/jsx/syntax-processor/process/build-element-node.ts
|
|
@@ -962,13 +1040,13 @@ function buildElementNode(nodeIR, ctx) {
|
|
|
962
1040
|
return null;
|
|
963
1041
|
}
|
|
964
1042
|
const meta = nodeIR.meta;
|
|
965
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1043
|
+
if (_optionalChain([meta, 'optionalAccess', _21 => _21.condition]) && !meta.condition.isHandled) {
|
|
966
1044
|
return buildConditionNode(nodeIR, ctx);
|
|
967
1045
|
}
|
|
968
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1046
|
+
if (_optionalChain([meta, 'optionalAccess', _22 => _22.memo, 'optionalAccess', _23 => _23.isMemo]) && !meta.memo.isHandled) {
|
|
969
1047
|
return buildMemoNode(nodeIR, ctx);
|
|
970
1048
|
}
|
|
971
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1049
|
+
if (_optionalChain([meta, 'optionalAccess', _24 => _24.loop, 'optionalAccess', _25 => _25.isLoop]) && !meta.loop.isHandled) {
|
|
972
1050
|
return buildLoopNode(nodeIR, ctx);
|
|
973
1051
|
}
|
|
974
1052
|
const props = buildProps(nodeIR, ctx);
|
|
@@ -998,8 +1076,8 @@ function buildConditionNode(nodeIR, ctx) {
|
|
|
998
1076
|
}
|
|
999
1077
|
const testExpression = condition.babelExp.ast;
|
|
1000
1078
|
const trueBranchExpression = convertJsxChildToExpression(buildCurrentNode());
|
|
1001
|
-
const falseBranchExpression = nextNodeIR ? convertJsxChildToExpression(buildElementNode(nextNodeIR, ctx)) :
|
|
1002
|
-
const conditionalExpression2 =
|
|
1079
|
+
const falseBranchExpression = nextNodeIR ? convertJsxChildToExpression(buildElementNode(nextNodeIR, ctx)) : t10.nullLiteral();
|
|
1080
|
+
const conditionalExpression2 = t10.conditionalExpression(
|
|
1003
1081
|
testExpression,
|
|
1004
1082
|
// 条件测试部分
|
|
1005
1083
|
trueBranchExpression,
|
|
@@ -1015,23 +1093,23 @@ function buildConditionNode(nodeIR, ctx) {
|
|
|
1015
1093
|
function buildCtxProviderNode(nodeIR, ctx, children) {
|
|
1016
1094
|
const { name, value, provide: nextProvide } = nodeIR;
|
|
1017
1095
|
let childNodes = children;
|
|
1018
|
-
if (_optionalChain([nextProvide, 'optionalAccess',
|
|
1096
|
+
if (_optionalChain([nextProvide, 'optionalAccess', _26 => _26.isOccupied])) {
|
|
1019
1097
|
childNodes = [buildCtxProviderNode(nextProvide, ctx, children)];
|
|
1020
1098
|
}
|
|
1021
1099
|
const parseProviderExpr = (raw) => {
|
|
1022
|
-
if (!raw) return
|
|
1100
|
+
if (!raw) return t11.stringLiteral("");
|
|
1023
1101
|
try {
|
|
1024
1102
|
return stringToExpr(raw, ctx.scriptData.lang, ctx.filename);
|
|
1025
|
-
} catch (
|
|
1026
|
-
return
|
|
1103
|
+
} catch (e5) {
|
|
1104
|
+
return t11.stringLiteral(raw);
|
|
1027
1105
|
}
|
|
1028
1106
|
};
|
|
1029
|
-
const nameProp =
|
|
1030
|
-
|
|
1107
|
+
const nameProp = t11.jsxAttribute(
|
|
1108
|
+
t11.jsxIdentifier("name"),
|
|
1031
1109
|
buildJsxExpressionNode(parseProviderExpr(name))
|
|
1032
1110
|
);
|
|
1033
|
-
const valueProp =
|
|
1034
|
-
|
|
1111
|
+
const valueProp = t11.jsxAttribute(
|
|
1112
|
+
t11.jsxIdentifier("value"),
|
|
1035
1113
|
buildJsxExpressionNode(parseProviderExpr(value))
|
|
1036
1114
|
);
|
|
1037
1115
|
void ctx;
|
|
@@ -1078,7 +1156,7 @@ function jsxBuilder(nodeIR, ctx, state, options) {
|
|
|
1078
1156
|
|
|
1079
1157
|
// src/core/codegen/component/jsx/index.ts
|
|
1080
1158
|
function buildJSX(nodeIR, ctx) {
|
|
1081
|
-
if (!_optionalChain([nodeIR, 'optionalAccess',
|
|
1159
|
+
if (!_optionalChain([nodeIR, 'optionalAccess', _27 => _27.children, 'access', _28 => _28.length])) {
|
|
1082
1160
|
return null;
|
|
1083
1161
|
}
|
|
1084
1162
|
return buildJSXChild(nodeIR, ctx);
|
|
@@ -1092,16 +1170,16 @@ function buildJSX(nodeIR, ctx) {
|
|
|
1092
1170
|
function buildProgramNode(nodeIR, ctx, state) {
|
|
1093
1171
|
const statements = [...state.preambleStatements];
|
|
1094
1172
|
if (!state.component) {
|
|
1095
|
-
state.result =
|
|
1173
|
+
state.result = t12.program(statements, void 0, "module");
|
|
1096
1174
|
return;
|
|
1097
1175
|
}
|
|
1098
1176
|
statements.push(state.component);
|
|
1099
1177
|
if (state.expose) {
|
|
1100
1178
|
const [declarator] = state.component.declarations;
|
|
1101
1179
|
const { name } = declarator.id;
|
|
1102
|
-
statements.push(
|
|
1180
|
+
statements.push(t12.exportDefaultDeclaration(t12.identifier(name)));
|
|
1103
1181
|
}
|
|
1104
|
-
state.result =
|
|
1182
|
+
state.result = t12.program(statements, void 0, "module");
|
|
1105
1183
|
void nodeIR;
|
|
1106
1184
|
void ctx;
|
|
1107
1185
|
}
|
|
@@ -1121,19 +1199,6 @@ var REACT_API_MAP = {
|
|
|
1121
1199
|
useImperativeHandle: "useImperativeHandle"
|
|
1122
1200
|
};
|
|
1123
1201
|
|
|
1124
|
-
// src/utils/camelCase.ts
|
|
1125
|
-
var camelCase = (str) => {
|
|
1126
|
-
if (str.includes("-")) {
|
|
1127
|
-
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
1128
|
-
}
|
|
1129
|
-
return str;
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
// src/utils/capitalize.ts
|
|
1133
|
-
var capitalize = (str) => {
|
|
1134
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
1202
|
// src/utils/hash.ts
|
|
1138
1203
|
var _xxhashjs = require('xxhashjs'); var _xxhashjs2 = _interopRequireDefault(_xxhashjs);
|
|
1139
1204
|
function genHashByXXH(str) {
|
|
@@ -1157,7 +1222,7 @@ function buildComponent(scriptIR, ctx, state) {
|
|
|
1157
1222
|
} = ctx;
|
|
1158
1223
|
const hasProps = getHasProps(propsTSIface.propsTypes) || getHasProps(propsTSIface.emitTypes) || getHasProps(propsTSIface.slotTypes);
|
|
1159
1224
|
const shouldMemo = scriptIR !== null || hasProps;
|
|
1160
|
-
const jsxStatement =
|
|
1225
|
+
const jsxStatement = t13.returnStatement(state.jsx || t13.nullLiteral());
|
|
1161
1226
|
const component = !shouldMemo ? resolvePureUIComponent(jsxStatement, ctx) : resolveMemoComponent(scriptIR.statement.local, jsxStatement, ctx);
|
|
1162
1227
|
state.component = component;
|
|
1163
1228
|
}
|
|
@@ -1165,24 +1230,24 @@ function getHasProps(list) {
|
|
|
1165
1230
|
return list.length > 0;
|
|
1166
1231
|
}
|
|
1167
1232
|
function resolvePureUIComponent(jsxStmt, ctx) {
|
|
1168
|
-
return
|
|
1169
|
-
|
|
1233
|
+
return t13.variableDeclaration("const", [
|
|
1234
|
+
t13.variableDeclarator(
|
|
1170
1235
|
resolveComponentName(ctx),
|
|
1171
|
-
|
|
1236
|
+
t13.arrowFunctionExpression([], t13.blockStatement([jsxStmt]))
|
|
1172
1237
|
)
|
|
1173
1238
|
]);
|
|
1174
1239
|
}
|
|
1175
1240
|
function resolveMemoComponent(local, jsxStmt, ctx) {
|
|
1176
1241
|
const name = resolveComponentName(ctx);
|
|
1177
1242
|
const param = resolvePropsParam(ctx);
|
|
1178
|
-
const body =
|
|
1243
|
+
const body = t13.blockStatement(resolveLocalStatements(local, jsxStmt));
|
|
1179
1244
|
const component = resolveComponent(param, body, ctx);
|
|
1180
1245
|
let compFn = component;
|
|
1181
1246
|
if (ctx.scriptData.forwardRef.enabled) {
|
|
1182
1247
|
compFn = resolveForwardRef(body, ctx);
|
|
1183
1248
|
}
|
|
1184
|
-
const memoCall =
|
|
1185
|
-
return
|
|
1249
|
+
const memoCall = t13.callExpression(t13.identifier(REACT_API_MAP.memo), [compFn]);
|
|
1250
|
+
return t13.variableDeclaration("const", [t13.variableDeclarator(name, memoCall)]);
|
|
1186
1251
|
}
|
|
1187
1252
|
function resolveComponentName(ctx) {
|
|
1188
1253
|
const { filename, compName } = ctx;
|
|
@@ -1196,14 +1261,14 @@ function resolveComponentName(ctx) {
|
|
|
1196
1261
|
file: filename
|
|
1197
1262
|
});
|
|
1198
1263
|
}
|
|
1199
|
-
return
|
|
1264
|
+
return t13.identifier(name);
|
|
1200
1265
|
}
|
|
1201
1266
|
function resolveLocalStatements(local, jsx) {
|
|
1202
1267
|
const stmts = [jsx];
|
|
1203
1268
|
if (!local) return stmts;
|
|
1204
1269
|
if (typeof local === "object" && "program" in local) {
|
|
1205
1270
|
const program3 = local.program;
|
|
1206
|
-
if (_optionalChain([program3, 'optionalAccess',
|
|
1271
|
+
if (_optionalChain([program3, 'optionalAccess', _29 => _29.body, 'optionalAccess', _30 => _30.length])) {
|
|
1207
1272
|
return [...program3.body, jsx];
|
|
1208
1273
|
}
|
|
1209
1274
|
}
|
|
@@ -1216,7 +1281,7 @@ function resolveComponent(param, body, ctx) {
|
|
|
1216
1281
|
if (forwardRef.enabled) {
|
|
1217
1282
|
return resolveForwardRef(body, ctx);
|
|
1218
1283
|
}
|
|
1219
|
-
const baseComponent =
|
|
1284
|
+
const baseComponent = t13.arrowFunctionExpression(!param ? [] : [param], body);
|
|
1220
1285
|
return baseComponent;
|
|
1221
1286
|
}
|
|
1222
1287
|
function resolveForwardRef(body, ctx) {
|
|
@@ -1224,18 +1289,18 @@ function resolveForwardRef(body, ctx) {
|
|
|
1224
1289
|
propField,
|
|
1225
1290
|
scriptData: { forwardRef, lang }
|
|
1226
1291
|
} = ctx;
|
|
1227
|
-
const params = [
|
|
1292
|
+
const params = [t13.identifier(forwardRef.refField)];
|
|
1228
1293
|
const propsId = resolvePropsParam(ctx);
|
|
1229
|
-
const callExpr =
|
|
1230
|
-
|
|
1294
|
+
const callExpr = t13.callExpression(t13.identifier(REACT_API_MAP.forwardRef), [
|
|
1295
|
+
t13.arrowFunctionExpression(params, body)
|
|
1231
1296
|
]);
|
|
1232
1297
|
if (lang.startsWith("ts")) {
|
|
1233
|
-
const types = [
|
|
1298
|
+
const types = [t13.tsAnyKeyword()];
|
|
1234
1299
|
if (propsId) {
|
|
1235
|
-
const propsType = _optionalChain([propsId, 'optionalAccess',
|
|
1236
|
-
types.push(propsType ||
|
|
1300
|
+
const propsType = _optionalChain([propsId, 'optionalAccess', _31 => _31.typeAnnotation, 'optionalAccess', _32 => _32.typeAnnotation]);
|
|
1301
|
+
types.push(propsType || t13.tsAnyKeyword());
|
|
1237
1302
|
}
|
|
1238
|
-
callExpr.typeParameters =
|
|
1303
|
+
callExpr.typeParameters = t13.tsTypeParameterInstantiation(types);
|
|
1239
1304
|
}
|
|
1240
1305
|
if (propsId) {
|
|
1241
1306
|
propsId.typeAnnotation = null;
|
|
@@ -1246,7 +1311,7 @@ function resolveForwardRef(body, ctx) {
|
|
|
1246
1311
|
function resolvePropsParam(ctx) {
|
|
1247
1312
|
const { propField, scriptData } = ctx;
|
|
1248
1313
|
const { propsTSIface } = scriptData;
|
|
1249
|
-
const propsIdentifier =
|
|
1314
|
+
const propsIdentifier = t13.identifier(propField);
|
|
1250
1315
|
if (scriptData.lang.startsWith("js")) {
|
|
1251
1316
|
if (propsTSIface.hasPropsInJsEnv) {
|
|
1252
1317
|
return propsIdentifier;
|
|
@@ -1256,14 +1321,14 @@ function resolvePropsParam(ctx) {
|
|
|
1256
1321
|
if (!propsTSIface.name) {
|
|
1257
1322
|
return;
|
|
1258
1323
|
}
|
|
1259
|
-
const typeIdentifier =
|
|
1260
|
-
propsIdentifier.typeAnnotation =
|
|
1324
|
+
const typeIdentifier = t13.identifier(propsTSIface.name);
|
|
1325
|
+
propsIdentifier.typeAnnotation = t13.tsTypeAnnotation(t13.tsTypeReference(typeIdentifier));
|
|
1261
1326
|
return propsIdentifier;
|
|
1262
1327
|
}
|
|
1263
1328
|
|
|
1264
1329
|
// src/core/codegen/component/script/syntax-processor/process/build-program-preamble.ts
|
|
1265
1330
|
function buildProgramPreamble(nodeIR, ctx, state) {
|
|
1266
|
-
const statements = [_optionalChain([nodeIR, 'optionalAccess',
|
|
1331
|
+
const statements = [_optionalChain([nodeIR, 'optionalAccess', _33 => _33.imports]), _optionalChain([nodeIR, 'optionalAccess', _34 => _34.tsTypes]), _optionalChain([nodeIR, 'optionalAccess', _35 => _35.exports]), _optionalChain([nodeIR, 'optionalAccess', _36 => _36.statement, 'access', _37 => _37.global])].flat().filter(Boolean);
|
|
1267
1332
|
state.preambleStatements = statements;
|
|
1268
1333
|
void ctx;
|
|
1269
1334
|
}
|
|
@@ -1282,7 +1347,7 @@ function buildScriptSyntax(nodeIR, ctx, jsx, expose = true) {
|
|
|
1282
1347
|
process: [buildProgramPreamble, buildComponent],
|
|
1283
1348
|
postprocess: [buildProgramNode]
|
|
1284
1349
|
});
|
|
1285
|
-
return state.result ||
|
|
1350
|
+
return state.result || t14.program([], void 0, "module");
|
|
1286
1351
|
}
|
|
1287
1352
|
function scriptSyntaxProcessor(nodeIR, ctx, state, options) {
|
|
1288
1353
|
const run = (p) => {
|
|
@@ -1318,7 +1383,7 @@ function generateComponent(ir, ctx, options) {
|
|
|
1318
1383
|
code,
|
|
1319
1384
|
source: ctx.source
|
|
1320
1385
|
};
|
|
1321
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1386
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _38 => _38.plugins]), result, ctx);
|
|
1322
1387
|
return result;
|
|
1323
1388
|
}
|
|
1324
1389
|
|
|
@@ -1332,7 +1397,7 @@ function generateOnlyScript(ir, ctx, options) {
|
|
|
1332
1397
|
code,
|
|
1333
1398
|
source: ctx.source
|
|
1334
1399
|
};
|
|
1335
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1400
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _39 => _39.plugins]), result, ctx);
|
|
1336
1401
|
return result;
|
|
1337
1402
|
}
|
|
1338
1403
|
|
|
@@ -1365,7 +1430,7 @@ function parseOnlyScript(source, ctx, options) {
|
|
|
1365
1430
|
};
|
|
1366
1431
|
ctx.scriptData.lang = lang;
|
|
1367
1432
|
ctx.scriptData.source = source;
|
|
1368
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1433
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _40 => _40.plugins]), result, ctx);
|
|
1369
1434
|
return result;
|
|
1370
1435
|
}
|
|
1371
1436
|
|
|
@@ -1400,8 +1465,8 @@ function resolveScript(descriptor, ctx, pResult) {
|
|
|
1400
1465
|
} else {
|
|
1401
1466
|
result.ast = _parser.parse.call(void 0, result.source.content, options);
|
|
1402
1467
|
}
|
|
1403
|
-
if (_optionalChain([scriptBlock, 'optionalAccess',
|
|
1404
|
-
_optionalChain([scriptBlock, 'optionalAccess',
|
|
1468
|
+
if (_optionalChain([scriptBlock, 'optionalAccess', _41 => _41.warnings])) {
|
|
1469
|
+
_optionalChain([scriptBlock, 'optionalAccess', _42 => _42.warnings, 'access', _43 => _43.forEach, 'call', _44 => _44((msg) => {
|
|
1405
1470
|
logger.warn(msg, { file: ctx.filename });
|
|
1406
1471
|
})]);
|
|
1407
1472
|
}
|
|
@@ -1419,41 +1484,41 @@ function extractSetupBodyToTopLevel(content, options) {
|
|
|
1419
1484
|
const otherTopLevel = [];
|
|
1420
1485
|
let setupStatements = [];
|
|
1421
1486
|
for (const node of ast.program.body) {
|
|
1422
|
-
if (
|
|
1487
|
+
if (t15.isImportDeclaration(node)) {
|
|
1423
1488
|
importNodes.push(node);
|
|
1424
1489
|
continue;
|
|
1425
1490
|
}
|
|
1426
|
-
if (
|
|
1491
|
+
if (t15.isExportDefaultDeclaration(node)) {
|
|
1427
1492
|
const decl = node.declaration;
|
|
1428
|
-
if (decl &&
|
|
1493
|
+
if (decl && t15.isObjectExpression(decl)) {
|
|
1429
1494
|
const nameProp = decl.properties.find((p) => {
|
|
1430
|
-
if (
|
|
1495
|
+
if (t15.isObjectProperty(p)) {
|
|
1431
1496
|
const key = p.key;
|
|
1432
|
-
return
|
|
1497
|
+
return t15.isIdentifier(key) && key.name === "name" || t15.isStringLiteral(key) && key.value === "name";
|
|
1433
1498
|
}
|
|
1434
1499
|
return false;
|
|
1435
1500
|
});
|
|
1436
|
-
if (nameProp &&
|
|
1437
|
-
if (
|
|
1501
|
+
if (nameProp && t15.isObjectProperty(nameProp)) {
|
|
1502
|
+
if (t15.isStringLiteral(nameProp.value)) {
|
|
1438
1503
|
name = nameProp.value.value;
|
|
1439
1504
|
}
|
|
1440
1505
|
}
|
|
1441
1506
|
const setupProp = decl.properties.find((p) => {
|
|
1442
|
-
if (
|
|
1507
|
+
if (t15.isObjectMethod(p)) {
|
|
1443
1508
|
return p.key && p.key.name === "setup";
|
|
1444
1509
|
}
|
|
1445
|
-
if (
|
|
1510
|
+
if (t15.isObjectProperty(p)) {
|
|
1446
1511
|
const key = p.key;
|
|
1447
|
-
return
|
|
1512
|
+
return t15.isIdentifier(key) && key.name === "setup" || t15.isStringLiteral(key) && key.value === "setup";
|
|
1448
1513
|
}
|
|
1449
1514
|
return false;
|
|
1450
1515
|
});
|
|
1451
1516
|
if (setupProp) {
|
|
1452
|
-
const value =
|
|
1453
|
-
if (value && (
|
|
1454
|
-
const fnBody =
|
|
1517
|
+
const value = t15.isObjectMethod(setupProp) ? setupProp : t15.isObjectProperty(setupProp) ? setupProp.value : null;
|
|
1518
|
+
if (value && (t15.isFunction(value) || t15.isObjectMethod(value))) {
|
|
1519
|
+
const fnBody = t15.isBlockStatement(value.body) ? value.body.body : [];
|
|
1455
1520
|
for (const stmt of fnBody) {
|
|
1456
|
-
if (
|
|
1521
|
+
if (t15.isReturnStatement(stmt)) continue;
|
|
1457
1522
|
setupStatements.push(stmt);
|
|
1458
1523
|
}
|
|
1459
1524
|
}
|
|
@@ -1476,7 +1541,7 @@ function extractSetupBodyToTopLevel(content, options) {
|
|
|
1476
1541
|
}
|
|
1477
1542
|
function extractCompName(source) {
|
|
1478
1543
|
const nameMatch = source.match(/@vr-name:\s*(\w+)/);
|
|
1479
|
-
return _optionalChain([nameMatch, 'optionalAccess',
|
|
1544
|
+
return _optionalChain([nameMatch, 'optionalAccess', _45 => _45[1], 'optionalAccess', _46 => _46.trim, 'call', _47 => _47()]) || "";
|
|
1480
1545
|
}
|
|
1481
1546
|
|
|
1482
1547
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
@@ -1582,15 +1647,15 @@ function getReactiveStateApis() {
|
|
|
1582
1647
|
|
|
1583
1648
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
1584
1649
|
function resolveScriptMeta(result, ctx) {
|
|
1585
|
-
const scriptAST = _optionalChain([result, 'access',
|
|
1650
|
+
const scriptAST = _optionalChain([result, 'access', _48 => _48.script, 'optionalAccess', _49 => _49.ast]);
|
|
1586
1651
|
if (!scriptAST) return;
|
|
1587
1652
|
_core.traverse.call(void 0, scriptAST, {
|
|
1588
|
-
VariableDeclarator(
|
|
1589
|
-
const { node } =
|
|
1590
|
-
if (!atComponentOrHookRoot(
|
|
1653
|
+
VariableDeclarator(path8) {
|
|
1654
|
+
const { node } = path8;
|
|
1655
|
+
if (!atComponentOrHookRoot(path8, scriptAST.program) || !t16.isIdentifier(node.id)) {
|
|
1591
1656
|
return;
|
|
1592
1657
|
}
|
|
1593
|
-
if (node.init &&
|
|
1658
|
+
if (node.init && t16.isCallExpression(node.init) && t16.isIdentifier(node.init.callee)) {
|
|
1594
1659
|
collectReactiveBindings(node, ctx);
|
|
1595
1660
|
collectRefBindings(node, ctx);
|
|
1596
1661
|
}
|
|
@@ -1622,7 +1687,7 @@ function collectRefBindings(node, ctx) {
|
|
|
1622
1687
|
const callee = init.callee;
|
|
1623
1688
|
if (callee.name !== VUE_API_MAP.useTemplateRef) return;
|
|
1624
1689
|
const idName = node.id.name;
|
|
1625
|
-
const tag = _optionalChain([init, 'access',
|
|
1690
|
+
const tag = _optionalChain([init, 'access', _50 => _50.arguments, 'access', _51 => _51[0], 'optionalAccess', _52 => _52.value]);
|
|
1626
1691
|
refBindings.domRefs[idName] = {
|
|
1627
1692
|
tag,
|
|
1628
1693
|
htmlType: HTML_TAG_TYPES[tag] || "HTMLElement",
|
|
@@ -1796,7 +1861,7 @@ function resolveStyles(descriptor, ctx, result) {
|
|
|
1796
1861
|
var _compilercore = require('@vue/compiler-core');
|
|
1797
1862
|
function resolveTemplate(descriptor, _, result) {
|
|
1798
1863
|
const block = descriptor.template;
|
|
1799
|
-
if (!_optionalChain([block, 'optionalAccess',
|
|
1864
|
+
if (!_optionalChain([block, 'optionalAccess', _53 => _53.content])) return null;
|
|
1800
1865
|
result.template = {
|
|
1801
1866
|
ast: _compilercore.baseParse.call(void 0, block.content),
|
|
1802
1867
|
source: block
|
|
@@ -1813,7 +1878,7 @@ function processVueSyntax(descriptor, ctx, result) {
|
|
|
1813
1878
|
}
|
|
1814
1879
|
function vueSyntaxProcessor(descriptor, ctx, result, options) {
|
|
1815
1880
|
const run = (p, type) => {
|
|
1816
|
-
_optionalChain([p, 'optionalAccess',
|
|
1881
|
+
_optionalChain([p, 'optionalAccess', _54 => _54.forEach, 'call', _55 => _55((handler) => {
|
|
1817
1882
|
if (type === "post") {
|
|
1818
1883
|
handler(result, ctx);
|
|
1819
1884
|
return;
|
|
@@ -1837,7 +1902,7 @@ function parseSFC(source, ctx, options) {
|
|
|
1837
1902
|
};
|
|
1838
1903
|
collectErrs(descriptor, errors);
|
|
1839
1904
|
processVueSyntax(descriptor, ctx, result);
|
|
1840
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1905
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _56 => _56.plugins]), result, ctx);
|
|
1841
1906
|
return result;
|
|
1842
1907
|
}
|
|
1843
1908
|
function collectErrs(descriptor, errors) {
|
|
@@ -1845,7 +1910,7 @@ function collectErrs(descriptor, errors) {
|
|
|
1845
1910
|
logger.error(err.message, {
|
|
1846
1911
|
source: descriptor.source,
|
|
1847
1912
|
file: descriptor.filename,
|
|
1848
|
-
loc: _optionalChain([err, 'optionalAccess',
|
|
1913
|
+
loc: _optionalChain([err, 'optionalAccess', _57 => _57.loc])
|
|
1849
1914
|
});
|
|
1850
1915
|
}
|
|
1851
1916
|
if (descriptor.cssVars.length) {
|
|
@@ -1877,9 +1942,9 @@ function insertCSSImport(ctx) {
|
|
|
1877
1942
|
const scriptIR = getScriptIR(ctx);
|
|
1878
1943
|
const filename = normalizePath(filePath).split("/").pop();
|
|
1879
1944
|
const importPath = `./${filename}`;
|
|
1880
|
-
const importDecl =
|
|
1881
|
-
!moduleName ? [] : [
|
|
1882
|
-
|
|
1945
|
+
const importDecl = t17.importDeclaration(
|
|
1946
|
+
!moduleName ? [] : [t17.importDefaultSpecifier(t17.identifier(moduleName))],
|
|
1947
|
+
t17.stringLiteral(importPath)
|
|
1883
1948
|
);
|
|
1884
1949
|
scriptIR.imports.push(importDecl);
|
|
1885
1950
|
}
|
|
@@ -1921,36 +1986,36 @@ function insertRequiredImports(ctx) {
|
|
|
1921
1986
|
const processedModules = /* @__PURE__ */ new Set();
|
|
1922
1987
|
let hasProcessedImports = false;
|
|
1923
1988
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
|
|
1924
|
-
function resolveRequiredImport(
|
|
1925
|
-
const { node } =
|
|
1989
|
+
function resolveRequiredImport(path8) {
|
|
1990
|
+
const { node } = path8;
|
|
1926
1991
|
const moduleName = node.source.value.toLowerCase();
|
|
1927
1992
|
const isVueLike = isVueEcosystemPackage(moduleName);
|
|
1928
1993
|
mergeImports(node, ctx);
|
|
1929
|
-
if (processedModules.has(moduleName) && !
|
|
1930
|
-
|
|
1994
|
+
if (processedModules.has(moduleName) && !path8.removed) {
|
|
1995
|
+
path8.remove();
|
|
1931
1996
|
return;
|
|
1932
1997
|
}
|
|
1933
1998
|
processedModules.add(moduleName);
|
|
1934
1999
|
if (!hasProcessedImports) {
|
|
1935
2000
|
const required = createRequiredImports(ctx);
|
|
1936
2001
|
if (isVueLike) {
|
|
1937
|
-
|
|
2002
|
+
path8.replaceWithMultiple(required);
|
|
1938
2003
|
} else if (moduleName === PACKAGE_NAME.react) {
|
|
1939
|
-
|
|
2004
|
+
path8.insertAfter(required);
|
|
1940
2005
|
} else {
|
|
1941
|
-
|
|
2006
|
+
path8.insertBefore(required);
|
|
1942
2007
|
}
|
|
1943
2008
|
hasProcessedImports = true;
|
|
1944
2009
|
}
|
|
1945
|
-
if (isVueLike && !
|
|
1946
|
-
|
|
2010
|
+
if (isVueLike && !path8.removed) {
|
|
2011
|
+
path8.remove();
|
|
1947
2012
|
return;
|
|
1948
2013
|
}
|
|
1949
2014
|
replaceVueSuffix(ctx, node.source);
|
|
1950
2015
|
}
|
|
1951
|
-
function resolveStyleFileExt(
|
|
2016
|
+
function resolveStyleFileExt(path8) {
|
|
1952
2017
|
if (!ctx.preprocessStyles) return;
|
|
1953
|
-
const { node } =
|
|
2018
|
+
const { node } = path8;
|
|
1954
2019
|
if (!node || !node.source || !node.source.value) return;
|
|
1955
2020
|
const importSource = node.source.value;
|
|
1956
2021
|
if (typeof importSource !== "string") return;
|
|
@@ -1962,16 +2027,16 @@ function insertRequiredImports(ctx) {
|
|
|
1962
2027
|
return {
|
|
1963
2028
|
// 增加 Program.exit 兜底注入 required imports(处理无 ImportDeclaration 的 SFC)
|
|
1964
2029
|
Program: {
|
|
1965
|
-
exit(
|
|
2030
|
+
exit(path8) {
|
|
1966
2031
|
if (hasProcessedImports) return;
|
|
1967
2032
|
const required = createRequiredImports(ctx);
|
|
1968
|
-
|
|
2033
|
+
path8.unshiftContainer("body", required);
|
|
1969
2034
|
hasProcessedImports = true;
|
|
1970
2035
|
}
|
|
1971
2036
|
},
|
|
1972
|
-
ImportDeclaration(
|
|
1973
|
-
resolveRequiredImport(
|
|
1974
|
-
resolveStyleFileExt(
|
|
2037
|
+
ImportDeclaration(path8) {
|
|
2038
|
+
resolveRequiredImport(path8);
|
|
2039
|
+
resolveStyleFileExt(path8);
|
|
1975
2040
|
}
|
|
1976
2041
|
};
|
|
1977
2042
|
}
|
|
@@ -1990,22 +2055,22 @@ function isVueEcosystemPackage(moduleName) {
|
|
|
1990
2055
|
function mergeImports(currentNode, ctx) {
|
|
1991
2056
|
const moduleName = currentNode.source.value.toLowerCase();
|
|
1992
2057
|
const ctxImportItems = ctx.imports.get(moduleName);
|
|
1993
|
-
if (!_optionalChain([ctxImportItems, 'optionalAccess',
|
|
2058
|
+
if (!_optionalChain([ctxImportItems, 'optionalAccess', _58 => _58.length])) {
|
|
1994
2059
|
return;
|
|
1995
2060
|
}
|
|
1996
2061
|
const currentImports = /* @__PURE__ */ new Set();
|
|
1997
2062
|
for (const spec of currentNode.specifiers) {
|
|
1998
|
-
if (
|
|
2063
|
+
if (t18.isImportSpecifier(spec) && t18.isIdentifier(spec.imported)) {
|
|
1999
2064
|
currentImports.add(spec.imported.name);
|
|
2000
2065
|
}
|
|
2001
|
-
if (
|
|
2066
|
+
if (t18.isImportDefaultSpecifier(spec) && t18.isIdentifier(spec.local)) {
|
|
2002
2067
|
currentImports.add(spec.local.name);
|
|
2003
2068
|
}
|
|
2004
2069
|
}
|
|
2005
2070
|
for (const item of ctxImportItems) {
|
|
2006
2071
|
if (currentImports.has(item.name)) return;
|
|
2007
|
-
const local =
|
|
2008
|
-
const newNode = !item.onDemand ?
|
|
2072
|
+
const local = t18.identifier(item.name);
|
|
2073
|
+
const newNode = !item.onDemand ? t18.importDefaultSpecifier(local) : t18.importSpecifier(local, local);
|
|
2009
2074
|
currentNode.specifiers.push(newNode);
|
|
2010
2075
|
}
|
|
2011
2076
|
ctx.imports.delete(moduleName);
|
|
@@ -2016,18 +2081,18 @@ function createRequiredImports(ctx) {
|
|
|
2016
2081
|
ctx.imports.forEach((items, moduleName) => {
|
|
2017
2082
|
const specifier = [];
|
|
2018
2083
|
for (const item of items) {
|
|
2019
|
-
const local =
|
|
2084
|
+
const local = t18.identifier(item.name);
|
|
2020
2085
|
if (!item.onDemand) {
|
|
2021
|
-
specifier.push(
|
|
2086
|
+
specifier.push(t18.importDefaultSpecifier(local));
|
|
2022
2087
|
} else {
|
|
2023
|
-
specifier.push(
|
|
2088
|
+
specifier.push(t18.importSpecifier(local, local));
|
|
2024
2089
|
}
|
|
2025
2090
|
}
|
|
2026
2091
|
importMap[moduleName] = specifier;
|
|
2027
2092
|
});
|
|
2028
2093
|
for (const name in importMap) {
|
|
2029
2094
|
const specifiers = importMap[name];
|
|
2030
|
-
const importDecl =
|
|
2095
|
+
const importDecl = t18.importDeclaration(specifiers, t18.stringLiteral(name));
|
|
2031
2096
|
if (name === PACKAGE_NAME.react) {
|
|
2032
2097
|
result.unshift(importDecl);
|
|
2033
2098
|
} else {
|
|
@@ -2042,29 +2107,29 @@ function createRequiredImports(ctx) {
|
|
|
2042
2107
|
|
|
2043
2108
|
// src/core/transform/sfc/script/shared/babel-utils.ts
|
|
2044
2109
|
|
|
2045
|
-
function findRootVariablePath(
|
|
2046
|
-
const rootId = findRootIdentifier(
|
|
2047
|
-
if (!_optionalChain([rootId, 'optionalAccess',
|
|
2048
|
-
const binding =
|
|
2110
|
+
function findRootVariablePath(path8) {
|
|
2111
|
+
const rootId = findRootIdentifier(path8.node);
|
|
2112
|
+
if (!_optionalChain([rootId, 'optionalAccess', _59 => _59.name])) return null;
|
|
2113
|
+
const binding = path8.scope.getBinding(rootId.name);
|
|
2049
2114
|
if (!binding) return null;
|
|
2050
2115
|
const rootPath = getVariableDeclaratorPath(binding.path);
|
|
2051
2116
|
return rootPath;
|
|
2052
2117
|
}
|
|
2053
2118
|
function findRootIdentifier(node) {
|
|
2054
2119
|
let current = node.object;
|
|
2055
|
-
while (
|
|
2120
|
+
while (t19.isMemberExpression(current) || t19.isOptionalMemberExpression(current)) {
|
|
2056
2121
|
current = current.object;
|
|
2057
2122
|
}
|
|
2058
|
-
return
|
|
2123
|
+
return t19.isIdentifier(current) ? current : null;
|
|
2059
2124
|
}
|
|
2060
|
-
function getVariableDeclaratorPath(
|
|
2061
|
-
if (
|
|
2062
|
-
return
|
|
2125
|
+
function getVariableDeclaratorPath(path8) {
|
|
2126
|
+
if (path8.isVariableDeclarator()) {
|
|
2127
|
+
return path8;
|
|
2063
2128
|
}
|
|
2064
|
-
return
|
|
2129
|
+
return path8.findParent((p) => p.isVariableDeclarator());
|
|
2065
2130
|
}
|
|
2066
|
-
function isVariableDeclTopLevel(
|
|
2067
|
-
const variableDeclaratorPath =
|
|
2131
|
+
function isVariableDeclTopLevel(path8) {
|
|
2132
|
+
const variableDeclaratorPath = path8;
|
|
2068
2133
|
const variableDeclarationPath = variableDeclaratorPath.parentPath;
|
|
2069
2134
|
if (!variableDeclarationPath) {
|
|
2070
2135
|
return false;
|
|
@@ -2078,75 +2143,75 @@ function isVariableDeclTopLevel(path7) {
|
|
|
2078
2143
|
}
|
|
2079
2144
|
return false;
|
|
2080
2145
|
}
|
|
2081
|
-
function isRealVariableAccess(
|
|
2082
|
-
return isIdentifierAccess(
|
|
2146
|
+
function isRealVariableAccess(path8) {
|
|
2147
|
+
return isIdentifierAccess(path8) && !isPropertyName(path8);
|
|
2083
2148
|
}
|
|
2084
|
-
function isIdentifierAccess(
|
|
2085
|
-
if (isIdentifierDeclaration(
|
|
2149
|
+
function isIdentifierAccess(path8) {
|
|
2150
|
+
if (isIdentifierDeclaration(path8)) {
|
|
2086
2151
|
return false;
|
|
2087
2152
|
}
|
|
2088
|
-
const binding =
|
|
2153
|
+
const binding = path8.scope.getBinding(path8.node.name);
|
|
2089
2154
|
if (!binding) {
|
|
2090
2155
|
return true;
|
|
2091
2156
|
}
|
|
2092
|
-
return binding.identifier !==
|
|
2157
|
+
return binding.identifier !== path8.node;
|
|
2093
2158
|
}
|
|
2094
|
-
function isIdentifierDeclaration(
|
|
2095
|
-
const parent =
|
|
2159
|
+
function isIdentifierDeclaration(path8) {
|
|
2160
|
+
const parent = path8.parentPath;
|
|
2096
2161
|
if (!parent) return false;
|
|
2097
|
-
if (parent.isVariableDeclarator() && parent.node.id ===
|
|
2162
|
+
if (parent.isVariableDeclarator() && parent.node.id === path8.node) {
|
|
2098
2163
|
return true;
|
|
2099
2164
|
}
|
|
2100
|
-
if (parent.isFunctionDeclaration() && parent.node.id ===
|
|
2165
|
+
if (parent.isFunctionDeclaration() && parent.node.id === path8.node) {
|
|
2101
2166
|
return true;
|
|
2102
2167
|
}
|
|
2103
|
-
if (parent.isFunctionExpression() && parent.node.id ===
|
|
2168
|
+
if (parent.isFunctionExpression() && parent.node.id === path8.node) {
|
|
2104
2169
|
return true;
|
|
2105
2170
|
}
|
|
2106
|
-
if (parent.isClassDeclaration() && parent.node.id ===
|
|
2171
|
+
if (parent.isClassDeclaration() && parent.node.id === path8.node) {
|
|
2107
2172
|
return true;
|
|
2108
2173
|
}
|
|
2109
|
-
if (parent.isImportSpecifier() && parent.node.local ===
|
|
2174
|
+
if (parent.isImportSpecifier() && parent.node.local === path8.node) {
|
|
2110
2175
|
return true;
|
|
2111
2176
|
}
|
|
2112
|
-
if (parent.isImportDefaultSpecifier() && parent.node.local ===
|
|
2177
|
+
if (parent.isImportDefaultSpecifier() && parent.node.local === path8.node) {
|
|
2113
2178
|
return true;
|
|
2114
2179
|
}
|
|
2115
|
-
if (parent.isImportNamespaceSpecifier() && parent.node.local ===
|
|
2180
|
+
if (parent.isImportNamespaceSpecifier() && parent.node.local === path8.node) {
|
|
2116
2181
|
return true;
|
|
2117
2182
|
}
|
|
2118
|
-
if (parent.isFunction() && parent.node.params.includes(
|
|
2183
|
+
if (parent.isFunction() && parent.node.params.includes(path8.node)) {
|
|
2119
2184
|
return true;
|
|
2120
2185
|
}
|
|
2121
|
-
if (parent.isCatchClause() && parent.node.param ===
|
|
2186
|
+
if (parent.isCatchClause() && parent.node.param === path8.node) {
|
|
2122
2187
|
return true;
|
|
2123
2188
|
}
|
|
2124
2189
|
return false;
|
|
2125
2190
|
}
|
|
2126
|
-
function isPropertyName(
|
|
2127
|
-
const parent =
|
|
2191
|
+
function isPropertyName(path8) {
|
|
2192
|
+
const parent = path8.parentPath;
|
|
2128
2193
|
if (!parent) return false;
|
|
2129
|
-
if (parent.isObjectProperty() && parent.node.key ===
|
|
2194
|
+
if (parent.isObjectProperty() && parent.node.key === path8.node) {
|
|
2130
2195
|
return true;
|
|
2131
2196
|
}
|
|
2132
|
-
if (parent.isClassProperty() && parent.node.key ===
|
|
2197
|
+
if (parent.isClassProperty() && parent.node.key === path8.node) {
|
|
2133
2198
|
return true;
|
|
2134
2199
|
}
|
|
2135
|
-
if (parent.isMemberExpression() && parent.node.property ===
|
|
2200
|
+
if (parent.isMemberExpression() && parent.node.property === path8.node) {
|
|
2136
2201
|
return true;
|
|
2137
2202
|
}
|
|
2138
2203
|
return false;
|
|
2139
2204
|
}
|
|
2140
2205
|
function replaceCallName(callExp, identifierName) {
|
|
2141
2206
|
const { callee } = callExp;
|
|
2142
|
-
if (!
|
|
2207
|
+
if (!t19.isIdentifier(callee)) return;
|
|
2143
2208
|
callee.name = identifierName;
|
|
2144
2209
|
if (callee.loc) {
|
|
2145
2210
|
callee.loc.identifierName = identifierName;
|
|
2146
2211
|
}
|
|
2147
2212
|
}
|
|
2148
2213
|
function replaceIdName(id, newName) {
|
|
2149
|
-
if (!
|
|
2214
|
+
if (!t19.isIdentifier(id)) return;
|
|
2150
2215
|
id.name = newName;
|
|
2151
2216
|
if (id.loc) {
|
|
2152
2217
|
id.loc.identifierName = newName;
|
|
@@ -2156,65 +2221,65 @@ function stringValueToTSType(ctx, input, tsTypeAnnotation7) {
|
|
|
2156
2221
|
const { filename, scriptData } = ctx;
|
|
2157
2222
|
const exp = stringToExpr(input, scriptData.lang, filename);
|
|
2158
2223
|
const ts = expressionToTSType(exp);
|
|
2159
|
-
return tsTypeAnnotation7 ?
|
|
2224
|
+
return tsTypeAnnotation7 ? t19.tsTypeAnnotation(ts) : ts;
|
|
2160
2225
|
}
|
|
2161
2226
|
function expressionToTSType(exp) {
|
|
2162
|
-
if (
|
|
2163
|
-
if (
|
|
2164
|
-
if (
|
|
2165
|
-
if (
|
|
2166
|
-
if (
|
|
2227
|
+
if (t19.isStringLiteral(exp)) return t19.tsStringKeyword();
|
|
2228
|
+
if (t19.isNumericLiteral(exp)) return t19.tsNumberKeyword();
|
|
2229
|
+
if (t19.isBooleanLiteral(exp)) return t19.tsBooleanKeyword();
|
|
2230
|
+
if (t19.isArrayExpression(exp)) return t19.tsArrayType(t19.tsAnyKeyword());
|
|
2231
|
+
if (t19.isObjectExpression(exp)) {
|
|
2167
2232
|
const members = [];
|
|
2168
2233
|
for (const p of exp.properties) {
|
|
2169
|
-
if (!
|
|
2234
|
+
if (!t19.isObjectProperty(p)) continue;
|
|
2170
2235
|
let key;
|
|
2171
|
-
if (
|
|
2172
|
-
else if (
|
|
2236
|
+
if (t19.isIdentifier(p.key)) key = p.key.name;
|
|
2237
|
+
else if (t19.isStringLiteral(p.key)) key = p.key.value;
|
|
2173
2238
|
if (!key) continue;
|
|
2174
|
-
if (
|
|
2239
|
+
if (t19.isExpression(p.value)) {
|
|
2175
2240
|
members.push(
|
|
2176
|
-
|
|
2241
|
+
t19.tsPropertySignature(t19.identifier(key), t19.tsTypeAnnotation(expressionToTSType(p.value)))
|
|
2177
2242
|
);
|
|
2178
2243
|
} else {
|
|
2179
2244
|
members.push(
|
|
2180
|
-
|
|
2245
|
+
t19.tsPropertySignature(t19.identifier(key), t19.tsTypeAnnotation(t19.tsAnyKeyword()))
|
|
2181
2246
|
);
|
|
2182
2247
|
}
|
|
2183
2248
|
}
|
|
2184
|
-
return
|
|
2249
|
+
return t19.tsTypeLiteral(members);
|
|
2185
2250
|
}
|
|
2186
|
-
if (
|
|
2251
|
+
if (t19.isArrowFunctionExpression(exp) || t19.isFunctionExpression(exp)) {
|
|
2187
2252
|
const params = exp.params.map((p, i) => {
|
|
2188
|
-
const id =
|
|
2189
|
-
id.typeAnnotation =
|
|
2253
|
+
const id = t19.isIdentifier(p) ? t19.identifier(p.name) : t19.identifier(`arg${i}`);
|
|
2254
|
+
id.typeAnnotation = t19.tsTypeAnnotation(t19.tsAnyKeyword());
|
|
2190
2255
|
return id;
|
|
2191
2256
|
});
|
|
2192
|
-
let returnType =
|
|
2193
|
-
if (
|
|
2257
|
+
let returnType = t19.tsAnyKeyword();
|
|
2258
|
+
if (t19.isBlockStatement(exp.body)) {
|
|
2194
2259
|
for (const stmt of exp.body.body) {
|
|
2195
|
-
if (
|
|
2196
|
-
if (
|
|
2260
|
+
if (t19.isReturnStatement(stmt) && stmt.argument) {
|
|
2261
|
+
if (t19.isExpression(stmt.argument)) {
|
|
2197
2262
|
returnType = expressionToTSType(stmt.argument);
|
|
2198
2263
|
break;
|
|
2199
2264
|
}
|
|
2200
2265
|
}
|
|
2201
2266
|
}
|
|
2202
|
-
} else if (
|
|
2267
|
+
} else if (t19.isExpression(exp.body)) {
|
|
2203
2268
|
returnType = expressionToTSType(exp.body);
|
|
2204
2269
|
}
|
|
2205
|
-
return
|
|
2270
|
+
return t19.tsFunctionType(null, params, t19.tsTypeAnnotation(returnType));
|
|
2206
2271
|
}
|
|
2207
|
-
return
|
|
2272
|
+
return t19.tsAnyKeyword();
|
|
2208
2273
|
}
|
|
2209
2274
|
function isCalleeNamed(node, name) {
|
|
2210
|
-
if (!
|
|
2275
|
+
if (!t19.isIdentifier(node.callee)) {
|
|
2211
2276
|
return false;
|
|
2212
2277
|
}
|
|
2213
2278
|
return node.callee.name === name;
|
|
2214
2279
|
}
|
|
2215
2280
|
function isSimpleLiteral(node) {
|
|
2216
2281
|
if (!node) return false;
|
|
2217
|
-
if (
|
|
2282
|
+
if (t19.isStringLiteral(node) || t19.isNumericLiteral(node) || t19.isBooleanLiteral(node) || t19.isNullLiteral(node) || t19.isRegExpLiteral(node) || t19.isBigIntLiteral(node) || t19.isDecimalLiteral(node)) {
|
|
2218
2283
|
return true;
|
|
2219
2284
|
}
|
|
2220
2285
|
return false;
|
|
@@ -2243,26 +2308,26 @@ function resolveStaticHoisting(ctx) {
|
|
|
2243
2308
|
return {};
|
|
2244
2309
|
}
|
|
2245
2310
|
return {
|
|
2246
|
-
"ImportDeclaration|ExportDeclaration"(
|
|
2247
|
-
if (
|
|
2248
|
-
scriptIR.imports.push(
|
|
2249
|
-
} else if (
|
|
2250
|
-
scriptIR.exports.push(
|
|
2311
|
+
"ImportDeclaration|ExportDeclaration"(path8) {
|
|
2312
|
+
if (t20.isImportDeclaration(path8.node)) {
|
|
2313
|
+
scriptIR.imports.push(path8.node);
|
|
2314
|
+
} else if (t20.isExportDeclaration(path8.node)) {
|
|
2315
|
+
scriptIR.exports.push(path8.node);
|
|
2251
2316
|
}
|
|
2252
|
-
|
|
2317
|
+
path8.remove();
|
|
2253
2318
|
},
|
|
2254
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(
|
|
2255
|
-
if (
|
|
2256
|
-
scriptIR.tsTypes.push(
|
|
2257
|
-
|
|
2319
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path8) {
|
|
2320
|
+
if (t20.isProgram(path8.parent)) {
|
|
2321
|
+
scriptIR.tsTypes.push(path8.node);
|
|
2322
|
+
path8.remove();
|
|
2258
2323
|
}
|
|
2259
2324
|
},
|
|
2260
|
-
VariableDeclarator(
|
|
2261
|
-
const { node } =
|
|
2262
|
-
if (!isVariableDeclTopLevel(
|
|
2325
|
+
VariableDeclarator(path8) {
|
|
2326
|
+
const { node } = path8;
|
|
2327
|
+
if (!isVariableDeclTopLevel(path8) || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
|
|
2263
2328
|
return;
|
|
2264
2329
|
}
|
|
2265
|
-
const declarationPath =
|
|
2330
|
+
const declarationPath = path8.findParent((p) => p.isVariableDeclaration());
|
|
2266
2331
|
if (!declarationPath) return;
|
|
2267
2332
|
scriptIR.statement.global.push(declarationPath.node);
|
|
2268
2333
|
declarationPath.remove();
|
|
@@ -2279,24 +2344,24 @@ function collectLocalStatements(ctx, ast) {
|
|
|
2279
2344
|
|
|
2280
2345
|
function resolveDefineAsyncComponent(ctx) {
|
|
2281
2346
|
return {
|
|
2282
|
-
CallExpression(
|
|
2283
|
-
const { node } =
|
|
2347
|
+
CallExpression(path8) {
|
|
2348
|
+
const { node } = path8;
|
|
2284
2349
|
if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
|
|
2285
2350
|
return;
|
|
2286
2351
|
}
|
|
2287
2352
|
const [arg] = node.arguments;
|
|
2288
2353
|
checkIsUnsupported(ctx, arg);
|
|
2289
|
-
pushToGlobalScope(
|
|
2354
|
+
pushToGlobalScope(path8, ctx);
|
|
2290
2355
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.lazy);
|
|
2291
2356
|
}
|
|
2292
2357
|
};
|
|
2293
2358
|
}
|
|
2294
2359
|
function checkIsUnsupported(ctx, arg) {
|
|
2295
|
-
if (
|
|
2360
|
+
if (t21.isFunction(arg)) {
|
|
2296
2361
|
checkIsDynamicImport(ctx, arg);
|
|
2297
|
-
} else if (
|
|
2362
|
+
} else if (t21.isObjectExpression(arg)) {
|
|
2298
2363
|
const { value } = arg.properties.find(
|
|
2299
|
-
(p) =>
|
|
2364
|
+
(p) => t21.isObjectProperty(p) && t21.isIdentifier(p.key) && p.key.name === "loader"
|
|
2300
2365
|
);
|
|
2301
2366
|
checkIsDynamicImport(ctx, value);
|
|
2302
2367
|
if (arg.properties.length > 1) {
|
|
@@ -2307,31 +2372,31 @@ function checkIsUnsupported(ctx, arg) {
|
|
|
2307
2372
|
function checkIsDynamicImport(ctx, node) {
|
|
2308
2373
|
const { scriptData, filename } = ctx;
|
|
2309
2374
|
const warnIsNotImport = (target) => {
|
|
2310
|
-
if (!target || !
|
|
2375
|
+
if (!target || !t21.isImport(target)) {
|
|
2311
2376
|
logger.error(
|
|
2312
2377
|
`Only ES module dynamic imports are supported. You must use and return import('...').`,
|
|
2313
2378
|
{
|
|
2314
2379
|
source: scriptData.source,
|
|
2315
2380
|
file: filename,
|
|
2316
|
-
loc: _optionalChain([target, 'optionalAccess',
|
|
2381
|
+
loc: _optionalChain([target, 'optionalAccess', _60 => _60.loc]) || {}
|
|
2317
2382
|
}
|
|
2318
2383
|
);
|
|
2319
2384
|
}
|
|
2320
2385
|
};
|
|
2321
|
-
if (
|
|
2386
|
+
if (t21.isFunction(node)) {
|
|
2322
2387
|
checkIsDynamicImport(ctx, node.body);
|
|
2323
2388
|
return;
|
|
2324
2389
|
}
|
|
2325
|
-
if (
|
|
2390
|
+
if (t21.isBlockStatement(node)) {
|
|
2326
2391
|
const [returnSmt] = node.body;
|
|
2327
|
-
if (
|
|
2392
|
+
if (t21.isReturnStatement(returnSmt)) {
|
|
2328
2393
|
warnIsNotImport(returnSmt.argument);
|
|
2329
2394
|
}
|
|
2330
2395
|
return;
|
|
2331
2396
|
}
|
|
2332
|
-
if (
|
|
2397
|
+
if (t21.isCallExpression(node)) {
|
|
2333
2398
|
warnIsNotImport(node.callee);
|
|
2334
|
-
if (
|
|
2399
|
+
if (t21.isStringLiteral(node.arguments[0])) {
|
|
2335
2400
|
replaceVueSuffix(ctx, node.arguments[0]);
|
|
2336
2401
|
}
|
|
2337
2402
|
return;
|
|
@@ -2349,15 +2414,15 @@ function warnMultipleOptionsUsed(ctx, node) {
|
|
|
2349
2414
|
}
|
|
2350
2415
|
);
|
|
2351
2416
|
}
|
|
2352
|
-
function pushToGlobalScope(
|
|
2353
|
-
const { node } =
|
|
2417
|
+
function pushToGlobalScope(path8, ctx) {
|
|
2418
|
+
const { node } = path8;
|
|
2354
2419
|
const callee = node.callee;
|
|
2355
2420
|
callee.name = REACT_API_MAP.lazy;
|
|
2356
2421
|
callee.loc.identifierName = REACT_API_MAP.lazy;
|
|
2357
2422
|
if (node.typeParameters) {
|
|
2358
2423
|
node.typeParameters = void 0;
|
|
2359
2424
|
}
|
|
2360
|
-
let declarationPath =
|
|
2425
|
+
let declarationPath = path8.parentPath;
|
|
2361
2426
|
while (declarationPath) {
|
|
2362
2427
|
if (declarationPath.isVariableDeclaration()) {
|
|
2363
2428
|
break;
|
|
@@ -2365,15 +2430,15 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2365
2430
|
declarationPath = declarationPath.parentPath;
|
|
2366
2431
|
}
|
|
2367
2432
|
let fullNode;
|
|
2368
|
-
if (_optionalChain([declarationPath, 'optionalAccess',
|
|
2433
|
+
if (_optionalChain([declarationPath, 'optionalAccess', _61 => _61.isVariableDeclaration, 'call', _62 => _62()])) {
|
|
2369
2434
|
fullNode = declarationPath.node;
|
|
2370
2435
|
declarationPath.remove();
|
|
2371
|
-
} else if (
|
|
2372
|
-
fullNode =
|
|
2373
|
-
|
|
2436
|
+
} else if (path8.parentPath.isVariableDeclarator()) {
|
|
2437
|
+
fullNode = path8.parent;
|
|
2438
|
+
path8.parentPath.remove();
|
|
2374
2439
|
} else {
|
|
2375
|
-
fullNode =
|
|
2376
|
-
|
|
2440
|
+
fullNode = path8.node;
|
|
2441
|
+
path8.remove();
|
|
2377
2442
|
}
|
|
2378
2443
|
const scriptIR = getScriptIR(ctx);
|
|
2379
2444
|
scriptIR.statement.global.push(fullNode);
|
|
@@ -2385,51 +2450,51 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2385
2450
|
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
2386
2451
|
|
|
2387
2452
|
function createUseCallback(body, deps) {
|
|
2388
|
-
return
|
|
2453
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useCallback), [
|
|
2389
2454
|
body,
|
|
2390
|
-
_nullishCoalesce(deps, () => (
|
|
2455
|
+
_nullishCoalesce(deps, () => ( t22.arrayExpression([])))
|
|
2391
2456
|
]);
|
|
2392
2457
|
}
|
|
2393
2458
|
function createUseMemo(body, deps) {
|
|
2394
|
-
return
|
|
2395
|
-
|
|
2396
|
-
_nullishCoalesce(deps, () => (
|
|
2459
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useMemo), [
|
|
2460
|
+
t22.arrowFunctionExpression([], body),
|
|
2461
|
+
_nullishCoalesce(deps, () => ( t22.arrayExpression([])))
|
|
2397
2462
|
]);
|
|
2398
2463
|
}
|
|
2399
2464
|
function createUseImperativeHandle(refId, init) {
|
|
2400
|
-
return
|
|
2465
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
2401
2466
|
}
|
|
2402
2467
|
|
|
2403
2468
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
2404
2469
|
function resolveDefineExpose(ctx) {
|
|
2405
2470
|
if (ctx.inputType !== "sfc") return {};
|
|
2406
2471
|
return {
|
|
2407
|
-
CallExpression(
|
|
2408
|
-
const { node } =
|
|
2472
|
+
CallExpression(path8) {
|
|
2473
|
+
const { node } = path8;
|
|
2409
2474
|
const { filename, scriptData } = ctx;
|
|
2410
2475
|
if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
|
|
2411
2476
|
return;
|
|
2412
2477
|
}
|
|
2413
2478
|
const [expose] = node.arguments;
|
|
2414
2479
|
if (!expose) {
|
|
2415
|
-
|
|
2480
|
+
path8.remove();
|
|
2416
2481
|
return;
|
|
2417
2482
|
}
|
|
2418
2483
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
2419
2484
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
2420
2485
|
recordImport(ctx, adapter.package, adapter.target);
|
|
2421
|
-
if (!
|
|
2486
|
+
if (!t23.isObjectExpression(expose) && !t23.isFunction(expose)) {
|
|
2422
2487
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
2423
2488
|
file: filename,
|
|
2424
2489
|
loc: expose.loc,
|
|
2425
2490
|
source: scriptData.source
|
|
2426
2491
|
});
|
|
2427
2492
|
}
|
|
2428
|
-
const init = !
|
|
2493
|
+
const init = !t23.isFunction(expose) ? t23.arrowFunctionExpression([], expose) : expose;
|
|
2429
2494
|
const { forwardRef } = scriptData;
|
|
2430
|
-
const newNode = createUseImperativeHandle(
|
|
2495
|
+
const newNode = createUseImperativeHandle(t23.identifier(forwardRef.refField), init);
|
|
2431
2496
|
forwardRef.enabled = true;
|
|
2432
|
-
|
|
2497
|
+
path8.replaceWith(newNode);
|
|
2433
2498
|
}
|
|
2434
2499
|
};
|
|
2435
2500
|
}
|
|
@@ -2438,8 +2503,8 @@ function resolveDefineExpose(ctx) {
|
|
|
2438
2503
|
|
|
2439
2504
|
function resolveDefineOptions(ctx) {
|
|
2440
2505
|
return {
|
|
2441
|
-
CallExpression(
|
|
2442
|
-
const { node } =
|
|
2506
|
+
CallExpression(path8) {
|
|
2507
|
+
const { node } = path8;
|
|
2443
2508
|
if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
|
|
2444
2509
|
return;
|
|
2445
2510
|
}
|
|
@@ -2449,26 +2514,26 @@ function resolveDefineOptions(ctx) {
|
|
|
2449
2514
|
logger.warn("defineOptions was found, but no options were provided.", {
|
|
2450
2515
|
source: scriptData.source,
|
|
2451
2516
|
file: filename,
|
|
2452
|
-
loc: _optionalChain([node, 'optionalAccess',
|
|
2517
|
+
loc: _optionalChain([node, 'optionalAccess', _63 => _63.loc])
|
|
2453
2518
|
});
|
|
2454
|
-
|
|
2519
|
+
path8.remove();
|
|
2455
2520
|
return;
|
|
2456
2521
|
}
|
|
2457
|
-
if (!
|
|
2522
|
+
if (!t24.isObjectExpression(options)) {
|
|
2458
2523
|
logger.warn("Argument for defineOptions must be an object expression.", {
|
|
2459
2524
|
source: scriptData.source,
|
|
2460
2525
|
file: filename,
|
|
2461
|
-
loc: _optionalChain([options, 'optionalAccess',
|
|
2526
|
+
loc: _optionalChain([options, 'optionalAccess', _64 => _64.loc])
|
|
2462
2527
|
});
|
|
2463
2528
|
} else {
|
|
2464
2529
|
for (const prop of options.properties) {
|
|
2465
|
-
if (!
|
|
2530
|
+
if (!t24.isObjectProperty(prop) || !t24.isIdentifier(prop.key)) {
|
|
2466
2531
|
continue;
|
|
2467
2532
|
}
|
|
2468
2533
|
extractName(prop, ctx);
|
|
2469
2534
|
}
|
|
2470
2535
|
}
|
|
2471
|
-
|
|
2536
|
+
path8.remove();
|
|
2472
2537
|
}
|
|
2473
2538
|
};
|
|
2474
2539
|
}
|
|
@@ -2476,14 +2541,14 @@ function extractName(prop, ctx) {
|
|
|
2476
2541
|
if (ctx.compName) return;
|
|
2477
2542
|
const { filename, scriptData } = ctx;
|
|
2478
2543
|
if (!prop.computed && prop.key.name === "name") {
|
|
2479
|
-
if (
|
|
2544
|
+
if (t24.isStringLiteral(prop.value)) {
|
|
2480
2545
|
ctx.compName = prop.value.value;
|
|
2481
2546
|
return;
|
|
2482
2547
|
}
|
|
2483
2548
|
logger.error(`name must be a string type, but got ${prop.value.type}`, {
|
|
2484
2549
|
source: scriptData.source,
|
|
2485
2550
|
file: filename,
|
|
2486
|
-
loc: _optionalChain([prop, 'access',
|
|
2551
|
+
loc: _optionalChain([prop, 'access', _65 => _65.key, 'optionalAccess', _66 => _66.loc])
|
|
2487
2552
|
});
|
|
2488
2553
|
}
|
|
2489
2554
|
}
|
|
@@ -2500,10 +2565,10 @@ function resolveEmitCalls(ctx) {
|
|
|
2500
2565
|
return `on${capitalize(camelCase(normalized))}`;
|
|
2501
2566
|
};
|
|
2502
2567
|
return {
|
|
2503
|
-
CallExpression(
|
|
2504
|
-
const { node } =
|
|
2568
|
+
CallExpression(path8) {
|
|
2569
|
+
const { node } = path8;
|
|
2505
2570
|
const { filename, templateData, scriptData } = ctx;
|
|
2506
|
-
if (!
|
|
2571
|
+
if (!t25.isIdentifier(node.callee)) return;
|
|
2507
2572
|
const { name } = node.callee;
|
|
2508
2573
|
const checkIfFromDefineEmits = () => {
|
|
2509
2574
|
let result = false;
|
|
@@ -2512,10 +2577,10 @@ function resolveEmitCalls(ctx) {
|
|
|
2512
2577
|
result = meta.source === MACRO_API_NAMES.emits;
|
|
2513
2578
|
}
|
|
2514
2579
|
if (!result) {
|
|
2515
|
-
const binding =
|
|
2580
|
+
const binding = path8.scope.getBinding(name);
|
|
2516
2581
|
if (binding) {
|
|
2517
2582
|
const parent = binding.path.node;
|
|
2518
|
-
if (
|
|
2583
|
+
if (t25.isVariableDeclarator(parent) && t25.isCallExpression(parent.init) && t25.isIdentifier(parent.init.callee)) {
|
|
2519
2584
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
2520
2585
|
}
|
|
2521
2586
|
}
|
|
@@ -2524,26 +2589,27 @@ function resolveEmitCalls(ctx) {
|
|
|
2524
2589
|
};
|
|
2525
2590
|
if (!checkIfFromDefineEmits()) return;
|
|
2526
2591
|
const [callee, ...args] = node.arguments;
|
|
2527
|
-
const eventName =
|
|
2592
|
+
const eventName = t25.isStringLiteral(callee) ? formatEmitEventName(callee.value) : void 0;
|
|
2528
2593
|
if (!eventName) {
|
|
2529
|
-
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess',
|
|
2594
|
+
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess', _67 => _67.type])}, expression will be removed`, {
|
|
2530
2595
|
file: filename,
|
|
2531
2596
|
source: scriptData.source,
|
|
2532
|
-
loc: _optionalChain([callee, 'optionalAccess',
|
|
2597
|
+
loc: _optionalChain([callee, 'optionalAccess', _68 => _68.loc])
|
|
2533
2598
|
});
|
|
2534
|
-
|
|
2599
|
+
path8.remove();
|
|
2535
2600
|
return;
|
|
2536
2601
|
}
|
|
2537
|
-
const propCall =
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2602
|
+
const propCall = t25.optionalCallExpression(
|
|
2603
|
+
t25.optionalMemberExpression(
|
|
2604
|
+
t25.identifier(ctx.propField),
|
|
2605
|
+
t25.identifier(eventName),
|
|
2541
2606
|
false,
|
|
2542
2607
|
true
|
|
2543
2608
|
),
|
|
2544
|
-
args
|
|
2609
|
+
args,
|
|
2610
|
+
true
|
|
2545
2611
|
);
|
|
2546
|
-
|
|
2612
|
+
path8.replaceWith(propCall);
|
|
2547
2613
|
}
|
|
2548
2614
|
};
|
|
2549
2615
|
}
|
|
@@ -2558,21 +2624,21 @@ function resolveEmitCalls(ctx) {
|
|
|
2558
2624
|
|
|
2559
2625
|
function cloneCallableParams(params) {
|
|
2560
2626
|
const cloneCallableParam = (param, index) => {
|
|
2561
|
-
if (
|
|
2627
|
+
if (t26.isRestElement(param)) {
|
|
2562
2628
|
const arg = param.argument;
|
|
2563
|
-
const name =
|
|
2564
|
-
const rest =
|
|
2565
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
2629
|
+
const name = t26.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
2630
|
+
const rest = t26.restElement(t26.identifier(name));
|
|
2631
|
+
rest.typeAnnotation = param.typeAnnotation || (t26.isIdentifier(arg) ? arg.typeAnnotation : null) || t26.tsTypeAnnotation(t26.tsArrayType(t26.tsAnyKeyword()));
|
|
2566
2632
|
return rest;
|
|
2567
2633
|
}
|
|
2568
|
-
if (
|
|
2569
|
-
const id =
|
|
2634
|
+
if (t26.isIdentifier(param)) {
|
|
2635
|
+
const id = t26.identifier(param.name || `arg${index}`);
|
|
2570
2636
|
id.optional = param.optional;
|
|
2571
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
2637
|
+
id.typeAnnotation = param.typeAnnotation || t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2572
2638
|
return id;
|
|
2573
2639
|
}
|
|
2574
|
-
const fallback =
|
|
2575
|
-
fallback.typeAnnotation =
|
|
2640
|
+
const fallback = t26.identifier(`arg${index}`);
|
|
2641
|
+
fallback.typeAnnotation = t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2576
2642
|
return fallback;
|
|
2577
2643
|
};
|
|
2578
2644
|
return params.map(cloneCallableParam);
|
|
@@ -2581,19 +2647,19 @@ function cloneCallableParams(params) {
|
|
|
2581
2647
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
|
|
2582
2648
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
2583
2649
|
return {
|
|
2584
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(
|
|
2585
|
-
if (!
|
|
2586
|
-
const { node } =
|
|
2587
|
-
if (
|
|
2588
|
-
const typeLiteral =
|
|
2650
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
2651
|
+
if (!t27.isProgram(path8.parent)) return;
|
|
2652
|
+
const { node } = path8;
|
|
2653
|
+
if (t27.isTSInterfaceDeclaration(node)) {
|
|
2654
|
+
const typeLiteral = t27.tsTypeLiteral(node.body.body);
|
|
2589
2655
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
2590
2656
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
2591
|
-
if (resolved &&
|
|
2657
|
+
if (resolved && t27.isTSTypeLiteral(resolved)) {
|
|
2592
2658
|
node.body.body = resolved.members;
|
|
2593
2659
|
}
|
|
2594
2660
|
return;
|
|
2595
2661
|
}
|
|
2596
|
-
if (
|
|
2662
|
+
if (t27.isTSTypeAliasDeclaration(node)) {
|
|
2597
2663
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
2598
2664
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
2599
2665
|
if (resolved) {
|
|
@@ -2604,55 +2670,55 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
2604
2670
|
};
|
|
2605
2671
|
}
|
|
2606
2672
|
function resolveTopLevelEmitType(tsType) {
|
|
2607
|
-
if (
|
|
2673
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2608
2674
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
2609
2675
|
}
|
|
2610
|
-
if (
|
|
2676
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2611
2677
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2612
2678
|
return tsType;
|
|
2613
2679
|
}
|
|
2614
2680
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
2615
|
-
return
|
|
2681
|
+
return t27.tsTypeReference(
|
|
2616
2682
|
tsType.typeName,
|
|
2617
|
-
|
|
2683
|
+
t27.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2618
2684
|
);
|
|
2619
2685
|
}
|
|
2620
|
-
if (
|
|
2686
|
+
if (t27.isTSIntersectionType(tsType)) {
|
|
2621
2687
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2622
2688
|
if (!types.length) return null;
|
|
2623
2689
|
if (types.length === 1) return types[0];
|
|
2624
|
-
return
|
|
2690
|
+
return t27.tsIntersectionType(types);
|
|
2625
2691
|
}
|
|
2626
|
-
if (
|
|
2692
|
+
if (t27.isTSUnionType(tsType)) {
|
|
2627
2693
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2628
2694
|
if (!types.length) return null;
|
|
2629
2695
|
if (types.length === 1) return types[0];
|
|
2630
|
-
return
|
|
2696
|
+
return t27.tsUnionType(types);
|
|
2631
2697
|
}
|
|
2632
|
-
if (
|
|
2698
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2633
2699
|
const members = [];
|
|
2634
2700
|
for (const member of tsType.members) {
|
|
2635
|
-
if (
|
|
2701
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2636
2702
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2637
2703
|
continue;
|
|
2638
2704
|
}
|
|
2639
2705
|
members.push(member);
|
|
2640
2706
|
}
|
|
2641
2707
|
if (!members.length) return null;
|
|
2642
|
-
return
|
|
2708
|
+
return t27.tsTypeLiteral(members);
|
|
2643
2709
|
}
|
|
2644
|
-
if (
|
|
2710
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2645
2711
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2646
2712
|
if (!props.length) return null;
|
|
2647
|
-
return
|
|
2713
|
+
return t27.tsTypeLiteral(props);
|
|
2648
2714
|
}
|
|
2649
2715
|
return tsType;
|
|
2650
2716
|
}
|
|
2651
|
-
function resolveDefineEmitsIface(
|
|
2652
|
-
const { node } =
|
|
2717
|
+
function resolveDefineEmitsIface(path8, ctx) {
|
|
2718
|
+
const { node } = path8;
|
|
2653
2719
|
const [runtimeArg] = node.arguments;
|
|
2654
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2655
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
2720
|
+
const tsParams = _optionalChain([node, 'access', _69 => _69.typeParameters, 'optionalAccess', _70 => _70.params]);
|
|
2721
|
+
if (_optionalChain([tsParams, 'optionalAccess', _71 => _71.length])) {
|
|
2656
2722
|
processExplicitType(ctx, tsParams);
|
|
2657
2723
|
return;
|
|
2658
2724
|
}
|
|
@@ -2665,41 +2731,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
2665
2731
|
propsTSIface: { emitTypes }
|
|
2666
2732
|
} = ctx.scriptData;
|
|
2667
2733
|
const members = [];
|
|
2668
|
-
if (
|
|
2734
|
+
if (t27.isArrayExpression(runtimeArg)) {
|
|
2669
2735
|
for (const element of runtimeArg.elements) {
|
|
2670
|
-
if (!element || !
|
|
2736
|
+
if (!element || !t27.isStringLiteral(element)) continue;
|
|
2671
2737
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
2672
2738
|
const key = buildKey(handlerName);
|
|
2673
|
-
const fnType =
|
|
2739
|
+
const fnType = t27.tsFunctionType(
|
|
2674
2740
|
null,
|
|
2675
2741
|
[createRestAnyParam("args")],
|
|
2676
|
-
|
|
2742
|
+
t27.tsTypeAnnotation(t27.tsAnyKeyword())
|
|
2677
2743
|
);
|
|
2678
|
-
const prop =
|
|
2744
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2679
2745
|
prop.optional = true;
|
|
2680
2746
|
members.push(prop);
|
|
2681
2747
|
}
|
|
2682
2748
|
if (members.length) {
|
|
2683
|
-
emitTypes.push(
|
|
2749
|
+
emitTypes.push(t27.tsTypeLiteral(members));
|
|
2684
2750
|
}
|
|
2685
2751
|
return;
|
|
2686
2752
|
}
|
|
2687
|
-
if (
|
|
2753
|
+
if (t27.isObjectExpression(runtimeArg)) {
|
|
2688
2754
|
for (const prop of runtimeArg.properties) {
|
|
2689
|
-
if (!
|
|
2690
|
-
if (
|
|
2755
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
2756
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
2691
2757
|
const rawName = resolvePropName(prop.key);
|
|
2692
2758
|
if (!rawName) continue;
|
|
2693
2759
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2694
2760
|
const key = buildKey(handlerName);
|
|
2695
|
-
const params =
|
|
2696
|
-
const fnType =
|
|
2697
|
-
const propSig =
|
|
2761
|
+
const params = t27.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
2762
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
2763
|
+
const propSig = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2698
2764
|
propSig.optional = true;
|
|
2699
2765
|
members.push(propSig);
|
|
2700
2766
|
}
|
|
2701
2767
|
if (members.length) {
|
|
2702
|
-
emitTypes.push(
|
|
2768
|
+
emitTypes.push(t27.tsTypeLiteral(members));
|
|
2703
2769
|
}
|
|
2704
2770
|
}
|
|
2705
2771
|
}
|
|
@@ -2720,129 +2786,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
2720
2786
|
return `on${name}`;
|
|
2721
2787
|
}
|
|
2722
2788
|
function resolvePropName(key) {
|
|
2723
|
-
if (
|
|
2724
|
-
if (
|
|
2725
|
-
if (
|
|
2789
|
+
if (t27.isIdentifier(key)) return key.name;
|
|
2790
|
+
if (t27.isStringLiteral(key)) return key.value;
|
|
2791
|
+
if (t27.isNumericLiteral(key)) return String(key.value);
|
|
2726
2792
|
return null;
|
|
2727
2793
|
}
|
|
2728
2794
|
function buildKey(name) {
|
|
2729
|
-
return
|
|
2795
|
+
return t27.isValidIdentifier(name) ? t27.identifier(name) : t27.stringLiteral(name);
|
|
2730
2796
|
}
|
|
2731
2797
|
function createRestAnyParam(name) {
|
|
2732
|
-
const id =
|
|
2733
|
-
const rest =
|
|
2734
|
-
rest.typeAnnotation =
|
|
2798
|
+
const id = t27.identifier(name);
|
|
2799
|
+
const rest = t27.restElement(id);
|
|
2800
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(t27.tsArrayType(t27.tsAnyKeyword()));
|
|
2735
2801
|
return rest;
|
|
2736
2802
|
}
|
|
2737
2803
|
function resolveRuntimeTupleParams(value) {
|
|
2738
2804
|
const params = [];
|
|
2739
2805
|
value.elements.forEach((element, index) => {
|
|
2740
2806
|
if (!element) return;
|
|
2741
|
-
if (
|
|
2807
|
+
if (t27.isSpreadElement(element)) {
|
|
2742
2808
|
params.push(createRestAnyParam(`args${index}`));
|
|
2743
2809
|
return;
|
|
2744
2810
|
}
|
|
2745
|
-
if (
|
|
2746
|
-
const id =
|
|
2747
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
2811
|
+
if (t27.isIdentifier(element)) {
|
|
2812
|
+
const id = t27.identifier(element.name);
|
|
2813
|
+
id.typeAnnotation = element.typeAnnotation || t27.tsTypeAnnotation(t27.tsAnyKeyword());
|
|
2748
2814
|
params.push(id);
|
|
2749
2815
|
return;
|
|
2750
2816
|
}
|
|
2751
|
-
if (
|
|
2752
|
-
const id =
|
|
2753
|
-
id.typeAnnotation =
|
|
2817
|
+
if (t27.isTSAsExpression(element)) {
|
|
2818
|
+
const id = t27.identifier(`arg${index}`);
|
|
2819
|
+
id.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2754
2820
|
params.push(id);
|
|
2755
2821
|
return;
|
|
2756
2822
|
}
|
|
2757
|
-
const fallback =
|
|
2758
|
-
fallback.typeAnnotation =
|
|
2823
|
+
const fallback = t27.identifier(`arg${index}`);
|
|
2824
|
+
fallback.typeAnnotation = t27.tsTypeAnnotation(t27.tsAnyKeyword());
|
|
2759
2825
|
params.push(fallback);
|
|
2760
2826
|
});
|
|
2761
2827
|
return params;
|
|
2762
2828
|
}
|
|
2763
2829
|
function resolveExplicitEmitType(tsType) {
|
|
2764
|
-
if (
|
|
2830
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2765
2831
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
2766
2832
|
}
|
|
2767
|
-
if (
|
|
2833
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2768
2834
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2769
2835
|
return tsType;
|
|
2770
2836
|
}
|
|
2771
2837
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
2772
|
-
return
|
|
2838
|
+
return t27.tsTypeReference(
|
|
2773
2839
|
tsType.typeName,
|
|
2774
|
-
|
|
2840
|
+
t27.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2775
2841
|
);
|
|
2776
2842
|
}
|
|
2777
|
-
if (
|
|
2843
|
+
if (t27.isTSIntersectionType(tsType)) {
|
|
2778
2844
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2779
2845
|
if (!types.length) return null;
|
|
2780
2846
|
if (types.length === 1) return types[0];
|
|
2781
|
-
return
|
|
2847
|
+
return t27.tsIntersectionType(types);
|
|
2782
2848
|
}
|
|
2783
|
-
if (
|
|
2849
|
+
if (t27.isTSUnionType(tsType)) {
|
|
2784
2850
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2785
2851
|
if (!types.length) return null;
|
|
2786
2852
|
if (types.length === 1) return types[0];
|
|
2787
|
-
return
|
|
2853
|
+
return t27.tsUnionType(types);
|
|
2788
2854
|
}
|
|
2789
|
-
if (
|
|
2855
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2790
2856
|
const members = [];
|
|
2791
2857
|
for (const member of tsType.members) {
|
|
2792
|
-
if (
|
|
2858
|
+
if (t27.isTSPropertySignature(member)) {
|
|
2793
2859
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
2794
2860
|
if (prop) members.push(prop);
|
|
2795
2861
|
continue;
|
|
2796
2862
|
}
|
|
2797
|
-
if (
|
|
2863
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2798
2864
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2799
2865
|
continue;
|
|
2800
2866
|
}
|
|
2801
2867
|
}
|
|
2802
2868
|
if (!members.length) return null;
|
|
2803
|
-
return
|
|
2869
|
+
return t27.tsTypeLiteral(members);
|
|
2804
2870
|
}
|
|
2805
|
-
if (
|
|
2871
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2806
2872
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2807
2873
|
if (!props.length) return null;
|
|
2808
|
-
return
|
|
2874
|
+
return t27.tsTypeLiteral(props);
|
|
2809
2875
|
}
|
|
2810
2876
|
return tsType;
|
|
2811
2877
|
}
|
|
2812
2878
|
function hasEmitsSignatureInType(tsType) {
|
|
2813
|
-
if (
|
|
2879
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2814
2880
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
2815
2881
|
}
|
|
2816
|
-
if (
|
|
2882
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2817
2883
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2818
2884
|
return false;
|
|
2819
2885
|
}
|
|
2820
2886
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
2821
2887
|
}
|
|
2822
|
-
if (
|
|
2888
|
+
if (t27.isTSIntersectionType(tsType) || t27.isTSUnionType(tsType)) {
|
|
2823
2889
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
2824
2890
|
}
|
|
2825
|
-
if (
|
|
2891
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2826
2892
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
2827
2893
|
}
|
|
2828
|
-
if (
|
|
2894
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2829
2895
|
return isEmitsCallable(tsType.parameters);
|
|
2830
2896
|
}
|
|
2831
2897
|
return false;
|
|
2832
2898
|
}
|
|
2833
2899
|
function hasEmitsSignatureInMember(member) {
|
|
2834
|
-
if (
|
|
2900
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2835
2901
|
return isEmitsCallable(member.parameters);
|
|
2836
2902
|
}
|
|
2837
2903
|
return false;
|
|
2838
2904
|
}
|
|
2839
2905
|
function isEmitsCallable(parameters) {
|
|
2840
2906
|
const [eventParam] = parameters;
|
|
2841
|
-
if (!eventParam || !
|
|
2907
|
+
if (!eventParam || !t27.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2842
2908
|
return false;
|
|
2843
2909
|
}
|
|
2844
2910
|
const { typeAnnotation } = eventParam;
|
|
2845
|
-
if (
|
|
2911
|
+
if (t27.isNoop(typeAnnotation)) return false;
|
|
2846
2912
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
2847
2913
|
}
|
|
2848
2914
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -2850,21 +2916,21 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
2850
2916
|
if (!rawName) return null;
|
|
2851
2917
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2852
2918
|
const key = buildKey(handlerName);
|
|
2853
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
2919
|
+
const typeAnnotation = _optionalChain([member, 'access', _72 => _72.typeAnnotation, 'optionalAccess', _73 => _73.typeAnnotation]);
|
|
2854
2920
|
let params = [];
|
|
2855
|
-
let returnType =
|
|
2856
|
-
if (typeAnnotation &&
|
|
2921
|
+
let returnType = t27.tsAnyKeyword();
|
|
2922
|
+
if (typeAnnotation && t27.isTSFunctionType(typeAnnotation)) {
|
|
2857
2923
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
2858
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
2859
|
-
} else if (typeAnnotation &&
|
|
2924
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _74 => _74.typeAnnotation, 'optionalAccess', _75 => _75.typeAnnotation]), () => ( returnType));
|
|
2925
|
+
} else if (typeAnnotation && t27.isTSTupleType(typeAnnotation)) {
|
|
2860
2926
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
2861
2927
|
} else if (typeAnnotation) {
|
|
2862
|
-
const id =
|
|
2863
|
-
id.typeAnnotation =
|
|
2928
|
+
const id = t27.identifier("value");
|
|
2929
|
+
id.typeAnnotation = t27.tsTypeAnnotation(typeAnnotation);
|
|
2864
2930
|
params = [id];
|
|
2865
2931
|
}
|
|
2866
|
-
const fnType =
|
|
2867
|
-
const prop =
|
|
2932
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(returnType));
|
|
2933
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2868
2934
|
prop.optional = !!member.optional;
|
|
2869
2935
|
return prop;
|
|
2870
2936
|
}
|
|
@@ -2873,32 +2939,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
2873
2939
|
}
|
|
2874
2940
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
2875
2941
|
const [eventParam, ...restParams] = parameters;
|
|
2876
|
-
if (!eventParam || !
|
|
2942
|
+
if (!eventParam || !t27.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2877
2943
|
return [];
|
|
2878
2944
|
}
|
|
2879
2945
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
2880
|
-
if (
|
|
2946
|
+
if (t27.isNoop(paramTypeAnnotation)) return [];
|
|
2881
2947
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
2882
2948
|
if (!eventNames.length) return [];
|
|
2883
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
2949
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _76 => _76.typeAnnotation]), () => ( t27.tsAnyKeyword()));
|
|
2884
2950
|
return eventNames.map((eventName) => {
|
|
2885
2951
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
2886
2952
|
const key = buildKey(handlerName);
|
|
2887
2953
|
const params = cloneCallableParams(restParams);
|
|
2888
|
-
const fnType =
|
|
2889
|
-
const prop =
|
|
2954
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(returnType));
|
|
2955
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2890
2956
|
prop.optional = true;
|
|
2891
2957
|
return prop;
|
|
2892
2958
|
});
|
|
2893
2959
|
}
|
|
2894
2960
|
function resolveEventNames(type) {
|
|
2895
|
-
if (
|
|
2961
|
+
if (t27.isTSLiteralType(type) && t27.isStringLiteral(type.literal)) {
|
|
2896
2962
|
return [type.literal.value];
|
|
2897
2963
|
}
|
|
2898
|
-
if (
|
|
2964
|
+
if (t27.isTSUnionType(type)) {
|
|
2899
2965
|
return type.types.flatMap(resolveEventNames);
|
|
2900
2966
|
}
|
|
2901
|
-
if (
|
|
2967
|
+
if (t27.isTSParenthesizedType(type)) {
|
|
2902
2968
|
return resolveEventNames(type.typeAnnotation);
|
|
2903
2969
|
}
|
|
2904
2970
|
return [];
|
|
@@ -2911,49 +2977,49 @@ function resolveTupleTypeParams(tuple) {
|
|
|
2911
2977
|
return params;
|
|
2912
2978
|
}
|
|
2913
2979
|
function resolveTupleElementParam(element, index) {
|
|
2914
|
-
const isNamedTuple = typeof
|
|
2980
|
+
const isNamedTuple = typeof t27.isTSNamedTupleMember === "function" && t27.isTSNamedTupleMember(element);
|
|
2915
2981
|
if (isNamedTuple) {
|
|
2916
2982
|
const tupleMember = element;
|
|
2917
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
2983
|
+
const name = _optionalChain([tupleMember, 'access', _77 => _77.label, 'optionalAccess', _78 => _78.name]) || `arg${index}`;
|
|
2918
2984
|
let innerType = tupleMember.elementType;
|
|
2919
2985
|
let optional = tupleMember.optional;
|
|
2920
|
-
if (
|
|
2986
|
+
if (t27.isTSOptionalType(innerType)) {
|
|
2921
2987
|
optional = true;
|
|
2922
2988
|
innerType = innerType.typeAnnotation;
|
|
2923
2989
|
}
|
|
2924
|
-
if (
|
|
2925
|
-
const rest =
|
|
2926
|
-
rest.typeAnnotation =
|
|
2990
|
+
if (t27.isTSRestType(innerType)) {
|
|
2991
|
+
const rest = t27.restElement(t27.identifier(name));
|
|
2992
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(innerType.typeAnnotation);
|
|
2927
2993
|
return rest;
|
|
2928
2994
|
}
|
|
2929
|
-
const id2 =
|
|
2995
|
+
const id2 = t27.identifier(name);
|
|
2930
2996
|
id2.optional = optional;
|
|
2931
|
-
id2.typeAnnotation =
|
|
2997
|
+
id2.typeAnnotation = t27.tsTypeAnnotation(innerType);
|
|
2932
2998
|
return id2;
|
|
2933
2999
|
}
|
|
2934
|
-
if (
|
|
2935
|
-
const rest =
|
|
2936
|
-
rest.typeAnnotation =
|
|
3000
|
+
if (t27.isTSRestType(element)) {
|
|
3001
|
+
const rest = t27.restElement(t27.identifier(`args${index}`));
|
|
3002
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2937
3003
|
return rest;
|
|
2938
3004
|
}
|
|
2939
|
-
if (
|
|
2940
|
-
const id2 =
|
|
3005
|
+
if (t27.isTSOptionalType(element)) {
|
|
3006
|
+
const id2 = t27.identifier(`arg${index}`);
|
|
2941
3007
|
id2.optional = true;
|
|
2942
|
-
id2.typeAnnotation =
|
|
3008
|
+
id2.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2943
3009
|
return id2;
|
|
2944
3010
|
}
|
|
2945
|
-
const id =
|
|
2946
|
-
id.typeAnnotation =
|
|
3011
|
+
const id = t27.identifier(`arg${index}`);
|
|
3012
|
+
id.typeAnnotation = t27.tsTypeAnnotation(element);
|
|
2947
3013
|
return id;
|
|
2948
3014
|
}
|
|
2949
3015
|
|
|
2950
3016
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
2951
3017
|
|
|
2952
|
-
function resolveDefinePropsIface(
|
|
2953
|
-
const { node } =
|
|
3018
|
+
function resolveDefinePropsIface(path8, ctx) {
|
|
3019
|
+
const { node } = path8;
|
|
2954
3020
|
const [runtimeArg] = node.arguments;
|
|
2955
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2956
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
3021
|
+
const tsParams = _optionalChain([node, 'access', _79 => _79.typeParameters, 'optionalAccess', _80 => _80.params]);
|
|
3022
|
+
if (_optionalChain([tsParams, 'optionalAccess', _81 => _81.length])) {
|
|
2957
3023
|
const { propsTSIface } = ctx.scriptData;
|
|
2958
3024
|
propsTSIface.propsTypes = tsParams;
|
|
2959
3025
|
return;
|
|
@@ -2968,38 +3034,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
2968
3034
|
} = scriptData;
|
|
2969
3035
|
if (!runtimeArg) return;
|
|
2970
3036
|
const members = [];
|
|
2971
|
-
if (
|
|
3037
|
+
if (t28.isArrayExpression(runtimeArg)) {
|
|
2972
3038
|
for (const element of runtimeArg.elements) {
|
|
2973
|
-
if (!element || !
|
|
2974
|
-
const key =
|
|
2975
|
-
const prop =
|
|
3039
|
+
if (!element || !t28.isStringLiteral(element)) continue;
|
|
3040
|
+
const key = t28.isValidIdentifier(element.value) ? t28.identifier(element.value) : t28.stringLiteral(element.value);
|
|
3041
|
+
const prop = t28.tsPropertySignature(key, t28.tsTypeAnnotation(t28.tsAnyKeyword()));
|
|
2976
3042
|
prop.optional = true;
|
|
2977
3043
|
members.push(prop);
|
|
2978
3044
|
}
|
|
2979
3045
|
if (members.length) {
|
|
2980
|
-
propsTypes.push(
|
|
3046
|
+
propsTypes.push(t28.tsTypeLiteral(members));
|
|
2981
3047
|
}
|
|
2982
3048
|
return;
|
|
2983
3049
|
}
|
|
2984
|
-
if (
|
|
3050
|
+
if (t28.isObjectExpression(runtimeArg)) {
|
|
2985
3051
|
for (const prop of runtimeArg.properties) {
|
|
2986
|
-
if (!
|
|
2987
|
-
if (
|
|
3052
|
+
if (!t28.isObjectProperty(prop)) continue;
|
|
3053
|
+
if (t28.isSpreadElement(prop)) continue;
|
|
2988
3054
|
const key = prop.key;
|
|
2989
3055
|
let propName = null;
|
|
2990
|
-
if (
|
|
2991
|
-
if (
|
|
2992
|
-
if (
|
|
3056
|
+
if (t28.isIdentifier(key)) propName = key.name;
|
|
3057
|
+
if (t28.isStringLiteral(key)) propName = key.value;
|
|
3058
|
+
if (t28.isNumericLiteral(key)) propName = String(key.value);
|
|
2993
3059
|
if (!propName) continue;
|
|
2994
3060
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
2995
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
2996
|
-
const tsKey =
|
|
2997
|
-
const tsProp =
|
|
3061
|
+
const tsType = _nullishCoalesce(type, () => ( t28.tsAnyKeyword()));
|
|
3062
|
+
const tsKey = t28.isValidIdentifier(propName) ? t28.identifier(propName) : t28.stringLiteral(propName);
|
|
3063
|
+
const tsProp = t28.tsPropertySignature(tsKey, t28.tsTypeAnnotation(tsType));
|
|
2998
3064
|
tsProp.optional = !required;
|
|
2999
3065
|
members.push(tsProp);
|
|
3000
3066
|
}
|
|
3001
3067
|
if (members.length) {
|
|
3002
|
-
propsTypes.push(
|
|
3068
|
+
propsTypes.push(t28.tsTypeLiteral(members));
|
|
3003
3069
|
}
|
|
3004
3070
|
return;
|
|
3005
3071
|
}
|
|
@@ -3008,47 +3074,47 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3008
3074
|
{
|
|
3009
3075
|
source,
|
|
3010
3076
|
file: filename,
|
|
3011
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
3077
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _82 => _82.loc])
|
|
3012
3078
|
}
|
|
3013
3079
|
);
|
|
3014
3080
|
}
|
|
3015
3081
|
function resolveRuntimePropMeta(value) {
|
|
3016
|
-
if (
|
|
3082
|
+
if (t28.isIdentifier(value)) {
|
|
3017
3083
|
return {
|
|
3018
3084
|
type: mapRuntimeTypeToTSType(value),
|
|
3019
3085
|
required: false
|
|
3020
3086
|
};
|
|
3021
3087
|
}
|
|
3022
|
-
if (
|
|
3088
|
+
if (t28.isArrayExpression(value)) {
|
|
3023
3089
|
return {
|
|
3024
3090
|
type: resolveRuntimeUnionType(value),
|
|
3025
3091
|
required: false
|
|
3026
3092
|
};
|
|
3027
3093
|
}
|
|
3028
|
-
if (!
|
|
3094
|
+
if (!t28.isObjectExpression(value)) {
|
|
3029
3095
|
return { required: false };
|
|
3030
3096
|
}
|
|
3031
3097
|
let type;
|
|
3032
3098
|
let required = false;
|
|
3033
3099
|
for (const prop of value.properties) {
|
|
3034
|
-
if (!
|
|
3035
|
-
if (
|
|
3100
|
+
if (!t28.isObjectProperty(prop)) continue;
|
|
3101
|
+
if (t28.isSpreadElement(prop)) continue;
|
|
3036
3102
|
const key = prop.key;
|
|
3037
|
-
const propName =
|
|
3103
|
+
const propName = t28.isIdentifier(key) ? key.name : t28.isStringLiteral(key) ? key.value : null;
|
|
3038
3104
|
if (!propName) continue;
|
|
3039
3105
|
if (propName === "type") {
|
|
3040
3106
|
const valueNode = prop.value;
|
|
3041
|
-
if (
|
|
3107
|
+
if (t28.isArrayExpression(valueNode)) {
|
|
3042
3108
|
type = resolveRuntimeUnionType(valueNode);
|
|
3043
3109
|
continue;
|
|
3044
3110
|
}
|
|
3045
|
-
if (
|
|
3111
|
+
if (t28.isIdentifier(valueNode)) {
|
|
3046
3112
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3047
3113
|
continue;
|
|
3048
3114
|
}
|
|
3049
3115
|
}
|
|
3050
3116
|
if (propName === "required") {
|
|
3051
|
-
if (
|
|
3117
|
+
if (t28.isBooleanLiteral(prop.value)) {
|
|
3052
3118
|
required = prop.value.value;
|
|
3053
3119
|
}
|
|
3054
3120
|
}
|
|
@@ -3058,34 +3124,34 @@ function resolveRuntimePropMeta(value) {
|
|
|
3058
3124
|
function resolveRuntimeUnionType(value) {
|
|
3059
3125
|
const types = [];
|
|
3060
3126
|
for (const element of value.elements) {
|
|
3061
|
-
if (!element || !
|
|
3127
|
+
if (!element || !t28.isIdentifier(element)) continue;
|
|
3062
3128
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3063
3129
|
if (resolved) types.push(resolved);
|
|
3064
3130
|
}
|
|
3065
|
-
if (!types.length) return
|
|
3131
|
+
if (!types.length) return t28.tsAnyKeyword();
|
|
3066
3132
|
if (types.length === 1) return types[0];
|
|
3067
|
-
return
|
|
3133
|
+
return t28.tsUnionType(types);
|
|
3068
3134
|
}
|
|
3069
3135
|
function mapRuntimeTypeToTSType(value) {
|
|
3070
3136
|
switch (value.name) {
|
|
3071
3137
|
case "String":
|
|
3072
|
-
return
|
|
3138
|
+
return t28.tsStringKeyword();
|
|
3073
3139
|
case "Number":
|
|
3074
|
-
return
|
|
3140
|
+
return t28.tsNumberKeyword();
|
|
3075
3141
|
case "Boolean":
|
|
3076
|
-
return
|
|
3142
|
+
return t28.tsBooleanKeyword();
|
|
3077
3143
|
case "Object":
|
|
3078
|
-
return
|
|
3144
|
+
return t28.tsTypeLiteral([]);
|
|
3079
3145
|
case "Array":
|
|
3080
|
-
return
|
|
3146
|
+
return t28.tsArrayType(t28.tsAnyKeyword());
|
|
3081
3147
|
case "Function":
|
|
3082
|
-
return
|
|
3148
|
+
return t28.tsFunctionType(null, [], t28.tsTypeAnnotation(t28.tsAnyKeyword()));
|
|
3083
3149
|
case "Symbol":
|
|
3084
|
-
return
|
|
3150
|
+
return t28.tsSymbolKeyword();
|
|
3085
3151
|
case "BigInt":
|
|
3086
|
-
return
|
|
3152
|
+
return t28.tsBigIntKeyword();
|
|
3087
3153
|
default:
|
|
3088
|
-
return
|
|
3154
|
+
return t28.tsAnyKeyword();
|
|
3089
3155
|
}
|
|
3090
3156
|
}
|
|
3091
3157
|
|
|
@@ -3096,20 +3162,20 @@ var SLOT_CHILDREN_NAME = "children";
|
|
|
3096
3162
|
var SLOT_FN_PARAM_NAME = "props";
|
|
3097
3163
|
function resolveSlotsTopLevelTypes(ctx) {
|
|
3098
3164
|
return {
|
|
3099
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(
|
|
3100
|
-
if (!
|
|
3101
|
-
const { node } =
|
|
3102
|
-
if (
|
|
3103
|
-
const typeLiteral =
|
|
3165
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3166
|
+
if (!t29.isProgram(path8.parent)) return;
|
|
3167
|
+
const { node } = path8;
|
|
3168
|
+
if (t29.isTSInterfaceDeclaration(node)) {
|
|
3169
|
+
const typeLiteral = t29.tsTypeLiteral(node.body.body);
|
|
3104
3170
|
if (!hasSlotsSignatureInType(typeLiteral)) return;
|
|
3105
3171
|
const resolved = resolveSlotType(typeLiteral);
|
|
3106
|
-
if (resolved &&
|
|
3172
|
+
if (resolved && t29.isTSTypeLiteral(resolved)) {
|
|
3107
3173
|
node.body.body = resolved.members;
|
|
3108
3174
|
recordReactNode(ctx);
|
|
3109
3175
|
}
|
|
3110
3176
|
return;
|
|
3111
3177
|
}
|
|
3112
|
-
if (
|
|
3178
|
+
if (t29.isTSTypeAliasDeclaration(node)) {
|
|
3113
3179
|
if (!hasSlotsSignatureInType(node.typeAnnotation)) return;
|
|
3114
3180
|
const resolved = resolveSlotType(node.typeAnnotation);
|
|
3115
3181
|
if (resolved) {
|
|
@@ -3120,10 +3186,10 @@ function resolveSlotsTopLevelTypes(ctx) {
|
|
|
3120
3186
|
}
|
|
3121
3187
|
};
|
|
3122
3188
|
}
|
|
3123
|
-
function resolveDefineSlotsIface(
|
|
3124
|
-
const { node } =
|
|
3125
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3126
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
3189
|
+
function resolveDefineSlotsIface(path8, ctx) {
|
|
3190
|
+
const { node } = path8;
|
|
3191
|
+
const tsParams = _optionalChain([node, 'access', _83 => _83.typeParameters, 'optionalAccess', _84 => _84.params]);
|
|
3192
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _85 => _85.length])) return;
|
|
3127
3193
|
const {
|
|
3128
3194
|
propsTSIface: { slotTypes }
|
|
3129
3195
|
} = ctx.scriptData;
|
|
@@ -3154,7 +3220,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
3154
3220
|
}
|
|
3155
3221
|
if (tsMembers.length) {
|
|
3156
3222
|
recordReactNode(ctx);
|
|
3157
|
-
slotTypes.push(
|
|
3223
|
+
slotTypes.push(t29.tsTypeLiteral(tsMembers));
|
|
3158
3224
|
}
|
|
3159
3225
|
}
|
|
3160
3226
|
function recordReactNode(ctx) {
|
|
@@ -3164,32 +3230,32 @@ function recordReactNode(ctx) {
|
|
|
3164
3230
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
|
|
3165
3231
|
}
|
|
3166
3232
|
function resolveSlotType(tsType) {
|
|
3167
|
-
if (
|
|
3233
|
+
if (t29.isTSParenthesizedType(tsType)) {
|
|
3168
3234
|
return resolveSlotType(tsType.typeAnnotation);
|
|
3169
3235
|
}
|
|
3170
|
-
if (
|
|
3236
|
+
if (t29.isTSTypeReference(tsType)) {
|
|
3171
3237
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3172
3238
|
return tsType;
|
|
3173
3239
|
}
|
|
3174
3240
|
const params = tsType.typeParameters.params.map((param) => resolveSlotType(param)).filter(Boolean);
|
|
3175
|
-
return
|
|
3241
|
+
return t29.tsTypeReference(
|
|
3176
3242
|
tsType.typeName,
|
|
3177
|
-
|
|
3243
|
+
t29.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3178
3244
|
);
|
|
3179
3245
|
}
|
|
3180
|
-
if (
|
|
3246
|
+
if (t29.isTSIntersectionType(tsType)) {
|
|
3181
3247
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3182
3248
|
if (!types.length) return null;
|
|
3183
3249
|
if (types.length === 1) return types[0];
|
|
3184
|
-
return
|
|
3250
|
+
return t29.tsIntersectionType(types);
|
|
3185
3251
|
}
|
|
3186
|
-
if (
|
|
3252
|
+
if (t29.isTSUnionType(tsType)) {
|
|
3187
3253
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3188
3254
|
if (!types.length) return null;
|
|
3189
3255
|
if (types.length === 1) return types[0];
|
|
3190
|
-
return
|
|
3256
|
+
return t29.tsUnionType(types);
|
|
3191
3257
|
}
|
|
3192
|
-
if (
|
|
3258
|
+
if (t29.isTSTypeLiteral(tsType)) {
|
|
3193
3259
|
const members = [];
|
|
3194
3260
|
for (const member of tsType.members) {
|
|
3195
3261
|
const resolved = resolveSlotPropFromMember(member);
|
|
@@ -3200,111 +3266,111 @@ function resolveSlotType(tsType) {
|
|
|
3200
3266
|
members.push(member);
|
|
3201
3267
|
}
|
|
3202
3268
|
if (!members.length) return null;
|
|
3203
|
-
return
|
|
3269
|
+
return t29.tsTypeLiteral(members);
|
|
3204
3270
|
}
|
|
3205
|
-
if (
|
|
3271
|
+
if (t29.isTSFunctionType(tsType)) {
|
|
3206
3272
|
const props = buildSlotPropSignature(
|
|
3207
3273
|
SLOT_DEFAULT_NAME,
|
|
3208
3274
|
cloneCallableParams(tsType.parameters),
|
|
3209
3275
|
false
|
|
3210
3276
|
);
|
|
3211
|
-
return
|
|
3277
|
+
return t29.tsTypeLiteral([props]);
|
|
3212
3278
|
}
|
|
3213
3279
|
return tsType;
|
|
3214
3280
|
}
|
|
3215
3281
|
function hasSlotsSignatureInType(tsType) {
|
|
3216
|
-
if (
|
|
3282
|
+
if (t29.isTSParenthesizedType(tsType)) {
|
|
3217
3283
|
return hasSlotsSignatureInType(tsType.typeAnnotation);
|
|
3218
3284
|
}
|
|
3219
|
-
if (
|
|
3285
|
+
if (t29.isTSTypeReference(tsType)) {
|
|
3220
3286
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3221
3287
|
return false;
|
|
3222
3288
|
}
|
|
3223
3289
|
return tsType.typeParameters.params.some(hasSlotsSignatureInType);
|
|
3224
3290
|
}
|
|
3225
|
-
if (
|
|
3291
|
+
if (t29.isTSIntersectionType(tsType) || t29.isTSUnionType(tsType)) {
|
|
3226
3292
|
return tsType.types.some(hasSlotsSignatureInType);
|
|
3227
3293
|
}
|
|
3228
|
-
if (
|
|
3294
|
+
if (t29.isTSTypeLiteral(tsType)) {
|
|
3229
3295
|
return tsType.members.some(hasSlotsSignatureInMember);
|
|
3230
3296
|
}
|
|
3231
|
-
if (
|
|
3297
|
+
if (t29.isTSFunctionType(tsType)) {
|
|
3232
3298
|
return true;
|
|
3233
3299
|
}
|
|
3234
3300
|
return false;
|
|
3235
3301
|
}
|
|
3236
3302
|
function hasSlotsSignatureInMember(member) {
|
|
3237
|
-
if (
|
|
3238
|
-
if (
|
|
3239
|
-
if (
|
|
3240
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3303
|
+
if (t29.isTSMethodSignature(member)) return true;
|
|
3304
|
+
if (t29.isTSCallSignatureDeclaration(member)) return true;
|
|
3305
|
+
if (t29.isTSPropertySignature(member)) {
|
|
3306
|
+
const typeAnnotation = _optionalChain([member, 'access', _86 => _86.typeAnnotation, 'optionalAccess', _87 => _87.typeAnnotation]);
|
|
3241
3307
|
return !!(typeAnnotation && resolveCallableType(typeAnnotation));
|
|
3242
3308
|
}
|
|
3243
3309
|
return false;
|
|
3244
3310
|
}
|
|
3245
3311
|
function resolveSlotPropFromMember(member) {
|
|
3246
|
-
if (
|
|
3312
|
+
if (t29.isTSMethodSignature(member)) {
|
|
3247
3313
|
const rawName = resolvePropName2(member.key);
|
|
3248
3314
|
if (!rawName) return null;
|
|
3249
3315
|
const params = cloneCallableParams(member.parameters);
|
|
3250
3316
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3251
3317
|
}
|
|
3252
|
-
if (
|
|
3318
|
+
if (t29.isTSPropertySignature(member)) {
|
|
3253
3319
|
const rawName = resolvePropName2(member.key);
|
|
3254
3320
|
if (!rawName) return null;
|
|
3255
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3321
|
+
const typeAnnotation = _optionalChain([member, 'access', _88 => _88.typeAnnotation, 'optionalAccess', _89 => _89.typeAnnotation]);
|
|
3256
3322
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
3257
3323
|
if (!callable) return null;
|
|
3258
3324
|
const params = cloneCallableParams(callable.parameters);
|
|
3259
3325
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3260
3326
|
}
|
|
3261
|
-
if (
|
|
3327
|
+
if (t29.isTSCallSignatureDeclaration(member)) {
|
|
3262
3328
|
const params = cloneCallableParams(member.parameters);
|
|
3263
3329
|
return buildSlotPropSignature(SLOT_DEFAULT_NAME, params, true);
|
|
3264
3330
|
}
|
|
3265
3331
|
return null;
|
|
3266
3332
|
}
|
|
3267
3333
|
function resolveCallableType(tsType) {
|
|
3268
|
-
if (
|
|
3269
|
-
if (
|
|
3334
|
+
if (t29.isTSFunctionType(tsType)) return tsType;
|
|
3335
|
+
if (t29.isTSParenthesizedType(tsType)) return resolveCallableType(tsType.typeAnnotation);
|
|
3270
3336
|
return null;
|
|
3271
3337
|
}
|
|
3272
3338
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3273
3339
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3274
|
-
const key =
|
|
3275
|
-
const reactNodeType =
|
|
3276
|
-
|
|
3340
|
+
const key = t29.isValidIdentifier(propName) ? t29.identifier(propName) : t29.stringLiteral(propName);
|
|
3341
|
+
const reactNodeType = t29.tsTypeAnnotation(
|
|
3342
|
+
t29.tsTypeReference(t29.identifier(REACT_API_MAP.ReactNode))
|
|
3277
3343
|
);
|
|
3278
3344
|
let typeAnnotation;
|
|
3279
3345
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3280
3346
|
typeAnnotation = reactNodeType;
|
|
3281
3347
|
} else {
|
|
3282
|
-
const fnType =
|
|
3283
|
-
typeAnnotation =
|
|
3348
|
+
const fnType = t29.tsFunctionType(null, params, reactNodeType);
|
|
3349
|
+
typeAnnotation = t29.tsTypeAnnotation(fnType);
|
|
3284
3350
|
}
|
|
3285
|
-
const prop =
|
|
3351
|
+
const prop = t29.tsPropertySignature(key, typeAnnotation);
|
|
3286
3352
|
prop.optional = optional;
|
|
3287
3353
|
return prop;
|
|
3288
3354
|
}
|
|
3289
3355
|
function createSlotScopeParam(props, ctx) {
|
|
3290
|
-
const paramId =
|
|
3356
|
+
const paramId = t29.identifier(SLOT_FN_PARAM_NAME);
|
|
3291
3357
|
const propsSigns = [];
|
|
3292
3358
|
const { reactiveBindings } = ctx.templateData;
|
|
3293
3359
|
props.forEach(({ prop, tsType }) => {
|
|
3294
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
3360
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _90 => _90[prop], 'optionalAccess', _91 => _91.value]);
|
|
3295
3361
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3296
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3297
|
-
const key =
|
|
3298
|
-
const propSign =
|
|
3362
|
+
const typeAnnotation = foundBindingTypes ? t29.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
3363
|
+
const key = t29.isValidIdentifier(prop) ? t29.identifier(prop) : t29.stringLiteral(prop);
|
|
3364
|
+
const propSign = t29.tsPropertySignature(key, typeAnnotation);
|
|
3299
3365
|
propsSigns.push(propSign);
|
|
3300
3366
|
});
|
|
3301
|
-
paramId.typeAnnotation =
|
|
3367
|
+
paramId.typeAnnotation = t29.tsTypeAnnotation(t29.tsTypeLiteral(propsSigns));
|
|
3302
3368
|
return paramId;
|
|
3303
3369
|
}
|
|
3304
3370
|
function resolvePropName2(key) {
|
|
3305
|
-
if (
|
|
3306
|
-
if (
|
|
3307
|
-
if (
|
|
3371
|
+
if (t29.isIdentifier(key)) return key.name;
|
|
3372
|
+
if (t29.isStringLiteral(key)) return key.value;
|
|
3373
|
+
if (t29.isNumericLiteral(key)) return String(key.value);
|
|
3308
3374
|
return null;
|
|
3309
3375
|
}
|
|
3310
3376
|
|
|
@@ -3312,8 +3378,8 @@ function resolvePropName2(key) {
|
|
|
3312
3378
|
function resolvePropsIface(ctx) {
|
|
3313
3379
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
3314
3380
|
return {
|
|
3315
|
-
CallExpression(
|
|
3316
|
-
const { node, parentPath } =
|
|
3381
|
+
CallExpression(path8) {
|
|
3382
|
+
const { node, parentPath } = path8;
|
|
3317
3383
|
const name = node.callee.name;
|
|
3318
3384
|
if (!isCalleeNamed(node, MACRO_API_NAMES.props) && !isCalleeNamed(node, MACRO_API_NAMES.emits) && !isCalleeNamed(node, MACRO_API_NAMES.slots)) {
|
|
3319
3385
|
return;
|
|
@@ -3322,7 +3388,7 @@ function resolvePropsIface(ctx) {
|
|
|
3322
3388
|
if (parentPath.isVariableDeclaration() || parentPath.isVariableDeclarator()) {
|
|
3323
3389
|
parentPath.remove();
|
|
3324
3390
|
} else {
|
|
3325
|
-
|
|
3391
|
+
path8.remove();
|
|
3326
3392
|
}
|
|
3327
3393
|
};
|
|
3328
3394
|
if (ctx.inputType !== "sfc") {
|
|
@@ -3336,11 +3402,11 @@ function resolvePropsIface(ctx) {
|
|
|
3336
3402
|
propsTSIface.hasPropsInJsEnv = true;
|
|
3337
3403
|
} else {
|
|
3338
3404
|
if (name === MACRO_API_NAMES.props) {
|
|
3339
|
-
resolveDefinePropsIface(
|
|
3405
|
+
resolveDefinePropsIface(path8, ctx);
|
|
3340
3406
|
} else if (name === MACRO_API_NAMES.emits) {
|
|
3341
|
-
resolveDefineEmitsIface(
|
|
3407
|
+
resolveDefineEmitsIface(path8, ctx);
|
|
3342
3408
|
} else if (name === MACRO_API_NAMES.slots) {
|
|
3343
|
-
resolveDefineSlotsIface(
|
|
3409
|
+
resolveDefineSlotsIface(path8, ctx);
|
|
3344
3410
|
}
|
|
3345
3411
|
}
|
|
3346
3412
|
removePath();
|
|
@@ -3356,9 +3422,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3356
3422
|
}
|
|
3357
3423
|
const n = ctx.compName || "Comp";
|
|
3358
3424
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
3359
|
-
const typeNode =
|
|
3360
|
-
const typeAliasDecl =
|
|
3361
|
-
const exportDecl =
|
|
3425
|
+
const typeNode = t30.tsIntersectionType(tsTypes);
|
|
3426
|
+
const typeAliasDecl = t30.tsTypeAliasDeclaration(t30.identifier(ns), null, typeNode);
|
|
3427
|
+
const exportDecl = t30.exportNamedDeclaration(typeAliasDecl);
|
|
3362
3428
|
propsTSIface.name = ns;
|
|
3363
3429
|
const scriptIR = getScriptIR(ctx);
|
|
3364
3430
|
scriptIR.exports.push(exportDecl);
|
|
@@ -3374,9 +3440,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3374
3440
|
var TRACE_MAX_DEPTH = 20;
|
|
3375
3441
|
function analyzeDeps(node, ctx, parentPath) {
|
|
3376
3442
|
if (!parentPath) {
|
|
3377
|
-
return
|
|
3443
|
+
return t31.arrayExpression([]);
|
|
3378
3444
|
}
|
|
3379
|
-
const isFnExpr =
|
|
3445
|
+
const isFnExpr = t31.isArrowFunctionExpression(node) || t31.isFunctionExpression(node);
|
|
3380
3446
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
3381
3447
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
3382
3448
|
const reactiveStateApis = getReactiveStateApis();
|
|
@@ -3389,11 +3455,11 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3389
3455
|
analyzeTarget,
|
|
3390
3456
|
{
|
|
3391
3457
|
"MemberExpression|OptionalMemberExpression"(memberPath) {
|
|
3392
|
-
const
|
|
3393
|
-
if (isNestedMemberObject(
|
|
3394
|
-
const rootId = findRootIdentifier(
|
|
3458
|
+
const path8 = memberPath;
|
|
3459
|
+
if (isNestedMemberObject(path8)) return;
|
|
3460
|
+
const rootId = findRootIdentifier(path8.node);
|
|
3395
3461
|
if (!rootId) return;
|
|
3396
|
-
tryAddDependency(
|
|
3462
|
+
tryAddDependency(path8, rootId.name, path8.scope);
|
|
3397
3463
|
processedIdentifiers.add(rootId);
|
|
3398
3464
|
},
|
|
3399
3465
|
Identifier(idPath) {
|
|
@@ -3428,40 +3494,41 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3428
3494
|
addDependency(sourcedExpression);
|
|
3429
3495
|
}
|
|
3430
3496
|
}
|
|
3431
|
-
function normalizeDependencyExpr(
|
|
3432
|
-
if (
|
|
3433
|
-
return
|
|
3497
|
+
function normalizeDependencyExpr(path8, rootName) {
|
|
3498
|
+
if (t31.isIdentifier(path8.node)) {
|
|
3499
|
+
return t31.identifier(path8.node.name);
|
|
3434
3500
|
}
|
|
3435
|
-
if (
|
|
3436
|
-
const normalizedExp = normalizeMemberForCallSite(
|
|
3437
|
-
|
|
3438
|
-
|
|
3501
|
+
if (t31.isMemberExpression(path8.node) || t31.isOptionalMemberExpression(path8.node)) {
|
|
3502
|
+
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
3503
|
+
const safeExp = t31.isMemberExpression(normalizedExp) || t31.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForRefValue(normalizedExp) : normalizedExp;
|
|
3504
|
+
if (isReactValidDependencyExpr(safeExp)) {
|
|
3505
|
+
return t31.cloneNode(safeExp, true);
|
|
3439
3506
|
}
|
|
3440
|
-
return
|
|
3507
|
+
return t31.identifier(rootName);
|
|
3441
3508
|
}
|
|
3442
3509
|
return null;
|
|
3443
3510
|
}
|
|
3444
3511
|
function isReactValidDependencyExpr(node2) {
|
|
3445
|
-
if (
|
|
3512
|
+
if (t31.isIdentifier(node2)) {
|
|
3446
3513
|
return true;
|
|
3447
3514
|
}
|
|
3448
|
-
if (
|
|
3515
|
+
if (t31.isMemberExpression(node2) || t31.isOptionalMemberExpression(node2)) {
|
|
3449
3516
|
return isStaticMemberChain(node2);
|
|
3450
3517
|
}
|
|
3451
3518
|
return false;
|
|
3452
3519
|
}
|
|
3453
3520
|
function isStaticMemberChain(node2) {
|
|
3454
3521
|
let current = node2;
|
|
3455
|
-
while (
|
|
3456
|
-
if (!current.computed && !
|
|
3522
|
+
while (t31.isMemberExpression(current) || t31.isOptionalMemberExpression(current)) {
|
|
3523
|
+
if (!current.computed && !t31.isIdentifier(current.property)) {
|
|
3457
3524
|
return false;
|
|
3458
3525
|
}
|
|
3459
|
-
if (current.computed && !
|
|
3526
|
+
if (current.computed && !t31.isStringLiteral(current.property) && !t31.isNumericLiteral(current.property)) {
|
|
3460
3527
|
return false;
|
|
3461
3528
|
}
|
|
3462
3529
|
current = current.object;
|
|
3463
3530
|
}
|
|
3464
|
-
return
|
|
3531
|
+
return t31.isIdentifier(current);
|
|
3465
3532
|
}
|
|
3466
3533
|
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
3467
3534
|
let current = binding.path;
|
|
@@ -3473,17 +3540,42 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3473
3540
|
}
|
|
3474
3541
|
return false;
|
|
3475
3542
|
}
|
|
3476
|
-
function normalizeMemberForCallSite(
|
|
3477
|
-
const parent =
|
|
3543
|
+
function normalizeMemberForCallSite(path8, node2) {
|
|
3544
|
+
const parent = path8.parentPath;
|
|
3478
3545
|
const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node2 || parent.isOptionalCallExpression() && parent.node.callee === node2);
|
|
3479
3546
|
if (!isDirectCallee) {
|
|
3480
3547
|
return node2;
|
|
3481
3548
|
}
|
|
3482
|
-
if (!
|
|
3549
|
+
if (!t31.isExpression(node2.object)) {
|
|
3483
3550
|
return node2;
|
|
3484
3551
|
}
|
|
3485
3552
|
return node2.object;
|
|
3486
3553
|
}
|
|
3554
|
+
function ensureOptionalForRefValue(node2) {
|
|
3555
|
+
if (!hasRefValueAccess(node2)) {
|
|
3556
|
+
return node2;
|
|
3557
|
+
}
|
|
3558
|
+
if (t31.isOptionalMemberExpression(node2) && node2.optional) {
|
|
3559
|
+
return node2;
|
|
3560
|
+
}
|
|
3561
|
+
const object = t31.cloneNode(node2.object, true);
|
|
3562
|
+
const property = t31.cloneNode(node2.property, true);
|
|
3563
|
+
return t31.optionalMemberExpression(object, property, node2.computed, true);
|
|
3564
|
+
}
|
|
3565
|
+
function hasRefValueAccess(node2) {
|
|
3566
|
+
let current = node2;
|
|
3567
|
+
while (t31.isMemberExpression(current) || t31.isOptionalMemberExpression(current)) {
|
|
3568
|
+
if (current.computed) {
|
|
3569
|
+
if (t31.isStringLiteral(current.property) && current.property.value === "value") {
|
|
3570
|
+
return true;
|
|
3571
|
+
}
|
|
3572
|
+
} else if (t31.isIdentifier(current.property) && current.property.name === "value") {
|
|
3573
|
+
return true;
|
|
3574
|
+
}
|
|
3575
|
+
current = current.object;
|
|
3576
|
+
}
|
|
3577
|
+
return false;
|
|
3578
|
+
}
|
|
3487
3579
|
function isEligibleBindingSource(binding) {
|
|
3488
3580
|
if (binding.kind === "param") {
|
|
3489
3581
|
return false;
|
|
@@ -3492,20 +3584,20 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3492
3584
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
3493
3585
|
const isImportBinding = bindingPath.isImportSpecifier() || bindingPath.isImportDefaultSpecifier() || bindingPath.isImportNamespaceSpecifier();
|
|
3494
3586
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
3495
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess',
|
|
3496
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
3497
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
3498
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
3499
|
-
if (declaratorPath && nodeInit && (
|
|
3587
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _92 => _92.node, 'access', _93 => _93.init]);
|
|
3588
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && t31.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
3589
|
+
const isHookCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
3590
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit));
|
|
3591
|
+
if (declaratorPath && nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit))) {
|
|
3500
3592
|
markAsAnalyzed(nodeInit, false);
|
|
3501
3593
|
}
|
|
3502
3594
|
return isImportBinding || isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isFunctionBinding;
|
|
3503
3595
|
}
|
|
3504
3596
|
function isHookLikeCallee(callee) {
|
|
3505
|
-
if (
|
|
3597
|
+
if (t31.isIdentifier(callee)) {
|
|
3506
3598
|
return callee.name.startsWith("use");
|
|
3507
3599
|
}
|
|
3508
|
-
if (
|
|
3600
|
+
if (t31.isMemberExpression(callee) && !callee.computed && t31.isIdentifier(callee.property)) {
|
|
3509
3601
|
return callee.property.name.startsWith("use");
|
|
3510
3602
|
}
|
|
3511
3603
|
return false;
|
|
@@ -3521,7 +3613,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3521
3613
|
}
|
|
3522
3614
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
3523
3615
|
if (depth <= 0) return null;
|
|
3524
|
-
if (
|
|
3616
|
+
if (t31.isIdentifier(exp)) {
|
|
3525
3617
|
const sourceBinding = scope.getBinding(exp.name);
|
|
3526
3618
|
if (!sourceBinding) return null;
|
|
3527
3619
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -3529,13 +3621,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3529
3621
|
}
|
|
3530
3622
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3531
3623
|
}
|
|
3532
|
-
if (
|
|
3624
|
+
if (t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp)) {
|
|
3533
3625
|
const root = findRootIdentifier(exp);
|
|
3534
3626
|
if (!root) return null;
|
|
3535
3627
|
const sourceBinding = scope.getBinding(root.name);
|
|
3536
3628
|
if (!sourceBinding) return null;
|
|
3537
3629
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
3538
|
-
return
|
|
3630
|
+
return t31.cloneNode(exp);
|
|
3539
3631
|
}
|
|
3540
3632
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3541
3633
|
if (sourcedRoot) {
|
|
@@ -3543,17 +3635,17 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3543
3635
|
if (rebuilt) {
|
|
3544
3636
|
return rebuilt;
|
|
3545
3637
|
}
|
|
3546
|
-
return
|
|
3638
|
+
return t31.cloneNode(sourcedRoot, true);
|
|
3547
3639
|
}
|
|
3548
3640
|
}
|
|
3549
3641
|
return null;
|
|
3550
3642
|
}
|
|
3551
3643
|
function rebuildMemberWithNewRoot(node2, nextRoot) {
|
|
3552
3644
|
const replacedObject = (() => {
|
|
3553
|
-
if (
|
|
3554
|
-
return
|
|
3645
|
+
if (t31.isIdentifier(node2.object)) {
|
|
3646
|
+
return t31.cloneNode(nextRoot, true);
|
|
3555
3647
|
}
|
|
3556
|
-
if (
|
|
3648
|
+
if (t31.isMemberExpression(node2.object) || t31.isOptionalMemberExpression(node2.object)) {
|
|
3557
3649
|
return rebuildMemberWithNewRoot(node2.object, nextRoot);
|
|
3558
3650
|
}
|
|
3559
3651
|
return null;
|
|
@@ -3561,51 +3653,51 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3561
3653
|
if (!replacedObject) {
|
|
3562
3654
|
return null;
|
|
3563
3655
|
}
|
|
3564
|
-
const property =
|
|
3565
|
-
if (
|
|
3566
|
-
return
|
|
3656
|
+
const property = t31.cloneNode(node2.property, true);
|
|
3657
|
+
if (t31.isMemberExpression(node2)) {
|
|
3658
|
+
return t31.memberExpression(
|
|
3567
3659
|
replacedObject,
|
|
3568
3660
|
property,
|
|
3569
3661
|
node2.computed
|
|
3570
3662
|
);
|
|
3571
3663
|
}
|
|
3572
|
-
return
|
|
3664
|
+
return t31.optionalMemberExpression(
|
|
3573
3665
|
replacedObject,
|
|
3574
3666
|
property,
|
|
3575
3667
|
node2.computed,
|
|
3576
3668
|
node2.optional
|
|
3577
3669
|
);
|
|
3578
3670
|
}
|
|
3579
|
-
return
|
|
3671
|
+
return t31.arrayExpression(Array.from(deps.values()));
|
|
3580
3672
|
}
|
|
3581
3673
|
function getDependencyKey(exp) {
|
|
3582
|
-
if (
|
|
3674
|
+
if (t31.isIdentifier(exp)) {
|
|
3583
3675
|
return exp.name;
|
|
3584
3676
|
}
|
|
3585
|
-
if (
|
|
3677
|
+
if (t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp)) {
|
|
3586
3678
|
const objectKey = getDependencyKey(exp.object);
|
|
3587
3679
|
const opt = exp.optional ? "?" : "";
|
|
3588
|
-
if (!exp.computed &&
|
|
3680
|
+
if (!exp.computed && t31.isIdentifier(exp.property)) {
|
|
3589
3681
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
3590
3682
|
}
|
|
3591
|
-
if (
|
|
3683
|
+
if (t31.isStringLiteral(exp.property) || t31.isNumericLiteral(exp.property)) {
|
|
3592
3684
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
3593
3685
|
}
|
|
3594
3686
|
return `${objectKey}${opt}[*]`;
|
|
3595
3687
|
}
|
|
3596
3688
|
return exp.type;
|
|
3597
3689
|
}
|
|
3598
|
-
function isNestedMemberObject(
|
|
3599
|
-
const parent =
|
|
3690
|
+
function isNestedMemberObject(path8) {
|
|
3691
|
+
const parent = path8.parentPath;
|
|
3600
3692
|
if (!parent) return false;
|
|
3601
3693
|
if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
|
|
3602
|
-
return parent.node.object ===
|
|
3694
|
+
return parent.node.object === path8.node;
|
|
3603
3695
|
}
|
|
3604
3696
|
return false;
|
|
3605
3697
|
}
|
|
3606
3698
|
function isReactiveBinding(node) {
|
|
3607
3699
|
if (!node) return false;
|
|
3608
|
-
return !!_optionalChain([getScriptNodeMeta, 'call',
|
|
3700
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _94 => _94(node), 'optionalAccess', _95 => _95.is_reactive]);
|
|
3609
3701
|
}
|
|
3610
3702
|
function markAsAnalyzed(node, flag = true) {
|
|
3611
3703
|
const analyzed = getIsAnalyzed(node);
|
|
@@ -3613,21 +3705,21 @@ function markAsAnalyzed(node, flag = true) {
|
|
|
3613
3705
|
setScriptNodeMeta(node, { is_deps_analyzed: flag });
|
|
3614
3706
|
}
|
|
3615
3707
|
function getIsAnalyzed(node) {
|
|
3616
|
-
return _optionalChain([getScriptNodeMeta, 'call',
|
|
3708
|
+
return _optionalChain([getScriptNodeMeta, 'call', _96 => _96(node), 'optionalAccess', _97 => _97.is_deps_analyzed]);
|
|
3617
3709
|
}
|
|
3618
3710
|
|
|
3619
3711
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
3620
3712
|
function resolveAnalysisOnlyAdapter(ctx) {
|
|
3621
3713
|
return {
|
|
3622
|
-
"CallExpression|Identifier"(
|
|
3623
|
-
const node =
|
|
3714
|
+
"CallExpression|Identifier"(path8) {
|
|
3715
|
+
const node = path8.node;
|
|
3624
3716
|
const apiName = getApiName(node);
|
|
3625
3717
|
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
3626
3718
|
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
3627
3719
|
return;
|
|
3628
3720
|
}
|
|
3629
|
-
if (
|
|
3630
|
-
resolveCallNode(
|
|
3721
|
+
if (t32.isCallExpression(node)) {
|
|
3722
|
+
resolveCallNode(path8, adapter, ctx);
|
|
3631
3723
|
} else {
|
|
3632
3724
|
replaceIdName(node, adapter.target);
|
|
3633
3725
|
}
|
|
@@ -3636,24 +3728,24 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
3636
3728
|
};
|
|
3637
3729
|
}
|
|
3638
3730
|
function getApiName(node) {
|
|
3639
|
-
const isCallNode =
|
|
3731
|
+
const isCallNode = t32.isCallExpression(node);
|
|
3640
3732
|
let apiName = "";
|
|
3641
|
-
if (
|
|
3733
|
+
if (t32.isIdentifier(node)) {
|
|
3642
3734
|
apiName = node.name;
|
|
3643
|
-
} else if (isCallNode &&
|
|
3735
|
+
} else if (isCallNode && t32.isIdentifier(node.callee)) {
|
|
3644
3736
|
apiName = node.callee.name;
|
|
3645
3737
|
}
|
|
3646
3738
|
return apiName;
|
|
3647
3739
|
}
|
|
3648
|
-
function resolveCallNode(
|
|
3649
|
-
const { node } =
|
|
3740
|
+
function resolveCallNode(path8, adapter, ctx) {
|
|
3741
|
+
const { node } = path8;
|
|
3650
3742
|
const { arguments: args } = node;
|
|
3651
3743
|
if (!args.length) return;
|
|
3652
3744
|
const fn = args[0];
|
|
3653
|
-
if (!
|
|
3745
|
+
if (!t32.isArrowFunctionExpression(fn) && !t32.isFunctionExpression(fn)) {
|
|
3654
3746
|
return;
|
|
3655
3747
|
}
|
|
3656
|
-
const fnPath =
|
|
3748
|
+
const fnPath = path8.get("arguments")[0];
|
|
3657
3749
|
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
3658
3750
|
args.push(deps);
|
|
3659
3751
|
replaceCallName(node, adapter.target);
|
|
@@ -3663,41 +3755,41 @@ function resolveCallNode(path7, adapter, ctx) {
|
|
|
3663
3755
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
|
|
3664
3756
|
function resolveArrowFnDeps(ctx, ast) {
|
|
3665
3757
|
return {
|
|
3666
|
-
ArrowFunctionExpression(
|
|
3667
|
-
const { node, parentPath } =
|
|
3668
|
-
if (isSkip(
|
|
3758
|
+
ArrowFunctionExpression(path8) {
|
|
3759
|
+
const { node, parentPath } = path8;
|
|
3760
|
+
if (isSkip(path8) || !atComponentOrHookRoot(parentPath, ast.program)) {
|
|
3669
3761
|
return;
|
|
3670
3762
|
}
|
|
3671
|
-
const deps = analyzeDeps(node, ctx,
|
|
3763
|
+
const deps = analyzeDeps(node, ctx, path8);
|
|
3672
3764
|
if (!deps.elements.length) return;
|
|
3673
3765
|
const newNode = createUseCallback(node, deps);
|
|
3674
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3766
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
3675
3767
|
markAsAnalyzed(newNode.arguments[0]);
|
|
3676
3768
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
3677
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
3678
|
-
|
|
3769
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _98 => _98.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
3770
|
+
path8.replaceWith(newNode);
|
|
3679
3771
|
}
|
|
3680
3772
|
};
|
|
3681
3773
|
}
|
|
3682
3774
|
function resolveUnanalyzedArrow(ctx) {
|
|
3683
3775
|
return {
|
|
3684
|
-
ArrowFunctionExpression(
|
|
3685
|
-
const { node } =
|
|
3776
|
+
ArrowFunctionExpression(path8) {
|
|
3777
|
+
const { node } = path8;
|
|
3686
3778
|
const analyzed = getIsAnalyzed(node);
|
|
3687
3779
|
if (typeof analyzed === "undefined" || analyzed) return;
|
|
3688
3780
|
const newNode = createUseCallback(node);
|
|
3689
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3690
|
-
if (_optionalChain([declaratorPath, 'optionalAccess',
|
|
3781
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
3782
|
+
if (_optionalChain([declaratorPath, 'optionalAccess', _99 => _99.node])) {
|
|
3691
3783
|
setScriptNodeMeta(declaratorPath.node, { is_reactive: true, reactive_type: "indirect" });
|
|
3692
3784
|
}
|
|
3693
3785
|
markAsAnalyzed(newNode.arguments[0]);
|
|
3694
|
-
|
|
3786
|
+
path8.replaceWith(newNode);
|
|
3695
3787
|
}
|
|
3696
3788
|
};
|
|
3697
3789
|
}
|
|
3698
|
-
function isSkip(
|
|
3699
|
-
const { parentPath } =
|
|
3700
|
-
const isVariableDecl = () => getVariableDeclaratorPath(
|
|
3790
|
+
function isSkip(path8) {
|
|
3791
|
+
const { parentPath } = path8;
|
|
3792
|
+
const isVariableDecl = () => getVariableDeclaratorPath(path8) !== null;
|
|
3701
3793
|
const isReturnFunc = () => !isVariableDecl() && parentPath.isReturnStatement();
|
|
3702
3794
|
const isCallback = () => {
|
|
3703
3795
|
if (!parentPath) {
|
|
@@ -3706,12 +3798,12 @@ function isSkip(path7) {
|
|
|
3706
3798
|
if (parentPath.isCallExpression()) {
|
|
3707
3799
|
const callExpressionPath = parentPath;
|
|
3708
3800
|
const args = callExpressionPath.node.arguments;
|
|
3709
|
-
return args.some((arg) => arg ===
|
|
3801
|
+
return args.some((arg) => arg === path8.node);
|
|
3710
3802
|
}
|
|
3711
3803
|
if (parentPath.isArrayExpression()) {
|
|
3712
3804
|
const arrayExpressionPath = parentPath;
|
|
3713
3805
|
const elements = arrayExpressionPath.node.elements;
|
|
3714
|
-
return elements.some((element) => element ===
|
|
3806
|
+
return elements.some((element) => element === path8.node);
|
|
3715
3807
|
}
|
|
3716
3808
|
return false;
|
|
3717
3809
|
};
|
|
@@ -3735,13 +3827,13 @@ function isSkip(path7) {
|
|
|
3735
3827
|
|
|
3736
3828
|
function resolveElementRef(ctx) {
|
|
3737
3829
|
return {
|
|
3738
|
-
CallExpression(
|
|
3830
|
+
CallExpression(path8) {
|
|
3739
3831
|
const {
|
|
3740
3832
|
inputType,
|
|
3741
3833
|
templateData: { refBindings }
|
|
3742
3834
|
} = ctx;
|
|
3743
3835
|
if (inputType !== "sfc") return;
|
|
3744
|
-
const { node } =
|
|
3836
|
+
const { node } = path8;
|
|
3745
3837
|
const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
|
|
3746
3838
|
const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
|
|
3747
3839
|
const shouldProcess = isUseTemplateRef || isCompRefBindings;
|
|
@@ -3749,31 +3841,31 @@ function resolveElementRef(ctx) {
|
|
|
3749
3841
|
return;
|
|
3750
3842
|
}
|
|
3751
3843
|
if (isCompRefBindings) {
|
|
3752
|
-
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3753
|
-
if (!
|
|
3844
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _100 => _100(path8), 'optionalAccess', _101 => _101.node]);
|
|
3845
|
+
if (!t33.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _102 => _102.id]))) {
|
|
3754
3846
|
return;
|
|
3755
3847
|
}
|
|
3756
3848
|
const varName = varDeclaratorPath.id.name;
|
|
3757
3849
|
const compRef = refBindings.componentRefs[varName];
|
|
3758
3850
|
if (!compRef) return;
|
|
3759
3851
|
}
|
|
3760
|
-
node.arguments[0] =
|
|
3761
|
-
resolveTypeParameters(ctx,
|
|
3852
|
+
node.arguments[0] = t33.identifier("null");
|
|
3853
|
+
resolveTypeParameters(ctx, path8);
|
|
3762
3854
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
3763
3855
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
3764
3856
|
},
|
|
3765
|
-
MemberExpression(
|
|
3766
|
-
resolveRefValueToCurrent(
|
|
3857
|
+
MemberExpression(path8) {
|
|
3858
|
+
resolveRefValueToCurrent(path8);
|
|
3767
3859
|
}
|
|
3768
3860
|
};
|
|
3769
3861
|
}
|
|
3770
|
-
function resolveTypeParameters(ctx,
|
|
3862
|
+
function resolveTypeParameters(ctx, path8) {
|
|
3771
3863
|
const {
|
|
3772
3864
|
templateData: { refBindings },
|
|
3773
3865
|
scriptData
|
|
3774
3866
|
} = ctx;
|
|
3775
|
-
const { node } =
|
|
3776
|
-
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3867
|
+
const { node } = path8;
|
|
3868
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _103 => _103(path8), 'optionalAccess', _104 => _104.node]);
|
|
3777
3869
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
3778
3870
|
return;
|
|
3779
3871
|
}
|
|
@@ -3782,20 +3874,20 @@ function resolveTypeParameters(ctx, path7) {
|
|
|
3782
3874
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
3783
3875
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
3784
3876
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
3785
|
-
node.typeParameters =
|
|
3877
|
+
node.typeParameters = t33.tsTypeParameterInstantiation([t33.tsTypeReference(t33.identifier(type))]);
|
|
3786
3878
|
}
|
|
3787
3879
|
}
|
|
3788
|
-
function resolveRefValueToCurrent(
|
|
3789
|
-
const { node } =
|
|
3790
|
-
if (node.computed || !
|
|
3880
|
+
function resolveRefValueToCurrent(path8) {
|
|
3881
|
+
const { node } = path8;
|
|
3882
|
+
if (node.computed || !t33.isIdentifier(node.property) || node.property.name !== "value") {
|
|
3791
3883
|
return;
|
|
3792
3884
|
}
|
|
3793
|
-
const rootPath = findRootVariablePath(
|
|
3794
|
-
if (!_optionalChain([rootPath, 'optionalAccess',
|
|
3885
|
+
const rootPath = findRootVariablePath(path8);
|
|
3886
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _105 => _105.node]) || !t33.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
3795
3887
|
return;
|
|
3796
3888
|
}
|
|
3797
3889
|
const rootId = findRootIdentifier(node);
|
|
3798
|
-
if (!
|
|
3890
|
+
if (!t33.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _106 => _106.name])) {
|
|
3799
3891
|
return;
|
|
3800
3892
|
}
|
|
3801
3893
|
node.property.name = "current";
|
|
@@ -3806,21 +3898,21 @@ function resolveRefValueToCurrent(path7) {
|
|
|
3806
3898
|
function resolveExprMemo(ctx, ast) {
|
|
3807
3899
|
const isScriptFile = ctx.inputType !== "sfc";
|
|
3808
3900
|
return {
|
|
3809
|
-
VariableDeclarator(
|
|
3810
|
-
const { node } =
|
|
3901
|
+
VariableDeclarator(path8) {
|
|
3902
|
+
const { node } = path8;
|
|
3811
3903
|
const { init } = node;
|
|
3812
3904
|
if (!init) return;
|
|
3813
3905
|
const shouldMemo = () => {
|
|
3814
|
-
if (!atComponentOrHookRoot(
|
|
3906
|
+
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
3815
3907
|
return false;
|
|
3816
3908
|
}
|
|
3817
|
-
if (
|
|
3909
|
+
if (t34.isCallExpression(init) && t34.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
3818
3910
|
return false;
|
|
3819
3911
|
}
|
|
3820
3912
|
return true;
|
|
3821
3913
|
};
|
|
3822
3914
|
if (!shouldMemo()) return;
|
|
3823
|
-
const initPath =
|
|
3915
|
+
const initPath = path8.get("init");
|
|
3824
3916
|
if (!initPath.isExpression()) return;
|
|
3825
3917
|
const deps = analyzeDeps(initPath.node, ctx, initPath);
|
|
3826
3918
|
if (!deps.elements.length) return;
|
|
@@ -3836,9 +3928,9 @@ function resolveExprMemo(ctx, ast) {
|
|
|
3836
3928
|
function resolveLintRules(ctx, ast) {
|
|
3837
3929
|
const inScriptFile = ctx.inputType !== "sfc";
|
|
3838
3930
|
return {
|
|
3839
|
-
CallExpression(
|
|
3840
|
-
const { node, parentPath } =
|
|
3841
|
-
if (!
|
|
3931
|
+
CallExpression(path8) {
|
|
3932
|
+
const { node, parentPath } = path8;
|
|
3933
|
+
if (!t35.isIdentifier(node.callee)) return;
|
|
3842
3934
|
const { name: callName } = node.callee;
|
|
3843
3935
|
const addLog = (t41) => {
|
|
3844
3936
|
logger.error(t41, {
|
|
@@ -3856,7 +3948,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
3856
3948
|
);
|
|
3857
3949
|
return;
|
|
3858
3950
|
}
|
|
3859
|
-
if (!atComponentOrHookRoot(
|
|
3951
|
+
if (!atComponentOrHookRoot(path8, ast.program)) {
|
|
3860
3952
|
addLog(
|
|
3861
3953
|
`The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
|
|
3862
3954
|
);
|
|
@@ -3872,7 +3964,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
3872
3964
|
};
|
|
3873
3965
|
const lintHooks = () => {
|
|
3874
3966
|
if (!callName.startsWith("use")) return;
|
|
3875
|
-
if (!atComponentOrHookRoot(
|
|
3967
|
+
if (!atComponentOrHookRoot(path8, ast.program, inScriptFile)) {
|
|
3876
3968
|
addLog(
|
|
3877
3969
|
`The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
|
|
3878
3970
|
);
|
|
@@ -3890,9 +3982,9 @@ function resolveLintRules(ctx, ast) {
|
|
|
3890
3982
|
function resolveProvide(ctx) {
|
|
3891
3983
|
if (ctx.inputType === "style") return {};
|
|
3892
3984
|
return {
|
|
3893
|
-
CallExpression(
|
|
3894
|
-
const { node } =
|
|
3895
|
-
const providerTarget = _optionalChain([ADAPTER_RULES, 'access',
|
|
3985
|
+
CallExpression(path8) {
|
|
3986
|
+
const { node } = path8;
|
|
3987
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _107 => _107.runtime, 'access', _108 => _108[VUE_API_MAP.provide], 'optionalAccess', _109 => _109.target]);
|
|
3896
3988
|
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
3897
3989
|
if (!isProvideCall) return;
|
|
3898
3990
|
const { provide } = ctx.scriptData;
|
|
@@ -3901,7 +3993,7 @@ function resolveProvide(ctx) {
|
|
|
3901
3993
|
const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
3902
3994
|
assignProviderValue(target, key, value);
|
|
3903
3995
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3904
|
-
|
|
3996
|
+
path8.parentPath.remove();
|
|
3905
3997
|
}
|
|
3906
3998
|
};
|
|
3907
3999
|
}
|
|
@@ -3910,7 +4002,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
3910
4002
|
return root;
|
|
3911
4003
|
}
|
|
3912
4004
|
let cur = root.provide;
|
|
3913
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
4005
|
+
while (_optionalChain([cur, 'optionalAccess', _110 => _110.isOccupied])) {
|
|
3914
4006
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
3915
4007
|
}
|
|
3916
4008
|
return cur || (root.provide = {});
|
|
@@ -3918,18 +4010,18 @@ function findOrCreateCtxProvider(root) {
|
|
|
3918
4010
|
function assignProviderValue(target, key, value) {
|
|
3919
4011
|
const getRawExp = (exp) => {
|
|
3920
4012
|
if (!exp) return "''";
|
|
3921
|
-
if (
|
|
4013
|
+
if (t36.isStringLiteral(exp)) {
|
|
3922
4014
|
return JSON.stringify(exp.value);
|
|
3923
4015
|
}
|
|
3924
|
-
if (
|
|
4016
|
+
if (t36.isNumericLiteral(exp)) {
|
|
3925
4017
|
return exp.value.toString();
|
|
3926
4018
|
}
|
|
3927
|
-
if (
|
|
4019
|
+
if (t36.isIdentifier(exp)) {
|
|
3928
4020
|
return exp.name;
|
|
3929
4021
|
}
|
|
3930
4022
|
try {
|
|
3931
4023
|
return _generator.generate.call(void 0, exp).code;
|
|
3932
|
-
} catch (
|
|
4024
|
+
} catch (e6) {
|
|
3933
4025
|
return "null";
|
|
3934
4026
|
}
|
|
3935
4027
|
};
|
|
@@ -3943,13 +4035,13 @@ function assignProviderValue(target, key, value) {
|
|
|
3943
4035
|
|
|
3944
4036
|
function resolveRenameAdapter(ctx) {
|
|
3945
4037
|
return {
|
|
3946
|
-
"CallExpression|Identifier"(
|
|
3947
|
-
const node =
|
|
3948
|
-
const isCallNode =
|
|
4038
|
+
"CallExpression|Identifier"(path8) {
|
|
4039
|
+
const node = path8.node;
|
|
4040
|
+
const isCallNode = t37.isCallExpression(node);
|
|
3949
4041
|
let apiName = "";
|
|
3950
|
-
if (
|
|
4042
|
+
if (t37.isIdentifier(node)) {
|
|
3951
4043
|
apiName = node.name;
|
|
3952
|
-
} else if (isCallNode &&
|
|
4044
|
+
} else if (isCallNode && t37.isIdentifier(node.callee)) {
|
|
3953
4045
|
apiName = node.callee.name;
|
|
3954
4046
|
}
|
|
3955
4047
|
const runtimeAdapter = ADAPTER_RULES.runtime[apiName];
|
|
@@ -3960,8 +4052,8 @@ function resolveRenameAdapter(ctx) {
|
|
|
3960
4052
|
}
|
|
3961
4053
|
if (adapter.isTrackable) {
|
|
3962
4054
|
const reactiveType = getReactiveType(apiName);
|
|
3963
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3964
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
4055
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
4056
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _111 => _111.node]), {
|
|
3965
4057
|
is_reactive: true,
|
|
3966
4058
|
reactive_type: reactiveType
|
|
3967
4059
|
});
|
|
@@ -4015,12 +4107,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
4015
4107
|
}
|
|
4016
4108
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
4017
4109
|
const runExcludeThenApply = (cfg) => {
|
|
4018
|
-
_optionalChain([cfg, 'access',
|
|
4019
|
-
_optionalChain([cfg, 'access',
|
|
4110
|
+
_optionalChain([cfg, 'access', _112 => _112.excludeBabel, 'optionalAccess', _113 => _113.forEach, 'call', _114 => _114((fn) => fn(ctx, ast))]);
|
|
4111
|
+
_optionalChain([cfg, 'access', _115 => _115.applyBabel, 'optionalAccess', _116 => _116.forEach, 'call', _117 => _117((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4020
4112
|
};
|
|
4021
4113
|
const runApplyThenExclude = (cfg) => {
|
|
4022
|
-
_optionalChain([cfg, 'access',
|
|
4023
|
-
_optionalChain([cfg, 'access',
|
|
4114
|
+
_optionalChain([cfg, 'access', _118 => _118.applyBabel, 'optionalAccess', _119 => _119.forEach, 'call', _120 => _120((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4115
|
+
_optionalChain([cfg, 'access', _121 => _121.excludeBabel, 'optionalAccess', _122 => _122.forEach, 'call', _123 => _123((fn) => fn(ctx, ast))]);
|
|
4024
4116
|
};
|
|
4025
4117
|
runExcludeThenApply(options.preprocess);
|
|
4026
4118
|
runExcludeThenApply(options.process);
|
|
@@ -4115,25 +4207,25 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
4115
4207
|
let node;
|
|
4116
4208
|
try {
|
|
4117
4209
|
node = _parser.parseExpression.call(void 0, code);
|
|
4118
|
-
} catch (
|
|
4210
|
+
} catch (e7) {
|
|
4119
4211
|
return false;
|
|
4120
4212
|
}
|
|
4121
|
-
if (
|
|
4213
|
+
if (t38.isLiteral(node)) {
|
|
4122
4214
|
return true;
|
|
4123
4215
|
}
|
|
4124
|
-
if (!excludeVar &&
|
|
4216
|
+
if (!excludeVar && t38.isIdentifier(node)) {
|
|
4125
4217
|
return true;
|
|
4126
4218
|
}
|
|
4127
|
-
if (
|
|
4128
|
-
return isSimpleExpression(node.object) &&
|
|
4219
|
+
if (t38.isMemberExpression(node)) {
|
|
4220
|
+
return isSimpleExpression(node.object) && t38.isIdentifier(node.property);
|
|
4129
4221
|
}
|
|
4130
|
-
if (
|
|
4222
|
+
if (t38.isObjectExpression(node) || t38.isArrayExpression(node)) {
|
|
4131
4223
|
return false;
|
|
4132
4224
|
}
|
|
4133
|
-
if (
|
|
4225
|
+
if (t38.isCallExpression(node) || t38.isAssignmentExpression(node)) {
|
|
4134
4226
|
return false;
|
|
4135
4227
|
}
|
|
4136
|
-
if (
|
|
4228
|
+
if (t38.isBinaryExpression(node) || t38.isUnaryExpression(node)) {
|
|
4137
4229
|
return true;
|
|
4138
4230
|
}
|
|
4139
4231
|
return false;
|
|
@@ -4141,74 +4233,17 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
4141
4233
|
function isIdentifier20(code) {
|
|
4142
4234
|
try {
|
|
4143
4235
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4144
|
-
return
|
|
4145
|
-
} catch (
|
|
4236
|
+
return t38.isIdentifier(node);
|
|
4237
|
+
} catch (e8) {
|
|
4146
4238
|
return false;
|
|
4147
4239
|
}
|
|
4148
4240
|
}
|
|
4149
4241
|
function isStringLiteral12(code) {
|
|
4150
4242
|
try {
|
|
4151
4243
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4152
|
-
return
|
|
4153
|
-
} catch (e8) {
|
|
4154
|
-
return false;
|
|
4155
|
-
}
|
|
4156
|
-
}
|
|
4157
|
-
|
|
4158
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/special-expressions.ts
|
|
4162
|
-
function resolveSpecialExpressions(input, ctx) {
|
|
4163
|
-
input = resolveEmitsCalls(input, ctx);
|
|
4164
|
-
input = resolveRefVariable(input, ctx);
|
|
4165
|
-
return input;
|
|
4166
|
-
}
|
|
4167
|
-
function resolveEmitsCalls(input, ctx) {
|
|
4168
|
-
const result = matchEmitCalls(input, ctx);
|
|
4169
|
-
if (!result) return input;
|
|
4170
|
-
const [, , eventName, args] = result;
|
|
4171
|
-
const callee = eventName.split(/[:\-]/).map((part) => capitalize(camelCase(part))).join("");
|
|
4172
|
-
const event = args ? `on${callee}?.(${args})` : `on${callee}?.()`;
|
|
4173
|
-
return `${ctx.propField}?.${event}`;
|
|
4174
|
-
}
|
|
4175
|
-
function matchEmitCalls(input, ctx) {
|
|
4176
|
-
const { reactiveBindings } = ctx.templateData;
|
|
4177
|
-
const macroBinding = Object.values(reactiveBindings).find((b) => b.source === "defineEmits");
|
|
4178
|
-
if (!macroBinding) return null;
|
|
4179
|
-
const escapedName = macroBinding.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4180
|
-
const regex = new RegExp(
|
|
4181
|
-
`${escapedName}\\s*\\(\\s*(['"\`])([^\\1]*?)\\1\\s*(?:,\\s*(.*?))?\\s*\\)$`,
|
|
4182
|
-
// 可选的第二个参数
|
|
4183
|
-
"s"
|
|
4184
|
-
// s 标志让 . 匹配换行符
|
|
4185
|
-
);
|
|
4186
|
-
return input.trim().match(regex);
|
|
4187
|
-
}
|
|
4188
|
-
function resolveRefVariable(input, ctx) {
|
|
4189
|
-
const { reactiveBindings } = ctx.templateData;
|
|
4190
|
-
const addValueProperty = (input2, varName) => {
|
|
4191
|
-
const escapedVarName = varName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4192
|
-
const regex = new RegExp(`(?<![a-zA-Z0-9_])${escapedVarName}(?![a-zA-Z0-9_])(?!\\.value)`, "g");
|
|
4193
|
-
return input2.replace(regex, `${varName}.value`);
|
|
4194
|
-
};
|
|
4195
|
-
for (const name in reactiveBindings) {
|
|
4196
|
-
const binding = reactiveBindings[name];
|
|
4197
|
-
if (_optionalChain([binding, 'optionalAccess', _123 => _123.reactiveType]) !== "ref") continue;
|
|
4198
|
-
input = addValueProperty(input, name);
|
|
4199
|
-
}
|
|
4200
|
-
return input;
|
|
4201
|
-
}
|
|
4202
|
-
|
|
4203
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
4204
|
-
function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
4205
|
-
if (toStrLiteral) return t38.stringLiteral(input);
|
|
4206
|
-
const { filename, scriptData } = ctx;
|
|
4207
|
-
const newContent = resolveSpecialExpressions(input, ctx);
|
|
4208
|
-
try {
|
|
4209
|
-
return stringToExpr(newContent, scriptData.lang, filename);
|
|
4244
|
+
return t38.isStringLiteral(node) || t38.isTemplateLiteral(node);
|
|
4210
4245
|
} catch (e9) {
|
|
4211
|
-
return
|
|
4246
|
+
return false;
|
|
4212
4247
|
}
|
|
4213
4248
|
}
|
|
4214
4249
|
|
|
@@ -5425,7 +5460,7 @@ function transform(ast, ctx, options) {
|
|
|
5425
5460
|
}
|
|
5426
5461
|
|
|
5427
5462
|
// package.json
|
|
5428
|
-
var version = "1.
|
|
5463
|
+
var version = "1.3.0";
|
|
5429
5464
|
var bin = {
|
|
5430
5465
|
vureact: "./bin/vureact.js"
|
|
5431
5466
|
};
|
|
@@ -5737,9 +5772,9 @@ var Helper = (_class3 = class {
|
|
|
5737
5772
|
};
|
|
5738
5773
|
}
|
|
5739
5774
|
async removeOutputFile(filePath, resolveOutputPath) {
|
|
5740
|
-
const
|
|
5741
|
-
if (!_fs2.default.existsSync(
|
|
5742
|
-
await _fs2.default.promises.unlink(
|
|
5775
|
+
const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
|
|
5776
|
+
if (!_fs2.default.existsSync(path8)) return;
|
|
5777
|
+
await _fs2.default.promises.unlink(path8);
|
|
5743
5778
|
}
|
|
5744
5779
|
updateCache(targetFile, newData, cache) {
|
|
5745
5780
|
const index = cache.target.findIndex((c) => c.file === targetFile);
|
|
@@ -5804,12 +5839,12 @@ var Helper = (_class3 = class {
|
|
|
5804
5839
|
/**
|
|
5805
5840
|
* 读取 package.json 文件内容,并处理成对象返回
|
|
5806
5841
|
*/
|
|
5807
|
-
async resolvePackageFile(
|
|
5842
|
+
async resolvePackageFile(path8) {
|
|
5808
5843
|
try {
|
|
5809
|
-
if (!_fs2.default.existsSync(
|
|
5844
|
+
if (!_fs2.default.existsSync(path8)) {
|
|
5810
5845
|
return {};
|
|
5811
5846
|
}
|
|
5812
|
-
return JSON.parse(await _fs2.default.promises.readFile(
|
|
5847
|
+
return JSON.parse(await _fs2.default.promises.readFile(path8, "utf-8"));
|
|
5813
5848
|
} catch (error) {
|
|
5814
5849
|
console.error(error);
|
|
5815
5850
|
return {};
|
|
@@ -6330,10 +6365,12 @@ var CacheManager = class {
|
|
|
6330
6365
|
const meta = { ...unit };
|
|
6331
6366
|
delete meta.source;
|
|
6332
6367
|
if (key === "sfc" /* SFC */) {
|
|
6333
|
-
|
|
6334
|
-
|
|
6368
|
+
_optionalChainDelete([meta, 'access', _221 => _221.output, 'optionalAccess', _222 => _222.jsx, 'access', _223 => delete _223.code]);
|
|
6369
|
+
_optionalChainDelete([meta, 'access', _224 => _224.output, 'optionalAccess', _225 => _225.css, 'access', _226 => delete _226.code]);
|
|
6335
6370
|
} else if (key === "script" /* SCRIPT */) {
|
|
6336
|
-
|
|
6371
|
+
_optionalChainDelete([meta, 'access', _227 => _227.output, 'optionalAccess', _228 => _228.script, 'access', _229 => delete _229.code]);
|
|
6372
|
+
} else if (key === "style" /* STYLE */) {
|
|
6373
|
+
_optionalChainDelete([meta, 'access', _230 => _230.output, 'optionalAccess', _231 => _231.style, 'access', _232 => delete _232.code]);
|
|
6337
6374
|
}
|
|
6338
6375
|
this.updateCache(unit.file, meta, cache);
|
|
6339
6376
|
await this.fileCompiler.saveCache(cache);
|
|
@@ -6381,10 +6418,10 @@ var CleanupManager = class {
|
|
|
6381
6418
|
const removeFn = async (m) => {
|
|
6382
6419
|
if (key === "sfc" /* SFC */) {
|
|
6383
6420
|
const meta = m;
|
|
6384
|
-
if (!_optionalChain([meta, 'optionalAccess',
|
|
6421
|
+
if (!_optionalChain([meta, 'optionalAccess', _233 => _233.output])) return;
|
|
6385
6422
|
const { jsx, css } = meta.output;
|
|
6386
6423
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
6387
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
6424
|
+
if (_optionalChain([css, 'optionalAccess', _234 => _234.file])) {
|
|
6388
6425
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
6389
6426
|
}
|
|
6390
6427
|
} else if (key === "script" /* SCRIPT */ || key === "copied" /* ASSET */) {
|
|
@@ -6428,7 +6465,7 @@ var CompilationUnitProcessor = class {
|
|
|
6428
6465
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
6429
6466
|
const isStyleFile = key === "style" /* STYLE */;
|
|
6430
6467
|
if (isSFC || isScriptFile) {
|
|
6431
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
6468
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _235 => _235.hasRoute]);
|
|
6432
6469
|
}
|
|
6433
6470
|
const resolveFileInfo = () => {
|
|
6434
6471
|
if (isSFC) {
|
|
@@ -6448,7 +6485,7 @@ var CompilationUnitProcessor = class {
|
|
|
6448
6485
|
const { script } = result.fileInfo;
|
|
6449
6486
|
unit.output = {
|
|
6450
6487
|
script: {
|
|
6451
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
6488
|
+
file: _optionalChain([script, 'optionalAccess', _236 => _236.file]),
|
|
6452
6489
|
code
|
|
6453
6490
|
}
|
|
6454
6491
|
};
|
|
@@ -6494,6 +6531,7 @@ var CompilationUnitProcessor = class {
|
|
|
6494
6531
|
|
|
6495
6532
|
// src/compiler/shared/file-compiler/file-processor.ts
|
|
6496
6533
|
|
|
6534
|
+
|
|
6497
6535
|
var FileProcessor = (_class7 = class {
|
|
6498
6536
|
constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class7.prototype.__init11.call(this);
|
|
6499
6537
|
this.fileCompiler = fileCompiler;
|
|
@@ -6528,7 +6566,7 @@ var FileProcessor = (_class7 = class {
|
|
|
6528
6566
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
6529
6567
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
6530
6568
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
|
|
6531
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
6569
|
+
const record = _optionalChain([cache, 'optionalAccess', _237 => _237.target, 'access', _238 => _238.find, 'call', _239 => _239((c) => c.file === absPath)]);
|
|
6532
6570
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
6533
6571
|
fileMeta,
|
|
6534
6572
|
record,
|
|
@@ -6547,11 +6585,12 @@ var FileProcessor = (_class7 = class {
|
|
|
6547
6585
|
hash: hash || this.fileCompiler.genHash(source)
|
|
6548
6586
|
};
|
|
6549
6587
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
6550
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6588
|
+
if (_optionalChain([processed, 'optionalAccess', _240 => _240.output])) {
|
|
6551
6589
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
6552
6590
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
6553
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6591
|
+
if (_optionalChain([processed, 'optionalAccess', _241 => _241.hasRoute])) {
|
|
6554
6592
|
await this.injectVuReactRouteDep();
|
|
6593
|
+
await this.copyRouteSetupNotes();
|
|
6555
6594
|
}
|
|
6556
6595
|
}
|
|
6557
6596
|
await this.cacheManager.updateCacheIncrementally(processed, key);
|
|
@@ -6562,9 +6601,30 @@ var FileProcessor = (_class7 = class {
|
|
|
6562
6601
|
const pkgPath = this.fileCompiler.getOutputPkgPath();
|
|
6563
6602
|
const pkg = await this.fileCompiler.resolvePackageFile(pkgPath);
|
|
6564
6603
|
const { router } = this.pkgs;
|
|
6604
|
+
if (!pkg["dependencies"]) {
|
|
6605
|
+
pkg["dependencies"] = {};
|
|
6606
|
+
}
|
|
6565
6607
|
pkg["dependencies"][router.name] = router.version;
|
|
6566
6608
|
await _fs2.default.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2), "utf-8");
|
|
6567
6609
|
}
|
|
6610
|
+
/**
|
|
6611
|
+
* 如果使用了路由,则拷贝路由配置说明文档到输出目录根部。
|
|
6612
|
+
*/
|
|
6613
|
+
async copyRouteSetupNotes() {
|
|
6614
|
+
const outputDir = this.fileCompiler.getOuputPath();
|
|
6615
|
+
const packageRoot = _path2.default.resolve(getDirname(import.meta.url), "../");
|
|
6616
|
+
const templateDir = _path2.default.join(packageRoot, "templates");
|
|
6617
|
+
if (!_fs2.default.existsSync(templateDir)) {
|
|
6618
|
+
return;
|
|
6619
|
+
}
|
|
6620
|
+
const files = ["route-setup-notes.md", "route-setup-notes.zh.md"];
|
|
6621
|
+
for (const file of files) {
|
|
6622
|
+
const srcPath = _path2.default.join(templateDir, file);
|
|
6623
|
+
if (!_fs2.default.existsSync(srcPath)) continue;
|
|
6624
|
+
const destPath = _path2.default.join(outputDir, file);
|
|
6625
|
+
await _fs2.default.promises.copyFile(srcPath, destPath);
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6568
6628
|
}, _class7);
|
|
6569
6629
|
|
|
6570
6630
|
// src/compiler/shared/file-compiler/pipeline-manager.ts
|
|
@@ -6740,7 +6800,7 @@ var ViteBootstrapper = (_class9 = class {
|
|
|
6740
6800
|
*/
|
|
6741
6801
|
resolveViteCreateApp() {
|
|
6742
6802
|
const { output } = this.options;
|
|
6743
|
-
const config = _optionalChain([output, 'optionalAccess',
|
|
6803
|
+
const config = _optionalChain([output, 'optionalAccess', _242 => _242.bootstrapVite]);
|
|
6744
6804
|
const template = typeof config === "object" ? config.template : "react-ts";
|
|
6745
6805
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
6746
6806
|
const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
|
|
@@ -6816,27 +6876,55 @@ var FileCompiler = (_class10 = class extends BaseCompiler {
|
|
|
6816
6876
|
}
|
|
6817
6877
|
await this.viteBootstrapper.bootstrapIfNeeded();
|
|
6818
6878
|
try {
|
|
6819
|
-
this.
|
|
6820
|
-
const
|
|
6821
|
-
this.
|
|
6822
|
-
this.
|
|
6823
|
-
|
|
6824
|
-
this.spinner.stop();
|
|
6825
|
-
this.spinner.start("Compiling style files...");
|
|
6826
|
-
const styleCount = await this.pipelineManager.runStylePipeline();
|
|
6827
|
-
this.spinner.stop();
|
|
6828
|
-
this.spinner.start("Copying assets...");
|
|
6829
|
-
const assetCount = await this.assetManager.runAssetPipeline();
|
|
6830
|
-
this.spinner.stop();
|
|
6831
|
-
await _optionalChain([this, 'access', _231 => _231.options, 'access', _232 => _232.onSuccess, 'optionalCall', _233 => _233()]);
|
|
6879
|
+
const sfcCount = await this.runPipelineWithSpinner("sfc" /* SFC */);
|
|
6880
|
+
const scriptCount = await this.runPipelineWithSpinner("script" /* SCRIPT */);
|
|
6881
|
+
const styleCount = await this.runPipelineWithSpinner("style" /* STYLE */);
|
|
6882
|
+
const assetCount = await this.runPipelineWithSpinner("copied" /* ASSET */);
|
|
6883
|
+
await _optionalChain([this, 'access', _243 => _243.options, 'access', _244 => _244.onSuccess, 'optionalCall', _245 => _245()]);
|
|
6832
6884
|
const endTime = calcElapsedTime(startTime);
|
|
6833
6885
|
this.printCoreLogs();
|
|
6834
6886
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|
|
6835
6887
|
} catch (error) {
|
|
6836
|
-
this.spinner.stop();
|
|
6837
6888
|
const endTime = calcElapsedTime(startTime);
|
|
6838
|
-
console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}
|
|
6839
|
-
|
|
6889
|
+
console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}`);
|
|
6890
|
+
console.error(error);
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
/**
|
|
6894
|
+
* 运行管线并显示加载动画
|
|
6895
|
+
*
|
|
6896
|
+
* @private
|
|
6897
|
+
* @param text - 加载动画显示的文本
|
|
6898
|
+
* @param pipelineFn - 要执行的管线函数
|
|
6899
|
+
* @returns 返回的处理的文件数
|
|
6900
|
+
*/
|
|
6901
|
+
async runPipelineWithSpinner(name) {
|
|
6902
|
+
const options = {
|
|
6903
|
+
["sfc" /* SFC */]: {
|
|
6904
|
+
text: "Compiling Vue files...",
|
|
6905
|
+
pipeline: () => this.pipelineManager.runSfcPipeline()
|
|
6906
|
+
},
|
|
6907
|
+
["script" /* SCRIPT */]: {
|
|
6908
|
+
text: "Compiling script files...",
|
|
6909
|
+
pipeline: () => this.pipelineManager.runScriptPipeline()
|
|
6910
|
+
},
|
|
6911
|
+
["style" /* STYLE */]: {
|
|
6912
|
+
text: "Compiling style files...",
|
|
6913
|
+
pipeline: () => this.pipelineManager.runStylePipeline()
|
|
6914
|
+
},
|
|
6915
|
+
["copied" /* ASSET */]: {
|
|
6916
|
+
text: "Copying assets...",
|
|
6917
|
+
pipeline: () => this.assetManager.runAssetPipeline()
|
|
6918
|
+
}
|
|
6919
|
+
};
|
|
6920
|
+
const { text, pipeline } = options[name];
|
|
6921
|
+
try {
|
|
6922
|
+
this.spinner.start(text);
|
|
6923
|
+
return await pipeline();
|
|
6924
|
+
} catch (err) {
|
|
6925
|
+
throw err;
|
|
6926
|
+
} finally {
|
|
6927
|
+
this.spinner.stop();
|
|
6840
6928
|
}
|
|
6841
6929
|
}
|
|
6842
6930
|
/**
|
|
@@ -7023,4 +7111,5 @@ var VuReact = class extends FileCompiler {
|
|
|
7023
7111
|
|
|
7024
7112
|
|
|
7025
7113
|
|
|
7026
|
-
|
|
7114
|
+
|
|
7115
|
+
exports.getDirname = getDirname; exports.normalizePath = normalizePath; exports.calcElapsedTime = calcElapsedTime; exports.generateComponent = generateComponent; exports.generateOnlyScript = generateOnlyScript; exports.generate = generate; exports.parseOnlyScript = parseOnlyScript; exports.parseSFC = parseSFC; exports.parse = parse; exports.transform = transform; exports.version = version; exports.bin = bin; exports.CacheKey = CacheKey; exports.Helper = Helper; exports.BaseCompiler = BaseCompiler; exports.FileCompiler = FileCompiler; exports.defineConfig = defineConfig; exports.VuReact = VuReact;
|