@vureact/compiler-core 1.8.5 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/README.zh-CN.md +4 -2
- package/lib/{chunk-6FMNT76F.js → chunk-4DEDEJYM.js} +729 -497
- package/lib/{chunk-FWYPSB43.esm.js → chunk-MBEPCMRP.esm.js} +586 -354
- package/lib/cli.esm.js +2 -2
- package/lib/cli.js +10 -10
- package/lib/compiler-core.d.cts +5 -1
- package/lib/compiler-core.d.ts +5 -1
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +105 -102
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.9.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -48,7 +48,8 @@ var MACRO_API_NAMES = {
|
|
|
48
48
|
emits: "defineEmits",
|
|
49
49
|
slots: "defineSlots",
|
|
50
50
|
options: "defineOptions",
|
|
51
|
-
expose: "defineExpose"
|
|
51
|
+
expose: "defineExpose",
|
|
52
|
+
model: "defineModel"
|
|
52
53
|
};
|
|
53
54
|
var DOLLAR_IDENTIFIERS = [
|
|
54
55
|
"$data",
|
|
@@ -950,21 +951,21 @@ var Logger = class {
|
|
|
950
951
|
}
|
|
951
952
|
printAll(opts) {
|
|
952
953
|
if (this.logs.length === 0) {
|
|
953
|
-
console.log("No logs to display.");
|
|
954
|
+
!opts?._testMode && console.log("No logs to display.");
|
|
954
955
|
return;
|
|
955
956
|
}
|
|
956
957
|
const orderedLogs = this.getOrderedLogs(opts);
|
|
957
958
|
for (const log of orderedLogs) {
|
|
958
|
-
console.log();
|
|
959
|
+
!opts?._testMode && console.log();
|
|
959
960
|
console.log(this.formatHeader(log));
|
|
960
961
|
const context = this.formatContext(log);
|
|
961
962
|
if (context) {
|
|
962
963
|
console.log(context);
|
|
963
964
|
}
|
|
964
|
-
console.log();
|
|
965
|
+
!opts?._testMode && console.log();
|
|
965
966
|
}
|
|
966
967
|
this.printSummary();
|
|
967
|
-
console.log();
|
|
968
|
+
!opts?._testMode && console.log();
|
|
968
969
|
}
|
|
969
970
|
clear() {
|
|
970
971
|
this.logs = [];
|
|
@@ -1060,7 +1061,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1060
1061
|
babelExp: { ast: keyAST },
|
|
1061
1062
|
value: {
|
|
1062
1063
|
content,
|
|
1063
|
-
isStringLiteral:
|
|
1064
|
+
isStringLiteral: isStringLiteral15,
|
|
1064
1065
|
babelExp: { ast: valueAST }
|
|
1065
1066
|
}
|
|
1066
1067
|
} = nodeIR;
|
|
@@ -1069,7 +1070,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1069
1070
|
}
|
|
1070
1071
|
let value;
|
|
1071
1072
|
if (content !== "true") {
|
|
1072
|
-
value =
|
|
1073
|
+
value = isStringLiteral15 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
1073
1074
|
}
|
|
1074
1075
|
return t9.jsxAttribute(keyAST, value);
|
|
1075
1076
|
}
|
|
@@ -1266,6 +1267,7 @@ var REACT_API_MAP = {
|
|
|
1266
1267
|
memo: "memo",
|
|
1267
1268
|
useRef: "useRef",
|
|
1268
1269
|
useMemo: "useMemo",
|
|
1270
|
+
useEffect: "useEffect",
|
|
1269
1271
|
ReactNode: "ReactNode",
|
|
1270
1272
|
forwardRef: "forwardRef",
|
|
1271
1273
|
useCallback: "useCallback",
|
|
@@ -1642,11 +1644,11 @@ function replaceIdName(id, newName) {
|
|
|
1642
1644
|
id.loc.identifierName = newName;
|
|
1643
1645
|
}
|
|
1644
1646
|
}
|
|
1645
|
-
function stringValueToTSType(ctx, input,
|
|
1647
|
+
function stringValueToTSType(ctx, input, tsTypeAnnotation8) {
|
|
1646
1648
|
const { filename, scriptData } = ctx;
|
|
1647
1649
|
const exp = stringToExpr(input, scriptData.lang, filename);
|
|
1648
1650
|
const ts = expressionToTSType(exp);
|
|
1649
|
-
return
|
|
1651
|
+
return tsTypeAnnotation8 ? t15.tsTypeAnnotation(ts) : ts;
|
|
1650
1652
|
}
|
|
1651
1653
|
function expressionToTSType(exp) {
|
|
1652
1654
|
if (t15.isStringLiteral(exp)) return t15.tsStringKeyword();
|
|
@@ -1740,6 +1742,28 @@ function cleanNodeComments(node) {
|
|
|
1740
1742
|
node.innerComments = null;
|
|
1741
1743
|
node.trailingComments = null;
|
|
1742
1744
|
}
|
|
1745
|
+
function mapRuntimeTypeToTSType(value) {
|
|
1746
|
+
switch (value.name) {
|
|
1747
|
+
case "String":
|
|
1748
|
+
return t15.tsStringKeyword();
|
|
1749
|
+
case "Number":
|
|
1750
|
+
return t15.tsNumberKeyword();
|
|
1751
|
+
case "Boolean":
|
|
1752
|
+
return t15.tsBooleanKeyword();
|
|
1753
|
+
case "Object":
|
|
1754
|
+
return t15.tsTypeLiteral([]);
|
|
1755
|
+
case "Array":
|
|
1756
|
+
return t15.tsArrayType(t15.tsAnyKeyword());
|
|
1757
|
+
case "Function":
|
|
1758
|
+
return t15.tsFunctionType(null, [], t15.tsTypeAnnotation(t15.tsAnyKeyword()));
|
|
1759
|
+
case "Symbol":
|
|
1760
|
+
return t15.tsSymbolKeyword();
|
|
1761
|
+
case "BigInt":
|
|
1762
|
+
return t15.tsBigIntKeyword();
|
|
1763
|
+
default:
|
|
1764
|
+
return t15.tsAnyKeyword();
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1743
1767
|
|
|
1744
1768
|
// src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-options.ts
|
|
1745
1769
|
function resolveDeclaredOptions(path8, ctx) {
|
|
@@ -2218,6 +2242,7 @@ var REACTIVE_TYPE_MAP = {
|
|
|
2218
2242
|
toRefs: "ref",
|
|
2219
2243
|
customRef: "ref",
|
|
2220
2244
|
shallowRef: "ref",
|
|
2245
|
+
defineModel: "ref",
|
|
2221
2246
|
reactive: "reactive",
|
|
2222
2247
|
shallowReactive: "reactive",
|
|
2223
2248
|
computed: "ref",
|
|
@@ -3325,6 +3350,13 @@ function createUseMemo(body, deps) {
|
|
|
3325
3350
|
function createUseImperativeHandle(refId, init) {
|
|
3326
3351
|
return t27.callExpression(t27.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
3327
3352
|
}
|
|
3353
|
+
function createUseUpdated(body, deps) {
|
|
3354
|
+
const adapter = ADAPTER_RULES.runtime.onUpdated;
|
|
3355
|
+
return t27.callExpression(t27.identifier(adapter.target), [
|
|
3356
|
+
t27.arrowFunctionExpression([], body),
|
|
3357
|
+
deps ?? t27.identifier("undefined")
|
|
3358
|
+
]);
|
|
3359
|
+
}
|
|
3328
3360
|
|
|
3329
3361
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
3330
3362
|
function resolveDefineExpose(ctx) {
|
|
@@ -3360,6 +3392,226 @@ function resolveDefineExpose(ctx) {
|
|
|
3360
3392
|
};
|
|
3361
3393
|
}
|
|
3362
3394
|
|
|
3395
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-model.ts
|
|
3396
|
+
import * as t29 from "@babel/types";
|
|
3397
|
+
function resolveDefineModel(ctx, ast) {
|
|
3398
|
+
if (ctx.inputType !== "sfc") return {};
|
|
3399
|
+
return {
|
|
3400
|
+
CallExpression(path8) {
|
|
3401
|
+
const { node } = path8;
|
|
3402
|
+
if (!isCalleeNamed(node, MACRO_API_NAMES.model)) {
|
|
3403
|
+
return;
|
|
3404
|
+
}
|
|
3405
|
+
if (!validateDefineModelUsage(path8, ctx)) {
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
const propInfo = extractPropInfo(node, ctx);
|
|
3409
|
+
replaceToUseVRef(node, propInfo, ctx);
|
|
3410
|
+
resolveAutoUpdate(ast, path8, propInfo, ctx);
|
|
3411
|
+
resolveInterface(propInfo, ctx);
|
|
3412
|
+
}
|
|
3413
|
+
};
|
|
3414
|
+
}
|
|
3415
|
+
function validateDefineModelUsage(path8, ctx) {
|
|
3416
|
+
const { node, parent } = path8;
|
|
3417
|
+
const { filename, scriptData } = ctx;
|
|
3418
|
+
const [arg1, arg2] = node.arguments;
|
|
3419
|
+
if (!t29.isObjectExpression(arg1) && !t29.isStringLiteral(arg1)) {
|
|
3420
|
+
logger.error(`Invalid argument type for defineModel. Expected a string.`, {
|
|
3421
|
+
file: filename,
|
|
3422
|
+
source: scriptData.source,
|
|
3423
|
+
loc: arg1?.loc
|
|
3424
|
+
});
|
|
3425
|
+
return false;
|
|
3426
|
+
}
|
|
3427
|
+
const hasUnsupportedOption = (arg) => {
|
|
3428
|
+
if (!t29.isObjectExpression(arg)) {
|
|
3429
|
+
return false;
|
|
3430
|
+
}
|
|
3431
|
+
const result = arg.properties.some((prop) => {
|
|
3432
|
+
if ((t29.isObjectProperty(prop) || t29.isObjectMethod(prop)) && t29.isIdentifier(prop.key)) {
|
|
3433
|
+
const keyName = prop.key.name;
|
|
3434
|
+
if (keyName === "get" || keyName === "set" || keyName === "validator") {
|
|
3435
|
+
logger.error(`defineModel does not support '${keyName}' option.`, {
|
|
3436
|
+
file: filename,
|
|
3437
|
+
source: scriptData.source,
|
|
3438
|
+
loc: prop.key.loc
|
|
3439
|
+
});
|
|
3440
|
+
return true;
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
});
|
|
3444
|
+
return !!result;
|
|
3445
|
+
};
|
|
3446
|
+
const isValidVariableAssignment = () => {
|
|
3447
|
+
const varDeclaration = path8.parentPath.parentPath;
|
|
3448
|
+
if (varDeclaration?.isVariableDeclaration() && varDeclaration.node.declarations.length === 1 && t29.isArrayPattern(varDeclaration.node.declarations[0]?.id)) {
|
|
3449
|
+
logger.error(
|
|
3450
|
+
`defineModel return value cannot be destructured with array pattern. Please use single variable assignment.`,
|
|
3451
|
+
{
|
|
3452
|
+
file: filename,
|
|
3453
|
+
source: scriptData.source,
|
|
3454
|
+
loc: varDeclaration.node.loc
|
|
3455
|
+
}
|
|
3456
|
+
);
|
|
3457
|
+
return false;
|
|
3458
|
+
}
|
|
3459
|
+
return true;
|
|
3460
|
+
};
|
|
3461
|
+
return !hasUnsupportedOption(arg1) && !hasUnsupportedOption(arg2) && isValidVariableAssignment();
|
|
3462
|
+
}
|
|
3463
|
+
function extractPropInfo(node, ctx) {
|
|
3464
|
+
const [arg1, arg2] = node.arguments;
|
|
3465
|
+
const propInfo = {
|
|
3466
|
+
name: "modelValue",
|
|
3467
|
+
updateEventName: "onUpdateModelValue",
|
|
3468
|
+
type: void 0,
|
|
3469
|
+
required: false,
|
|
3470
|
+
default: void 0
|
|
3471
|
+
};
|
|
3472
|
+
const findObjectProperty = (objExpr, propName) => {
|
|
3473
|
+
return objExpr.properties.find(
|
|
3474
|
+
(prop) => t29.isObjectProperty(prop) && t29.isIdentifier(prop.key) && prop.key.name === propName
|
|
3475
|
+
);
|
|
3476
|
+
};
|
|
3477
|
+
const setPropName = (info, value) => {
|
|
3478
|
+
if (!value.trim()) return;
|
|
3479
|
+
info.name = value;
|
|
3480
|
+
info.updateEventName = `onUpdate${capitalize(camelCase(value))}`;
|
|
3481
|
+
};
|
|
3482
|
+
const extractPropInfoFromObject = (objExpr) => {
|
|
3483
|
+
const result = {};
|
|
3484
|
+
const nameProp = findObjectProperty(objExpr, "name");
|
|
3485
|
+
const typeProp = findObjectProperty(objExpr, "type");
|
|
3486
|
+
const defaultProp = findObjectProperty(objExpr, "default");
|
|
3487
|
+
const requiredProp = findObjectProperty(objExpr, "required");
|
|
3488
|
+
if (nameProp && t29.isStringLiteral(nameProp.value)) {
|
|
3489
|
+
setPropName(result, nameProp.value.value);
|
|
3490
|
+
}
|
|
3491
|
+
if (defaultProp) {
|
|
3492
|
+
result.default = defaultProp.value;
|
|
3493
|
+
}
|
|
3494
|
+
if (requiredProp && t29.isBooleanLiteral(requiredProp.value)) {
|
|
3495
|
+
result.required = requiredProp.value.value;
|
|
3496
|
+
}
|
|
3497
|
+
if (typeProp && t29.isIdentifier(typeProp.value)) {
|
|
3498
|
+
result.type = mapRuntimeTypeToTSType(typeProp.value);
|
|
3499
|
+
} else if (node.typeParameters) {
|
|
3500
|
+
const [typeParam] = node.typeParameters.params;
|
|
3501
|
+
if (t29.isTSType(typeParam)) {
|
|
3502
|
+
result.type = typeParam;
|
|
3503
|
+
}
|
|
3504
|
+
} else if (defaultProp) {
|
|
3505
|
+
result.type = expressionToTSType(defaultProp.value);
|
|
3506
|
+
}
|
|
3507
|
+
return result;
|
|
3508
|
+
};
|
|
3509
|
+
const safeAssign = (target, source) => {
|
|
3510
|
+
if (source.name !== void 0) {
|
|
3511
|
+
target.name = source.name;
|
|
3512
|
+
}
|
|
3513
|
+
if (source.updateEventName !== void 0) {
|
|
3514
|
+
target.updateEventName = source.updateEventName;
|
|
3515
|
+
}
|
|
3516
|
+
if (source.type !== void 0) {
|
|
3517
|
+
target.type = source.type;
|
|
3518
|
+
}
|
|
3519
|
+
if (source.required !== void 0) {
|
|
3520
|
+
target.required = source.required;
|
|
3521
|
+
}
|
|
3522
|
+
if (source.default !== void 0) {
|
|
3523
|
+
target.default = source.default;
|
|
3524
|
+
}
|
|
3525
|
+
};
|
|
3526
|
+
const extractTypeFromTypeParams = (info) => {
|
|
3527
|
+
if (!node.typeParameters) return;
|
|
3528
|
+
const isDefaultAny = !info.type || t29.isTSAnyKeyword(info.type);
|
|
3529
|
+
if (!isDefaultAny) return;
|
|
3530
|
+
const [typeParam] = node.typeParameters.params;
|
|
3531
|
+
if (t29.isTSType(typeParam)) {
|
|
3532
|
+
info.type = typeParam;
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
if (t29.isStringLiteral(arg1)) {
|
|
3536
|
+
setPropName(propInfo, arg1.value);
|
|
3537
|
+
extractTypeFromTypeParams(propInfo);
|
|
3538
|
+
} else if (t29.isObjectExpression(arg1)) {
|
|
3539
|
+
safeAssign(propInfo, extractPropInfoFromObject(arg1));
|
|
3540
|
+
}
|
|
3541
|
+
if (!t29.isObjectExpression(arg1) && t29.isObjectExpression(arg2)) {
|
|
3542
|
+
safeAssign(propInfo, extractPropInfoFromObject(arg2));
|
|
3543
|
+
}
|
|
3544
|
+
return propInfo;
|
|
3545
|
+
}
|
|
3546
|
+
function replaceToUseVRef(node, propInfo, ctx) {
|
|
3547
|
+
const refAdapter = ADAPTER_RULES.runtime.ref;
|
|
3548
|
+
replaceCallName(node, refAdapter.target);
|
|
3549
|
+
recordImport(ctx, refAdapter.package, refAdapter.target);
|
|
3550
|
+
const defaultValue = propInfo.default;
|
|
3551
|
+
const propRef = t29.identifier(`${ctx.propField}.${propInfo.name}`);
|
|
3552
|
+
if (!defaultValue) {
|
|
3553
|
+
node.arguments = [propRef];
|
|
3554
|
+
} else {
|
|
3555
|
+
node.arguments = [t29.logicalExpression("??", propRef, defaultValue)];
|
|
3556
|
+
}
|
|
3557
|
+
if (ctx.scriptData.lang.startsWith("ts") && !node.typeParameters && propInfo.type) {
|
|
3558
|
+
node.typeParameters = t29.tsTypeParameterInstantiation([propInfo.type]);
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
function resolveAutoUpdate(ast, path8, propInfo, ctx) {
|
|
3562
|
+
const { parent } = path8;
|
|
3563
|
+
if (!t29.isVariableDeclarator(parent)) {
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
const modelId = parent.id;
|
|
3567
|
+
if (!t29.isIdentifier(modelId)) {
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
const memberAccess = t29.memberExpression(
|
|
3571
|
+
t29.identifier(ctx.propField),
|
|
3572
|
+
t29.identifier(propInfo.updateEventName)
|
|
3573
|
+
);
|
|
3574
|
+
const dep = t29.memberExpression(modelId, t29.identifier("value"));
|
|
3575
|
+
const updateCall = t29.optionalCallExpression(memberAccess, [dep], true);
|
|
3576
|
+
const callExpr = createUseUpdated(
|
|
3577
|
+
t29.blockStatement([t29.expressionStatement(updateCall)]),
|
|
3578
|
+
t29.arrayExpression([dep])
|
|
3579
|
+
);
|
|
3580
|
+
ast.program.body.push(t29.expressionStatement(callExpr));
|
|
3581
|
+
const adapter = ADAPTER_RULES.runtime.onUpdated;
|
|
3582
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
3583
|
+
}
|
|
3584
|
+
function resolveInterface(propInfo, ctx) {
|
|
3585
|
+
const { name, updateEventName, required } = propInfo;
|
|
3586
|
+
const { lang, propsTSIface } = ctx.scriptData;
|
|
3587
|
+
if (!lang.startsWith("ts")) {
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
const propType = propInfo.type || t29.tsAnyKeyword();
|
|
3591
|
+
const propSignature = t29.tsPropertySignature(
|
|
3592
|
+
t29.isValidIdentifier(name) ? t29.identifier(name) : t29.stringLiteral(name),
|
|
3593
|
+
t29.tsTypeAnnotation(propType)
|
|
3594
|
+
);
|
|
3595
|
+
propSignature.optional = !required;
|
|
3596
|
+
const emitArg = t29.identifier("arg");
|
|
3597
|
+
emitArg.typeAnnotation = t29.tsTypeAnnotation(propType);
|
|
3598
|
+
const emitSignature = t29.tsPropertySignature(
|
|
3599
|
+
t29.isValidIdentifier(updateEventName) ? t29.identifier(updateEventName) : t29.stringLiteral(updateEventName),
|
|
3600
|
+
t29.tsTypeAnnotation(t29.tsFunctionType(null, [emitArg], t29.tsTypeAnnotation(t29.tsVoidKeyword())))
|
|
3601
|
+
);
|
|
3602
|
+
emitSignature.optional = true;
|
|
3603
|
+
const appendToTypeLiteral = (list, member) => {
|
|
3604
|
+
const existing = list.find((item) => t29.isTSTypeLiteral(item));
|
|
3605
|
+
if (existing) {
|
|
3606
|
+
existing.members.push(member);
|
|
3607
|
+
} else {
|
|
3608
|
+
list.push(t29.tsTypeLiteral([member]));
|
|
3609
|
+
}
|
|
3610
|
+
};
|
|
3611
|
+
appendToTypeLiteral(propsTSIface.propsTypes, propSignature);
|
|
3612
|
+
appendToTypeLiteral(propsTSIface.emitTypes, emitSignature);
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3363
3615
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-options.ts
|
|
3364
3616
|
function resolveDefineOptions(ctx) {
|
|
3365
3617
|
return {
|
|
@@ -3374,7 +3626,7 @@ function resolveDefineOptions(ctx) {
|
|
|
3374
3626
|
}
|
|
3375
3627
|
|
|
3376
3628
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-emit-calls.ts
|
|
3377
|
-
import * as
|
|
3629
|
+
import * as t30 from "@babel/types";
|
|
3378
3630
|
function resolveEmitCalls(ctx) {
|
|
3379
3631
|
const formatEmitEventName = (raw) => {
|
|
3380
3632
|
if (raw.startsWith("update:")) {
|
|
@@ -3388,7 +3640,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3388
3640
|
CallExpression(path8) {
|
|
3389
3641
|
const { node } = path8;
|
|
3390
3642
|
const { filename, templateData, scriptData } = ctx;
|
|
3391
|
-
if (!
|
|
3643
|
+
if (!t30.isIdentifier(node.callee)) return;
|
|
3392
3644
|
const { name } = node.callee;
|
|
3393
3645
|
const checkIfFromDefineEmits = () => {
|
|
3394
3646
|
let result = false;
|
|
@@ -3400,7 +3652,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3400
3652
|
const binding = path8.scope.getBinding(name);
|
|
3401
3653
|
if (binding) {
|
|
3402
3654
|
const parent = binding.path.node;
|
|
3403
|
-
if (
|
|
3655
|
+
if (t30.isVariableDeclarator(parent) && t30.isCallExpression(parent.init) && t30.isIdentifier(parent.init.callee)) {
|
|
3404
3656
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
3405
3657
|
}
|
|
3406
3658
|
}
|
|
@@ -3410,9 +3662,9 @@ function resolveEmitCalls(ctx) {
|
|
|
3410
3662
|
if (!checkIfFromDefineEmits()) return;
|
|
3411
3663
|
const [callee, ...args] = node.arguments;
|
|
3412
3664
|
let propCall;
|
|
3413
|
-
if (
|
|
3665
|
+
if (t30.isStringLiteral(callee)) {
|
|
3414
3666
|
const eventName = formatEmitEventName(callee.value);
|
|
3415
|
-
propCall = createPropCall(ctx.propField,
|
|
3667
|
+
propCall = createPropCall(ctx.propField, t30.identifier(eventName), args);
|
|
3416
3668
|
} else {
|
|
3417
3669
|
propCall = createPropCall(ctx.propField, callee, args, true);
|
|
3418
3670
|
logger.error(
|
|
@@ -3429,38 +3681,38 @@ function resolveEmitCalls(ctx) {
|
|
|
3429
3681
|
};
|
|
3430
3682
|
}
|
|
3431
3683
|
function createPropCall(rootName, callee, args, computed = false) {
|
|
3432
|
-
return
|
|
3433
|
-
|
|
3684
|
+
return t30.optionalCallExpression(
|
|
3685
|
+
t30.memberExpression(t30.identifier(rootName), callee, computed),
|
|
3434
3686
|
args,
|
|
3435
3687
|
true
|
|
3436
3688
|
);
|
|
3437
3689
|
}
|
|
3438
3690
|
|
|
3439
3691
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/index.ts
|
|
3440
|
-
import * as
|
|
3692
|
+
import * as t38 from "@babel/types";
|
|
3441
3693
|
|
|
3442
3694
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
|
|
3443
|
-
import * as
|
|
3695
|
+
import * as t32 from "@babel/types";
|
|
3444
3696
|
|
|
3445
3697
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/shared.ts
|
|
3446
|
-
import * as
|
|
3698
|
+
import * as t31 from "@babel/types";
|
|
3447
3699
|
function cloneCallableParams(params) {
|
|
3448
3700
|
const cloneCallableParam = (param, index) => {
|
|
3449
|
-
if (
|
|
3701
|
+
if (t31.isRestElement(param)) {
|
|
3450
3702
|
const arg = param.argument;
|
|
3451
|
-
const name =
|
|
3452
|
-
const rest =
|
|
3453
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
3703
|
+
const name = t31.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
3704
|
+
const rest = t31.restElement(t31.identifier(name));
|
|
3705
|
+
rest.typeAnnotation = param.typeAnnotation || (t31.isIdentifier(arg) ? arg.typeAnnotation : null) || t31.tsTypeAnnotation(t31.tsArrayType(t31.tsAnyKeyword()));
|
|
3454
3706
|
return rest;
|
|
3455
3707
|
}
|
|
3456
|
-
if (
|
|
3457
|
-
const id =
|
|
3708
|
+
if (t31.isIdentifier(param)) {
|
|
3709
|
+
const id = t31.identifier(param.name || `arg${index}`);
|
|
3458
3710
|
id.optional = param.optional;
|
|
3459
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
3711
|
+
id.typeAnnotation = param.typeAnnotation || t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3460
3712
|
return id;
|
|
3461
3713
|
}
|
|
3462
|
-
const fallback =
|
|
3463
|
-
fallback.typeAnnotation =
|
|
3714
|
+
const fallback = t31.identifier(`arg${index}`);
|
|
3715
|
+
fallback.typeAnnotation = t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3464
3716
|
return fallback;
|
|
3465
3717
|
};
|
|
3466
3718
|
return params.map(cloneCallableParam);
|
|
@@ -3470,18 +3722,18 @@ function cloneCallableParams(params) {
|
|
|
3470
3722
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
3471
3723
|
return {
|
|
3472
3724
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3473
|
-
if (!
|
|
3725
|
+
if (!t32.isProgram(path8.parent)) return;
|
|
3474
3726
|
const { node } = path8;
|
|
3475
|
-
if (
|
|
3476
|
-
const typeLiteral =
|
|
3727
|
+
if (t32.isTSInterfaceDeclaration(node)) {
|
|
3728
|
+
const typeLiteral = t32.tsTypeLiteral(node.body.body);
|
|
3477
3729
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
3478
3730
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
3479
|
-
if (resolved &&
|
|
3731
|
+
if (resolved && t32.isTSTypeLiteral(resolved)) {
|
|
3480
3732
|
node.body.body = resolved.members;
|
|
3481
3733
|
}
|
|
3482
3734
|
return;
|
|
3483
3735
|
}
|
|
3484
|
-
if (
|
|
3736
|
+
if (t32.isTSTypeAliasDeclaration(node)) {
|
|
3485
3737
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
3486
3738
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
3487
3739
|
if (resolved) {
|
|
@@ -3492,47 +3744,47 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
3492
3744
|
};
|
|
3493
3745
|
}
|
|
3494
3746
|
function resolveTopLevelEmitType(tsType) {
|
|
3495
|
-
if (
|
|
3747
|
+
if (t32.isTSParenthesizedType(tsType)) {
|
|
3496
3748
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
3497
3749
|
}
|
|
3498
|
-
if (
|
|
3750
|
+
if (t32.isTSTypeReference(tsType)) {
|
|
3499
3751
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3500
3752
|
return tsType;
|
|
3501
3753
|
}
|
|
3502
3754
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
3503
|
-
return
|
|
3755
|
+
return t32.tsTypeReference(
|
|
3504
3756
|
tsType.typeName,
|
|
3505
|
-
|
|
3757
|
+
t32.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3506
3758
|
);
|
|
3507
3759
|
}
|
|
3508
|
-
if (
|
|
3760
|
+
if (t32.isTSIntersectionType(tsType)) {
|
|
3509
3761
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3510
3762
|
if (!types.length) return null;
|
|
3511
3763
|
if (types.length === 1) return types[0];
|
|
3512
|
-
return
|
|
3764
|
+
return t32.tsIntersectionType(types);
|
|
3513
3765
|
}
|
|
3514
|
-
if (
|
|
3766
|
+
if (t32.isTSUnionType(tsType)) {
|
|
3515
3767
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3516
3768
|
if (!types.length) return null;
|
|
3517
3769
|
if (types.length === 1) return types[0];
|
|
3518
|
-
return
|
|
3770
|
+
return t32.tsUnionType(types);
|
|
3519
3771
|
}
|
|
3520
|
-
if (
|
|
3772
|
+
if (t32.isTSTypeLiteral(tsType)) {
|
|
3521
3773
|
const members = [];
|
|
3522
3774
|
for (const member of tsType.members) {
|
|
3523
|
-
if (
|
|
3775
|
+
if (t32.isTSCallSignatureDeclaration(member)) {
|
|
3524
3776
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3525
3777
|
continue;
|
|
3526
3778
|
}
|
|
3527
3779
|
members.push(member);
|
|
3528
3780
|
}
|
|
3529
3781
|
if (!members.length) return null;
|
|
3530
|
-
return
|
|
3782
|
+
return t32.tsTypeLiteral(members);
|
|
3531
3783
|
}
|
|
3532
|
-
if (
|
|
3784
|
+
if (t32.isTSFunctionType(tsType)) {
|
|
3533
3785
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3534
3786
|
if (!props.length) return null;
|
|
3535
|
-
return
|
|
3787
|
+
return t32.tsTypeLiteral(props);
|
|
3536
3788
|
}
|
|
3537
3789
|
return tsType;
|
|
3538
3790
|
}
|
|
@@ -3553,41 +3805,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
3553
3805
|
propsTSIface: { emitTypes }
|
|
3554
3806
|
} = ctx.scriptData;
|
|
3555
3807
|
const members = [];
|
|
3556
|
-
if (
|
|
3808
|
+
if (t32.isArrayExpression(runtimeArg)) {
|
|
3557
3809
|
for (const element of runtimeArg.elements) {
|
|
3558
|
-
if (!element || !
|
|
3810
|
+
if (!element || !t32.isStringLiteral(element)) continue;
|
|
3559
3811
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
3560
3812
|
const key = buildKey(handlerName);
|
|
3561
|
-
const fnType =
|
|
3813
|
+
const fnType = t32.tsFunctionType(
|
|
3562
3814
|
null,
|
|
3563
3815
|
[createRestAnyParam("args")],
|
|
3564
|
-
|
|
3816
|
+
t32.tsTypeAnnotation(t32.tsAnyKeyword())
|
|
3565
3817
|
);
|
|
3566
|
-
const prop =
|
|
3818
|
+
const prop = t32.tsPropertySignature(key, t32.tsTypeAnnotation(fnType));
|
|
3567
3819
|
prop.optional = true;
|
|
3568
3820
|
members.push(prop);
|
|
3569
3821
|
}
|
|
3570
3822
|
if (members.length) {
|
|
3571
|
-
emitTypes.push(
|
|
3823
|
+
emitTypes.push(t32.tsTypeLiteral(members));
|
|
3572
3824
|
}
|
|
3573
3825
|
return;
|
|
3574
3826
|
}
|
|
3575
|
-
if (
|
|
3827
|
+
if (t32.isObjectExpression(runtimeArg)) {
|
|
3576
3828
|
for (const prop of runtimeArg.properties) {
|
|
3577
|
-
if (!
|
|
3578
|
-
if (
|
|
3829
|
+
if (!t32.isObjectProperty(prop)) continue;
|
|
3830
|
+
if (t32.isSpreadElement(prop)) continue;
|
|
3579
3831
|
const rawName = resolvePropName(prop.key);
|
|
3580
3832
|
if (!rawName) continue;
|
|
3581
3833
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3582
3834
|
const key = buildKey(handlerName);
|
|
3583
|
-
const params =
|
|
3584
|
-
const fnType =
|
|
3585
|
-
const propSig =
|
|
3835
|
+
const params = t32.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
3836
|
+
const fnType = t32.tsFunctionType(null, params, t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3837
|
+
const propSig = t32.tsPropertySignature(key, t32.tsTypeAnnotation(fnType));
|
|
3586
3838
|
propSig.optional = true;
|
|
3587
3839
|
members.push(propSig);
|
|
3588
3840
|
}
|
|
3589
3841
|
if (members.length) {
|
|
3590
|
-
emitTypes.push(
|
|
3842
|
+
emitTypes.push(t32.tsTypeLiteral(members));
|
|
3591
3843
|
}
|
|
3592
3844
|
}
|
|
3593
3845
|
}
|
|
@@ -3608,129 +3860,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
3608
3860
|
return `on${name}`;
|
|
3609
3861
|
}
|
|
3610
3862
|
function resolvePropName(key) {
|
|
3611
|
-
if (
|
|
3612
|
-
if (
|
|
3613
|
-
if (
|
|
3863
|
+
if (t32.isIdentifier(key)) return key.name;
|
|
3864
|
+
if (t32.isStringLiteral(key)) return key.value;
|
|
3865
|
+
if (t32.isNumericLiteral(key)) return String(key.value);
|
|
3614
3866
|
return null;
|
|
3615
3867
|
}
|
|
3616
3868
|
function buildKey(name) {
|
|
3617
|
-
return
|
|
3869
|
+
return t32.isValidIdentifier(name) ? t32.identifier(name) : t32.stringLiteral(name);
|
|
3618
3870
|
}
|
|
3619
3871
|
function createRestAnyParam(name) {
|
|
3620
|
-
const id =
|
|
3621
|
-
const rest =
|
|
3622
|
-
rest.typeAnnotation =
|
|
3872
|
+
const id = t32.identifier(name);
|
|
3873
|
+
const rest = t32.restElement(id);
|
|
3874
|
+
rest.typeAnnotation = t32.tsTypeAnnotation(t32.tsArrayType(t32.tsAnyKeyword()));
|
|
3623
3875
|
return rest;
|
|
3624
3876
|
}
|
|
3625
3877
|
function resolveRuntimeTupleParams(value) {
|
|
3626
3878
|
const params = [];
|
|
3627
3879
|
value.elements.forEach((element, index) => {
|
|
3628
3880
|
if (!element) return;
|
|
3629
|
-
if (
|
|
3881
|
+
if (t32.isSpreadElement(element)) {
|
|
3630
3882
|
params.push(createRestAnyParam(`args${index}`));
|
|
3631
3883
|
return;
|
|
3632
3884
|
}
|
|
3633
|
-
if (
|
|
3634
|
-
const id =
|
|
3635
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
3885
|
+
if (t32.isIdentifier(element)) {
|
|
3886
|
+
const id = t32.identifier(element.name);
|
|
3887
|
+
id.typeAnnotation = element.typeAnnotation || t32.tsTypeAnnotation(t32.tsAnyKeyword());
|
|
3636
3888
|
params.push(id);
|
|
3637
3889
|
return;
|
|
3638
3890
|
}
|
|
3639
|
-
if (
|
|
3640
|
-
const id =
|
|
3641
|
-
id.typeAnnotation =
|
|
3891
|
+
if (t32.isTSAsExpression(element)) {
|
|
3892
|
+
const id = t32.identifier(`arg${index}`);
|
|
3893
|
+
id.typeAnnotation = t32.tsTypeAnnotation(element.typeAnnotation);
|
|
3642
3894
|
params.push(id);
|
|
3643
3895
|
return;
|
|
3644
3896
|
}
|
|
3645
|
-
const fallback =
|
|
3646
|
-
fallback.typeAnnotation =
|
|
3897
|
+
const fallback = t32.identifier(`arg${index}`);
|
|
3898
|
+
fallback.typeAnnotation = t32.tsTypeAnnotation(t32.tsAnyKeyword());
|
|
3647
3899
|
params.push(fallback);
|
|
3648
3900
|
});
|
|
3649
3901
|
return params;
|
|
3650
3902
|
}
|
|
3651
3903
|
function resolveExplicitEmitType(tsType) {
|
|
3652
|
-
if (
|
|
3904
|
+
if (t32.isTSParenthesizedType(tsType)) {
|
|
3653
3905
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
3654
3906
|
}
|
|
3655
|
-
if (
|
|
3907
|
+
if (t32.isTSTypeReference(tsType)) {
|
|
3656
3908
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3657
3909
|
return tsType;
|
|
3658
3910
|
}
|
|
3659
3911
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
3660
|
-
return
|
|
3912
|
+
return t32.tsTypeReference(
|
|
3661
3913
|
tsType.typeName,
|
|
3662
|
-
|
|
3914
|
+
t32.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3663
3915
|
);
|
|
3664
3916
|
}
|
|
3665
|
-
if (
|
|
3917
|
+
if (t32.isTSIntersectionType(tsType)) {
|
|
3666
3918
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3667
3919
|
if (!types.length) return null;
|
|
3668
3920
|
if (types.length === 1) return types[0];
|
|
3669
|
-
return
|
|
3921
|
+
return t32.tsIntersectionType(types);
|
|
3670
3922
|
}
|
|
3671
|
-
if (
|
|
3923
|
+
if (t32.isTSUnionType(tsType)) {
|
|
3672
3924
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3673
3925
|
if (!types.length) return null;
|
|
3674
3926
|
if (types.length === 1) return types[0];
|
|
3675
|
-
return
|
|
3927
|
+
return t32.tsUnionType(types);
|
|
3676
3928
|
}
|
|
3677
|
-
if (
|
|
3929
|
+
if (t32.isTSTypeLiteral(tsType)) {
|
|
3678
3930
|
const members = [];
|
|
3679
3931
|
for (const member of tsType.members) {
|
|
3680
|
-
if (
|
|
3932
|
+
if (t32.isTSPropertySignature(member)) {
|
|
3681
3933
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
3682
3934
|
if (prop) members.push(prop);
|
|
3683
3935
|
continue;
|
|
3684
3936
|
}
|
|
3685
|
-
if (
|
|
3937
|
+
if (t32.isTSCallSignatureDeclaration(member)) {
|
|
3686
3938
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3687
3939
|
continue;
|
|
3688
3940
|
}
|
|
3689
3941
|
}
|
|
3690
3942
|
if (!members.length) return null;
|
|
3691
|
-
return
|
|
3943
|
+
return t32.tsTypeLiteral(members);
|
|
3692
3944
|
}
|
|
3693
|
-
if (
|
|
3945
|
+
if (t32.isTSFunctionType(tsType)) {
|
|
3694
3946
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3695
3947
|
if (!props.length) return null;
|
|
3696
|
-
return
|
|
3948
|
+
return t32.tsTypeLiteral(props);
|
|
3697
3949
|
}
|
|
3698
3950
|
return tsType;
|
|
3699
3951
|
}
|
|
3700
3952
|
function hasEmitsSignatureInType(tsType) {
|
|
3701
|
-
if (
|
|
3953
|
+
if (t32.isTSParenthesizedType(tsType)) {
|
|
3702
3954
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
3703
3955
|
}
|
|
3704
|
-
if (
|
|
3956
|
+
if (t32.isTSTypeReference(tsType)) {
|
|
3705
3957
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3706
3958
|
return false;
|
|
3707
3959
|
}
|
|
3708
3960
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
3709
3961
|
}
|
|
3710
|
-
if (
|
|
3962
|
+
if (t32.isTSIntersectionType(tsType) || t32.isTSUnionType(tsType)) {
|
|
3711
3963
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
3712
3964
|
}
|
|
3713
|
-
if (
|
|
3965
|
+
if (t32.isTSTypeLiteral(tsType)) {
|
|
3714
3966
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
3715
3967
|
}
|
|
3716
|
-
if (
|
|
3968
|
+
if (t32.isTSFunctionType(tsType)) {
|
|
3717
3969
|
return isEmitsCallable(tsType.parameters);
|
|
3718
3970
|
}
|
|
3719
3971
|
return false;
|
|
3720
3972
|
}
|
|
3721
3973
|
function hasEmitsSignatureInMember(member) {
|
|
3722
|
-
if (
|
|
3974
|
+
if (t32.isTSCallSignatureDeclaration(member)) {
|
|
3723
3975
|
return isEmitsCallable(member.parameters);
|
|
3724
3976
|
}
|
|
3725
3977
|
return false;
|
|
3726
3978
|
}
|
|
3727
3979
|
function isEmitsCallable(parameters) {
|
|
3728
3980
|
const [eventParam] = parameters;
|
|
3729
|
-
if (!eventParam || !
|
|
3981
|
+
if (!eventParam || !t32.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3730
3982
|
return false;
|
|
3731
3983
|
}
|
|
3732
3984
|
const { typeAnnotation } = eventParam;
|
|
3733
|
-
if (
|
|
3985
|
+
if (t32.isNoop(typeAnnotation)) return false;
|
|
3734
3986
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
3735
3987
|
}
|
|
3736
3988
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -3740,19 +3992,19 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3740
3992
|
const key = buildKey(handlerName);
|
|
3741
3993
|
const typeAnnotation = member.typeAnnotation?.typeAnnotation;
|
|
3742
3994
|
let params = [];
|
|
3743
|
-
let returnType =
|
|
3744
|
-
if (typeAnnotation &&
|
|
3995
|
+
let returnType = t32.tsAnyKeyword();
|
|
3996
|
+
if (typeAnnotation && t32.isTSFunctionType(typeAnnotation)) {
|
|
3745
3997
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3746
3998
|
returnType = typeAnnotation.typeAnnotation?.typeAnnotation ?? returnType;
|
|
3747
|
-
} else if (typeAnnotation &&
|
|
3999
|
+
} else if (typeAnnotation && t32.isTSTupleType(typeAnnotation)) {
|
|
3748
4000
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
3749
4001
|
} else if (typeAnnotation) {
|
|
3750
|
-
const id =
|
|
3751
|
-
id.typeAnnotation =
|
|
4002
|
+
const id = t32.identifier("value");
|
|
4003
|
+
id.typeAnnotation = t32.tsTypeAnnotation(typeAnnotation);
|
|
3752
4004
|
params = [id];
|
|
3753
4005
|
}
|
|
3754
|
-
const fnType =
|
|
3755
|
-
const prop =
|
|
4006
|
+
const fnType = t32.tsFunctionType(null, params, t32.tsTypeAnnotation(returnType));
|
|
4007
|
+
const prop = t32.tsPropertySignature(key, t32.tsTypeAnnotation(fnType));
|
|
3756
4008
|
prop.optional = !!member.optional;
|
|
3757
4009
|
return prop;
|
|
3758
4010
|
}
|
|
@@ -3761,32 +4013,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
3761
4013
|
}
|
|
3762
4014
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
3763
4015
|
const [eventParam, ...restParams] = parameters;
|
|
3764
|
-
if (!eventParam || !
|
|
4016
|
+
if (!eventParam || !t32.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3765
4017
|
return [];
|
|
3766
4018
|
}
|
|
3767
4019
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
3768
|
-
if (
|
|
4020
|
+
if (t32.isNoop(paramTypeAnnotation)) return [];
|
|
3769
4021
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
3770
4022
|
if (!eventNames.length) return [];
|
|
3771
|
-
const returnType = typeAnnotation?.typeAnnotation ??
|
|
4023
|
+
const returnType = typeAnnotation?.typeAnnotation ?? t32.tsAnyKeyword();
|
|
3772
4024
|
return eventNames.map((eventName) => {
|
|
3773
4025
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
3774
4026
|
const key = buildKey(handlerName);
|
|
3775
4027
|
const params = cloneCallableParams(restParams);
|
|
3776
|
-
const fnType =
|
|
3777
|
-
const prop =
|
|
4028
|
+
const fnType = t32.tsFunctionType(null, params, t32.tsTypeAnnotation(returnType));
|
|
4029
|
+
const prop = t32.tsPropertySignature(key, t32.tsTypeAnnotation(fnType));
|
|
3778
4030
|
prop.optional = true;
|
|
3779
4031
|
return prop;
|
|
3780
4032
|
});
|
|
3781
4033
|
}
|
|
3782
4034
|
function resolveEventNames(type) {
|
|
3783
|
-
if (
|
|
4035
|
+
if (t32.isTSLiteralType(type) && t32.isStringLiteral(type.literal)) {
|
|
3784
4036
|
return [type.literal.value];
|
|
3785
4037
|
}
|
|
3786
|
-
if (
|
|
4038
|
+
if (t32.isTSUnionType(type)) {
|
|
3787
4039
|
return type.types.flatMap(resolveEventNames);
|
|
3788
4040
|
}
|
|
3789
|
-
if (
|
|
4041
|
+
if (t32.isTSParenthesizedType(type)) {
|
|
3790
4042
|
return resolveEventNames(type.typeAnnotation);
|
|
3791
4043
|
}
|
|
3792
4044
|
return [];
|
|
@@ -3799,44 +4051,44 @@ function resolveTupleTypeParams(tuple) {
|
|
|
3799
4051
|
return params;
|
|
3800
4052
|
}
|
|
3801
4053
|
function resolveTupleElementParam(element, index) {
|
|
3802
|
-
const isNamedTuple = typeof
|
|
4054
|
+
const isNamedTuple = typeof t32.isTSNamedTupleMember === "function" && t32.isTSNamedTupleMember(element);
|
|
3803
4055
|
if (isNamedTuple) {
|
|
3804
4056
|
const tupleMember = element;
|
|
3805
4057
|
const name = tupleMember.label?.name || `arg${index}`;
|
|
3806
4058
|
let innerType = tupleMember.elementType;
|
|
3807
4059
|
let optional = tupleMember.optional;
|
|
3808
|
-
if (
|
|
4060
|
+
if (t32.isTSOptionalType(innerType)) {
|
|
3809
4061
|
optional = true;
|
|
3810
4062
|
innerType = innerType.typeAnnotation;
|
|
3811
4063
|
}
|
|
3812
|
-
if (
|
|
3813
|
-
const rest =
|
|
3814
|
-
rest.typeAnnotation =
|
|
4064
|
+
if (t32.isTSRestType(innerType)) {
|
|
4065
|
+
const rest = t32.restElement(t32.identifier(name));
|
|
4066
|
+
rest.typeAnnotation = t32.tsTypeAnnotation(innerType.typeAnnotation);
|
|
3815
4067
|
return rest;
|
|
3816
4068
|
}
|
|
3817
|
-
const id2 =
|
|
4069
|
+
const id2 = t32.identifier(name);
|
|
3818
4070
|
id2.optional = optional;
|
|
3819
|
-
id2.typeAnnotation =
|
|
4071
|
+
id2.typeAnnotation = t32.tsTypeAnnotation(innerType);
|
|
3820
4072
|
return id2;
|
|
3821
4073
|
}
|
|
3822
|
-
if (
|
|
3823
|
-
const rest =
|
|
3824
|
-
rest.typeAnnotation =
|
|
4074
|
+
if (t32.isTSRestType(element)) {
|
|
4075
|
+
const rest = t32.restElement(t32.identifier(`args${index}`));
|
|
4076
|
+
rest.typeAnnotation = t32.tsTypeAnnotation(element.typeAnnotation);
|
|
3825
4077
|
return rest;
|
|
3826
4078
|
}
|
|
3827
|
-
if (
|
|
3828
|
-
const id2 =
|
|
4079
|
+
if (t32.isTSOptionalType(element)) {
|
|
4080
|
+
const id2 = t32.identifier(`arg${index}`);
|
|
3829
4081
|
id2.optional = true;
|
|
3830
|
-
id2.typeAnnotation =
|
|
4082
|
+
id2.typeAnnotation = t32.tsTypeAnnotation(element.typeAnnotation);
|
|
3831
4083
|
return id2;
|
|
3832
4084
|
}
|
|
3833
|
-
const id =
|
|
3834
|
-
id.typeAnnotation =
|
|
4085
|
+
const id = t32.identifier(`arg${index}`);
|
|
4086
|
+
id.typeAnnotation = t32.tsTypeAnnotation(element);
|
|
3835
4087
|
return id;
|
|
3836
4088
|
}
|
|
3837
4089
|
|
|
3838
4090
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
3839
|
-
import * as
|
|
4091
|
+
import * as t33 from "@babel/types";
|
|
3840
4092
|
function resolveDefinePropsIface(path8, ctx) {
|
|
3841
4093
|
const { node } = path8;
|
|
3842
4094
|
const [runtimeArg] = node.arguments;
|
|
@@ -3856,38 +4108,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3856
4108
|
} = scriptData;
|
|
3857
4109
|
if (!runtimeArg) return;
|
|
3858
4110
|
const members = [];
|
|
3859
|
-
if (
|
|
4111
|
+
if (t33.isArrayExpression(runtimeArg)) {
|
|
3860
4112
|
for (const element of runtimeArg.elements) {
|
|
3861
|
-
if (!element || !
|
|
3862
|
-
const key =
|
|
3863
|
-
const prop =
|
|
4113
|
+
if (!element || !t33.isStringLiteral(element)) continue;
|
|
4114
|
+
const key = t33.isValidIdentifier(element.value) ? t33.identifier(element.value) : t33.stringLiteral(element.value);
|
|
4115
|
+
const prop = t33.tsPropertySignature(key, t33.tsTypeAnnotation(t33.tsAnyKeyword()));
|
|
3864
4116
|
prop.optional = true;
|
|
3865
4117
|
members.push(prop);
|
|
3866
4118
|
}
|
|
3867
4119
|
if (members.length) {
|
|
3868
|
-
propsTypes.push(
|
|
4120
|
+
propsTypes.push(t33.tsTypeLiteral(members));
|
|
3869
4121
|
}
|
|
3870
4122
|
return;
|
|
3871
4123
|
}
|
|
3872
|
-
if (
|
|
4124
|
+
if (t33.isObjectExpression(runtimeArg)) {
|
|
3873
4125
|
for (const prop of runtimeArg.properties) {
|
|
3874
|
-
if (!
|
|
3875
|
-
if (
|
|
4126
|
+
if (!t33.isObjectProperty(prop)) continue;
|
|
4127
|
+
if (t33.isSpreadElement(prop)) continue;
|
|
3876
4128
|
const key = prop.key;
|
|
3877
4129
|
let propName = null;
|
|
3878
|
-
if (
|
|
3879
|
-
if (
|
|
3880
|
-
if (
|
|
4130
|
+
if (t33.isIdentifier(key)) propName = key.name;
|
|
4131
|
+
if (t33.isStringLiteral(key)) propName = key.value;
|
|
4132
|
+
if (t33.isNumericLiteral(key)) propName = String(key.value);
|
|
3881
4133
|
if (!propName) continue;
|
|
3882
4134
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
3883
|
-
const tsType = type ??
|
|
3884
|
-
const tsKey =
|
|
3885
|
-
const tsProp =
|
|
4135
|
+
const tsType = type ?? t33.tsAnyKeyword();
|
|
4136
|
+
const tsKey = t33.isValidIdentifier(propName) ? t33.identifier(propName) : t33.stringLiteral(propName);
|
|
4137
|
+
const tsProp = t33.tsPropertySignature(tsKey, t33.tsTypeAnnotation(tsType));
|
|
3886
4138
|
tsProp.optional = !required;
|
|
3887
4139
|
members.push(tsProp);
|
|
3888
4140
|
}
|
|
3889
4141
|
if (members.length) {
|
|
3890
|
-
propsTypes.push(
|
|
4142
|
+
propsTypes.push(t33.tsTypeLiteral(members));
|
|
3891
4143
|
}
|
|
3892
4144
|
return;
|
|
3893
4145
|
}
|
|
@@ -3901,42 +4153,42 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3901
4153
|
);
|
|
3902
4154
|
}
|
|
3903
4155
|
function resolveRuntimePropMeta(value) {
|
|
3904
|
-
if (
|
|
4156
|
+
if (t33.isIdentifier(value)) {
|
|
3905
4157
|
return {
|
|
3906
4158
|
type: mapRuntimeTypeToTSType(value),
|
|
3907
4159
|
required: false
|
|
3908
4160
|
};
|
|
3909
4161
|
}
|
|
3910
|
-
if (
|
|
4162
|
+
if (t33.isArrayExpression(value)) {
|
|
3911
4163
|
return {
|
|
3912
4164
|
type: resolveRuntimeUnionType(value),
|
|
3913
4165
|
required: false
|
|
3914
4166
|
};
|
|
3915
4167
|
}
|
|
3916
|
-
if (!
|
|
4168
|
+
if (!t33.isObjectExpression(value)) {
|
|
3917
4169
|
return { required: false };
|
|
3918
4170
|
}
|
|
3919
4171
|
let type;
|
|
3920
4172
|
let required = false;
|
|
3921
4173
|
for (const prop of value.properties) {
|
|
3922
|
-
if (!
|
|
3923
|
-
if (
|
|
4174
|
+
if (!t33.isObjectProperty(prop)) continue;
|
|
4175
|
+
if (t33.isSpreadElement(prop)) continue;
|
|
3924
4176
|
const key = prop.key;
|
|
3925
|
-
const propName =
|
|
4177
|
+
const propName = t33.isIdentifier(key) ? key.name : t33.isStringLiteral(key) ? key.value : null;
|
|
3926
4178
|
if (!propName) continue;
|
|
3927
4179
|
if (propName === "type") {
|
|
3928
4180
|
const valueNode = prop.value;
|
|
3929
|
-
if (
|
|
4181
|
+
if (t33.isArrayExpression(valueNode)) {
|
|
3930
4182
|
type = resolveRuntimeUnionType(valueNode);
|
|
3931
4183
|
continue;
|
|
3932
4184
|
}
|
|
3933
|
-
if (
|
|
4185
|
+
if (t33.isIdentifier(valueNode)) {
|
|
3934
4186
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3935
4187
|
continue;
|
|
3936
4188
|
}
|
|
3937
4189
|
}
|
|
3938
4190
|
if (propName === "required") {
|
|
3939
|
-
if (
|
|
4191
|
+
if (t33.isBooleanLiteral(prop.value)) {
|
|
3940
4192
|
required = prop.value.value;
|
|
3941
4193
|
}
|
|
3942
4194
|
}
|
|
@@ -3946,80 +4198,58 @@ function resolveRuntimePropMeta(value) {
|
|
|
3946
4198
|
function resolveRuntimeUnionType(value) {
|
|
3947
4199
|
const types = [];
|
|
3948
4200
|
for (const element of value.elements) {
|
|
3949
|
-
if (!element || !
|
|
4201
|
+
if (!element || !t33.isIdentifier(element)) continue;
|
|
3950
4202
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3951
4203
|
if (resolved) types.push(resolved);
|
|
3952
4204
|
}
|
|
3953
|
-
if (!types.length) return
|
|
4205
|
+
if (!types.length) return t33.tsAnyKeyword();
|
|
3954
4206
|
if (types.length === 1) return types[0];
|
|
3955
|
-
return
|
|
3956
|
-
}
|
|
3957
|
-
function mapRuntimeTypeToTSType(value) {
|
|
3958
|
-
switch (value.name) {
|
|
3959
|
-
case "String":
|
|
3960
|
-
return t32.tsStringKeyword();
|
|
3961
|
-
case "Number":
|
|
3962
|
-
return t32.tsNumberKeyword();
|
|
3963
|
-
case "Boolean":
|
|
3964
|
-
return t32.tsBooleanKeyword();
|
|
3965
|
-
case "Object":
|
|
3966
|
-
return t32.tsTypeLiteral([]);
|
|
3967
|
-
case "Array":
|
|
3968
|
-
return t32.tsArrayType(t32.tsAnyKeyword());
|
|
3969
|
-
case "Function":
|
|
3970
|
-
return t32.tsFunctionType(null, [], t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3971
|
-
case "Symbol":
|
|
3972
|
-
return t32.tsSymbolKeyword();
|
|
3973
|
-
case "BigInt":
|
|
3974
|
-
return t32.tsBigIntKeyword();
|
|
3975
|
-
default:
|
|
3976
|
-
return t32.tsAnyKeyword();
|
|
3977
|
-
}
|
|
4207
|
+
return t33.tsUnionType(types);
|
|
3978
4208
|
}
|
|
3979
4209
|
|
|
3980
4210
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
3981
|
-
import * as
|
|
4211
|
+
import * as t36 from "@babel/types";
|
|
3982
4212
|
|
|
3983
4213
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/slot-builder.ts
|
|
3984
|
-
import * as
|
|
4214
|
+
import * as t34 from "@babel/types";
|
|
3985
4215
|
var SLOT_DEFAULT_NAME = "default";
|
|
3986
4216
|
var SLOT_CHILDREN_NAME = "children";
|
|
3987
4217
|
var SLOT_FN_PARAM_NAME = "props";
|
|
3988
4218
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3989
4219
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3990
|
-
const key =
|
|
3991
|
-
const reactNodeType =
|
|
3992
|
-
|
|
4220
|
+
const key = t34.isValidIdentifier(propName) ? t34.identifier(propName) : t34.stringLiteral(propName);
|
|
4221
|
+
const reactNodeType = t34.tsTypeAnnotation(
|
|
4222
|
+
t34.tsTypeReference(t34.identifier(REACT_API_MAP.ReactNode))
|
|
3993
4223
|
);
|
|
3994
4224
|
let typeAnnotation;
|
|
3995
4225
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3996
4226
|
typeAnnotation = reactNodeType;
|
|
3997
4227
|
} else {
|
|
3998
|
-
const fnType =
|
|
3999
|
-
typeAnnotation =
|
|
4228
|
+
const fnType = t34.tsFunctionType(null, params, reactNodeType);
|
|
4229
|
+
typeAnnotation = t34.tsTypeAnnotation(fnType);
|
|
4000
4230
|
}
|
|
4001
|
-
const prop =
|
|
4231
|
+
const prop = t34.tsPropertySignature(key, typeAnnotation);
|
|
4002
4232
|
prop.optional = optional;
|
|
4003
4233
|
return prop;
|
|
4004
4234
|
}
|
|
4005
4235
|
function createSlotScopeParam(props, ctx) {
|
|
4006
|
-
const paramId =
|
|
4236
|
+
const paramId = t34.identifier(SLOT_FN_PARAM_NAME);
|
|
4007
4237
|
const propsSigns = [];
|
|
4008
4238
|
const { reactiveBindings } = ctx.templateData;
|
|
4009
4239
|
props.forEach(({ prop, tsType }) => {
|
|
4010
4240
|
const foundBindingValue = reactiveBindings[prop]?.value;
|
|
4011
4241
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
4012
|
-
const typeAnnotation = foundBindingTypes ?
|
|
4013
|
-
const key =
|
|
4014
|
-
const propSign =
|
|
4242
|
+
const typeAnnotation = foundBindingTypes ? t34.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
4243
|
+
const key = t34.isValidIdentifier(prop) ? t34.identifier(prop) : t34.stringLiteral(prop);
|
|
4244
|
+
const propSign = t34.tsPropertySignature(key, typeAnnotation);
|
|
4015
4245
|
propsSigns.push(propSign);
|
|
4016
4246
|
});
|
|
4017
|
-
paramId.typeAnnotation =
|
|
4247
|
+
paramId.typeAnnotation = t34.tsTypeAnnotation(t34.tsTypeLiteral(propsSigns));
|
|
4018
4248
|
return paramId;
|
|
4019
4249
|
}
|
|
4020
4250
|
|
|
4021
4251
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/utils.ts
|
|
4022
|
-
import * as
|
|
4252
|
+
import * as t35 from "@babel/types";
|
|
4023
4253
|
function recordReactNode(ctx) {
|
|
4024
4254
|
if (!ctx.scriptData.lang.startsWith("ts")) {
|
|
4025
4255
|
return;
|
|
@@ -4035,16 +4265,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4035
4265
|
return declarations;
|
|
4036
4266
|
}
|
|
4037
4267
|
for (const statement of programPath.node.body) {
|
|
4038
|
-
if (
|
|
4268
|
+
if (t35.isTSInterfaceDeclaration(statement)) {
|
|
4039
4269
|
declarations.set(statement.id.name, {
|
|
4040
|
-
type:
|
|
4270
|
+
type: t35.tsTypeLiteral(statement.body.body),
|
|
4041
4271
|
// 将接口体转换为类型字面量
|
|
4042
4272
|
hasTypeParameters: !!statement.typeParameters?.params.length
|
|
4043
4273
|
// 检查是否有泛型参数
|
|
4044
4274
|
});
|
|
4045
4275
|
continue;
|
|
4046
4276
|
}
|
|
4047
|
-
if (
|
|
4277
|
+
if (t35.isTSTypeAliasDeclaration(statement)) {
|
|
4048
4278
|
declarations.set(statement.id.name, {
|
|
4049
4279
|
type: statement.typeAnnotation,
|
|
4050
4280
|
// 直接使用类型注解
|
|
@@ -4053,16 +4283,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4053
4283
|
});
|
|
4054
4284
|
continue;
|
|
4055
4285
|
}
|
|
4056
|
-
if (
|
|
4286
|
+
if (t35.isExportNamedDeclaration(statement) && statement.declaration) {
|
|
4057
4287
|
const declaration = statement.declaration;
|
|
4058
|
-
if (
|
|
4288
|
+
if (t35.isTSInterfaceDeclaration(declaration)) {
|
|
4059
4289
|
declarations.set(declaration.id.name, {
|
|
4060
|
-
type:
|
|
4290
|
+
type: t35.tsTypeLiteral(declaration.body.body),
|
|
4061
4291
|
// 将接口体转换为类型字面量
|
|
4062
4292
|
hasTypeParameters: !!declaration.typeParameters?.params.length
|
|
4063
4293
|
// 检查是否有泛型参数
|
|
4064
4294
|
});
|
|
4065
|
-
} else if (
|
|
4295
|
+
} else if (t35.isTSTypeAliasDeclaration(declaration)) {
|
|
4066
4296
|
declarations.set(declaration.id.name, {
|
|
4067
4297
|
type: declaration.typeAnnotation,
|
|
4068
4298
|
// 直接使用类型注解
|
|
@@ -4075,22 +4305,22 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4075
4305
|
return declarations;
|
|
4076
4306
|
}
|
|
4077
4307
|
function resolvePropName2(key) {
|
|
4078
|
-
if (
|
|
4308
|
+
if (t35.isIdentifier(key)) {
|
|
4079
4309
|
return key.name;
|
|
4080
4310
|
}
|
|
4081
|
-
if (
|
|
4311
|
+
if (t35.isStringLiteral(key)) {
|
|
4082
4312
|
return key.value;
|
|
4083
4313
|
}
|
|
4084
|
-
if (
|
|
4314
|
+
if (t35.isNumericLiteral(key)) {
|
|
4085
4315
|
return String(key.value);
|
|
4086
4316
|
}
|
|
4087
4317
|
return null;
|
|
4088
4318
|
}
|
|
4089
4319
|
function resolveCallableType(tsType) {
|
|
4090
|
-
if (
|
|
4320
|
+
if (t35.isTSFunctionType(tsType)) {
|
|
4091
4321
|
return tsType;
|
|
4092
4322
|
}
|
|
4093
|
-
if (
|
|
4323
|
+
if (t35.isTSParenthesizedType(tsType)) {
|
|
4094
4324
|
return resolveCallableType(tsType.typeAnnotation);
|
|
4095
4325
|
}
|
|
4096
4326
|
return null;
|
|
@@ -4099,10 +4329,10 @@ function resolveCallableType(tsType) {
|
|
|
4099
4329
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
4100
4330
|
var SLOT_DEFAULT_NAME2 = "default";
|
|
4101
4331
|
function resolveSlotType(tsType, options) {
|
|
4102
|
-
if (
|
|
4332
|
+
if (t36.isTSParenthesizedType(tsType)) {
|
|
4103
4333
|
return resolveSlotType(tsType.typeAnnotation, options);
|
|
4104
4334
|
}
|
|
4105
|
-
if (
|
|
4335
|
+
if (t36.isTSTypeReference(tsType)) {
|
|
4106
4336
|
let shouldRecordReactNode = false;
|
|
4107
4337
|
if (tsType.typeParameters?.params.length) {
|
|
4108
4338
|
const params = [];
|
|
@@ -4118,11 +4348,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4118
4348
|
};
|
|
4119
4349
|
}
|
|
4120
4350
|
return {
|
|
4121
|
-
type:
|
|
4351
|
+
type: t36.tsTypeReference(tsType.typeName, t36.tsTypeParameterInstantiation(params)),
|
|
4122
4352
|
shouldRecordReactNode
|
|
4123
4353
|
};
|
|
4124
4354
|
}
|
|
4125
|
-
if (!
|
|
4355
|
+
if (!t36.isIdentifier(tsType.typeName)) {
|
|
4126
4356
|
return {
|
|
4127
4357
|
type: tsType,
|
|
4128
4358
|
shouldRecordReactNode: false
|
|
@@ -4153,7 +4383,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4153
4383
|
}
|
|
4154
4384
|
return resolved;
|
|
4155
4385
|
}
|
|
4156
|
-
if (
|
|
4386
|
+
if (t36.isTSIntersectionType(tsType)) {
|
|
4157
4387
|
const types = [];
|
|
4158
4388
|
let shouldRecordReactNode = false;
|
|
4159
4389
|
for (const item of tsType.types) {
|
|
@@ -4176,11 +4406,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4176
4406
|
};
|
|
4177
4407
|
}
|
|
4178
4408
|
return {
|
|
4179
|
-
type:
|
|
4409
|
+
type: t36.tsIntersectionType(types),
|
|
4180
4410
|
shouldRecordReactNode
|
|
4181
4411
|
};
|
|
4182
4412
|
}
|
|
4183
|
-
if (
|
|
4413
|
+
if (t36.isTSUnionType(tsType)) {
|
|
4184
4414
|
const types = [];
|
|
4185
4415
|
let shouldRecordReactNode = false;
|
|
4186
4416
|
for (const item of tsType.types) {
|
|
@@ -4203,11 +4433,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4203
4433
|
};
|
|
4204
4434
|
}
|
|
4205
4435
|
return {
|
|
4206
|
-
type:
|
|
4436
|
+
type: t36.tsUnionType(types),
|
|
4207
4437
|
shouldRecordReactNode
|
|
4208
4438
|
};
|
|
4209
4439
|
}
|
|
4210
|
-
if (
|
|
4440
|
+
if (t36.isTSTypeLiteral(tsType)) {
|
|
4211
4441
|
const members = [];
|
|
4212
4442
|
let shouldRecordReactNode = false;
|
|
4213
4443
|
for (const item of tsType.members) {
|
|
@@ -4222,11 +4452,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4222
4452
|
};
|
|
4223
4453
|
}
|
|
4224
4454
|
return {
|
|
4225
|
-
type:
|
|
4455
|
+
type: t36.tsTypeLiteral(members),
|
|
4226
4456
|
shouldRecordReactNode
|
|
4227
4457
|
};
|
|
4228
4458
|
}
|
|
4229
|
-
if (
|
|
4459
|
+
if (t36.isTSFunctionType(tsType)) {
|
|
4230
4460
|
const props = buildSlotPropSignature(
|
|
4231
4461
|
SLOT_DEFAULT_NAME2,
|
|
4232
4462
|
cloneCallableParams(tsType.parameters),
|
|
@@ -4234,7 +4464,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4234
4464
|
// 默认插槽不是可选的
|
|
4235
4465
|
);
|
|
4236
4466
|
return {
|
|
4237
|
-
type:
|
|
4467
|
+
type: t36.tsTypeLiteral([props]),
|
|
4238
4468
|
shouldRecordReactNode: true
|
|
4239
4469
|
// 函数类型总是需要记录 ReactNode
|
|
4240
4470
|
};
|
|
@@ -4245,7 +4475,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4245
4475
|
};
|
|
4246
4476
|
}
|
|
4247
4477
|
function resolveSlotPropFromMember(member) {
|
|
4248
|
-
if (
|
|
4478
|
+
if (t36.isTSMethodSignature(member)) {
|
|
4249
4479
|
const rawName = resolvePropName2(member.key);
|
|
4250
4480
|
if (!rawName) {
|
|
4251
4481
|
return {
|
|
@@ -4260,7 +4490,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4260
4490
|
// 方法签名总是可调用,需要记录 ReactNode
|
|
4261
4491
|
};
|
|
4262
4492
|
}
|
|
4263
|
-
if (
|
|
4493
|
+
if (t36.isTSPropertySignature(member)) {
|
|
4264
4494
|
const rawName = resolvePropName2(member.key);
|
|
4265
4495
|
if (!rawName) {
|
|
4266
4496
|
return {
|
|
@@ -4283,7 +4513,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4283
4513
|
// 可调用属性需要记录 ReactNode
|
|
4284
4514
|
};
|
|
4285
4515
|
}
|
|
4286
|
-
if (
|
|
4516
|
+
if (t36.isTSCallSignatureDeclaration(member)) {
|
|
4287
4517
|
const params = cloneCallableParams(member.parameters);
|
|
4288
4518
|
return {
|
|
4289
4519
|
member: buildSlotPropSignature(SLOT_DEFAULT_NAME2, params, true),
|
|
@@ -4323,7 +4553,7 @@ function resolveDefineSlotsIface(path8, ctx) {
|
|
|
4323
4553
|
}
|
|
4324
4554
|
|
|
4325
4555
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/template-slots.ts
|
|
4326
|
-
import * as
|
|
4556
|
+
import * as t37 from "@babel/types";
|
|
4327
4557
|
function resolveTemplateSlotIface(ctx) {
|
|
4328
4558
|
if (ctx.inputType !== "sfc") return;
|
|
4329
4559
|
const {
|
|
@@ -4341,7 +4571,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
4341
4571
|
}
|
|
4342
4572
|
if (tsMembers.length) {
|
|
4343
4573
|
recordReactNode(ctx);
|
|
4344
|
-
slotTypes.push(
|
|
4574
|
+
slotTypes.push(t37.tsTypeLiteral(tsMembers));
|
|
4345
4575
|
}
|
|
4346
4576
|
}
|
|
4347
4577
|
|
|
@@ -4393,9 +4623,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4393
4623
|
}
|
|
4394
4624
|
const n = declaredOptions.name || "Comp";
|
|
4395
4625
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
4396
|
-
const typeNode =
|
|
4397
|
-
const typeAliasDecl =
|
|
4398
|
-
const exportDecl =
|
|
4626
|
+
const typeNode = t38.tsIntersectionType(tsTypes);
|
|
4627
|
+
const typeAliasDecl = t38.tsTypeAliasDeclaration(t38.identifier(ns), null, typeNode);
|
|
4628
|
+
const exportDecl = t38.exportNamedDeclaration(typeAliasDecl);
|
|
4399
4629
|
propsTSIface.name = ns;
|
|
4400
4630
|
const scriptIR = getScriptIR(ctx);
|
|
4401
4631
|
scriptIR.exports.push(exportDecl);
|
|
@@ -4403,15 +4633,15 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4403
4633
|
}
|
|
4404
4634
|
|
|
4405
4635
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-use-attrs.ts
|
|
4406
|
-
import * as
|
|
4636
|
+
import * as t39 from "@babel/types";
|
|
4407
4637
|
function resolveUseAttrs(ctx) {
|
|
4408
4638
|
return {
|
|
4409
4639
|
VariableDeclarator(path8) {
|
|
4410
4640
|
const { init, id } = path8.node;
|
|
4411
4641
|
if (!init) return;
|
|
4412
4642
|
const initPath = path8.get("init");
|
|
4413
|
-
const propsIdentifier =
|
|
4414
|
-
if (
|
|
4643
|
+
const propsIdentifier = t39.identifier(ctx.propField);
|
|
4644
|
+
if (t39.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
|
|
4415
4645
|
const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
|
|
4416
4646
|
replaceNode(initPath, typeAssertion, init);
|
|
4417
4647
|
return;
|
|
@@ -4422,13 +4652,13 @@ function resolveUseAttrs(ctx) {
|
|
|
4422
4652
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
4423
4653
|
if (isTS) {
|
|
4424
4654
|
let typeAnnotation = null;
|
|
4425
|
-
if (
|
|
4655
|
+
if (t39.isIdentifier(id) && t39.isTSTypeAnnotation(id.typeAnnotation)) {
|
|
4426
4656
|
typeAnnotation = id.typeAnnotation.typeAnnotation;
|
|
4427
4657
|
id.typeAnnotation = null;
|
|
4428
4658
|
} else {
|
|
4429
|
-
typeAnnotation =
|
|
4430
|
-
|
|
4431
|
-
|
|
4659
|
+
typeAnnotation = t39.tsTypeReference(
|
|
4660
|
+
t39.identifier("Record"),
|
|
4661
|
+
t39.tsTypeParameterInstantiation([t39.tsStringKeyword(), t39.tsUnknownKeyword()])
|
|
4432
4662
|
);
|
|
4433
4663
|
}
|
|
4434
4664
|
const propsTypeAssertion = createPropsTypeAssertion(propsIdentifier, typeAnnotation);
|
|
@@ -4440,18 +4670,18 @@ function resolveUseAttrs(ctx) {
|
|
|
4440
4670
|
};
|
|
4441
4671
|
}
|
|
4442
4672
|
function isUseAttrsCall(expr) {
|
|
4443
|
-
return
|
|
4673
|
+
return t39.isCallExpression(expr) && isCalleeNamed(expr, VUE_API_MAP.useAttrs);
|
|
4444
4674
|
}
|
|
4445
4675
|
function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
4446
|
-
return
|
|
4676
|
+
return t39.tsAsExpression(propsIdentifier, typeAnnotation);
|
|
4447
4677
|
}
|
|
4448
4678
|
|
|
4449
4679
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4450
|
-
import * as
|
|
4680
|
+
import * as t45 from "@babel/types";
|
|
4451
4681
|
|
|
4452
4682
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4453
4683
|
import { traverse as traverse2 } from "@babel/core";
|
|
4454
|
-
import * as
|
|
4684
|
+
import * as t44 from "@babel/types";
|
|
4455
4685
|
|
|
4456
4686
|
// src/core/transform/sfc/script/shared/dependency-analyzer/binding-utils.ts
|
|
4457
4687
|
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
@@ -4470,7 +4700,7 @@ function isReactiveBinding(node) {
|
|
|
4470
4700
|
}
|
|
4471
4701
|
|
|
4472
4702
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
|
|
4473
|
-
import * as
|
|
4703
|
+
import * as t40 from "@babel/types";
|
|
4474
4704
|
function isEligibleBindingSource(binding) {
|
|
4475
4705
|
if (binding.kind === "param") {
|
|
4476
4706
|
return false;
|
|
@@ -4480,57 +4710,57 @@ function isEligibleBindingSource(binding) {
|
|
|
4480
4710
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4481
4711
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4482
4712
|
const nodeInit = declaratorPath?.node.init;
|
|
4483
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
4484
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
4485
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
4713
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t40.isCallExpression(nodeInit) && t40.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4714
|
+
const isHookCallVarBinding = !!declaratorPath && t40.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4715
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t40.isArrowFunctionExpression(nodeInit) || t40.isFunctionExpression(nodeInit));
|
|
4486
4716
|
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(declaratorPath?.node) || isReactiveBinding(bindingPath.node));
|
|
4487
4717
|
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4488
4718
|
}
|
|
4489
4719
|
function isReactValidDependencyExpr(node) {
|
|
4490
|
-
if (
|
|
4720
|
+
if (t40.isIdentifier(node)) {
|
|
4491
4721
|
return true;
|
|
4492
4722
|
}
|
|
4493
|
-
if (
|
|
4723
|
+
if (t40.isMemberExpression(node) || t40.isOptionalMemberExpression(node)) {
|
|
4494
4724
|
return isStaticMemberChain(node);
|
|
4495
4725
|
}
|
|
4496
4726
|
return false;
|
|
4497
4727
|
}
|
|
4498
4728
|
function isStaticMemberChain(node) {
|
|
4499
4729
|
let current = node;
|
|
4500
|
-
while (
|
|
4501
|
-
if (!current.computed && !
|
|
4730
|
+
while (t40.isMemberExpression(current) || t40.isOptionalMemberExpression(current)) {
|
|
4731
|
+
if (!current.computed && !t40.isIdentifier(current.property)) {
|
|
4502
4732
|
return false;
|
|
4503
4733
|
}
|
|
4504
|
-
if (current.computed && !
|
|
4734
|
+
if (current.computed && !t40.isStringLiteral(current.property) && !t40.isNumericLiteral(current.property)) {
|
|
4505
4735
|
return false;
|
|
4506
4736
|
}
|
|
4507
4737
|
current = current.object;
|
|
4508
4738
|
}
|
|
4509
|
-
return
|
|
4739
|
+
return t40.isIdentifier(current);
|
|
4510
4740
|
}
|
|
4511
4741
|
function isHookLikeCallee(callee) {
|
|
4512
|
-
if (
|
|
4742
|
+
if (t40.isIdentifier(callee)) {
|
|
4513
4743
|
return callee.name.startsWith("use");
|
|
4514
4744
|
}
|
|
4515
|
-
if (
|
|
4745
|
+
if (t40.isMemberExpression(callee) && !callee.computed && t40.isIdentifier(callee.property)) {
|
|
4516
4746
|
return callee.property.name.startsWith("use");
|
|
4517
4747
|
}
|
|
4518
4748
|
return false;
|
|
4519
4749
|
}
|
|
4520
4750
|
|
|
4521
4751
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
|
|
4522
|
-
import * as
|
|
4752
|
+
import * as t41 from "@babel/types";
|
|
4523
4753
|
function getDependencyKey(exp) {
|
|
4524
|
-
if (
|
|
4754
|
+
if (t41.isIdentifier(exp)) {
|
|
4525
4755
|
return exp.name;
|
|
4526
4756
|
}
|
|
4527
|
-
if (
|
|
4757
|
+
if (t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp)) {
|
|
4528
4758
|
const objectKey = getDependencyKey(exp.object);
|
|
4529
4759
|
const opt = exp.optional ? "?" : "";
|
|
4530
|
-
if (!exp.computed &&
|
|
4760
|
+
if (!exp.computed && t41.isIdentifier(exp.property)) {
|
|
4531
4761
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4532
4762
|
}
|
|
4533
|
-
if (
|
|
4763
|
+
if (t41.isStringLiteral(exp.property) || t41.isNumericLiteral(exp.property)) {
|
|
4534
4764
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4535
4765
|
}
|
|
4536
4766
|
return `${objectKey}${opt}[*]`;
|
|
@@ -4539,40 +4769,40 @@ function getDependencyKey(exp) {
|
|
|
4539
4769
|
}
|
|
4540
4770
|
|
|
4541
4771
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
|
|
4542
|
-
import * as
|
|
4772
|
+
import * as t42 from "@babel/types";
|
|
4543
4773
|
function normalizeDependencyExpr(path8, rootName, ctx) {
|
|
4544
|
-
if (
|
|
4545
|
-
return
|
|
4774
|
+
if (t42.isIdentifier(path8.node)) {
|
|
4775
|
+
return t42.identifier(path8.node.name);
|
|
4546
4776
|
}
|
|
4547
|
-
if (
|
|
4777
|
+
if (t42.isMemberExpression(path8.node) || t42.isOptionalMemberExpression(path8.node)) {
|
|
4548
4778
|
if (rootName === ctx.propField) {
|
|
4549
4779
|
const safePropsExp = ensureOptionalForMemberChain(path8.node);
|
|
4550
4780
|
if (isReactValidDependencyExpr(safePropsExp)) {
|
|
4551
|
-
return
|
|
4781
|
+
return t42.cloneNode(safePropsExp, true);
|
|
4552
4782
|
}
|
|
4553
|
-
return
|
|
4783
|
+
return t42.identifier(rootName);
|
|
4554
4784
|
}
|
|
4555
4785
|
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
4556
|
-
const safeExp =
|
|
4786
|
+
const safeExp = t42.isMemberExpression(normalizedExp) || t42.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
4557
4787
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4558
|
-
return
|
|
4788
|
+
return t42.cloneNode(safeExp, true);
|
|
4559
4789
|
}
|
|
4560
|
-
return
|
|
4790
|
+
return t42.identifier(rootName);
|
|
4561
4791
|
}
|
|
4562
4792
|
return null;
|
|
4563
4793
|
}
|
|
4564
4794
|
function normalizeSourcedDependency(exp) {
|
|
4565
|
-
if (
|
|
4566
|
-
return
|
|
4795
|
+
if (t42.isIdentifier(exp)) {
|
|
4796
|
+
return t42.identifier(exp.name);
|
|
4567
4797
|
}
|
|
4568
|
-
if (
|
|
4798
|
+
if (t42.isMemberExpression(exp) || t42.isOptionalMemberExpression(exp)) {
|
|
4569
4799
|
const root = findRootIdentifier(exp);
|
|
4570
4800
|
if (!root) return null;
|
|
4571
|
-
const safeExp =
|
|
4801
|
+
const safeExp = t42.isMemberExpression(exp) || t42.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4572
4802
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4573
|
-
return
|
|
4803
|
+
return t42.cloneNode(safeExp, true);
|
|
4574
4804
|
}
|
|
4575
|
-
return
|
|
4805
|
+
return t42.identifier(root.name);
|
|
4576
4806
|
}
|
|
4577
4807
|
return null;
|
|
4578
4808
|
}
|
|
@@ -4582,7 +4812,7 @@ function normalizeMemberForCallSite(path8, node) {
|
|
|
4582
4812
|
if (!isDirectCallee) {
|
|
4583
4813
|
return node;
|
|
4584
4814
|
}
|
|
4585
|
-
if (!
|
|
4815
|
+
if (!t42.isExpression(node.object)) {
|
|
4586
4816
|
return node;
|
|
4587
4817
|
}
|
|
4588
4818
|
return node.object;
|
|
@@ -4594,20 +4824,20 @@ function ensureOptionalForMemberChain(node) {
|
|
|
4594
4824
|
const rebuildWithOptionalChain = (node2) => {
|
|
4595
4825
|
const safeObject = ensureOptionalForMemberChain(node2.object);
|
|
4596
4826
|
if (safeObject !== node2.object) {
|
|
4597
|
-
const property =
|
|
4598
|
-
return
|
|
4827
|
+
const property = t42.cloneNode(node2.property, true);
|
|
4828
|
+
return t42.optionalMemberExpression(safeObject, property, node2.computed, true);
|
|
4599
4829
|
}
|
|
4600
|
-
if (
|
|
4601
|
-
const object =
|
|
4602
|
-
const property =
|
|
4603
|
-
return
|
|
4830
|
+
if (t42.isMemberExpression(node2)) {
|
|
4831
|
+
const object = t42.cloneNode(node2.object, true);
|
|
4832
|
+
const property = t42.cloneNode(node2.property, true);
|
|
4833
|
+
return t42.optionalMemberExpression(object, property, node2.computed, true);
|
|
4604
4834
|
}
|
|
4605
4835
|
return node2;
|
|
4606
4836
|
};
|
|
4607
4837
|
return rebuildWithOptionalChain(node);
|
|
4608
4838
|
}
|
|
4609
4839
|
function hasTrailingMemberAccess(node) {
|
|
4610
|
-
return
|
|
4840
|
+
return t42.isMemberExpression(node.object) || t42.isOptionalMemberExpression(node.object);
|
|
4611
4841
|
}
|
|
4612
4842
|
|
|
4613
4843
|
// src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
|
|
@@ -4622,7 +4852,7 @@ function isNestedMemberObject(path8) {
|
|
|
4622
4852
|
}
|
|
4623
4853
|
|
|
4624
4854
|
// src/core/transform/sfc/script/shared/dependency-analyzer/trace-utils.ts
|
|
4625
|
-
import * as
|
|
4855
|
+
import * as t43 from "@babel/types";
|
|
4626
4856
|
function traceBindingSource(binding, seen, depth) {
|
|
4627
4857
|
if (depth <= 0) return null;
|
|
4628
4858
|
const declaratorPath = getVariableDeclaratorPath(binding.path);
|
|
@@ -4634,7 +4864,7 @@ function traceBindingSource(binding, seen, depth) {
|
|
|
4634
4864
|
}
|
|
4635
4865
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4636
4866
|
if (depth <= 0) return null;
|
|
4637
|
-
if (
|
|
4867
|
+
if (t43.isIdentifier(exp)) {
|
|
4638
4868
|
const sourceBinding = scope.getBinding(exp.name);
|
|
4639
4869
|
if (!sourceBinding) return null;
|
|
4640
4870
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -4642,13 +4872,13 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4642
4872
|
}
|
|
4643
4873
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4644
4874
|
}
|
|
4645
|
-
if (
|
|
4875
|
+
if (t43.isMemberExpression(exp) || t43.isOptionalMemberExpression(exp)) {
|
|
4646
4876
|
const root = findRootIdentifier(exp);
|
|
4647
4877
|
if (!root) return null;
|
|
4648
4878
|
const sourceBinding = scope.getBinding(root.name);
|
|
4649
4879
|
if (!sourceBinding) return null;
|
|
4650
4880
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
4651
|
-
return
|
|
4881
|
+
return t43.cloneNode(exp);
|
|
4652
4882
|
}
|
|
4653
4883
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4654
4884
|
if (sourcedRoot) {
|
|
@@ -4656,17 +4886,17 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4656
4886
|
if (rebuilt) {
|
|
4657
4887
|
return rebuilt;
|
|
4658
4888
|
}
|
|
4659
|
-
return
|
|
4889
|
+
return t43.cloneNode(sourcedRoot, true);
|
|
4660
4890
|
}
|
|
4661
4891
|
}
|
|
4662
4892
|
return null;
|
|
4663
4893
|
}
|
|
4664
4894
|
function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
4665
4895
|
const replacedObject = (() => {
|
|
4666
|
-
if (
|
|
4667
|
-
return
|
|
4896
|
+
if (t43.isIdentifier(node.object)) {
|
|
4897
|
+
return t43.cloneNode(nextRoot, true);
|
|
4668
4898
|
}
|
|
4669
|
-
if (
|
|
4899
|
+
if (t43.isMemberExpression(node.object) || t43.isOptionalMemberExpression(node.object)) {
|
|
4670
4900
|
return rebuildMemberWithNewRoot(node.object, nextRoot);
|
|
4671
4901
|
}
|
|
4672
4902
|
return null;
|
|
@@ -4674,15 +4904,15 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4674
4904
|
if (!replacedObject) {
|
|
4675
4905
|
return null;
|
|
4676
4906
|
}
|
|
4677
|
-
const property =
|
|
4678
|
-
if (
|
|
4679
|
-
return
|
|
4907
|
+
const property = t43.cloneNode(node.property, true);
|
|
4908
|
+
if (t43.isMemberExpression(node)) {
|
|
4909
|
+
return t43.memberExpression(
|
|
4680
4910
|
replacedObject,
|
|
4681
4911
|
property,
|
|
4682
4912
|
node.computed
|
|
4683
4913
|
);
|
|
4684
4914
|
}
|
|
4685
|
-
return
|
|
4915
|
+
return t43.optionalMemberExpression(
|
|
4686
4916
|
replacedObject,
|
|
4687
4917
|
property,
|
|
4688
4918
|
node.computed,
|
|
@@ -4693,9 +4923,9 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4693
4923
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4694
4924
|
function analyzeDeps(node, ctx, parentPath) {
|
|
4695
4925
|
if (!parentPath) {
|
|
4696
|
-
return
|
|
4926
|
+
return t44.arrayExpression([]);
|
|
4697
4927
|
}
|
|
4698
|
-
const isFnExpr =
|
|
4928
|
+
const isFnExpr = t44.isArrowFunctionExpression(node) || t44.isFunctionExpression(node);
|
|
4699
4929
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
4700
4930
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
4701
4931
|
const deps = /* @__PURE__ */ new Map();
|
|
@@ -4705,13 +4935,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4705
4935
|
}
|
|
4706
4936
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
4707
4937
|
if (analyzeTargetPath) {
|
|
4708
|
-
if (
|
|
4938
|
+
if (t44.isMemberExpression(analyzeTarget) || t44.isOptionalMemberExpression(analyzeTarget)) {
|
|
4709
4939
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
4710
4940
|
if (rootId) {
|
|
4711
4941
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
4712
4942
|
processedIdentifiers.add(rootId);
|
|
4713
4943
|
}
|
|
4714
|
-
} else if (
|
|
4944
|
+
} else if (t44.isIdentifier(analyzeTarget)) {
|
|
4715
4945
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
4716
4946
|
}
|
|
4717
4947
|
}
|
|
@@ -4763,7 +4993,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4763
4993
|
}
|
|
4764
4994
|
}
|
|
4765
4995
|
}
|
|
4766
|
-
return
|
|
4996
|
+
return t44.arrayExpression(Array.from(deps.values()));
|
|
4767
4997
|
}
|
|
4768
4998
|
|
|
4769
4999
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -4779,7 +5009,7 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4779
5009
|
if (!isVueApiReference(path8, apiName)) {
|
|
4780
5010
|
return;
|
|
4781
5011
|
}
|
|
4782
|
-
if (
|
|
5012
|
+
if (t45.isCallExpression(node)) {
|
|
4783
5013
|
resolveCallNode(path8, adapter, ctx);
|
|
4784
5014
|
} else {
|
|
4785
5015
|
replaceIdName(node, adapter.target);
|
|
@@ -4789,11 +5019,11 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4789
5019
|
};
|
|
4790
5020
|
}
|
|
4791
5021
|
function getApiName(node) {
|
|
4792
|
-
const isCallNode =
|
|
5022
|
+
const isCallNode = t45.isCallExpression(node);
|
|
4793
5023
|
let apiName = "";
|
|
4794
|
-
if (
|
|
5024
|
+
if (t45.isIdentifier(node)) {
|
|
4795
5025
|
apiName = node.name;
|
|
4796
|
-
} else if (isCallNode &&
|
|
5026
|
+
} else if (isCallNode && t45.isIdentifier(node.callee)) {
|
|
4797
5027
|
apiName = node.callee.name;
|
|
4798
5028
|
}
|
|
4799
5029
|
return apiName;
|
|
@@ -4803,7 +5033,7 @@ function resolveCallNode(path8, adapter, ctx) {
|
|
|
4803
5033
|
const { arguments: args } = node;
|
|
4804
5034
|
if (!args.length) return;
|
|
4805
5035
|
const fn = args[0];
|
|
4806
|
-
if (!
|
|
5036
|
+
if (!t45.isArrowFunctionExpression(fn) && !t45.isFunctionExpression(fn)) {
|
|
4807
5037
|
return;
|
|
4808
5038
|
}
|
|
4809
5039
|
const fnPath = path8.get("arguments")[0];
|
|
@@ -4835,7 +5065,7 @@ function isVueImportBinding(binding) {
|
|
|
4835
5065
|
return false;
|
|
4836
5066
|
}
|
|
4837
5067
|
const parent = bindingPath.parentPath?.node;
|
|
4838
|
-
if (!parent || !
|
|
5068
|
+
if (!parent || !t45.isImportDeclaration(parent)) {
|
|
4839
5069
|
return false;
|
|
4840
5070
|
}
|
|
4841
5071
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4903,7 +5133,7 @@ function isSkip(path8) {
|
|
|
4903
5133
|
}
|
|
4904
5134
|
|
|
4905
5135
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-element-ref.ts
|
|
4906
|
-
import * as
|
|
5136
|
+
import * as t46 from "@babel/types";
|
|
4907
5137
|
function resolveElementRef(ctx) {
|
|
4908
5138
|
return {
|
|
4909
5139
|
CallExpression(path8) {
|
|
@@ -4921,14 +5151,14 @@ function resolveElementRef(ctx) {
|
|
|
4921
5151
|
}
|
|
4922
5152
|
if (isCompRefBindings) {
|
|
4923
5153
|
const varDeclaratorPath = getVariableDeclaratorPath(path8)?.node;
|
|
4924
|
-
if (!
|
|
5154
|
+
if (!t46.isIdentifier(varDeclaratorPath?.id)) {
|
|
4925
5155
|
return;
|
|
4926
5156
|
}
|
|
4927
5157
|
const varName = varDeclaratorPath.id.name;
|
|
4928
5158
|
const compRef = refBindings.componentRefs[varName];
|
|
4929
5159
|
if (!compRef) return;
|
|
4930
5160
|
}
|
|
4931
|
-
node.arguments[0] =
|
|
5161
|
+
node.arguments[0] = t46.identifier("null");
|
|
4932
5162
|
resolveTypeParameters(ctx, path8);
|
|
4933
5163
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
4934
5164
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
@@ -4953,27 +5183,27 @@ function resolveTypeParameters(ctx, path8) {
|
|
|
4953
5183
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
4954
5184
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
4955
5185
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
4956
|
-
node.typeParameters =
|
|
5186
|
+
node.typeParameters = t46.tsTypeParameterInstantiation([t46.tsTypeReference(t46.identifier(type))]);
|
|
4957
5187
|
}
|
|
4958
5188
|
}
|
|
4959
5189
|
function resolveRefValueToCurrent(path8) {
|
|
4960
5190
|
const { node } = path8;
|
|
4961
|
-
if (node.computed || !
|
|
5191
|
+
if (node.computed || !t46.isIdentifier(node.property) || node.property.name !== "value") {
|
|
4962
5192
|
return;
|
|
4963
5193
|
}
|
|
4964
5194
|
const rootPath = findRootVariablePath(path8);
|
|
4965
|
-
if (!rootPath?.node || !
|
|
5195
|
+
if (!rootPath?.node || !t46.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
4966
5196
|
return;
|
|
4967
5197
|
}
|
|
4968
5198
|
const rootId = findRootIdentifier(node);
|
|
4969
|
-
if (!
|
|
5199
|
+
if (!t46.isIdentifier(node.object) || node.object.name !== rootId?.name) {
|
|
4970
5200
|
return;
|
|
4971
5201
|
}
|
|
4972
5202
|
node.property.name = "current";
|
|
4973
5203
|
}
|
|
4974
5204
|
|
|
4975
5205
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-expression-memo.ts
|
|
4976
|
-
import * as
|
|
5206
|
+
import * as t47 from "@babel/types";
|
|
4977
5207
|
function resolveExprMemo(ctx, ast) {
|
|
4978
5208
|
const isScriptFile = ctx.inputType !== "sfc";
|
|
4979
5209
|
return {
|
|
@@ -4985,11 +5215,11 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4985
5215
|
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
4986
5216
|
return false;
|
|
4987
5217
|
}
|
|
4988
|
-
if (!
|
|
5218
|
+
if (!t47.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
|
|
4989
5219
|
return false;
|
|
4990
5220
|
}
|
|
4991
|
-
if (
|
|
4992
|
-
if (
|
|
5221
|
+
if (t47.isFunction(init)) return false;
|
|
5222
|
+
if (t47.isCallExpression(init) && t47.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
4993
5223
|
return false;
|
|
4994
5224
|
}
|
|
4995
5225
|
return true;
|
|
@@ -5008,16 +5238,16 @@ function resolveExprMemo(ctx, ast) {
|
|
|
5008
5238
|
}
|
|
5009
5239
|
|
|
5010
5240
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-lint-rules.ts
|
|
5011
|
-
import * as
|
|
5241
|
+
import * as t48 from "@babel/types";
|
|
5012
5242
|
function resolveLintRules(ctx, ast) {
|
|
5013
5243
|
const inScriptFile = ctx.inputType !== "sfc";
|
|
5014
5244
|
return {
|
|
5015
5245
|
CallExpression(path8) {
|
|
5016
5246
|
const { node, parentPath } = path8;
|
|
5017
|
-
if (!
|
|
5247
|
+
if (!t48.isIdentifier(node.callee)) return;
|
|
5018
5248
|
const { name: callName } = node.callee;
|
|
5019
|
-
const addLog = (
|
|
5020
|
-
logger.error(
|
|
5249
|
+
const addLog = (t54) => {
|
|
5250
|
+
logger.error(t54, {
|
|
5021
5251
|
file: ctx.filename,
|
|
5022
5252
|
source: ctx.scriptData.source,
|
|
5023
5253
|
loc: node.loc
|
|
@@ -5062,7 +5292,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
5062
5292
|
|
|
5063
5293
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-provide.ts
|
|
5064
5294
|
import { generate as generate2 } from "@babel/generator";
|
|
5065
|
-
import * as
|
|
5295
|
+
import * as t49 from "@babel/types";
|
|
5066
5296
|
function resolveProvide(ctx) {
|
|
5067
5297
|
const { filename, scriptData, inputType } = ctx;
|
|
5068
5298
|
if (inputType !== "sfc") {
|
|
@@ -5105,13 +5335,13 @@ function findOrCreateCtxProvider(root) {
|
|
|
5105
5335
|
function assignProviderValue(target, key, value) {
|
|
5106
5336
|
const getRawExp = (exp) => {
|
|
5107
5337
|
if (!exp) return "''";
|
|
5108
|
-
if (
|
|
5338
|
+
if (t49.isStringLiteral(exp)) {
|
|
5109
5339
|
return JSON.stringify(exp.value);
|
|
5110
5340
|
}
|
|
5111
|
-
if (
|
|
5341
|
+
if (t49.isNumericLiteral(exp)) {
|
|
5112
5342
|
return exp.value.toString();
|
|
5113
5343
|
}
|
|
5114
|
-
if (
|
|
5344
|
+
if (t49.isIdentifier(exp)) {
|
|
5115
5345
|
return exp.name;
|
|
5116
5346
|
}
|
|
5117
5347
|
try {
|
|
@@ -5127,16 +5357,16 @@ function assignProviderValue(target, key, value) {
|
|
|
5127
5357
|
}
|
|
5128
5358
|
|
|
5129
5359
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
5130
|
-
import * as
|
|
5360
|
+
import * as t50 from "@babel/types";
|
|
5131
5361
|
function resolveRenameAdapter(ctx) {
|
|
5132
5362
|
return {
|
|
5133
5363
|
"CallExpression|Identifier"(path8) {
|
|
5134
5364
|
const node = path8.node;
|
|
5135
|
-
const isCallNode =
|
|
5365
|
+
const isCallNode = t50.isCallExpression(node);
|
|
5136
5366
|
let apiName = "";
|
|
5137
|
-
if (
|
|
5367
|
+
if (t50.isIdentifier(node)) {
|
|
5138
5368
|
apiName = node.name;
|
|
5139
|
-
} else if (isCallNode &&
|
|
5369
|
+
} else if (isCallNode && t50.isIdentifier(node.callee)) {
|
|
5140
5370
|
apiName = node.callee.name;
|
|
5141
5371
|
}
|
|
5142
5372
|
if (!apiName) {
|
|
@@ -5198,7 +5428,7 @@ function isVueImportBinding2(binding) {
|
|
|
5198
5428
|
return false;
|
|
5199
5429
|
}
|
|
5200
5430
|
const parent = bindingPath.parentPath?.node;
|
|
5201
|
-
if (!parent || !
|
|
5431
|
+
if (!parent || !t50.isImportDeclaration(parent)) {
|
|
5202
5432
|
return false;
|
|
5203
5433
|
}
|
|
5204
5434
|
const source = parent.source.value.toLowerCase();
|
|
@@ -5223,7 +5453,9 @@ function processVueSyntax2(ast, ctx) {
|
|
|
5223
5453
|
resolveDefineAsyncComponent,
|
|
5224
5454
|
resolveEmitCalls,
|
|
5225
5455
|
// feature: https://github.com/vureact-js/core/issues/6
|
|
5226
|
-
resolveUseAttrs
|
|
5456
|
+
resolveUseAttrs,
|
|
5457
|
+
// feature: https://github.com/vureact-js/core/issues/56
|
|
5458
|
+
resolveDefineModel
|
|
5227
5459
|
]
|
|
5228
5460
|
},
|
|
5229
5461
|
process: {
|
|
@@ -5266,7 +5498,6 @@ function vueSyntaxProcessor2(ast, ctx, options) {
|
|
|
5266
5498
|
}
|
|
5267
5499
|
|
|
5268
5500
|
// src/core/transform/sfc/script/index.ts
|
|
5269
|
-
var SCRIPT_IR_KEY = "__vureact_script_block_ir";
|
|
5270
5501
|
function resolveScript2(ast, ctx) {
|
|
5271
5502
|
const scriptIR = createScriptIR();
|
|
5272
5503
|
setScriptIR(ctx, scriptIR);
|
|
@@ -5280,14 +5511,14 @@ function resolveScript2(ast, ctx) {
|
|
|
5280
5511
|
return scriptIR;
|
|
5281
5512
|
}
|
|
5282
5513
|
function getScriptIR(ctx) {
|
|
5283
|
-
const ir = ctx.scriptData
|
|
5514
|
+
const ir = ctx.scriptData.__vureact_script_block_ir;
|
|
5284
5515
|
if (!ir) {
|
|
5285
5516
|
throw new Error("Script IR is not initialized for current compilation context");
|
|
5286
5517
|
}
|
|
5287
5518
|
return ir;
|
|
5288
5519
|
}
|
|
5289
5520
|
function setScriptIR(ctx, ir) {
|
|
5290
|
-
ctx.scriptData
|
|
5521
|
+
ctx.scriptData.__vureact_script_block_ir = ir;
|
|
5291
5522
|
}
|
|
5292
5523
|
function createScriptIR() {
|
|
5293
5524
|
return {
|
|
@@ -5339,15 +5570,15 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
5339
5570
|
}
|
|
5340
5571
|
|
|
5341
5572
|
// src/core/transform/sfc/template/shared/prop-ir-utils.ts
|
|
5342
|
-
import * as
|
|
5573
|
+
import * as t52 from "@babel/types";
|
|
5343
5574
|
|
|
5344
5575
|
// src/shared/string-code-types.ts
|
|
5345
5576
|
import { parseExpression as parseExpression3 } from "@babel/parser";
|
|
5346
|
-
import * as
|
|
5577
|
+
import * as t51 from "@babel/types";
|
|
5347
5578
|
var strCodeTypes = {
|
|
5348
|
-
isIdentifier:
|
|
5579
|
+
isIdentifier: isIdentifier30,
|
|
5349
5580
|
isSimpleExpression,
|
|
5350
|
-
isStringLiteral:
|
|
5581
|
+
isStringLiteral: isStringLiteral14
|
|
5351
5582
|
};
|
|
5352
5583
|
function isSimpleExpression(code, excludeVar = false) {
|
|
5353
5584
|
let node;
|
|
@@ -5356,38 +5587,38 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
5356
5587
|
} catch {
|
|
5357
5588
|
return false;
|
|
5358
5589
|
}
|
|
5359
|
-
if (
|
|
5590
|
+
if (t51.isLiteral(node)) {
|
|
5360
5591
|
return true;
|
|
5361
5592
|
}
|
|
5362
|
-
if (!excludeVar &&
|
|
5593
|
+
if (!excludeVar && t51.isIdentifier(node)) {
|
|
5363
5594
|
return true;
|
|
5364
5595
|
}
|
|
5365
|
-
if (
|
|
5366
|
-
return isSimpleExpression(node.object) &&
|
|
5596
|
+
if (t51.isMemberExpression(node)) {
|
|
5597
|
+
return isSimpleExpression(node.object) && t51.isIdentifier(node.property);
|
|
5367
5598
|
}
|
|
5368
|
-
if (
|
|
5599
|
+
if (t51.isObjectExpression(node) || t51.isArrayExpression(node)) {
|
|
5369
5600
|
return false;
|
|
5370
5601
|
}
|
|
5371
|
-
if (
|
|
5602
|
+
if (t51.isCallExpression(node) || t51.isAssignmentExpression(node)) {
|
|
5372
5603
|
return false;
|
|
5373
5604
|
}
|
|
5374
|
-
if (
|
|
5605
|
+
if (t51.isBinaryExpression(node) || t51.isUnaryExpression(node)) {
|
|
5375
5606
|
return true;
|
|
5376
5607
|
}
|
|
5377
5608
|
return false;
|
|
5378
5609
|
}
|
|
5379
|
-
function
|
|
5610
|
+
function isIdentifier30(code) {
|
|
5380
5611
|
try {
|
|
5381
5612
|
const node = parseExpression3(code);
|
|
5382
|
-
return
|
|
5613
|
+
return t51.isIdentifier(node);
|
|
5383
5614
|
} catch {
|
|
5384
5615
|
return false;
|
|
5385
5616
|
}
|
|
5386
5617
|
}
|
|
5387
|
-
function
|
|
5618
|
+
function isStringLiteral14(code) {
|
|
5388
5619
|
try {
|
|
5389
5620
|
const node = parseExpression3(code);
|
|
5390
|
-
return
|
|
5621
|
+
return t51.isStringLiteral(node);
|
|
5391
5622
|
} catch {
|
|
5392
5623
|
return false;
|
|
5393
5624
|
}
|
|
@@ -5530,11 +5761,11 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5530
5761
|
const rule = ADAPTER_RULES.runtime;
|
|
5531
5762
|
const setNameIdentifier = (target, valueName) => {
|
|
5532
5763
|
target.content = valueName;
|
|
5533
|
-
target.ast =
|
|
5764
|
+
target.ast = t52.jsxIdentifier(valueName);
|
|
5534
5765
|
};
|
|
5535
|
-
const setValueExpression = (target, content,
|
|
5766
|
+
const setValueExpression = (target, content, isStringLiteral15) => {
|
|
5536
5767
|
target.content = content;
|
|
5537
|
-
target.ast = resolveStringExpr(content, ctx,
|
|
5768
|
+
target.ast = resolveStringExpr(content, ctx, isStringLiteral15);
|
|
5538
5769
|
};
|
|
5539
5770
|
const createRuntimeCall = (fnName, args) => {
|
|
5540
5771
|
const fnArgs = args.filter(Boolean).join(",");
|
|
@@ -5543,13 +5774,13 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5543
5774
|
const safeTypeAssertion = isTs ? valIsUndef ? "as never" : "" : "";
|
|
5544
5775
|
return `${fnName}(${fnArgs}) ${safeTypeAssertion}`;
|
|
5545
5776
|
};
|
|
5546
|
-
const applyRuntimeExpression = (expression, setName = false, nameIdentifier,
|
|
5777
|
+
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral15) => {
|
|
5547
5778
|
if (setName && nameIdentifier) {
|
|
5548
5779
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
5549
5780
|
}
|
|
5550
5781
|
const dir = rule.dir;
|
|
5551
5782
|
recordImport(ctx, dir.package, dir.target);
|
|
5552
|
-
setValueExpression(value.babelExp, expression,
|
|
5783
|
+
setValueExpression(value.babelExp, expression, isStringLiteral15);
|
|
5553
5784
|
};
|
|
5554
5785
|
if (ir.isKeyLessVBind) {
|
|
5555
5786
|
const dirKeyless = rule.dirKeyless;
|
|
@@ -5970,12 +6201,12 @@ function resolvePropertyIR(propsIR, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
5970
6201
|
content = propsIR.value.content = parseStyleString(content);
|
|
5971
6202
|
}
|
|
5972
6203
|
if (isDynamic) {
|
|
5973
|
-
const
|
|
5974
|
-
if (
|
|
6204
|
+
const isStringLiteral15 = strCodeTypes.isStringLiteral(content);
|
|
6205
|
+
if (isStringLiteral15) {
|
|
5975
6206
|
content = normalizeString(content);
|
|
5976
6207
|
propsIR.value.content = content;
|
|
5977
6208
|
}
|
|
5978
|
-
propsIR.value.isStringLiteral =
|
|
6209
|
+
propsIR.value.isStringLiteral = isStringLiteral15;
|
|
5979
6210
|
}
|
|
5980
6211
|
const existing = findSameProp(nodeIR.props, propsIR);
|
|
5981
6212
|
if (existing) {
|
|
@@ -6280,7 +6511,7 @@ function applyValueModifiers(valueExp, modifiers) {
|
|
|
6280
6511
|
}
|
|
6281
6512
|
|
|
6282
6513
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
|
|
6283
|
-
import * as
|
|
6514
|
+
import * as t53 from "@babel/types";
|
|
6284
6515
|
function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
6285
6516
|
const arg = directive.arg;
|
|
6286
6517
|
const exp = directive.exp;
|
|
@@ -6338,10 +6569,10 @@ function resolveHandler(handlerContent, ctx, modifiers) {
|
|
|
6338
6569
|
return handler;
|
|
6339
6570
|
}
|
|
6340
6571
|
function isConsoleCall(expr) {
|
|
6341
|
-
return
|
|
6572
|
+
return t53.isCallExpression(expr) && t53.isMemberExpression(expr.callee) && t53.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
|
|
6342
6573
|
}
|
|
6343
6574
|
function isFnReference(expr) {
|
|
6344
|
-
return
|
|
6575
|
+
return t53.isIdentifier(expr) || t53.isMemberExpression(expr) || t53.isFunction(expr);
|
|
6345
6576
|
}
|
|
6346
6577
|
|
|
6347
6578
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
|
|
@@ -6694,7 +6925,7 @@ function transform(ast, ctx, options) {
|
|
|
6694
6925
|
}
|
|
6695
6926
|
|
|
6696
6927
|
// package.json
|
|
6697
|
-
var version = "1.
|
|
6928
|
+
var version = "1.9.0";
|
|
6698
6929
|
var bin = {
|
|
6699
6930
|
vureact: "bin/vureact.js"
|
|
6700
6931
|
};
|
|
@@ -7248,7 +7479,8 @@ var CompilationContext = class {
|
|
|
7248
7479
|
refField: "expose"
|
|
7249
7480
|
},
|
|
7250
7481
|
declaredOptions: {},
|
|
7251
|
-
source: ""
|
|
7482
|
+
source: "",
|
|
7483
|
+
__vureact_script_block_ir: void 0
|
|
7252
7484
|
},
|
|
7253
7485
|
styleData: {
|
|
7254
7486
|
filePath: ""
|