@vureact/compiler-core 1.8.1 → 1.8.4
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 +64 -61
- package/README.zh-CN.md +193 -0
- package/lib/{chunk-SGP2JC7F.js → chunk-EH3325ZP.js} +465 -409
- package/lib/{chunk-QXYYGKFW.esm.js → chunk-S6IFUYGO.esm.js} +416 -360
- package/lib/cli.esm.js +15 -14
- package/lib/cli.js +20 -19
- package/lib/compiler-core.d.cts +0 -1
- package/lib/compiler-core.d.ts +0 -1
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +4 -3
- package/README.en.md +0 -192
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vureact/compiler-core v1.8.
|
|
2
|
+
* @vureact/compiler-core v1.8.4
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -39,7 +39,7 @@ var RUNTIME_PACKAGES = {
|
|
|
39
39
|
},
|
|
40
40
|
runtime: {
|
|
41
41
|
name: PACKAGE_NAME.runtime,
|
|
42
|
-
version: "^1.1.
|
|
42
|
+
version: "^1.1.1"
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
var STYLE_MODULE_NAME = "$style";
|
|
@@ -311,7 +311,8 @@ var ADAPTER_RULES = {
|
|
|
311
311
|
type: "rename"
|
|
312
312
|
},
|
|
313
313
|
dirOn: {
|
|
314
|
-
|
|
314
|
+
// fix: https://github.com/vureact-js/core/issues/49
|
|
315
|
+
target: "dir.on",
|
|
315
316
|
package: PACKAGE_NAME.runtime,
|
|
316
317
|
type: "rename"
|
|
317
318
|
},
|
|
@@ -568,7 +569,8 @@ function buildJsxChildrenProcessor(nodeIR, ctx, state) {
|
|
|
568
569
|
}
|
|
569
570
|
function buildJsxChildren(children, ctx) {
|
|
570
571
|
const result = [];
|
|
571
|
-
|
|
572
|
+
const normalizedChildren = Array.isArray(children) ? children : [];
|
|
573
|
+
for (const childIR of normalizedChildren) {
|
|
572
574
|
const jsxNode = buildJsxNode(childIR, ctx);
|
|
573
575
|
if (!jsxNode) continue;
|
|
574
576
|
result.push(jsxNode);
|
|
@@ -1314,9 +1316,6 @@ function resolveComponentName(ctx) {
|
|
|
1314
1316
|
if (!name) {
|
|
1315
1317
|
const defaultName = basename(filename).split(".")[0] || `FC${genHashByXXH(filename)}`;
|
|
1316
1318
|
name = capitalize(camelCase(defaultName));
|
|
1317
|
-
logger.warn(`Unnamed component detected. Using file name: <${name}>`, {
|
|
1318
|
-
file: filename
|
|
1319
|
-
});
|
|
1320
1319
|
}
|
|
1321
1320
|
scriptData.declaredOptions.name = name;
|
|
1322
1321
|
return t13.identifier(name);
|
|
@@ -3223,8 +3222,51 @@ function resolveSfcCssImport(ctx) {
|
|
|
3223
3222
|
scriptIR.imports.push(importDecl);
|
|
3224
3223
|
}
|
|
3225
3224
|
|
|
3226
|
-
// src/core/transform/sfc/script/syntax-processor/
|
|
3225
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-vue-type-as-any.ts
|
|
3227
3226
|
import * as t25 from "@babel/types";
|
|
3227
|
+
function resolveVueTypeAsAny(ctx) {
|
|
3228
|
+
return {
|
|
3229
|
+
TSTypeReference(path8) {
|
|
3230
|
+
if (isVueTypeRef(path8)) {
|
|
3231
|
+
replaceNode(path8, t25.tsAnyKeyword(), path8.node);
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
function isVueTypeRef(path8) {
|
|
3237
|
+
const id = resolveTypeNameId(path8.node.typeName);
|
|
3238
|
+
return id !== null && isVueImport(id, path8);
|
|
3239
|
+
}
|
|
3240
|
+
function resolveTypeNameId(typeName) {
|
|
3241
|
+
if (t25.isIdentifier(typeName)) {
|
|
3242
|
+
return typeName;
|
|
3243
|
+
}
|
|
3244
|
+
if (t25.isTSQualifiedName(typeName)) {
|
|
3245
|
+
let node = typeName;
|
|
3246
|
+
while (t25.isTSQualifiedName(node)) {
|
|
3247
|
+
node = node.left;
|
|
3248
|
+
}
|
|
3249
|
+
return t25.isIdentifier(node) ? node : null;
|
|
3250
|
+
}
|
|
3251
|
+
return null;
|
|
3252
|
+
}
|
|
3253
|
+
function isVueImport(id, path8) {
|
|
3254
|
+
const binding = path8.scope.getBinding(id.name);
|
|
3255
|
+
if (!binding) return false;
|
|
3256
|
+
const bp = binding.path;
|
|
3257
|
+
if (!bp.isImportSpecifier() && !bp.isImportDefaultSpecifier()) {
|
|
3258
|
+
return false;
|
|
3259
|
+
}
|
|
3260
|
+
const importDecl = bp.parentPath;
|
|
3261
|
+
if (!importDecl.isImportDeclaration()) {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3264
|
+
const moduleName = importDecl.node.source.value;
|
|
3265
|
+
return VUE_PACKAGES.some((pkg) => moduleName.includes(pkg));
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-async-component.ts
|
|
3269
|
+
import * as t26 from "@babel/types";
|
|
3228
3270
|
function resolveDefineAsyncComponent(ctx) {
|
|
3229
3271
|
return {
|
|
3230
3272
|
CallExpression(path8) {
|
|
@@ -3233,11 +3275,11 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3233
3275
|
return;
|
|
3234
3276
|
}
|
|
3235
3277
|
const [arg] = node.arguments;
|
|
3236
|
-
if (!
|
|
3278
|
+
if (!t26.isObjectExpression(arg)) {
|
|
3237
3279
|
return;
|
|
3238
3280
|
}
|
|
3239
3281
|
for (const prop of arg.properties) {
|
|
3240
|
-
if (!
|
|
3282
|
+
if (!t26.isObjectProperty(prop) || !t26.isIdentifier(prop.key) || prop.key.name !== "hydrate") {
|
|
3241
3283
|
continue;
|
|
3242
3284
|
}
|
|
3243
3285
|
logger.warn('Unsupported option "hydrate"', {
|
|
@@ -3252,24 +3294,24 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3252
3294
|
}
|
|
3253
3295
|
|
|
3254
3296
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
3255
|
-
import * as
|
|
3297
|
+
import * as t28 from "@babel/types";
|
|
3256
3298
|
|
|
3257
3299
|
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
3258
|
-
import * as
|
|
3300
|
+
import * as t27 from "@babel/types";
|
|
3259
3301
|
function createUseCallback(body, deps) {
|
|
3260
|
-
return
|
|
3302
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useCallback), [
|
|
3261
3303
|
body,
|
|
3262
|
-
deps ??
|
|
3304
|
+
deps ?? t27.arrayExpression([])
|
|
3263
3305
|
]);
|
|
3264
3306
|
}
|
|
3265
3307
|
function createUseMemo(body, deps) {
|
|
3266
|
-
return
|
|
3267
|
-
|
|
3268
|
-
deps ??
|
|
3308
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useMemo), [
|
|
3309
|
+
t27.arrowFunctionExpression([], body),
|
|
3310
|
+
deps ?? t27.arrayExpression([])
|
|
3269
3311
|
]);
|
|
3270
3312
|
}
|
|
3271
3313
|
function createUseImperativeHandle(refId, init) {
|
|
3272
|
-
return
|
|
3314
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
3273
3315
|
}
|
|
3274
3316
|
|
|
3275
3317
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
@@ -3290,16 +3332,16 @@ function resolveDefineExpose(ctx) {
|
|
|
3290
3332
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
3291
3333
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
3292
3334
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3293
|
-
if (!
|
|
3335
|
+
if (!t28.isObjectExpression(expose) && !t28.isFunction(expose)) {
|
|
3294
3336
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
3295
3337
|
file: filename,
|
|
3296
3338
|
loc: expose.loc,
|
|
3297
3339
|
source: scriptData.source
|
|
3298
3340
|
});
|
|
3299
3341
|
}
|
|
3300
|
-
const init = !
|
|
3342
|
+
const init = !t28.isFunction(expose) ? t28.arrowFunctionExpression([], expose) : expose;
|
|
3301
3343
|
const { forwardRef } = scriptData;
|
|
3302
|
-
const newNode = createUseImperativeHandle(
|
|
3344
|
+
const newNode = createUseImperativeHandle(t28.identifier(forwardRef.refField), init);
|
|
3303
3345
|
forwardRef.enabled = true;
|
|
3304
3346
|
replaceNode(path8, newNode, node);
|
|
3305
3347
|
}
|
|
@@ -3320,7 +3362,7 @@ function resolveDefineOptions(ctx) {
|
|
|
3320
3362
|
}
|
|
3321
3363
|
|
|
3322
3364
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-emit-calls.ts
|
|
3323
|
-
import * as
|
|
3365
|
+
import * as t29 from "@babel/types";
|
|
3324
3366
|
function resolveEmitCalls(ctx) {
|
|
3325
3367
|
const formatEmitEventName = (raw) => {
|
|
3326
3368
|
if (raw.startsWith("update:")) {
|
|
@@ -3334,7 +3376,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3334
3376
|
CallExpression(path8) {
|
|
3335
3377
|
const { node } = path8;
|
|
3336
3378
|
const { filename, templateData, scriptData } = ctx;
|
|
3337
|
-
if (!
|
|
3379
|
+
if (!t29.isIdentifier(node.callee)) return;
|
|
3338
3380
|
const { name } = node.callee;
|
|
3339
3381
|
const checkIfFromDefineEmits = () => {
|
|
3340
3382
|
let result = false;
|
|
@@ -3346,7 +3388,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3346
3388
|
const binding = path8.scope.getBinding(name);
|
|
3347
3389
|
if (binding) {
|
|
3348
3390
|
const parent = binding.path.node;
|
|
3349
|
-
if (
|
|
3391
|
+
if (t29.isVariableDeclarator(parent) && t29.isCallExpression(parent.init) && t29.isIdentifier(parent.init.callee)) {
|
|
3350
3392
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
3351
3393
|
}
|
|
3352
3394
|
}
|
|
@@ -3356,9 +3398,9 @@ function resolveEmitCalls(ctx) {
|
|
|
3356
3398
|
if (!checkIfFromDefineEmits()) return;
|
|
3357
3399
|
const [callee, ...args] = node.arguments;
|
|
3358
3400
|
let propCall;
|
|
3359
|
-
if (
|
|
3401
|
+
if (t29.isStringLiteral(callee)) {
|
|
3360
3402
|
const eventName = formatEmitEventName(callee.value);
|
|
3361
|
-
propCall = createPropCall(ctx.propField,
|
|
3403
|
+
propCall = createPropCall(ctx.propField, t29.identifier(eventName), args);
|
|
3362
3404
|
} else {
|
|
3363
3405
|
propCall = createPropCall(ctx.propField, callee, args, true);
|
|
3364
3406
|
logger.error(
|
|
@@ -3375,38 +3417,38 @@ function resolveEmitCalls(ctx) {
|
|
|
3375
3417
|
};
|
|
3376
3418
|
}
|
|
3377
3419
|
function createPropCall(rootName, callee, args, computed = false) {
|
|
3378
|
-
return
|
|
3379
|
-
|
|
3420
|
+
return t29.optionalCallExpression(
|
|
3421
|
+
t29.memberExpression(t29.identifier(rootName), callee, computed),
|
|
3380
3422
|
args,
|
|
3381
3423
|
true
|
|
3382
3424
|
);
|
|
3383
3425
|
}
|
|
3384
3426
|
|
|
3385
3427
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/index.ts
|
|
3386
|
-
import * as
|
|
3428
|
+
import * as t37 from "@babel/types";
|
|
3387
3429
|
|
|
3388
3430
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
|
|
3389
|
-
import * as
|
|
3431
|
+
import * as t31 from "@babel/types";
|
|
3390
3432
|
|
|
3391
3433
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/shared.ts
|
|
3392
|
-
import * as
|
|
3434
|
+
import * as t30 from "@babel/types";
|
|
3393
3435
|
function cloneCallableParams(params) {
|
|
3394
3436
|
const cloneCallableParam = (param, index) => {
|
|
3395
|
-
if (
|
|
3437
|
+
if (t30.isRestElement(param)) {
|
|
3396
3438
|
const arg = param.argument;
|
|
3397
|
-
const name =
|
|
3398
|
-
const rest =
|
|
3399
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
3439
|
+
const name = t30.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
3440
|
+
const rest = t30.restElement(t30.identifier(name));
|
|
3441
|
+
rest.typeAnnotation = param.typeAnnotation || (t30.isIdentifier(arg) ? arg.typeAnnotation : null) || t30.tsTypeAnnotation(t30.tsArrayType(t30.tsAnyKeyword()));
|
|
3400
3442
|
return rest;
|
|
3401
3443
|
}
|
|
3402
|
-
if (
|
|
3403
|
-
const id =
|
|
3444
|
+
if (t30.isIdentifier(param)) {
|
|
3445
|
+
const id = t30.identifier(param.name || `arg${index}`);
|
|
3404
3446
|
id.optional = param.optional;
|
|
3405
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
3447
|
+
id.typeAnnotation = param.typeAnnotation || t30.tsTypeAnnotation(t30.tsAnyKeyword());
|
|
3406
3448
|
return id;
|
|
3407
3449
|
}
|
|
3408
|
-
const fallback =
|
|
3409
|
-
fallback.typeAnnotation =
|
|
3450
|
+
const fallback = t30.identifier(`arg${index}`);
|
|
3451
|
+
fallback.typeAnnotation = t30.tsTypeAnnotation(t30.tsAnyKeyword());
|
|
3410
3452
|
return fallback;
|
|
3411
3453
|
};
|
|
3412
3454
|
return params.map(cloneCallableParam);
|
|
@@ -3416,18 +3458,18 @@ function cloneCallableParams(params) {
|
|
|
3416
3458
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
3417
3459
|
return {
|
|
3418
3460
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3419
|
-
if (!
|
|
3461
|
+
if (!t31.isProgram(path8.parent)) return;
|
|
3420
3462
|
const { node } = path8;
|
|
3421
|
-
if (
|
|
3422
|
-
const typeLiteral =
|
|
3463
|
+
if (t31.isTSInterfaceDeclaration(node)) {
|
|
3464
|
+
const typeLiteral = t31.tsTypeLiteral(node.body.body);
|
|
3423
3465
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
3424
3466
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
3425
|
-
if (resolved &&
|
|
3467
|
+
if (resolved && t31.isTSTypeLiteral(resolved)) {
|
|
3426
3468
|
node.body.body = resolved.members;
|
|
3427
3469
|
}
|
|
3428
3470
|
return;
|
|
3429
3471
|
}
|
|
3430
|
-
if (
|
|
3472
|
+
if (t31.isTSTypeAliasDeclaration(node)) {
|
|
3431
3473
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
3432
3474
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
3433
3475
|
if (resolved) {
|
|
@@ -3438,47 +3480,47 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
3438
3480
|
};
|
|
3439
3481
|
}
|
|
3440
3482
|
function resolveTopLevelEmitType(tsType) {
|
|
3441
|
-
if (
|
|
3483
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3442
3484
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
3443
3485
|
}
|
|
3444
|
-
if (
|
|
3486
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3445
3487
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3446
3488
|
return tsType;
|
|
3447
3489
|
}
|
|
3448
3490
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
3449
|
-
return
|
|
3491
|
+
return t31.tsTypeReference(
|
|
3450
3492
|
tsType.typeName,
|
|
3451
|
-
|
|
3493
|
+
t31.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3452
3494
|
);
|
|
3453
3495
|
}
|
|
3454
|
-
if (
|
|
3496
|
+
if (t31.isTSIntersectionType(tsType)) {
|
|
3455
3497
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3456
3498
|
if (!types.length) return null;
|
|
3457
3499
|
if (types.length === 1) return types[0];
|
|
3458
|
-
return
|
|
3500
|
+
return t31.tsIntersectionType(types);
|
|
3459
3501
|
}
|
|
3460
|
-
if (
|
|
3502
|
+
if (t31.isTSUnionType(tsType)) {
|
|
3461
3503
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3462
3504
|
if (!types.length) return null;
|
|
3463
3505
|
if (types.length === 1) return types[0];
|
|
3464
|
-
return
|
|
3506
|
+
return t31.tsUnionType(types);
|
|
3465
3507
|
}
|
|
3466
|
-
if (
|
|
3508
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3467
3509
|
const members = [];
|
|
3468
3510
|
for (const member of tsType.members) {
|
|
3469
|
-
if (
|
|
3511
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3470
3512
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3471
3513
|
continue;
|
|
3472
3514
|
}
|
|
3473
3515
|
members.push(member);
|
|
3474
3516
|
}
|
|
3475
3517
|
if (!members.length) return null;
|
|
3476
|
-
return
|
|
3518
|
+
return t31.tsTypeLiteral(members);
|
|
3477
3519
|
}
|
|
3478
|
-
if (
|
|
3520
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3479
3521
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3480
3522
|
if (!props.length) return null;
|
|
3481
|
-
return
|
|
3523
|
+
return t31.tsTypeLiteral(props);
|
|
3482
3524
|
}
|
|
3483
3525
|
return tsType;
|
|
3484
3526
|
}
|
|
@@ -3499,41 +3541,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
3499
3541
|
propsTSIface: { emitTypes }
|
|
3500
3542
|
} = ctx.scriptData;
|
|
3501
3543
|
const members = [];
|
|
3502
|
-
if (
|
|
3544
|
+
if (t31.isArrayExpression(runtimeArg)) {
|
|
3503
3545
|
for (const element of runtimeArg.elements) {
|
|
3504
|
-
if (!element || !
|
|
3546
|
+
if (!element || !t31.isStringLiteral(element)) continue;
|
|
3505
3547
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
3506
3548
|
const key = buildKey(handlerName);
|
|
3507
|
-
const fnType =
|
|
3549
|
+
const fnType = t31.tsFunctionType(
|
|
3508
3550
|
null,
|
|
3509
3551
|
[createRestAnyParam("args")],
|
|
3510
|
-
|
|
3552
|
+
t31.tsTypeAnnotation(t31.tsAnyKeyword())
|
|
3511
3553
|
);
|
|
3512
|
-
const prop =
|
|
3554
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3513
3555
|
prop.optional = true;
|
|
3514
3556
|
members.push(prop);
|
|
3515
3557
|
}
|
|
3516
3558
|
if (members.length) {
|
|
3517
|
-
emitTypes.push(
|
|
3559
|
+
emitTypes.push(t31.tsTypeLiteral(members));
|
|
3518
3560
|
}
|
|
3519
3561
|
return;
|
|
3520
3562
|
}
|
|
3521
|
-
if (
|
|
3563
|
+
if (t31.isObjectExpression(runtimeArg)) {
|
|
3522
3564
|
for (const prop of runtimeArg.properties) {
|
|
3523
|
-
if (!
|
|
3524
|
-
if (
|
|
3565
|
+
if (!t31.isObjectProperty(prop)) continue;
|
|
3566
|
+
if (t31.isSpreadElement(prop)) continue;
|
|
3525
3567
|
const rawName = resolvePropName(prop.key);
|
|
3526
3568
|
if (!rawName) continue;
|
|
3527
3569
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3528
3570
|
const key = buildKey(handlerName);
|
|
3529
|
-
const params =
|
|
3530
|
-
const fnType =
|
|
3531
|
-
const propSig =
|
|
3571
|
+
const params = t31.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
3572
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(t31.tsAnyKeyword()));
|
|
3573
|
+
const propSig = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3532
3574
|
propSig.optional = true;
|
|
3533
3575
|
members.push(propSig);
|
|
3534
3576
|
}
|
|
3535
3577
|
if (members.length) {
|
|
3536
|
-
emitTypes.push(
|
|
3578
|
+
emitTypes.push(t31.tsTypeLiteral(members));
|
|
3537
3579
|
}
|
|
3538
3580
|
}
|
|
3539
3581
|
}
|
|
@@ -3554,129 +3596,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
3554
3596
|
return `on${name}`;
|
|
3555
3597
|
}
|
|
3556
3598
|
function resolvePropName(key) {
|
|
3557
|
-
if (
|
|
3558
|
-
if (
|
|
3559
|
-
if (
|
|
3599
|
+
if (t31.isIdentifier(key)) return key.name;
|
|
3600
|
+
if (t31.isStringLiteral(key)) return key.value;
|
|
3601
|
+
if (t31.isNumericLiteral(key)) return String(key.value);
|
|
3560
3602
|
return null;
|
|
3561
3603
|
}
|
|
3562
3604
|
function buildKey(name) {
|
|
3563
|
-
return
|
|
3605
|
+
return t31.isValidIdentifier(name) ? t31.identifier(name) : t31.stringLiteral(name);
|
|
3564
3606
|
}
|
|
3565
3607
|
function createRestAnyParam(name) {
|
|
3566
|
-
const id =
|
|
3567
|
-
const rest =
|
|
3568
|
-
rest.typeAnnotation =
|
|
3608
|
+
const id = t31.identifier(name);
|
|
3609
|
+
const rest = t31.restElement(id);
|
|
3610
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(t31.tsArrayType(t31.tsAnyKeyword()));
|
|
3569
3611
|
return rest;
|
|
3570
3612
|
}
|
|
3571
3613
|
function resolveRuntimeTupleParams(value) {
|
|
3572
3614
|
const params = [];
|
|
3573
3615
|
value.elements.forEach((element, index) => {
|
|
3574
3616
|
if (!element) return;
|
|
3575
|
-
if (
|
|
3617
|
+
if (t31.isSpreadElement(element)) {
|
|
3576
3618
|
params.push(createRestAnyParam(`args${index}`));
|
|
3577
3619
|
return;
|
|
3578
3620
|
}
|
|
3579
|
-
if (
|
|
3580
|
-
const id =
|
|
3581
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
3621
|
+
if (t31.isIdentifier(element)) {
|
|
3622
|
+
const id = t31.identifier(element.name);
|
|
3623
|
+
id.typeAnnotation = element.typeAnnotation || t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3582
3624
|
params.push(id);
|
|
3583
3625
|
return;
|
|
3584
3626
|
}
|
|
3585
|
-
if (
|
|
3586
|
-
const id =
|
|
3587
|
-
id.typeAnnotation =
|
|
3627
|
+
if (t31.isTSAsExpression(element)) {
|
|
3628
|
+
const id = t31.identifier(`arg${index}`);
|
|
3629
|
+
id.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3588
3630
|
params.push(id);
|
|
3589
3631
|
return;
|
|
3590
3632
|
}
|
|
3591
|
-
const fallback =
|
|
3592
|
-
fallback.typeAnnotation =
|
|
3633
|
+
const fallback = t31.identifier(`arg${index}`);
|
|
3634
|
+
fallback.typeAnnotation = t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3593
3635
|
params.push(fallback);
|
|
3594
3636
|
});
|
|
3595
3637
|
return params;
|
|
3596
3638
|
}
|
|
3597
3639
|
function resolveExplicitEmitType(tsType) {
|
|
3598
|
-
if (
|
|
3640
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3599
3641
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
3600
3642
|
}
|
|
3601
|
-
if (
|
|
3643
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3602
3644
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3603
3645
|
return tsType;
|
|
3604
3646
|
}
|
|
3605
3647
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
3606
|
-
return
|
|
3648
|
+
return t31.tsTypeReference(
|
|
3607
3649
|
tsType.typeName,
|
|
3608
|
-
|
|
3650
|
+
t31.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3609
3651
|
);
|
|
3610
3652
|
}
|
|
3611
|
-
if (
|
|
3653
|
+
if (t31.isTSIntersectionType(tsType)) {
|
|
3612
3654
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3613
3655
|
if (!types.length) return null;
|
|
3614
3656
|
if (types.length === 1) return types[0];
|
|
3615
|
-
return
|
|
3657
|
+
return t31.tsIntersectionType(types);
|
|
3616
3658
|
}
|
|
3617
|
-
if (
|
|
3659
|
+
if (t31.isTSUnionType(tsType)) {
|
|
3618
3660
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3619
3661
|
if (!types.length) return null;
|
|
3620
3662
|
if (types.length === 1) return types[0];
|
|
3621
|
-
return
|
|
3663
|
+
return t31.tsUnionType(types);
|
|
3622
3664
|
}
|
|
3623
|
-
if (
|
|
3665
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3624
3666
|
const members = [];
|
|
3625
3667
|
for (const member of tsType.members) {
|
|
3626
|
-
if (
|
|
3668
|
+
if (t31.isTSPropertySignature(member)) {
|
|
3627
3669
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
3628
3670
|
if (prop) members.push(prop);
|
|
3629
3671
|
continue;
|
|
3630
3672
|
}
|
|
3631
|
-
if (
|
|
3673
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3632
3674
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3633
3675
|
continue;
|
|
3634
3676
|
}
|
|
3635
3677
|
}
|
|
3636
3678
|
if (!members.length) return null;
|
|
3637
|
-
return
|
|
3679
|
+
return t31.tsTypeLiteral(members);
|
|
3638
3680
|
}
|
|
3639
|
-
if (
|
|
3681
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3640
3682
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3641
3683
|
if (!props.length) return null;
|
|
3642
|
-
return
|
|
3684
|
+
return t31.tsTypeLiteral(props);
|
|
3643
3685
|
}
|
|
3644
3686
|
return tsType;
|
|
3645
3687
|
}
|
|
3646
3688
|
function hasEmitsSignatureInType(tsType) {
|
|
3647
|
-
if (
|
|
3689
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3648
3690
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
3649
3691
|
}
|
|
3650
|
-
if (
|
|
3692
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3651
3693
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3652
3694
|
return false;
|
|
3653
3695
|
}
|
|
3654
3696
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
3655
3697
|
}
|
|
3656
|
-
if (
|
|
3698
|
+
if (t31.isTSIntersectionType(tsType) || t31.isTSUnionType(tsType)) {
|
|
3657
3699
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
3658
3700
|
}
|
|
3659
|
-
if (
|
|
3701
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3660
3702
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
3661
3703
|
}
|
|
3662
|
-
if (
|
|
3704
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3663
3705
|
return isEmitsCallable(tsType.parameters);
|
|
3664
3706
|
}
|
|
3665
3707
|
return false;
|
|
3666
3708
|
}
|
|
3667
3709
|
function hasEmitsSignatureInMember(member) {
|
|
3668
|
-
if (
|
|
3710
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3669
3711
|
return isEmitsCallable(member.parameters);
|
|
3670
3712
|
}
|
|
3671
3713
|
return false;
|
|
3672
3714
|
}
|
|
3673
3715
|
function isEmitsCallable(parameters) {
|
|
3674
3716
|
const [eventParam] = parameters;
|
|
3675
|
-
if (!eventParam || !
|
|
3717
|
+
if (!eventParam || !t31.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3676
3718
|
return false;
|
|
3677
3719
|
}
|
|
3678
3720
|
const { typeAnnotation } = eventParam;
|
|
3679
|
-
if (
|
|
3721
|
+
if (t31.isNoop(typeAnnotation)) return false;
|
|
3680
3722
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
3681
3723
|
}
|
|
3682
3724
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -3686,19 +3728,19 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3686
3728
|
const key = buildKey(handlerName);
|
|
3687
3729
|
const typeAnnotation = member.typeAnnotation?.typeAnnotation;
|
|
3688
3730
|
let params = [];
|
|
3689
|
-
let returnType =
|
|
3690
|
-
if (typeAnnotation &&
|
|
3731
|
+
let returnType = t31.tsAnyKeyword();
|
|
3732
|
+
if (typeAnnotation && t31.isTSFunctionType(typeAnnotation)) {
|
|
3691
3733
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3692
3734
|
returnType = typeAnnotation.typeAnnotation?.typeAnnotation ?? returnType;
|
|
3693
|
-
} else if (typeAnnotation &&
|
|
3735
|
+
} else if (typeAnnotation && t31.isTSTupleType(typeAnnotation)) {
|
|
3694
3736
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
3695
3737
|
} else if (typeAnnotation) {
|
|
3696
|
-
const id =
|
|
3697
|
-
id.typeAnnotation =
|
|
3738
|
+
const id = t31.identifier("value");
|
|
3739
|
+
id.typeAnnotation = t31.tsTypeAnnotation(typeAnnotation);
|
|
3698
3740
|
params = [id];
|
|
3699
3741
|
}
|
|
3700
|
-
const fnType =
|
|
3701
|
-
const prop =
|
|
3742
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(returnType));
|
|
3743
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3702
3744
|
prop.optional = !!member.optional;
|
|
3703
3745
|
return prop;
|
|
3704
3746
|
}
|
|
@@ -3707,32 +3749,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
3707
3749
|
}
|
|
3708
3750
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
3709
3751
|
const [eventParam, ...restParams] = parameters;
|
|
3710
|
-
if (!eventParam || !
|
|
3752
|
+
if (!eventParam || !t31.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3711
3753
|
return [];
|
|
3712
3754
|
}
|
|
3713
3755
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
3714
|
-
if (
|
|
3756
|
+
if (t31.isNoop(paramTypeAnnotation)) return [];
|
|
3715
3757
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
3716
3758
|
if (!eventNames.length) return [];
|
|
3717
|
-
const returnType = typeAnnotation?.typeAnnotation ??
|
|
3759
|
+
const returnType = typeAnnotation?.typeAnnotation ?? t31.tsAnyKeyword();
|
|
3718
3760
|
return eventNames.map((eventName) => {
|
|
3719
3761
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
3720
3762
|
const key = buildKey(handlerName);
|
|
3721
3763
|
const params = cloneCallableParams(restParams);
|
|
3722
|
-
const fnType =
|
|
3723
|
-
const prop =
|
|
3764
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(returnType));
|
|
3765
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3724
3766
|
prop.optional = true;
|
|
3725
3767
|
return prop;
|
|
3726
3768
|
});
|
|
3727
3769
|
}
|
|
3728
3770
|
function resolveEventNames(type) {
|
|
3729
|
-
if (
|
|
3771
|
+
if (t31.isTSLiteralType(type) && t31.isStringLiteral(type.literal)) {
|
|
3730
3772
|
return [type.literal.value];
|
|
3731
3773
|
}
|
|
3732
|
-
if (
|
|
3774
|
+
if (t31.isTSUnionType(type)) {
|
|
3733
3775
|
return type.types.flatMap(resolveEventNames);
|
|
3734
3776
|
}
|
|
3735
|
-
if (
|
|
3777
|
+
if (t31.isTSParenthesizedType(type)) {
|
|
3736
3778
|
return resolveEventNames(type.typeAnnotation);
|
|
3737
3779
|
}
|
|
3738
3780
|
return [];
|
|
@@ -3745,44 +3787,44 @@ function resolveTupleTypeParams(tuple) {
|
|
|
3745
3787
|
return params;
|
|
3746
3788
|
}
|
|
3747
3789
|
function resolveTupleElementParam(element, index) {
|
|
3748
|
-
const isNamedTuple = typeof
|
|
3790
|
+
const isNamedTuple = typeof t31.isTSNamedTupleMember === "function" && t31.isTSNamedTupleMember(element);
|
|
3749
3791
|
if (isNamedTuple) {
|
|
3750
3792
|
const tupleMember = element;
|
|
3751
3793
|
const name = tupleMember.label?.name || `arg${index}`;
|
|
3752
3794
|
let innerType = tupleMember.elementType;
|
|
3753
3795
|
let optional = tupleMember.optional;
|
|
3754
|
-
if (
|
|
3796
|
+
if (t31.isTSOptionalType(innerType)) {
|
|
3755
3797
|
optional = true;
|
|
3756
3798
|
innerType = innerType.typeAnnotation;
|
|
3757
3799
|
}
|
|
3758
|
-
if (
|
|
3759
|
-
const rest =
|
|
3760
|
-
rest.typeAnnotation =
|
|
3800
|
+
if (t31.isTSRestType(innerType)) {
|
|
3801
|
+
const rest = t31.restElement(t31.identifier(name));
|
|
3802
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(innerType.typeAnnotation);
|
|
3761
3803
|
return rest;
|
|
3762
3804
|
}
|
|
3763
|
-
const id2 =
|
|
3805
|
+
const id2 = t31.identifier(name);
|
|
3764
3806
|
id2.optional = optional;
|
|
3765
|
-
id2.typeAnnotation =
|
|
3807
|
+
id2.typeAnnotation = t31.tsTypeAnnotation(innerType);
|
|
3766
3808
|
return id2;
|
|
3767
3809
|
}
|
|
3768
|
-
if (
|
|
3769
|
-
const rest =
|
|
3770
|
-
rest.typeAnnotation =
|
|
3810
|
+
if (t31.isTSRestType(element)) {
|
|
3811
|
+
const rest = t31.restElement(t31.identifier(`args${index}`));
|
|
3812
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3771
3813
|
return rest;
|
|
3772
3814
|
}
|
|
3773
|
-
if (
|
|
3774
|
-
const id2 =
|
|
3815
|
+
if (t31.isTSOptionalType(element)) {
|
|
3816
|
+
const id2 = t31.identifier(`arg${index}`);
|
|
3775
3817
|
id2.optional = true;
|
|
3776
|
-
id2.typeAnnotation =
|
|
3818
|
+
id2.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3777
3819
|
return id2;
|
|
3778
3820
|
}
|
|
3779
|
-
const id =
|
|
3780
|
-
id.typeAnnotation =
|
|
3821
|
+
const id = t31.identifier(`arg${index}`);
|
|
3822
|
+
id.typeAnnotation = t31.tsTypeAnnotation(element);
|
|
3781
3823
|
return id;
|
|
3782
3824
|
}
|
|
3783
3825
|
|
|
3784
3826
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
3785
|
-
import * as
|
|
3827
|
+
import * as t32 from "@babel/types";
|
|
3786
3828
|
function resolveDefinePropsIface(path8, ctx) {
|
|
3787
3829
|
const { node } = path8;
|
|
3788
3830
|
const [runtimeArg] = node.arguments;
|
|
@@ -3802,38 +3844,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3802
3844
|
} = scriptData;
|
|
3803
3845
|
if (!runtimeArg) return;
|
|
3804
3846
|
const members = [];
|
|
3805
|
-
if (
|
|
3847
|
+
if (t32.isArrayExpression(runtimeArg)) {
|
|
3806
3848
|
for (const element of runtimeArg.elements) {
|
|
3807
|
-
if (!element || !
|
|
3808
|
-
const key =
|
|
3809
|
-
const prop =
|
|
3849
|
+
if (!element || !t32.isStringLiteral(element)) continue;
|
|
3850
|
+
const key = t32.isValidIdentifier(element.value) ? t32.identifier(element.value) : t32.stringLiteral(element.value);
|
|
3851
|
+
const prop = t32.tsPropertySignature(key, t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3810
3852
|
prop.optional = true;
|
|
3811
3853
|
members.push(prop);
|
|
3812
3854
|
}
|
|
3813
3855
|
if (members.length) {
|
|
3814
|
-
propsTypes.push(
|
|
3856
|
+
propsTypes.push(t32.tsTypeLiteral(members));
|
|
3815
3857
|
}
|
|
3816
3858
|
return;
|
|
3817
3859
|
}
|
|
3818
|
-
if (
|
|
3860
|
+
if (t32.isObjectExpression(runtimeArg)) {
|
|
3819
3861
|
for (const prop of runtimeArg.properties) {
|
|
3820
|
-
if (!
|
|
3821
|
-
if (
|
|
3862
|
+
if (!t32.isObjectProperty(prop)) continue;
|
|
3863
|
+
if (t32.isSpreadElement(prop)) continue;
|
|
3822
3864
|
const key = prop.key;
|
|
3823
3865
|
let propName = null;
|
|
3824
|
-
if (
|
|
3825
|
-
if (
|
|
3826
|
-
if (
|
|
3866
|
+
if (t32.isIdentifier(key)) propName = key.name;
|
|
3867
|
+
if (t32.isStringLiteral(key)) propName = key.value;
|
|
3868
|
+
if (t32.isNumericLiteral(key)) propName = String(key.value);
|
|
3827
3869
|
if (!propName) continue;
|
|
3828
3870
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
3829
|
-
const tsType = type ??
|
|
3830
|
-
const tsKey =
|
|
3831
|
-
const tsProp =
|
|
3871
|
+
const tsType = type ?? t32.tsAnyKeyword();
|
|
3872
|
+
const tsKey = t32.isValidIdentifier(propName) ? t32.identifier(propName) : t32.stringLiteral(propName);
|
|
3873
|
+
const tsProp = t32.tsPropertySignature(tsKey, t32.tsTypeAnnotation(tsType));
|
|
3832
3874
|
tsProp.optional = !required;
|
|
3833
3875
|
members.push(tsProp);
|
|
3834
3876
|
}
|
|
3835
3877
|
if (members.length) {
|
|
3836
|
-
propsTypes.push(
|
|
3878
|
+
propsTypes.push(t32.tsTypeLiteral(members));
|
|
3837
3879
|
}
|
|
3838
3880
|
return;
|
|
3839
3881
|
}
|
|
@@ -3847,42 +3889,42 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3847
3889
|
);
|
|
3848
3890
|
}
|
|
3849
3891
|
function resolveRuntimePropMeta(value) {
|
|
3850
|
-
if (
|
|
3892
|
+
if (t32.isIdentifier(value)) {
|
|
3851
3893
|
return {
|
|
3852
3894
|
type: mapRuntimeTypeToTSType(value),
|
|
3853
3895
|
required: false
|
|
3854
3896
|
};
|
|
3855
3897
|
}
|
|
3856
|
-
if (
|
|
3898
|
+
if (t32.isArrayExpression(value)) {
|
|
3857
3899
|
return {
|
|
3858
3900
|
type: resolveRuntimeUnionType(value),
|
|
3859
3901
|
required: false
|
|
3860
3902
|
};
|
|
3861
3903
|
}
|
|
3862
|
-
if (!
|
|
3904
|
+
if (!t32.isObjectExpression(value)) {
|
|
3863
3905
|
return { required: false };
|
|
3864
3906
|
}
|
|
3865
3907
|
let type;
|
|
3866
3908
|
let required = false;
|
|
3867
3909
|
for (const prop of value.properties) {
|
|
3868
|
-
if (!
|
|
3869
|
-
if (
|
|
3910
|
+
if (!t32.isObjectProperty(prop)) continue;
|
|
3911
|
+
if (t32.isSpreadElement(prop)) continue;
|
|
3870
3912
|
const key = prop.key;
|
|
3871
|
-
const propName =
|
|
3913
|
+
const propName = t32.isIdentifier(key) ? key.name : t32.isStringLiteral(key) ? key.value : null;
|
|
3872
3914
|
if (!propName) continue;
|
|
3873
3915
|
if (propName === "type") {
|
|
3874
3916
|
const valueNode = prop.value;
|
|
3875
|
-
if (
|
|
3917
|
+
if (t32.isArrayExpression(valueNode)) {
|
|
3876
3918
|
type = resolveRuntimeUnionType(valueNode);
|
|
3877
3919
|
continue;
|
|
3878
3920
|
}
|
|
3879
|
-
if (
|
|
3921
|
+
if (t32.isIdentifier(valueNode)) {
|
|
3880
3922
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3881
3923
|
continue;
|
|
3882
3924
|
}
|
|
3883
3925
|
}
|
|
3884
3926
|
if (propName === "required") {
|
|
3885
|
-
if (
|
|
3927
|
+
if (t32.isBooleanLiteral(prop.value)) {
|
|
3886
3928
|
required = prop.value.value;
|
|
3887
3929
|
}
|
|
3888
3930
|
}
|
|
@@ -3892,80 +3934,80 @@ function resolveRuntimePropMeta(value) {
|
|
|
3892
3934
|
function resolveRuntimeUnionType(value) {
|
|
3893
3935
|
const types = [];
|
|
3894
3936
|
for (const element of value.elements) {
|
|
3895
|
-
if (!element || !
|
|
3937
|
+
if (!element || !t32.isIdentifier(element)) continue;
|
|
3896
3938
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3897
3939
|
if (resolved) types.push(resolved);
|
|
3898
3940
|
}
|
|
3899
|
-
if (!types.length) return
|
|
3941
|
+
if (!types.length) return t32.tsAnyKeyword();
|
|
3900
3942
|
if (types.length === 1) return types[0];
|
|
3901
|
-
return
|
|
3943
|
+
return t32.tsUnionType(types);
|
|
3902
3944
|
}
|
|
3903
3945
|
function mapRuntimeTypeToTSType(value) {
|
|
3904
3946
|
switch (value.name) {
|
|
3905
3947
|
case "String":
|
|
3906
|
-
return
|
|
3948
|
+
return t32.tsStringKeyword();
|
|
3907
3949
|
case "Number":
|
|
3908
|
-
return
|
|
3950
|
+
return t32.tsNumberKeyword();
|
|
3909
3951
|
case "Boolean":
|
|
3910
|
-
return
|
|
3952
|
+
return t32.tsBooleanKeyword();
|
|
3911
3953
|
case "Object":
|
|
3912
|
-
return
|
|
3954
|
+
return t32.tsTypeLiteral([]);
|
|
3913
3955
|
case "Array":
|
|
3914
|
-
return
|
|
3956
|
+
return t32.tsArrayType(t32.tsAnyKeyword());
|
|
3915
3957
|
case "Function":
|
|
3916
|
-
return
|
|
3958
|
+
return t32.tsFunctionType(null, [], t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3917
3959
|
case "Symbol":
|
|
3918
|
-
return
|
|
3960
|
+
return t32.tsSymbolKeyword();
|
|
3919
3961
|
case "BigInt":
|
|
3920
|
-
return
|
|
3962
|
+
return t32.tsBigIntKeyword();
|
|
3921
3963
|
default:
|
|
3922
|
-
return
|
|
3964
|
+
return t32.tsAnyKeyword();
|
|
3923
3965
|
}
|
|
3924
3966
|
}
|
|
3925
3967
|
|
|
3926
3968
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
3927
|
-
import * as
|
|
3969
|
+
import * as t35 from "@babel/types";
|
|
3928
3970
|
|
|
3929
3971
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/slot-builder.ts
|
|
3930
|
-
import * as
|
|
3972
|
+
import * as t33 from "@babel/types";
|
|
3931
3973
|
var SLOT_DEFAULT_NAME = "default";
|
|
3932
3974
|
var SLOT_CHILDREN_NAME = "children";
|
|
3933
3975
|
var SLOT_FN_PARAM_NAME = "props";
|
|
3934
3976
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3935
3977
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3936
|
-
const key =
|
|
3937
|
-
const reactNodeType =
|
|
3938
|
-
|
|
3978
|
+
const key = t33.isValidIdentifier(propName) ? t33.identifier(propName) : t33.stringLiteral(propName);
|
|
3979
|
+
const reactNodeType = t33.tsTypeAnnotation(
|
|
3980
|
+
t33.tsTypeReference(t33.identifier(REACT_API_MAP.ReactNode))
|
|
3939
3981
|
);
|
|
3940
3982
|
let typeAnnotation;
|
|
3941
3983
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3942
3984
|
typeAnnotation = reactNodeType;
|
|
3943
3985
|
} else {
|
|
3944
|
-
const fnType =
|
|
3945
|
-
typeAnnotation =
|
|
3986
|
+
const fnType = t33.tsFunctionType(null, params, reactNodeType);
|
|
3987
|
+
typeAnnotation = t33.tsTypeAnnotation(fnType);
|
|
3946
3988
|
}
|
|
3947
|
-
const prop =
|
|
3989
|
+
const prop = t33.tsPropertySignature(key, typeAnnotation);
|
|
3948
3990
|
prop.optional = optional;
|
|
3949
3991
|
return prop;
|
|
3950
3992
|
}
|
|
3951
3993
|
function createSlotScopeParam(props, ctx) {
|
|
3952
|
-
const paramId =
|
|
3994
|
+
const paramId = t33.identifier(SLOT_FN_PARAM_NAME);
|
|
3953
3995
|
const propsSigns = [];
|
|
3954
3996
|
const { reactiveBindings } = ctx.templateData;
|
|
3955
3997
|
props.forEach(({ prop, tsType }) => {
|
|
3956
3998
|
const foundBindingValue = reactiveBindings[prop]?.value;
|
|
3957
3999
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3958
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3959
|
-
const key =
|
|
3960
|
-
const propSign =
|
|
4000
|
+
const typeAnnotation = foundBindingTypes ? t33.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
4001
|
+
const key = t33.isValidIdentifier(prop) ? t33.identifier(prop) : t33.stringLiteral(prop);
|
|
4002
|
+
const propSign = t33.tsPropertySignature(key, typeAnnotation);
|
|
3961
4003
|
propsSigns.push(propSign);
|
|
3962
4004
|
});
|
|
3963
|
-
paramId.typeAnnotation =
|
|
4005
|
+
paramId.typeAnnotation = t33.tsTypeAnnotation(t33.tsTypeLiteral(propsSigns));
|
|
3964
4006
|
return paramId;
|
|
3965
4007
|
}
|
|
3966
4008
|
|
|
3967
4009
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/utils.ts
|
|
3968
|
-
import * as
|
|
4010
|
+
import * as t34 from "@babel/types";
|
|
3969
4011
|
function recordReactNode(ctx) {
|
|
3970
4012
|
if (!ctx.scriptData.lang.startsWith("ts")) {
|
|
3971
4013
|
return;
|
|
@@ -3981,16 +4023,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
3981
4023
|
return declarations;
|
|
3982
4024
|
}
|
|
3983
4025
|
for (const statement of programPath.node.body) {
|
|
3984
|
-
if (
|
|
4026
|
+
if (t34.isTSInterfaceDeclaration(statement)) {
|
|
3985
4027
|
declarations.set(statement.id.name, {
|
|
3986
|
-
type:
|
|
4028
|
+
type: t34.tsTypeLiteral(statement.body.body),
|
|
3987
4029
|
// 将接口体转换为类型字面量
|
|
3988
4030
|
hasTypeParameters: !!statement.typeParameters?.params.length
|
|
3989
4031
|
// 检查是否有泛型参数
|
|
3990
4032
|
});
|
|
3991
4033
|
continue;
|
|
3992
4034
|
}
|
|
3993
|
-
if (
|
|
4035
|
+
if (t34.isTSTypeAliasDeclaration(statement)) {
|
|
3994
4036
|
declarations.set(statement.id.name, {
|
|
3995
4037
|
type: statement.typeAnnotation,
|
|
3996
4038
|
// 直接使用类型注解
|
|
@@ -3999,16 +4041,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
3999
4041
|
});
|
|
4000
4042
|
continue;
|
|
4001
4043
|
}
|
|
4002
|
-
if (
|
|
4044
|
+
if (t34.isExportNamedDeclaration(statement) && statement.declaration) {
|
|
4003
4045
|
const declaration = statement.declaration;
|
|
4004
|
-
if (
|
|
4046
|
+
if (t34.isTSInterfaceDeclaration(declaration)) {
|
|
4005
4047
|
declarations.set(declaration.id.name, {
|
|
4006
|
-
type:
|
|
4048
|
+
type: t34.tsTypeLiteral(declaration.body.body),
|
|
4007
4049
|
// 将接口体转换为类型字面量
|
|
4008
4050
|
hasTypeParameters: !!declaration.typeParameters?.params.length
|
|
4009
4051
|
// 检查是否有泛型参数
|
|
4010
4052
|
});
|
|
4011
|
-
} else if (
|
|
4053
|
+
} else if (t34.isTSTypeAliasDeclaration(declaration)) {
|
|
4012
4054
|
declarations.set(declaration.id.name, {
|
|
4013
4055
|
type: declaration.typeAnnotation,
|
|
4014
4056
|
// 直接使用类型注解
|
|
@@ -4021,22 +4063,22 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4021
4063
|
return declarations;
|
|
4022
4064
|
}
|
|
4023
4065
|
function resolvePropName2(key) {
|
|
4024
|
-
if (
|
|
4066
|
+
if (t34.isIdentifier(key)) {
|
|
4025
4067
|
return key.name;
|
|
4026
4068
|
}
|
|
4027
|
-
if (
|
|
4069
|
+
if (t34.isStringLiteral(key)) {
|
|
4028
4070
|
return key.value;
|
|
4029
4071
|
}
|
|
4030
|
-
if (
|
|
4072
|
+
if (t34.isNumericLiteral(key)) {
|
|
4031
4073
|
return String(key.value);
|
|
4032
4074
|
}
|
|
4033
4075
|
return null;
|
|
4034
4076
|
}
|
|
4035
4077
|
function resolveCallableType(tsType) {
|
|
4036
|
-
if (
|
|
4078
|
+
if (t34.isTSFunctionType(tsType)) {
|
|
4037
4079
|
return tsType;
|
|
4038
4080
|
}
|
|
4039
|
-
if (
|
|
4081
|
+
if (t34.isTSParenthesizedType(tsType)) {
|
|
4040
4082
|
return resolveCallableType(tsType.typeAnnotation);
|
|
4041
4083
|
}
|
|
4042
4084
|
return null;
|
|
@@ -4045,10 +4087,10 @@ function resolveCallableType(tsType) {
|
|
|
4045
4087
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
4046
4088
|
var SLOT_DEFAULT_NAME2 = "default";
|
|
4047
4089
|
function resolveSlotType(tsType, options) {
|
|
4048
|
-
if (
|
|
4090
|
+
if (t35.isTSParenthesizedType(tsType)) {
|
|
4049
4091
|
return resolveSlotType(tsType.typeAnnotation, options);
|
|
4050
4092
|
}
|
|
4051
|
-
if (
|
|
4093
|
+
if (t35.isTSTypeReference(tsType)) {
|
|
4052
4094
|
let shouldRecordReactNode = false;
|
|
4053
4095
|
if (tsType.typeParameters?.params.length) {
|
|
4054
4096
|
const params = [];
|
|
@@ -4064,11 +4106,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4064
4106
|
};
|
|
4065
4107
|
}
|
|
4066
4108
|
return {
|
|
4067
|
-
type:
|
|
4109
|
+
type: t35.tsTypeReference(tsType.typeName, t35.tsTypeParameterInstantiation(params)),
|
|
4068
4110
|
shouldRecordReactNode
|
|
4069
4111
|
};
|
|
4070
4112
|
}
|
|
4071
|
-
if (!
|
|
4113
|
+
if (!t35.isIdentifier(tsType.typeName)) {
|
|
4072
4114
|
return {
|
|
4073
4115
|
type: tsType,
|
|
4074
4116
|
shouldRecordReactNode: false
|
|
@@ -4099,7 +4141,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4099
4141
|
}
|
|
4100
4142
|
return resolved;
|
|
4101
4143
|
}
|
|
4102
|
-
if (
|
|
4144
|
+
if (t35.isTSIntersectionType(tsType)) {
|
|
4103
4145
|
const types = [];
|
|
4104
4146
|
let shouldRecordReactNode = false;
|
|
4105
4147
|
for (const item of tsType.types) {
|
|
@@ -4122,11 +4164,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4122
4164
|
};
|
|
4123
4165
|
}
|
|
4124
4166
|
return {
|
|
4125
|
-
type:
|
|
4167
|
+
type: t35.tsIntersectionType(types),
|
|
4126
4168
|
shouldRecordReactNode
|
|
4127
4169
|
};
|
|
4128
4170
|
}
|
|
4129
|
-
if (
|
|
4171
|
+
if (t35.isTSUnionType(tsType)) {
|
|
4130
4172
|
const types = [];
|
|
4131
4173
|
let shouldRecordReactNode = false;
|
|
4132
4174
|
for (const item of tsType.types) {
|
|
@@ -4149,11 +4191,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4149
4191
|
};
|
|
4150
4192
|
}
|
|
4151
4193
|
return {
|
|
4152
|
-
type:
|
|
4194
|
+
type: t35.tsUnionType(types),
|
|
4153
4195
|
shouldRecordReactNode
|
|
4154
4196
|
};
|
|
4155
4197
|
}
|
|
4156
|
-
if (
|
|
4198
|
+
if (t35.isTSTypeLiteral(tsType)) {
|
|
4157
4199
|
const members = [];
|
|
4158
4200
|
let shouldRecordReactNode = false;
|
|
4159
4201
|
for (const item of tsType.members) {
|
|
@@ -4168,11 +4210,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4168
4210
|
};
|
|
4169
4211
|
}
|
|
4170
4212
|
return {
|
|
4171
|
-
type:
|
|
4213
|
+
type: t35.tsTypeLiteral(members),
|
|
4172
4214
|
shouldRecordReactNode
|
|
4173
4215
|
};
|
|
4174
4216
|
}
|
|
4175
|
-
if (
|
|
4217
|
+
if (t35.isTSFunctionType(tsType)) {
|
|
4176
4218
|
const props = buildSlotPropSignature(
|
|
4177
4219
|
SLOT_DEFAULT_NAME2,
|
|
4178
4220
|
cloneCallableParams(tsType.parameters),
|
|
@@ -4180,7 +4222,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4180
4222
|
// 默认插槽不是可选的
|
|
4181
4223
|
);
|
|
4182
4224
|
return {
|
|
4183
|
-
type:
|
|
4225
|
+
type: t35.tsTypeLiteral([props]),
|
|
4184
4226
|
shouldRecordReactNode: true
|
|
4185
4227
|
// 函数类型总是需要记录 ReactNode
|
|
4186
4228
|
};
|
|
@@ -4191,7 +4233,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4191
4233
|
};
|
|
4192
4234
|
}
|
|
4193
4235
|
function resolveSlotPropFromMember(member) {
|
|
4194
|
-
if (
|
|
4236
|
+
if (t35.isTSMethodSignature(member)) {
|
|
4195
4237
|
const rawName = resolvePropName2(member.key);
|
|
4196
4238
|
if (!rawName) {
|
|
4197
4239
|
return {
|
|
@@ -4206,7 +4248,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4206
4248
|
// 方法签名总是可调用,需要记录 ReactNode
|
|
4207
4249
|
};
|
|
4208
4250
|
}
|
|
4209
|
-
if (
|
|
4251
|
+
if (t35.isTSPropertySignature(member)) {
|
|
4210
4252
|
const rawName = resolvePropName2(member.key);
|
|
4211
4253
|
if (!rawName) {
|
|
4212
4254
|
return {
|
|
@@ -4229,7 +4271,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4229
4271
|
// 可调用属性需要记录 ReactNode
|
|
4230
4272
|
};
|
|
4231
4273
|
}
|
|
4232
|
-
if (
|
|
4274
|
+
if (t35.isTSCallSignatureDeclaration(member)) {
|
|
4233
4275
|
const params = cloneCallableParams(member.parameters);
|
|
4234
4276
|
return {
|
|
4235
4277
|
member: buildSlotPropSignature(SLOT_DEFAULT_NAME2, params, true),
|
|
@@ -4269,7 +4311,7 @@ function resolveDefineSlotsIface(path8, ctx) {
|
|
|
4269
4311
|
}
|
|
4270
4312
|
|
|
4271
4313
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/template-slots.ts
|
|
4272
|
-
import * as
|
|
4314
|
+
import * as t36 from "@babel/types";
|
|
4273
4315
|
function resolveTemplateSlotIface(ctx) {
|
|
4274
4316
|
if (ctx.inputType !== "sfc") return;
|
|
4275
4317
|
const {
|
|
@@ -4287,7 +4329,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
4287
4329
|
}
|
|
4288
4330
|
if (tsMembers.length) {
|
|
4289
4331
|
recordReactNode(ctx);
|
|
4290
|
-
slotTypes.push(
|
|
4332
|
+
slotTypes.push(t36.tsTypeLiteral(tsMembers));
|
|
4291
4333
|
}
|
|
4292
4334
|
}
|
|
4293
4335
|
|
|
@@ -4339,9 +4381,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4339
4381
|
}
|
|
4340
4382
|
const n = declaredOptions.name || "Comp";
|
|
4341
4383
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
4342
|
-
const typeNode =
|
|
4343
|
-
const typeAliasDecl =
|
|
4344
|
-
const exportDecl =
|
|
4384
|
+
const typeNode = t37.tsIntersectionType(tsTypes);
|
|
4385
|
+
const typeAliasDecl = t37.tsTypeAliasDeclaration(t37.identifier(ns), null, typeNode);
|
|
4386
|
+
const exportDecl = t37.exportNamedDeclaration(typeAliasDecl);
|
|
4345
4387
|
propsTSIface.name = ns;
|
|
4346
4388
|
const scriptIR = getScriptIR(ctx);
|
|
4347
4389
|
scriptIR.exports.push(exportDecl);
|
|
@@ -4349,15 +4391,15 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4349
4391
|
}
|
|
4350
4392
|
|
|
4351
4393
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-use-attrs.ts
|
|
4352
|
-
import * as
|
|
4394
|
+
import * as t38 from "@babel/types";
|
|
4353
4395
|
function resolveUseAttrs(ctx) {
|
|
4354
4396
|
return {
|
|
4355
4397
|
VariableDeclarator(path8) {
|
|
4356
4398
|
const { init, id } = path8.node;
|
|
4357
4399
|
if (!init) return;
|
|
4358
4400
|
const initPath = path8.get("init");
|
|
4359
|
-
const propsIdentifier =
|
|
4360
|
-
if (
|
|
4401
|
+
const propsIdentifier = t38.identifier(ctx.propField);
|
|
4402
|
+
if (t38.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
|
|
4361
4403
|
const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
|
|
4362
4404
|
replaceNode(initPath, typeAssertion, init);
|
|
4363
4405
|
return;
|
|
@@ -4368,13 +4410,13 @@ function resolveUseAttrs(ctx) {
|
|
|
4368
4410
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
4369
4411
|
if (isTS) {
|
|
4370
4412
|
let typeAnnotation = null;
|
|
4371
|
-
if (
|
|
4413
|
+
if (t38.isIdentifier(id) && t38.isTSTypeAnnotation(id.typeAnnotation)) {
|
|
4372
4414
|
typeAnnotation = id.typeAnnotation.typeAnnotation;
|
|
4373
4415
|
id.typeAnnotation = null;
|
|
4374
4416
|
} else {
|
|
4375
|
-
typeAnnotation =
|
|
4376
|
-
|
|
4377
|
-
|
|
4417
|
+
typeAnnotation = t38.tsTypeReference(
|
|
4418
|
+
t38.identifier("Record"),
|
|
4419
|
+
t38.tsTypeParameterInstantiation([t38.tsStringKeyword(), t38.tsUnknownKeyword()])
|
|
4378
4420
|
);
|
|
4379
4421
|
}
|
|
4380
4422
|
const propsTypeAssertion = createPropsTypeAssertion(propsIdentifier, typeAnnotation);
|
|
@@ -4386,18 +4428,18 @@ function resolveUseAttrs(ctx) {
|
|
|
4386
4428
|
};
|
|
4387
4429
|
}
|
|
4388
4430
|
function isUseAttrsCall(expr) {
|
|
4389
|
-
return
|
|
4431
|
+
return t38.isCallExpression(expr) && isCalleeNamed(expr, VUE_API_MAP.useAttrs);
|
|
4390
4432
|
}
|
|
4391
4433
|
function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
4392
|
-
return
|
|
4434
|
+
return t38.tsAsExpression(propsIdentifier, typeAnnotation);
|
|
4393
4435
|
}
|
|
4394
4436
|
|
|
4395
4437
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
4396
|
-
import * as
|
|
4438
|
+
import * as t44 from "@babel/types";
|
|
4397
4439
|
|
|
4398
4440
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4399
4441
|
import { traverse as traverse2 } from "@babel/core";
|
|
4400
|
-
import * as
|
|
4442
|
+
import * as t43 from "@babel/types";
|
|
4401
4443
|
|
|
4402
4444
|
// src/core/transform/sfc/script/shared/dependency-analyzer/binding-utils.ts
|
|
4403
4445
|
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
@@ -4416,7 +4458,7 @@ function isReactiveBinding(node) {
|
|
|
4416
4458
|
}
|
|
4417
4459
|
|
|
4418
4460
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
|
|
4419
|
-
import * as
|
|
4461
|
+
import * as t39 from "@babel/types";
|
|
4420
4462
|
function isEligibleBindingSource(binding) {
|
|
4421
4463
|
if (binding.kind === "param") {
|
|
4422
4464
|
return false;
|
|
@@ -4426,57 +4468,57 @@ function isEligibleBindingSource(binding) {
|
|
|
4426
4468
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4427
4469
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4428
4470
|
const nodeInit = declaratorPath?.node.init;
|
|
4429
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
4430
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
4431
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
4471
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t39.isCallExpression(nodeInit) && t39.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4472
|
+
const isHookCallVarBinding = !!declaratorPath && t39.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4473
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t39.isArrowFunctionExpression(nodeInit) || t39.isFunctionExpression(nodeInit));
|
|
4432
4474
|
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(declaratorPath?.node) || isReactiveBinding(bindingPath.node));
|
|
4433
4475
|
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4434
4476
|
}
|
|
4435
4477
|
function isReactValidDependencyExpr(node) {
|
|
4436
|
-
if (
|
|
4478
|
+
if (t39.isIdentifier(node)) {
|
|
4437
4479
|
return true;
|
|
4438
4480
|
}
|
|
4439
|
-
if (
|
|
4481
|
+
if (t39.isMemberExpression(node) || t39.isOptionalMemberExpression(node)) {
|
|
4440
4482
|
return isStaticMemberChain(node);
|
|
4441
4483
|
}
|
|
4442
4484
|
return false;
|
|
4443
4485
|
}
|
|
4444
4486
|
function isStaticMemberChain(node) {
|
|
4445
4487
|
let current = node;
|
|
4446
|
-
while (
|
|
4447
|
-
if (!current.computed && !
|
|
4488
|
+
while (t39.isMemberExpression(current) || t39.isOptionalMemberExpression(current)) {
|
|
4489
|
+
if (!current.computed && !t39.isIdentifier(current.property)) {
|
|
4448
4490
|
return false;
|
|
4449
4491
|
}
|
|
4450
|
-
if (current.computed && !
|
|
4492
|
+
if (current.computed && !t39.isStringLiteral(current.property) && !t39.isNumericLiteral(current.property)) {
|
|
4451
4493
|
return false;
|
|
4452
4494
|
}
|
|
4453
4495
|
current = current.object;
|
|
4454
4496
|
}
|
|
4455
|
-
return
|
|
4497
|
+
return t39.isIdentifier(current);
|
|
4456
4498
|
}
|
|
4457
4499
|
function isHookLikeCallee(callee) {
|
|
4458
|
-
if (
|
|
4500
|
+
if (t39.isIdentifier(callee)) {
|
|
4459
4501
|
return callee.name.startsWith("use");
|
|
4460
4502
|
}
|
|
4461
|
-
if (
|
|
4503
|
+
if (t39.isMemberExpression(callee) && !callee.computed && t39.isIdentifier(callee.property)) {
|
|
4462
4504
|
return callee.property.name.startsWith("use");
|
|
4463
4505
|
}
|
|
4464
4506
|
return false;
|
|
4465
4507
|
}
|
|
4466
4508
|
|
|
4467
4509
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
|
|
4468
|
-
import * as
|
|
4510
|
+
import * as t40 from "@babel/types";
|
|
4469
4511
|
function getDependencyKey(exp) {
|
|
4470
|
-
if (
|
|
4512
|
+
if (t40.isIdentifier(exp)) {
|
|
4471
4513
|
return exp.name;
|
|
4472
4514
|
}
|
|
4473
|
-
if (
|
|
4515
|
+
if (t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp)) {
|
|
4474
4516
|
const objectKey = getDependencyKey(exp.object);
|
|
4475
4517
|
const opt = exp.optional ? "?" : "";
|
|
4476
|
-
if (!exp.computed &&
|
|
4518
|
+
if (!exp.computed && t40.isIdentifier(exp.property)) {
|
|
4477
4519
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4478
4520
|
}
|
|
4479
|
-
if (
|
|
4521
|
+
if (t40.isStringLiteral(exp.property) || t40.isNumericLiteral(exp.property)) {
|
|
4480
4522
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4481
4523
|
}
|
|
4482
4524
|
return `${objectKey}${opt}[*]`;
|
|
@@ -4485,40 +4527,40 @@ function getDependencyKey(exp) {
|
|
|
4485
4527
|
}
|
|
4486
4528
|
|
|
4487
4529
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
|
|
4488
|
-
import * as
|
|
4530
|
+
import * as t41 from "@babel/types";
|
|
4489
4531
|
function normalizeDependencyExpr(path8, rootName, ctx) {
|
|
4490
|
-
if (
|
|
4491
|
-
return
|
|
4532
|
+
if (t41.isIdentifier(path8.node)) {
|
|
4533
|
+
return t41.identifier(path8.node.name);
|
|
4492
4534
|
}
|
|
4493
|
-
if (
|
|
4535
|
+
if (t41.isMemberExpression(path8.node) || t41.isOptionalMemberExpression(path8.node)) {
|
|
4494
4536
|
if (rootName === ctx.propField) {
|
|
4495
4537
|
const safePropsExp = ensureOptionalForMemberChain(path8.node);
|
|
4496
4538
|
if (isReactValidDependencyExpr(safePropsExp)) {
|
|
4497
|
-
return
|
|
4539
|
+
return t41.cloneNode(safePropsExp, true);
|
|
4498
4540
|
}
|
|
4499
|
-
return
|
|
4541
|
+
return t41.identifier(rootName);
|
|
4500
4542
|
}
|
|
4501
4543
|
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
4502
|
-
const safeExp =
|
|
4544
|
+
const safeExp = t41.isMemberExpression(normalizedExp) || t41.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
4503
4545
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4504
|
-
return
|
|
4546
|
+
return t41.cloneNode(safeExp, true);
|
|
4505
4547
|
}
|
|
4506
|
-
return
|
|
4548
|
+
return t41.identifier(rootName);
|
|
4507
4549
|
}
|
|
4508
4550
|
return null;
|
|
4509
4551
|
}
|
|
4510
4552
|
function normalizeSourcedDependency(exp) {
|
|
4511
|
-
if (
|
|
4512
|
-
return
|
|
4553
|
+
if (t41.isIdentifier(exp)) {
|
|
4554
|
+
return t41.identifier(exp.name);
|
|
4513
4555
|
}
|
|
4514
|
-
if (
|
|
4556
|
+
if (t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp)) {
|
|
4515
4557
|
const root = findRootIdentifier(exp);
|
|
4516
4558
|
if (!root) return null;
|
|
4517
|
-
const safeExp =
|
|
4559
|
+
const safeExp = t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4518
4560
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4519
|
-
return
|
|
4561
|
+
return t41.cloneNode(safeExp, true);
|
|
4520
4562
|
}
|
|
4521
|
-
return
|
|
4563
|
+
return t41.identifier(root.name);
|
|
4522
4564
|
}
|
|
4523
4565
|
return null;
|
|
4524
4566
|
}
|
|
@@ -4528,7 +4570,7 @@ function normalizeMemberForCallSite(path8, node) {
|
|
|
4528
4570
|
if (!isDirectCallee) {
|
|
4529
4571
|
return node;
|
|
4530
4572
|
}
|
|
4531
|
-
if (!
|
|
4573
|
+
if (!t41.isExpression(node.object)) {
|
|
4532
4574
|
return node;
|
|
4533
4575
|
}
|
|
4534
4576
|
return node.object;
|
|
@@ -4537,15 +4579,23 @@ function ensureOptionalForMemberChain(node) {
|
|
|
4537
4579
|
if (!hasTrailingMemberAccess(node)) {
|
|
4538
4580
|
return node;
|
|
4539
4581
|
}
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4582
|
+
const rebuildWithOptionalChain = (node2) => {
|
|
4583
|
+
const safeObject = ensureOptionalForMemberChain(node2.object);
|
|
4584
|
+
if (safeObject !== node2.object) {
|
|
4585
|
+
const property = t41.cloneNode(node2.property, true);
|
|
4586
|
+
return t41.optionalMemberExpression(safeObject, property, node2.computed, true);
|
|
4587
|
+
}
|
|
4588
|
+
if (t41.isMemberExpression(node2)) {
|
|
4589
|
+
const object = t41.cloneNode(node2.object, true);
|
|
4590
|
+
const property = t41.cloneNode(node2.property, true);
|
|
4591
|
+
return t41.optionalMemberExpression(object, property, node2.computed, true);
|
|
4592
|
+
}
|
|
4593
|
+
return node2;
|
|
4594
|
+
};
|
|
4595
|
+
return rebuildWithOptionalChain(node);
|
|
4546
4596
|
}
|
|
4547
4597
|
function hasTrailingMemberAccess(node) {
|
|
4548
|
-
return
|
|
4598
|
+
return t41.isMemberExpression(node.object) || t41.isOptionalMemberExpression(node.object);
|
|
4549
4599
|
}
|
|
4550
4600
|
|
|
4551
4601
|
// src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
|
|
@@ -4560,7 +4610,7 @@ function isNestedMemberObject(path8) {
|
|
|
4560
4610
|
}
|
|
4561
4611
|
|
|
4562
4612
|
// src/core/transform/sfc/script/shared/dependency-analyzer/trace-utils.ts
|
|
4563
|
-
import * as
|
|
4613
|
+
import * as t42 from "@babel/types";
|
|
4564
4614
|
function traceBindingSource(binding, seen, depth) {
|
|
4565
4615
|
if (depth <= 0) return null;
|
|
4566
4616
|
const declaratorPath = getVariableDeclaratorPath(binding.path);
|
|
@@ -4572,7 +4622,7 @@ function traceBindingSource(binding, seen, depth) {
|
|
|
4572
4622
|
}
|
|
4573
4623
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4574
4624
|
if (depth <= 0) return null;
|
|
4575
|
-
if (
|
|
4625
|
+
if (t42.isIdentifier(exp)) {
|
|
4576
4626
|
const sourceBinding = scope.getBinding(exp.name);
|
|
4577
4627
|
if (!sourceBinding) return null;
|
|
4578
4628
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -4580,13 +4630,13 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4580
4630
|
}
|
|
4581
4631
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4582
4632
|
}
|
|
4583
|
-
if (
|
|
4633
|
+
if (t42.isMemberExpression(exp) || t42.isOptionalMemberExpression(exp)) {
|
|
4584
4634
|
const root = findRootIdentifier(exp);
|
|
4585
4635
|
if (!root) return null;
|
|
4586
4636
|
const sourceBinding = scope.getBinding(root.name);
|
|
4587
4637
|
if (!sourceBinding) return null;
|
|
4588
4638
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
4589
|
-
return
|
|
4639
|
+
return t42.cloneNode(exp);
|
|
4590
4640
|
}
|
|
4591
4641
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4592
4642
|
if (sourcedRoot) {
|
|
@@ -4594,17 +4644,17 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4594
4644
|
if (rebuilt) {
|
|
4595
4645
|
return rebuilt;
|
|
4596
4646
|
}
|
|
4597
|
-
return
|
|
4647
|
+
return t42.cloneNode(sourcedRoot, true);
|
|
4598
4648
|
}
|
|
4599
4649
|
}
|
|
4600
4650
|
return null;
|
|
4601
4651
|
}
|
|
4602
4652
|
function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
4603
4653
|
const replacedObject = (() => {
|
|
4604
|
-
if (
|
|
4605
|
-
return
|
|
4654
|
+
if (t42.isIdentifier(node.object)) {
|
|
4655
|
+
return t42.cloneNode(nextRoot, true);
|
|
4606
4656
|
}
|
|
4607
|
-
if (
|
|
4657
|
+
if (t42.isMemberExpression(node.object) || t42.isOptionalMemberExpression(node.object)) {
|
|
4608
4658
|
return rebuildMemberWithNewRoot(node.object, nextRoot);
|
|
4609
4659
|
}
|
|
4610
4660
|
return null;
|
|
@@ -4612,15 +4662,15 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4612
4662
|
if (!replacedObject) {
|
|
4613
4663
|
return null;
|
|
4614
4664
|
}
|
|
4615
|
-
const property =
|
|
4616
|
-
if (
|
|
4617
|
-
return
|
|
4665
|
+
const property = t42.cloneNode(node.property, true);
|
|
4666
|
+
if (t42.isMemberExpression(node)) {
|
|
4667
|
+
return t42.memberExpression(
|
|
4618
4668
|
replacedObject,
|
|
4619
4669
|
property,
|
|
4620
4670
|
node.computed
|
|
4621
4671
|
);
|
|
4622
4672
|
}
|
|
4623
|
-
return
|
|
4673
|
+
return t42.optionalMemberExpression(
|
|
4624
4674
|
replacedObject,
|
|
4625
4675
|
property,
|
|
4626
4676
|
node.computed,
|
|
@@ -4631,9 +4681,9 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4631
4681
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4632
4682
|
function analyzeDeps(node, ctx, parentPath) {
|
|
4633
4683
|
if (!parentPath) {
|
|
4634
|
-
return
|
|
4684
|
+
return t43.arrayExpression([]);
|
|
4635
4685
|
}
|
|
4636
|
-
const isFnExpr =
|
|
4686
|
+
const isFnExpr = t43.isArrowFunctionExpression(node) || t43.isFunctionExpression(node);
|
|
4637
4687
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
4638
4688
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
4639
4689
|
const deps = /* @__PURE__ */ new Map();
|
|
@@ -4643,13 +4693,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4643
4693
|
}
|
|
4644
4694
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
4645
4695
|
if (analyzeTargetPath) {
|
|
4646
|
-
if (
|
|
4696
|
+
if (t43.isMemberExpression(analyzeTarget) || t43.isOptionalMemberExpression(analyzeTarget)) {
|
|
4647
4697
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
4648
4698
|
if (rootId) {
|
|
4649
4699
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
4650
4700
|
processedIdentifiers.add(rootId);
|
|
4651
4701
|
}
|
|
4652
|
-
} else if (
|
|
4702
|
+
} else if (t43.isIdentifier(analyzeTarget)) {
|
|
4653
4703
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
4654
4704
|
}
|
|
4655
4705
|
}
|
|
@@ -4701,7 +4751,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4701
4751
|
}
|
|
4702
4752
|
}
|
|
4703
4753
|
}
|
|
4704
|
-
return
|
|
4754
|
+
return t43.arrayExpression(Array.from(deps.values()));
|
|
4705
4755
|
}
|
|
4706
4756
|
|
|
4707
4757
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -4717,7 +4767,7 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4717
4767
|
if (!isVueApiReference(path8, apiName)) {
|
|
4718
4768
|
return;
|
|
4719
4769
|
}
|
|
4720
|
-
if (
|
|
4770
|
+
if (t44.isCallExpression(node)) {
|
|
4721
4771
|
resolveCallNode(path8, adapter, ctx);
|
|
4722
4772
|
} else {
|
|
4723
4773
|
replaceIdName(node, adapter.target);
|
|
@@ -4727,11 +4777,11 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4727
4777
|
};
|
|
4728
4778
|
}
|
|
4729
4779
|
function getApiName(node) {
|
|
4730
|
-
const isCallNode =
|
|
4780
|
+
const isCallNode = t44.isCallExpression(node);
|
|
4731
4781
|
let apiName = "";
|
|
4732
|
-
if (
|
|
4782
|
+
if (t44.isIdentifier(node)) {
|
|
4733
4783
|
apiName = node.name;
|
|
4734
|
-
} else if (isCallNode &&
|
|
4784
|
+
} else if (isCallNode && t44.isIdentifier(node.callee)) {
|
|
4735
4785
|
apiName = node.callee.name;
|
|
4736
4786
|
}
|
|
4737
4787
|
return apiName;
|
|
@@ -4741,7 +4791,7 @@ function resolveCallNode(path8, adapter, ctx) {
|
|
|
4741
4791
|
const { arguments: args } = node;
|
|
4742
4792
|
if (!args.length) return;
|
|
4743
4793
|
const fn = args[0];
|
|
4744
|
-
if (!
|
|
4794
|
+
if (!t44.isArrowFunctionExpression(fn) && !t44.isFunctionExpression(fn)) {
|
|
4745
4795
|
return;
|
|
4746
4796
|
}
|
|
4747
4797
|
const fnPath = path8.get("arguments")[0];
|
|
@@ -4773,7 +4823,7 @@ function isVueImportBinding(binding) {
|
|
|
4773
4823
|
return false;
|
|
4774
4824
|
}
|
|
4775
4825
|
const parent = bindingPath.parentPath?.node;
|
|
4776
|
-
if (!parent || !
|
|
4826
|
+
if (!parent || !t44.isImportDeclaration(parent)) {
|
|
4777
4827
|
return false;
|
|
4778
4828
|
}
|
|
4779
4829
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4841,7 +4891,7 @@ function isSkip(path8) {
|
|
|
4841
4891
|
}
|
|
4842
4892
|
|
|
4843
4893
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-element-ref.ts
|
|
4844
|
-
import * as
|
|
4894
|
+
import * as t45 from "@babel/types";
|
|
4845
4895
|
function resolveElementRef(ctx) {
|
|
4846
4896
|
return {
|
|
4847
4897
|
CallExpression(path8) {
|
|
@@ -4859,14 +4909,14 @@ function resolveElementRef(ctx) {
|
|
|
4859
4909
|
}
|
|
4860
4910
|
if (isCompRefBindings) {
|
|
4861
4911
|
const varDeclaratorPath = getVariableDeclaratorPath(path8)?.node;
|
|
4862
|
-
if (!
|
|
4912
|
+
if (!t45.isIdentifier(varDeclaratorPath?.id)) {
|
|
4863
4913
|
return;
|
|
4864
4914
|
}
|
|
4865
4915
|
const varName = varDeclaratorPath.id.name;
|
|
4866
4916
|
const compRef = refBindings.componentRefs[varName];
|
|
4867
4917
|
if (!compRef) return;
|
|
4868
4918
|
}
|
|
4869
|
-
node.arguments[0] =
|
|
4919
|
+
node.arguments[0] = t45.identifier("null");
|
|
4870
4920
|
resolveTypeParameters(ctx, path8);
|
|
4871
4921
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
4872
4922
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
@@ -4891,27 +4941,27 @@ function resolveTypeParameters(ctx, path8) {
|
|
|
4891
4941
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
4892
4942
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
4893
4943
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
4894
|
-
node.typeParameters =
|
|
4944
|
+
node.typeParameters = t45.tsTypeParameterInstantiation([t45.tsTypeReference(t45.identifier(type))]);
|
|
4895
4945
|
}
|
|
4896
4946
|
}
|
|
4897
4947
|
function resolveRefValueToCurrent(path8) {
|
|
4898
4948
|
const { node } = path8;
|
|
4899
|
-
if (node.computed || !
|
|
4949
|
+
if (node.computed || !t45.isIdentifier(node.property) || node.property.name !== "value") {
|
|
4900
4950
|
return;
|
|
4901
4951
|
}
|
|
4902
4952
|
const rootPath = findRootVariablePath(path8);
|
|
4903
|
-
if (!rootPath?.node || !
|
|
4953
|
+
if (!rootPath?.node || !t45.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
4904
4954
|
return;
|
|
4905
4955
|
}
|
|
4906
4956
|
const rootId = findRootIdentifier(node);
|
|
4907
|
-
if (!
|
|
4957
|
+
if (!t45.isIdentifier(node.object) || node.object.name !== rootId?.name) {
|
|
4908
4958
|
return;
|
|
4909
4959
|
}
|
|
4910
4960
|
node.property.name = "current";
|
|
4911
4961
|
}
|
|
4912
4962
|
|
|
4913
4963
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-expression-memo.ts
|
|
4914
|
-
import * as
|
|
4964
|
+
import * as t46 from "@babel/types";
|
|
4915
4965
|
function resolveExprMemo(ctx, ast) {
|
|
4916
4966
|
const isScriptFile = ctx.inputType !== "sfc";
|
|
4917
4967
|
return {
|
|
@@ -4923,11 +4973,11 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4923
4973
|
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
4924
4974
|
return false;
|
|
4925
4975
|
}
|
|
4926
|
-
if (!
|
|
4976
|
+
if (!t46.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
|
|
4927
4977
|
return false;
|
|
4928
4978
|
}
|
|
4929
|
-
if (
|
|
4930
|
-
if (
|
|
4979
|
+
if (t46.isFunction(init)) return false;
|
|
4980
|
+
if (t46.isCallExpression(init) && t46.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
4931
4981
|
return false;
|
|
4932
4982
|
}
|
|
4933
4983
|
return true;
|
|
@@ -4946,16 +4996,16 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4946
4996
|
}
|
|
4947
4997
|
|
|
4948
4998
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-lint-rules.ts
|
|
4949
|
-
import * as
|
|
4999
|
+
import * as t47 from "@babel/types";
|
|
4950
5000
|
function resolveLintRules(ctx, ast) {
|
|
4951
5001
|
const inScriptFile = ctx.inputType !== "sfc";
|
|
4952
5002
|
return {
|
|
4953
5003
|
CallExpression(path8) {
|
|
4954
5004
|
const { node, parentPath } = path8;
|
|
4955
|
-
if (!
|
|
5005
|
+
if (!t47.isIdentifier(node.callee)) return;
|
|
4956
5006
|
const { name: callName } = node.callee;
|
|
4957
|
-
const addLog = (
|
|
4958
|
-
logger.error(
|
|
5007
|
+
const addLog = (t53) => {
|
|
5008
|
+
logger.error(t53, {
|
|
4959
5009
|
file: ctx.filename,
|
|
4960
5010
|
source: ctx.scriptData.source,
|
|
4961
5011
|
loc: node.loc
|
|
@@ -5000,7 +5050,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
5000
5050
|
|
|
5001
5051
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-provide.ts
|
|
5002
5052
|
import { generate as generate2 } from "@babel/generator";
|
|
5003
|
-
import * as
|
|
5053
|
+
import * as t48 from "@babel/types";
|
|
5004
5054
|
function resolveProvide(ctx) {
|
|
5005
5055
|
if (ctx.inputType === "style") return {};
|
|
5006
5056
|
return {
|
|
@@ -5032,13 +5082,13 @@ function findOrCreateCtxProvider(root) {
|
|
|
5032
5082
|
function assignProviderValue(target, key, value) {
|
|
5033
5083
|
const getRawExp = (exp) => {
|
|
5034
5084
|
if (!exp) return "''";
|
|
5035
|
-
if (
|
|
5085
|
+
if (t48.isStringLiteral(exp)) {
|
|
5036
5086
|
return JSON.stringify(exp.value);
|
|
5037
5087
|
}
|
|
5038
|
-
if (
|
|
5088
|
+
if (t48.isNumericLiteral(exp)) {
|
|
5039
5089
|
return exp.value.toString();
|
|
5040
5090
|
}
|
|
5041
|
-
if (
|
|
5091
|
+
if (t48.isIdentifier(exp)) {
|
|
5042
5092
|
return exp.name;
|
|
5043
5093
|
}
|
|
5044
5094
|
try {
|
|
@@ -5054,16 +5104,16 @@ function assignProviderValue(target, key, value) {
|
|
|
5054
5104
|
}
|
|
5055
5105
|
|
|
5056
5106
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
5057
|
-
import * as
|
|
5107
|
+
import * as t49 from "@babel/types";
|
|
5058
5108
|
function resolveRenameAdapter(ctx) {
|
|
5059
5109
|
return {
|
|
5060
5110
|
"CallExpression|Identifier"(path8) {
|
|
5061
5111
|
const node = path8.node;
|
|
5062
|
-
const isCallNode =
|
|
5112
|
+
const isCallNode = t49.isCallExpression(node);
|
|
5063
5113
|
let apiName = "";
|
|
5064
|
-
if (
|
|
5114
|
+
if (t49.isIdentifier(node)) {
|
|
5065
5115
|
apiName = node.name;
|
|
5066
|
-
} else if (isCallNode &&
|
|
5116
|
+
} else if (isCallNode && t49.isIdentifier(node.callee)) {
|
|
5067
5117
|
apiName = node.callee.name;
|
|
5068
5118
|
}
|
|
5069
5119
|
if (!apiName) {
|
|
@@ -5125,7 +5175,7 @@ function isVueImportBinding2(binding) {
|
|
|
5125
5175
|
return false;
|
|
5126
5176
|
}
|
|
5127
5177
|
const parent = bindingPath.parentPath?.node;
|
|
5128
|
-
if (!parent || !
|
|
5178
|
+
if (!parent || !t49.isImportDeclaration(parent)) {
|
|
5129
5179
|
return false;
|
|
5130
5180
|
}
|
|
5131
5181
|
const source = parent.source.value.toLowerCase();
|
|
@@ -5169,7 +5219,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
5169
5219
|
excludeBabel: [resolveTemplateSlotIface, resolveCompIProps]
|
|
5170
5220
|
},
|
|
5171
5221
|
postprocess: {
|
|
5172
|
-
applyBabel: [
|
|
5222
|
+
applyBabel: [
|
|
5223
|
+
// 该 resolver 需确保放在所有类型处理之后,移除之前
|
|
5224
|
+
resolveVueTypeAsAny,
|
|
5225
|
+
resolveRuntimeImports,
|
|
5226
|
+
resolveASTChunks
|
|
5227
|
+
],
|
|
5173
5228
|
excludeBabel: [resolveSfcCssImport]
|
|
5174
5229
|
}
|
|
5175
5230
|
});
|
|
@@ -5262,13 +5317,13 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
5262
5317
|
}
|
|
5263
5318
|
|
|
5264
5319
|
// src/core/transform/sfc/template/shared/prop-ir-utils.ts
|
|
5265
|
-
import * as
|
|
5320
|
+
import * as t51 from "@babel/types";
|
|
5266
5321
|
|
|
5267
5322
|
// src/shared/string-code-types.ts
|
|
5268
5323
|
import { parseExpression as parseExpression3 } from "@babel/parser";
|
|
5269
|
-
import * as
|
|
5324
|
+
import * as t50 from "@babel/types";
|
|
5270
5325
|
var strCodeTypes = {
|
|
5271
|
-
isIdentifier:
|
|
5326
|
+
isIdentifier: isIdentifier29,
|
|
5272
5327
|
isSimpleExpression,
|
|
5273
5328
|
isStringLiteral: isStringLiteral13
|
|
5274
5329
|
};
|
|
@@ -5279,30 +5334,30 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
5279
5334
|
} catch {
|
|
5280
5335
|
return false;
|
|
5281
5336
|
}
|
|
5282
|
-
if (
|
|
5337
|
+
if (t50.isLiteral(node)) {
|
|
5283
5338
|
return true;
|
|
5284
5339
|
}
|
|
5285
|
-
if (!excludeVar &&
|
|
5340
|
+
if (!excludeVar && t50.isIdentifier(node)) {
|
|
5286
5341
|
return true;
|
|
5287
5342
|
}
|
|
5288
|
-
if (
|
|
5289
|
-
return isSimpleExpression(node.object) &&
|
|
5343
|
+
if (t50.isMemberExpression(node)) {
|
|
5344
|
+
return isSimpleExpression(node.object) && t50.isIdentifier(node.property);
|
|
5290
5345
|
}
|
|
5291
|
-
if (
|
|
5346
|
+
if (t50.isObjectExpression(node) || t50.isArrayExpression(node)) {
|
|
5292
5347
|
return false;
|
|
5293
5348
|
}
|
|
5294
|
-
if (
|
|
5349
|
+
if (t50.isCallExpression(node) || t50.isAssignmentExpression(node)) {
|
|
5295
5350
|
return false;
|
|
5296
5351
|
}
|
|
5297
|
-
if (
|
|
5352
|
+
if (t50.isBinaryExpression(node) || t50.isUnaryExpression(node)) {
|
|
5298
5353
|
return true;
|
|
5299
5354
|
}
|
|
5300
5355
|
return false;
|
|
5301
5356
|
}
|
|
5302
|
-
function
|
|
5357
|
+
function isIdentifier29(code) {
|
|
5303
5358
|
try {
|
|
5304
5359
|
const node = parseExpression3(code);
|
|
5305
|
-
return
|
|
5360
|
+
return t50.isIdentifier(node);
|
|
5306
5361
|
} catch {
|
|
5307
5362
|
return false;
|
|
5308
5363
|
}
|
|
@@ -5310,7 +5365,7 @@ function isIdentifier28(code) {
|
|
|
5310
5365
|
function isStringLiteral13(code) {
|
|
5311
5366
|
try {
|
|
5312
5367
|
const node = parseExpression3(code);
|
|
5313
|
-
return
|
|
5368
|
+
return t50.isStringLiteral(node);
|
|
5314
5369
|
} catch {
|
|
5315
5370
|
return false;
|
|
5316
5371
|
}
|
|
@@ -5450,9 +5505,10 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5450
5505
|
const value = ir.value;
|
|
5451
5506
|
const valueContent = value.content;
|
|
5452
5507
|
const mergedItems = value.merge;
|
|
5508
|
+
const rule = ADAPTER_RULES.runtime;
|
|
5453
5509
|
const setNameIdentifier = (target, valueName) => {
|
|
5454
5510
|
target.content = valueName;
|
|
5455
|
-
target.ast =
|
|
5511
|
+
target.ast = t51.jsxIdentifier(valueName);
|
|
5456
5512
|
};
|
|
5457
5513
|
const setValueExpression = (target, content, isStringLiteral14) => {
|
|
5458
5514
|
target.content = content;
|
|
@@ -5460,38 +5516,41 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5460
5516
|
};
|
|
5461
5517
|
const createRuntimeCall = (fnName, args) => {
|
|
5462
5518
|
const fnArgs = args.filter(Boolean).join(",");
|
|
5463
|
-
|
|
5519
|
+
const valIsUndef = fnName === rule.dirOn.target && args?.[1] === "undefined";
|
|
5520
|
+
const isTs = ctx.scriptData.lang.startsWith("ts");
|
|
5521
|
+
const safeTypeAssertion = isTs ? valIsUndef ? "as never" : "" : "";
|
|
5522
|
+
return `${fnName}(${fnArgs}) ${safeTypeAssertion}`;
|
|
5464
5523
|
};
|
|
5465
5524
|
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral14) => {
|
|
5466
5525
|
if (setName && nameIdentifier) {
|
|
5467
5526
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
5468
5527
|
}
|
|
5469
|
-
const dir =
|
|
5528
|
+
const dir = rule.dir;
|
|
5470
5529
|
recordImport(ctx, dir.package, dir.target);
|
|
5471
5530
|
setValueExpression(value.babelExp, expression, isStringLiteral14);
|
|
5472
5531
|
};
|
|
5473
5532
|
if (ir.isKeyLessVBind) {
|
|
5474
|
-
const dirKeyless =
|
|
5533
|
+
const dirKeyless = rule.dirKeyless;
|
|
5475
5534
|
const expression = createRuntimeCall(dirKeyless.target, [valueContent]);
|
|
5476
5535
|
applyRuntimeExpression(expression, false);
|
|
5477
5536
|
return;
|
|
5478
5537
|
}
|
|
5479
5538
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
5480
|
-
const dirCls =
|
|
5539
|
+
const dirCls = rule.dirCls;
|
|
5481
5540
|
const arg = mergedItems?.join(",") || wrapSingleQuotes(valueContent);
|
|
5482
5541
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
5483
5542
|
applyRuntimeExpression(expression, true, name);
|
|
5484
5543
|
return;
|
|
5485
5544
|
}
|
|
5486
5545
|
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || mergedItems?.some((item) => !isSimpleStyle(item)))) {
|
|
5487
|
-
const dirStyle =
|
|
5546
|
+
const dirStyle = rule.dirStyle;
|
|
5488
5547
|
const arg = mergedItems?.join(",") || valueContent;
|
|
5489
5548
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
5490
5549
|
applyRuntimeExpression(expression, true, name);
|
|
5491
5550
|
return;
|
|
5492
5551
|
}
|
|
5493
5552
|
if (ir.type === 3 /* EVENT */ && ir.modifiers?.length) {
|
|
5494
|
-
const dirOn =
|
|
5553
|
+
const dirOn = rule.dirOn;
|
|
5495
5554
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
5496
5555
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
5497
5556
|
applyRuntimeExpression(expression, true, name);
|
|
@@ -6199,14 +6258,15 @@ function applyValueModifiers(valueExp, modifiers) {
|
|
|
6199
6258
|
}
|
|
6200
6259
|
|
|
6201
6260
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
|
|
6202
|
-
import * as
|
|
6261
|
+
import * as t52 from "@babel/types";
|
|
6203
6262
|
function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
6204
6263
|
const arg = directive.arg;
|
|
6205
6264
|
const exp = directive.exp;
|
|
6206
6265
|
const modifiers = directive.modifiers.map((item) => item.content);
|
|
6207
6266
|
const captureIndex = resolveCaptureModifier(modifiers);
|
|
6208
6267
|
const eventName = resolveEventName(arg.content, captureIndex);
|
|
6209
|
-
const
|
|
6268
|
+
const handlerContent = exp?.content?.trim() || "undefined";
|
|
6269
|
+
const handler = resolveHandler(handlerContent, ctx, modifiers);
|
|
6210
6270
|
const originalVueEventName = modifiers.length ? `${arg.content}.${modifiers.join(".")}` : "";
|
|
6211
6271
|
const eventIR = createPropsIR(directive.rawName, eventName, handler);
|
|
6212
6272
|
eventIR.type = 3 /* EVENT */;
|
|
@@ -6256,10 +6316,10 @@ function resolveHandler(handlerContent, ctx, modifiers) {
|
|
|
6256
6316
|
return handler;
|
|
6257
6317
|
}
|
|
6258
6318
|
function isConsoleCall(expr) {
|
|
6259
|
-
return
|
|
6319
|
+
return t52.isCallExpression(expr) && t52.isMemberExpression(expr.callee) && t52.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
|
|
6260
6320
|
}
|
|
6261
6321
|
function isFnReference(expr) {
|
|
6262
|
-
return
|
|
6322
|
+
return t52.isIdentifier(expr) || t52.isMemberExpression(expr) || t52.isFunction(expr);
|
|
6263
6323
|
}
|
|
6264
6324
|
|
|
6265
6325
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
|
|
@@ -6491,11 +6551,8 @@ function resolveSlotOutletNode(node, nodeIR, ctx, parentIR, childrenIR) {
|
|
|
6491
6551
|
function resolveSlotProps(node, ctx) {
|
|
6492
6552
|
const result = {
|
|
6493
6553
|
name: "children",
|
|
6494
|
-
// 默认插槽名为'children'
|
|
6495
6554
|
isScope: false,
|
|
6496
|
-
// 默认非作用域插槽
|
|
6497
6555
|
props: []
|
|
6498
|
-
// 作用域参数列表
|
|
6499
6556
|
};
|
|
6500
6557
|
const { source, filename } = ctx;
|
|
6501
6558
|
const addSlotProp = (key, value) => {
|
|
@@ -6519,9 +6576,12 @@ function resolveSlotProps(node, ctx) {
|
|
|
6519
6576
|
continue;
|
|
6520
6577
|
}
|
|
6521
6578
|
if (prop.type === NodeTypes9.DIRECTIVE) {
|
|
6579
|
+
warnUnsupportedVueDollarVar(ctx, prop);
|
|
6580
|
+
if (!prop.arg) {
|
|
6581
|
+
continue;
|
|
6582
|
+
}
|
|
6522
6583
|
const arg = prop.arg;
|
|
6523
6584
|
const exp = prop.exp;
|
|
6524
|
-
warnUnsupportedVueDollarVar(ctx, prop);
|
|
6525
6585
|
if (!arg.isStatic) {
|
|
6526
6586
|
logger.warn("Avoid using dynamic slot names, as they may lead to unexpected behavior.", {
|
|
6527
6587
|
source,
|
|
@@ -6530,7 +6590,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6530
6590
|
});
|
|
6531
6591
|
}
|
|
6532
6592
|
const key = arg.content;
|
|
6533
|
-
const value = exp
|
|
6593
|
+
const value = exp?.content?.trim() || "undefined";
|
|
6534
6594
|
if (key === "name") {
|
|
6535
6595
|
result.name = camelCase(value);
|
|
6536
6596
|
} else {
|
|
@@ -6612,7 +6672,7 @@ function transform(ast, ctx, options) {
|
|
|
6612
6672
|
}
|
|
6613
6673
|
|
|
6614
6674
|
// package.json
|
|
6615
|
-
var version = "1.8.
|
|
6675
|
+
var version = "1.8.4";
|
|
6616
6676
|
var bin = {
|
|
6617
6677
|
vureact: "bin/vureact.js"
|
|
6618
6678
|
};
|
|
@@ -7036,13 +7096,6 @@ var Helper = class {
|
|
|
7036
7096
|
}
|
|
7037
7097
|
logger.clear();
|
|
7038
7098
|
}
|
|
7039
|
-
printCompileInfo(file, duration) {
|
|
7040
|
-
this.print(
|
|
7041
|
-
kleur4.green("Compiled"),
|
|
7042
|
-
kleur4.dim(normalizePath(this.relativePath(file))),
|
|
7043
|
-
kleur4.gray(`(${duration})`)
|
|
7044
|
-
);
|
|
7045
|
-
}
|
|
7046
7099
|
print(...message) {
|
|
7047
7100
|
if (this.compilerOpts.watch) {
|
|
7048
7101
|
const time = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
@@ -7817,6 +7870,9 @@ var FileProcessor = class {
|
|
|
7817
7870
|
}
|
|
7818
7871
|
}
|
|
7819
7872
|
await this.cacheManager.updateCacheIncrementally(processed, key);
|
|
7873
|
+
if (this.fileCompiler.getIsCache() && !existingCache) {
|
|
7874
|
+
await this.cacheManager.flushCache(key);
|
|
7875
|
+
}
|
|
7820
7876
|
}
|
|
7821
7877
|
return processed;
|
|
7822
7878
|
}
|
|
@@ -8156,7 +8212,7 @@ var ViteBootstrapper = class {
|
|
|
8156
8212
|
newPkg.devDependencies = newDevDeps;
|
|
8157
8213
|
newPkg = output?.packageJson?.(newPkg) || newPkg;
|
|
8158
8214
|
await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
|
|
8159
|
-
this.spinner.succeed("
|
|
8215
|
+
this.spinner.succeed("Vite React environment initialized");
|
|
8160
8216
|
return true;
|
|
8161
8217
|
}
|
|
8162
8218
|
/**
|
|
@@ -8292,7 +8348,7 @@ var FileCompiler = class extends BaseCompiler {
|
|
|
8292
8348
|
const { viteBootstrapper, fileProcessor, cacheManager, pipelineManager, assetManager } = this.manager;
|
|
8293
8349
|
let startTime = 0;
|
|
8294
8350
|
try {
|
|
8295
|
-
this.updateSpinner("Initializing
|
|
8351
|
+
this.updateSpinner("Initializing environment...");
|
|
8296
8352
|
await viteBootstrapper.bootstrapIfNeeded();
|
|
8297
8353
|
const cacheMap = await cacheManager.loadAllCache();
|
|
8298
8354
|
startTime = performance.now();
|