@vureact/compiler-core 1.9.0 → 1.10.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 +3 -4
- package/README.zh-CN.md +2 -3
- package/lib/{chunk-4DEDEJYM.js → chunk-AOWJPHTS.js} +769 -596
- package/lib/{chunk-MBEPCMRP.esm.js → chunk-ZTNVNBKF.esm.js} +681 -508
- package/lib/cli.esm.js +2 -2
- package/lib/cli.js +10 -10
- package/lib/compiler-core.d.cts +18 -3
- package/lib/compiler-core.d.ts +18 -3
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.10.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,7 +24,7 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var
|
|
27
|
+
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t41 = _interopRequireWildcard(_types); var t48 = _interopRequireWildcard(_types); var t46 = _interopRequireWildcard(_types); var t42 = _interopRequireWildcard(_types); var t43 = _interopRequireWildcard(_types); var t44 = _interopRequireWildcard(_types); var t45 = _interopRequireWildcard(_types); var t47 = _interopRequireWildcard(_types); var t49 = _interopRequireWildcard(_types); var t50 = _interopRequireWildcard(_types); var t51 = _interopRequireWildcard(_types); var t52 = _interopRequireWildcard(_types); var t54 = _interopRequireWildcard(_types); var t53 = _interopRequireWildcard(_types); var t55 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -49,7 +49,8 @@ var MACRO_API_NAMES = {
|
|
|
49
49
|
slots: "defineSlots",
|
|
50
50
|
options: "defineOptions",
|
|
51
51
|
expose: "defineExpose",
|
|
52
|
-
model: "defineModel"
|
|
52
|
+
model: "defineModel",
|
|
53
|
+
defaults: "withDefaults"
|
|
53
54
|
};
|
|
54
55
|
var DOLLAR_IDENTIFIERS = [
|
|
55
56
|
"$data",
|
|
@@ -403,6 +404,11 @@ var ADAPTER_RULES = {
|
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
406
|
};
|
|
407
|
+
var AUTO_IMPORTED_APIS = new Set(
|
|
408
|
+
Object.entries(ADAPTER_RULES).flatMap(
|
|
409
|
+
([_, rules]) => Object.keys(rules).filter((key) => !key.startsWith("dir"))
|
|
410
|
+
)
|
|
411
|
+
);
|
|
406
412
|
|
|
407
413
|
// src/consts/vue-api-map.ts
|
|
408
414
|
var VUE_API_MAP = {
|
|
@@ -1061,7 +1067,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1061
1067
|
babelExp: { ast: keyAST },
|
|
1062
1068
|
value: {
|
|
1063
1069
|
content,
|
|
1064
|
-
isStringLiteral:
|
|
1070
|
+
isStringLiteral: isStringLiteral16,
|
|
1065
1071
|
babelExp: { ast: valueAST }
|
|
1066
1072
|
}
|
|
1067
1073
|
} = nodeIR;
|
|
@@ -1070,7 +1076,7 @@ function buildStandardProp(nodeIR) {
|
|
|
1070
1076
|
}
|
|
1071
1077
|
let value;
|
|
1072
1078
|
if (content !== "true") {
|
|
1073
|
-
value =
|
|
1079
|
+
value = isStringLiteral16 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
1074
1080
|
}
|
|
1075
1081
|
return t9.jsxAttribute(keyAST, value);
|
|
1076
1082
|
}
|
|
@@ -2282,7 +2288,7 @@ function resolveReactiveBindings(node, ctx) {
|
|
|
2282
2288
|
source: callName,
|
|
2283
2289
|
reactiveType: getReactiveType(callName)
|
|
2284
2290
|
};
|
|
2285
|
-
if (callName === MACRO_API_NAMES.props) {
|
|
2291
|
+
if (callName === MACRO_API_NAMES.props || callName === MACRO_API_NAMES.defaults) {
|
|
2286
2292
|
ctx.propField = varName;
|
|
2287
2293
|
}
|
|
2288
2294
|
}
|
|
@@ -3302,6 +3308,234 @@ function isVueImport(id, path8) {
|
|
|
3302
3308
|
return VUE_PACKAGES.some((pkg) => moduleName.includes(pkg));
|
|
3303
3309
|
}
|
|
3304
3310
|
|
|
3311
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-with-defaults.ts
|
|
3312
|
+
|
|
3313
|
+
|
|
3314
|
+
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
3315
|
+
|
|
3316
|
+
function createUseCallback(body, deps) {
|
|
3317
|
+
return t26.callExpression(t26.identifier(REACT_API_MAP.useCallback), [
|
|
3318
|
+
body,
|
|
3319
|
+
_nullishCoalesce(deps, () => ( t26.arrayExpression([])))
|
|
3320
|
+
]);
|
|
3321
|
+
}
|
|
3322
|
+
function createUseMemo(body, deps) {
|
|
3323
|
+
return t26.callExpression(t26.identifier(REACT_API_MAP.useMemo), [
|
|
3324
|
+
t26.arrowFunctionExpression([], body),
|
|
3325
|
+
_nullishCoalesce(deps, () => ( t26.arrayExpression([])))
|
|
3326
|
+
]);
|
|
3327
|
+
}
|
|
3328
|
+
function createUseImperativeHandle(refId, init) {
|
|
3329
|
+
return t26.callExpression(t26.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
3330
|
+
}
|
|
3331
|
+
function createUseUpdated(body, deps) {
|
|
3332
|
+
const adapter = ADAPTER_RULES.runtime.onUpdated;
|
|
3333
|
+
return t26.callExpression(t26.identifier(adapter.target), [
|
|
3334
|
+
t26.arrowFunctionExpression([], body),
|
|
3335
|
+
_nullishCoalesce(deps, () => ( t26.identifier("undefined")))
|
|
3336
|
+
]);
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-with-defaults.ts
|
|
3340
|
+
|
|
3341
|
+
var WITH_DEFAULTS_PLACEHOLDER = " from withDefaults ";
|
|
3342
|
+
function resolveWithDefaultsOptions(ctx, ast) {
|
|
3343
|
+
if (ctx.inputType !== "sfc") return {};
|
|
3344
|
+
return {
|
|
3345
|
+
CallExpression(path8) {
|
|
3346
|
+
const { node } = path8;
|
|
3347
|
+
const { filename, scriptData } = ctx;
|
|
3348
|
+
if (!isCalleeNamed(node, MACRO_API_NAMES.defaults)) {
|
|
3349
|
+
return;
|
|
3350
|
+
}
|
|
3351
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
3352
|
+
if (!declaratorPath) {
|
|
3353
|
+
logger.error(
|
|
3354
|
+
`withDefaults() must be assigned to a variable (e.g., const props = withDefaults(...)).`,
|
|
3355
|
+
{ file: filename, source: scriptData.source, loc: node.loc }
|
|
3356
|
+
);
|
|
3357
|
+
return;
|
|
3358
|
+
}
|
|
3359
|
+
const varName = t27.isIdentifier(declaratorPath.node.id) ? declaratorPath.node.id.name : void 0;
|
|
3360
|
+
if (!varName) {
|
|
3361
|
+
logger.error("withDefaults() could not determine the variable name from the declaration.", {
|
|
3362
|
+
file: filename,
|
|
3363
|
+
source: scriptData.source,
|
|
3364
|
+
loc: node.loc
|
|
3365
|
+
});
|
|
3366
|
+
return;
|
|
3367
|
+
}
|
|
3368
|
+
ctx.propField = `vr${capitalize(ctx.propField)}`;
|
|
3369
|
+
const [defineProps, defaults] = node.arguments;
|
|
3370
|
+
if (!node.arguments.length) {
|
|
3371
|
+
logger.error("withDefaults() requires at least one argument (defineProps call).", {
|
|
3372
|
+
file: filename,
|
|
3373
|
+
source: scriptData.source,
|
|
3374
|
+
loc: node.loc
|
|
3375
|
+
});
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
if (!t27.isCallExpression(defineProps)) {
|
|
3379
|
+
logger.error(
|
|
3380
|
+
"withDefaults() first argument must be a call to defineProps (e.g., defineProps({...})).",
|
|
3381
|
+
{ file: filename, source: scriptData.source, loc: _optionalChain([defineProps, 'optionalAccess', _110 => _110.loc]) }
|
|
3382
|
+
);
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
if (defaults && !t27.isObjectExpression(defaults)) {
|
|
3386
|
+
logger.error(
|
|
3387
|
+
'withDefaults() second argument must be an object literal (e.g., { msg: "hello" }).',
|
|
3388
|
+
{ file: filename, source: scriptData.source, loc: _optionalChain([defaults, 'optionalAccess', _111 => _111.loc]) }
|
|
3389
|
+
);
|
|
3390
|
+
return;
|
|
3391
|
+
}
|
|
3392
|
+
recordPropsWithDefaults(ctx, varName, defineProps, defaults, node);
|
|
3393
|
+
declaratorPath.parentPath.insertAfter(createPlaceholder(node));
|
|
3394
|
+
replaceNode(path8, defineProps, node);
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
}
|
|
3398
|
+
function recordPropsWithDefaults(ctx, varName, defineProps, defaults, withDefaults) {
|
|
3399
|
+
const { scriptData } = ctx;
|
|
3400
|
+
const { start, end, loc, leadingComments, innerComments, trailingComments } = withDefaults;
|
|
3401
|
+
const values = flattenDefaultValues(defaults);
|
|
3402
|
+
const getTypeParameters = () => {
|
|
3403
|
+
if (!scriptData.lang.startsWith("ts")) {
|
|
3404
|
+
return;
|
|
3405
|
+
}
|
|
3406
|
+
const { propsTypes } = scriptData.propsTSIface;
|
|
3407
|
+
const typeParameters = defineProps.typeParameters || (propsTypes.length ? t27.tSTypeParameterInstantiation(propsTypes) : void 0);
|
|
3408
|
+
if (typeParameters) {
|
|
3409
|
+
return t27.tsTypeParameterInstantiation([
|
|
3410
|
+
t27.tsTypeReference(t27.identifier("Readonly"), typeParameters)
|
|
3411
|
+
]);
|
|
3412
|
+
}
|
|
3413
|
+
};
|
|
3414
|
+
scriptData.propsWithDefaults = {
|
|
3415
|
+
varName,
|
|
3416
|
+
values,
|
|
3417
|
+
start,
|
|
3418
|
+
end,
|
|
3419
|
+
loc,
|
|
3420
|
+
leadingComments,
|
|
3421
|
+
innerComments,
|
|
3422
|
+
trailingComments,
|
|
3423
|
+
typeParameters: getTypeParameters()
|
|
3424
|
+
};
|
|
3425
|
+
}
|
|
3426
|
+
function flattenDefaultValues(expr) {
|
|
3427
|
+
if (!expr) return;
|
|
3428
|
+
if (!t27.isObjectExpression(expr)) {
|
|
3429
|
+
return expr;
|
|
3430
|
+
}
|
|
3431
|
+
const properties = expr.properties.map((prop) => {
|
|
3432
|
+
if (!t27.isObjectProperty(prop)) {
|
|
3433
|
+
return prop;
|
|
3434
|
+
}
|
|
3435
|
+
const value = prop.value;
|
|
3436
|
+
if (t27.isArrowFunctionExpression(value) && t27.isBlockStatement(value.body)) {
|
|
3437
|
+
const returnStmt = value.body.body.find(
|
|
3438
|
+
(stmt) => t27.isReturnStatement(stmt)
|
|
3439
|
+
);
|
|
3440
|
+
if (_optionalChain([returnStmt, 'optionalAccess', _112 => _112.argument])) {
|
|
3441
|
+
return t27.objectProperty(prop.key, returnStmt.argument, prop.computed);
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
if (t27.isArrowFunctionExpression(value) && !t27.isBlockStatement(value.body)) {
|
|
3445
|
+
return t27.objectProperty(prop.key, value.body, prop.computed);
|
|
3446
|
+
}
|
|
3447
|
+
return prop;
|
|
3448
|
+
});
|
|
3449
|
+
return t27.objectExpression(properties);
|
|
3450
|
+
}
|
|
3451
|
+
function createPlaceholder(node) {
|
|
3452
|
+
const placeholder = t27.emptyStatement();
|
|
3453
|
+
const leadingComments = [
|
|
3454
|
+
{
|
|
3455
|
+
type: "CommentBlock",
|
|
3456
|
+
value: WITH_DEFAULTS_PLACEHOLDER,
|
|
3457
|
+
start: node.start,
|
|
3458
|
+
end: node.end
|
|
3459
|
+
}
|
|
3460
|
+
];
|
|
3461
|
+
placeholder.leadingComments = leadingComments;
|
|
3462
|
+
return placeholder;
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-with-defaults.ts
|
|
3466
|
+
function resolveWithDefaults(ctx) {
|
|
3467
|
+
const { inputType, scriptData } = ctx;
|
|
3468
|
+
const propsWithDefaults = scriptData.propsWithDefaults;
|
|
3469
|
+
if (inputType !== "sfc" || !_optionalChain([propsWithDefaults, 'optionalAccess', _113 => _113.values])) return {};
|
|
3470
|
+
return {
|
|
3471
|
+
Program: {
|
|
3472
|
+
exit(programPath) {
|
|
3473
|
+
const { body } = programPath.node;
|
|
3474
|
+
const placeholderIndex = findPlaceholderIndex(body);
|
|
3475
|
+
if (placeholderIndex === -1) return;
|
|
3476
|
+
const placeholder = body[placeholderIndex];
|
|
3477
|
+
const { varName, values, typeParameters } = propsWithDefaults;
|
|
3478
|
+
const varDeclaration = createVarDeclaration(
|
|
3479
|
+
varName,
|
|
3480
|
+
values,
|
|
3481
|
+
typeParameters,
|
|
3482
|
+
ctx.propField,
|
|
3483
|
+
propsWithDefaults
|
|
3484
|
+
);
|
|
3485
|
+
varDeclaration.leadingComments = placeholder.leadingComments;
|
|
3486
|
+
body.splice(placeholderIndex, 0, varDeclaration);
|
|
3487
|
+
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useMemo);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
};
|
|
3491
|
+
}
|
|
3492
|
+
function findPlaceholderIndex(body) {
|
|
3493
|
+
return body.findIndex((stmt) => {
|
|
3494
|
+
if (!t28.isEmptyStatement(stmt) || !stmt.leadingComments) {
|
|
3495
|
+
return false;
|
|
3496
|
+
}
|
|
3497
|
+
return stmt.leadingComments.some(
|
|
3498
|
+
(comment) => comment.type === "CommentBlock" && comment.value === WITH_DEFAULTS_PLACEHOLDER
|
|
3499
|
+
);
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
function createVarDeclaration(varName, values, typeParameters, propField, sourceInfo) {
|
|
3503
|
+
const { mergeMembers } = buildMergeLogic(values, propField);
|
|
3504
|
+
const deps = t28.arrayExpression([t28.identifier(propField)]);
|
|
3505
|
+
const useMemoCall = createUseMemo(t28.objectExpression(mergeMembers), deps);
|
|
3506
|
+
if (typeParameters) {
|
|
3507
|
+
useMemoCall.typeParameters = typeParameters;
|
|
3508
|
+
}
|
|
3509
|
+
useMemoCall.start = sourceInfo.start;
|
|
3510
|
+
useMemoCall.end = sourceInfo.end;
|
|
3511
|
+
useMemoCall.loc = sourceInfo.loc;
|
|
3512
|
+
useMemoCall.leadingComments = sourceInfo.leadingComments;
|
|
3513
|
+
useMemoCall.innerComments = sourceInfo.innerComments;
|
|
3514
|
+
useMemoCall.trailingComments = sourceInfo.trailingComments;
|
|
3515
|
+
const varDeclarator = t28.variableDeclarator(t28.identifier(varName), useMemoCall);
|
|
3516
|
+
return t28.variableDeclaration("const", [varDeclarator]);
|
|
3517
|
+
}
|
|
3518
|
+
function buildMergeLogic(values, propField) {
|
|
3519
|
+
const mergeMembers = [];
|
|
3520
|
+
const propFieldIdent = t28.identifier(propField);
|
|
3521
|
+
mergeMembers.push(t28.spreadElement(propFieldIdent));
|
|
3522
|
+
for (const defaultProp of values.properties) {
|
|
3523
|
+
if (!t28.isObjectProperty(defaultProp)) continue;
|
|
3524
|
+
const key = defaultProp.key;
|
|
3525
|
+
if (!t28.isIdentifier(key) && !t28.isStringLiteral(key)) continue;
|
|
3526
|
+
const keyName = t28.isIdentifier(key) ? key.name : key.value;
|
|
3527
|
+
const propAccess = t28.memberExpression(propFieldIdent, t28.identifier(keyName), false);
|
|
3528
|
+
const logicalExpr = t28.logicalExpression("??", propAccess, defaultProp.value);
|
|
3529
|
+
mergeMembers.push(
|
|
3530
|
+
t28.objectProperty(
|
|
3531
|
+
t28.isIdentifier(key) ? t28.identifier(keyName) : t28.stringLiteral(keyName),
|
|
3532
|
+
logicalExpr
|
|
3533
|
+
)
|
|
3534
|
+
);
|
|
3535
|
+
}
|
|
3536
|
+
return { mergeMembers };
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3305
3539
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-async-component.ts
|
|
3306
3540
|
|
|
3307
3541
|
function resolveDefineAsyncComponent(ctx) {
|
|
@@ -3312,11 +3546,11 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3312
3546
|
return;
|
|
3313
3547
|
}
|
|
3314
3548
|
const [arg] = node.arguments;
|
|
3315
|
-
if (!
|
|
3549
|
+
if (!t29.isObjectExpression(arg)) {
|
|
3316
3550
|
return;
|
|
3317
3551
|
}
|
|
3318
3552
|
for (const prop of arg.properties) {
|
|
3319
|
-
if (!
|
|
3553
|
+
if (!t29.isObjectProperty(prop) || !t29.isIdentifier(prop.key) || prop.key.name !== "hydrate") {
|
|
3320
3554
|
continue;
|
|
3321
3555
|
}
|
|
3322
3556
|
logger.warn('Unsupported option "hydrate"', {
|
|
@@ -3332,33 +3566,6 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3332
3566
|
|
|
3333
3567
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
3334
3568
|
|
|
3335
|
-
|
|
3336
|
-
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
3337
|
-
|
|
3338
|
-
function createUseCallback(body, deps) {
|
|
3339
|
-
return t27.callExpression(t27.identifier(REACT_API_MAP.useCallback), [
|
|
3340
|
-
body,
|
|
3341
|
-
_nullishCoalesce(deps, () => ( t27.arrayExpression([])))
|
|
3342
|
-
]);
|
|
3343
|
-
}
|
|
3344
|
-
function createUseMemo(body, deps) {
|
|
3345
|
-
return t27.callExpression(t27.identifier(REACT_API_MAP.useMemo), [
|
|
3346
|
-
t27.arrowFunctionExpression([], body),
|
|
3347
|
-
_nullishCoalesce(deps, () => ( t27.arrayExpression([])))
|
|
3348
|
-
]);
|
|
3349
|
-
}
|
|
3350
|
-
function createUseImperativeHandle(refId, init) {
|
|
3351
|
-
return t27.callExpression(t27.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
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
|
-
_nullishCoalesce(deps, () => ( t27.identifier("undefined")))
|
|
3358
|
-
]);
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
3362
3569
|
function resolveDefineExpose(ctx) {
|
|
3363
3570
|
if (ctx.inputType !== "sfc") return {};
|
|
3364
3571
|
return {
|
|
@@ -3376,16 +3583,16 @@ function resolveDefineExpose(ctx) {
|
|
|
3376
3583
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
3377
3584
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
3378
3585
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3379
|
-
if (!
|
|
3586
|
+
if (!t30.isObjectExpression(expose) && !t30.isFunction(expose)) {
|
|
3380
3587
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
3381
3588
|
file: filename,
|
|
3382
3589
|
loc: expose.loc,
|
|
3383
3590
|
source: scriptData.source
|
|
3384
3591
|
});
|
|
3385
3592
|
}
|
|
3386
|
-
const init = !
|
|
3593
|
+
const init = !t30.isFunction(expose) ? t30.arrowFunctionExpression([], expose) : expose;
|
|
3387
3594
|
const { forwardRef } = scriptData;
|
|
3388
|
-
const newNode = createUseImperativeHandle(
|
|
3595
|
+
const newNode = createUseImperativeHandle(t30.identifier(forwardRef.refField), init);
|
|
3389
3596
|
forwardRef.enabled = true;
|
|
3390
3597
|
replaceNode(path8, newNode, node);
|
|
3391
3598
|
}
|
|
@@ -3416,20 +3623,20 @@ function validateDefineModelUsage(path8, ctx) {
|
|
|
3416
3623
|
const { node, parent } = path8;
|
|
3417
3624
|
const { filename, scriptData } = ctx;
|
|
3418
3625
|
const [arg1, arg2] = node.arguments;
|
|
3419
|
-
if (!
|
|
3626
|
+
if (!t31.isObjectExpression(arg1) && !t31.isStringLiteral(arg1)) {
|
|
3420
3627
|
logger.error(`Invalid argument type for defineModel. Expected a string.`, {
|
|
3421
3628
|
file: filename,
|
|
3422
3629
|
source: scriptData.source,
|
|
3423
|
-
loc: _optionalChain([arg1, 'optionalAccess',
|
|
3630
|
+
loc: _optionalChain([arg1, 'optionalAccess', _114 => _114.loc])
|
|
3424
3631
|
});
|
|
3425
3632
|
return false;
|
|
3426
3633
|
}
|
|
3427
3634
|
const hasUnsupportedOption = (arg) => {
|
|
3428
|
-
if (!
|
|
3635
|
+
if (!t31.isObjectExpression(arg)) {
|
|
3429
3636
|
return false;
|
|
3430
3637
|
}
|
|
3431
3638
|
const result = arg.properties.some((prop) => {
|
|
3432
|
-
if ((
|
|
3639
|
+
if ((t31.isObjectProperty(prop) || t31.isObjectMethod(prop)) && t31.isIdentifier(prop.key)) {
|
|
3433
3640
|
const keyName = prop.key.name;
|
|
3434
3641
|
if (keyName === "get" || keyName === "set" || keyName === "validator") {
|
|
3435
3642
|
logger.error(`defineModel does not support '${keyName}' option.`, {
|
|
@@ -3445,7 +3652,7 @@ function validateDefineModelUsage(path8, ctx) {
|
|
|
3445
3652
|
};
|
|
3446
3653
|
const isValidVariableAssignment = () => {
|
|
3447
3654
|
const varDeclaration = path8.parentPath.parentPath;
|
|
3448
|
-
if (_optionalChain([varDeclaration, 'optionalAccess',
|
|
3655
|
+
if (_optionalChain([varDeclaration, 'optionalAccess', _115 => _115.isVariableDeclaration, 'call', _116 => _116()]) && varDeclaration.node.declarations.length === 1 && t31.isArrayPattern(_optionalChain([varDeclaration, 'access', _117 => _117.node, 'access', _118 => _118.declarations, 'access', _119 => _119[0], 'optionalAccess', _120 => _120.id]))) {
|
|
3449
3656
|
logger.error(
|
|
3450
3657
|
`defineModel return value cannot be destructured with array pattern. Please use single variable assignment.`,
|
|
3451
3658
|
{
|
|
@@ -3471,7 +3678,7 @@ function extractPropInfo(node, ctx) {
|
|
|
3471
3678
|
};
|
|
3472
3679
|
const findObjectProperty = (objExpr, propName) => {
|
|
3473
3680
|
return objExpr.properties.find(
|
|
3474
|
-
(prop) =>
|
|
3681
|
+
(prop) => t31.isObjectProperty(prop) && t31.isIdentifier(prop.key) && prop.key.name === propName
|
|
3475
3682
|
);
|
|
3476
3683
|
};
|
|
3477
3684
|
const setPropName = (info, value) => {
|
|
@@ -3485,20 +3692,20 @@ function extractPropInfo(node, ctx) {
|
|
|
3485
3692
|
const typeProp = findObjectProperty(objExpr, "type");
|
|
3486
3693
|
const defaultProp = findObjectProperty(objExpr, "default");
|
|
3487
3694
|
const requiredProp = findObjectProperty(objExpr, "required");
|
|
3488
|
-
if (nameProp &&
|
|
3695
|
+
if (nameProp && t31.isStringLiteral(nameProp.value)) {
|
|
3489
3696
|
setPropName(result, nameProp.value.value);
|
|
3490
3697
|
}
|
|
3491
3698
|
if (defaultProp) {
|
|
3492
3699
|
result.default = defaultProp.value;
|
|
3493
3700
|
}
|
|
3494
|
-
if (requiredProp &&
|
|
3701
|
+
if (requiredProp && t31.isBooleanLiteral(requiredProp.value)) {
|
|
3495
3702
|
result.required = requiredProp.value.value;
|
|
3496
3703
|
}
|
|
3497
|
-
if (typeProp &&
|
|
3704
|
+
if (typeProp && t31.isIdentifier(typeProp.value)) {
|
|
3498
3705
|
result.type = mapRuntimeTypeToTSType(typeProp.value);
|
|
3499
3706
|
} else if (node.typeParameters) {
|
|
3500
3707
|
const [typeParam] = node.typeParameters.params;
|
|
3501
|
-
if (
|
|
3708
|
+
if (t31.isTSType(typeParam)) {
|
|
3502
3709
|
result.type = typeParam;
|
|
3503
3710
|
}
|
|
3504
3711
|
} else if (defaultProp) {
|
|
@@ -3525,20 +3732,20 @@ function extractPropInfo(node, ctx) {
|
|
|
3525
3732
|
};
|
|
3526
3733
|
const extractTypeFromTypeParams = (info) => {
|
|
3527
3734
|
if (!node.typeParameters) return;
|
|
3528
|
-
const isDefaultAny = !info.type ||
|
|
3735
|
+
const isDefaultAny = !info.type || t31.isTSAnyKeyword(info.type);
|
|
3529
3736
|
if (!isDefaultAny) return;
|
|
3530
3737
|
const [typeParam] = node.typeParameters.params;
|
|
3531
|
-
if (
|
|
3738
|
+
if (t31.isTSType(typeParam)) {
|
|
3532
3739
|
info.type = typeParam;
|
|
3533
3740
|
}
|
|
3534
3741
|
};
|
|
3535
|
-
if (
|
|
3742
|
+
if (t31.isStringLiteral(arg1)) {
|
|
3536
3743
|
setPropName(propInfo, arg1.value);
|
|
3537
3744
|
extractTypeFromTypeParams(propInfo);
|
|
3538
|
-
} else if (
|
|
3745
|
+
} else if (t31.isObjectExpression(arg1)) {
|
|
3539
3746
|
safeAssign(propInfo, extractPropInfoFromObject(arg1));
|
|
3540
3747
|
}
|
|
3541
|
-
if (!
|
|
3748
|
+
if (!t31.isObjectExpression(arg1) && t31.isObjectExpression(arg2)) {
|
|
3542
3749
|
safeAssign(propInfo, extractPropInfoFromObject(arg2));
|
|
3543
3750
|
}
|
|
3544
3751
|
return propInfo;
|
|
@@ -3548,36 +3755,36 @@ function replaceToUseVRef(node, propInfo, ctx) {
|
|
|
3548
3755
|
replaceCallName(node, refAdapter.target);
|
|
3549
3756
|
recordImport(ctx, refAdapter.package, refAdapter.target);
|
|
3550
3757
|
const defaultValue = propInfo.default;
|
|
3551
|
-
const propRef =
|
|
3758
|
+
const propRef = t31.identifier(`${ctx.propField}.${propInfo.name}`);
|
|
3552
3759
|
if (!defaultValue) {
|
|
3553
3760
|
node.arguments = [propRef];
|
|
3554
3761
|
} else {
|
|
3555
|
-
node.arguments = [
|
|
3762
|
+
node.arguments = [t31.logicalExpression("??", propRef, defaultValue)];
|
|
3556
3763
|
}
|
|
3557
3764
|
if (ctx.scriptData.lang.startsWith("ts") && !node.typeParameters && propInfo.type) {
|
|
3558
|
-
node.typeParameters =
|
|
3765
|
+
node.typeParameters = t31.tsTypeParameterInstantiation([propInfo.type]);
|
|
3559
3766
|
}
|
|
3560
3767
|
}
|
|
3561
3768
|
function resolveAutoUpdate(ast, path8, propInfo, ctx) {
|
|
3562
3769
|
const { parent } = path8;
|
|
3563
|
-
if (!
|
|
3770
|
+
if (!t31.isVariableDeclarator(parent)) {
|
|
3564
3771
|
return;
|
|
3565
3772
|
}
|
|
3566
3773
|
const modelId = parent.id;
|
|
3567
|
-
if (!
|
|
3774
|
+
if (!t31.isIdentifier(modelId)) {
|
|
3568
3775
|
return;
|
|
3569
3776
|
}
|
|
3570
|
-
const memberAccess =
|
|
3571
|
-
|
|
3572
|
-
|
|
3777
|
+
const memberAccess = t31.memberExpression(
|
|
3778
|
+
t31.identifier(ctx.propField),
|
|
3779
|
+
t31.identifier(propInfo.updateEventName)
|
|
3573
3780
|
);
|
|
3574
|
-
const dep =
|
|
3575
|
-
const updateCall =
|
|
3781
|
+
const dep = t31.memberExpression(modelId, t31.identifier("value"));
|
|
3782
|
+
const updateCall = t31.optionalCallExpression(memberAccess, [dep], true);
|
|
3576
3783
|
const callExpr = createUseUpdated(
|
|
3577
|
-
|
|
3578
|
-
|
|
3784
|
+
t31.blockStatement([t31.expressionStatement(updateCall)]),
|
|
3785
|
+
t31.arrayExpression([dep])
|
|
3579
3786
|
);
|
|
3580
|
-
ast.program.body.push(
|
|
3787
|
+
ast.program.body.push(t31.expressionStatement(callExpr));
|
|
3581
3788
|
const adapter = ADAPTER_RULES.runtime.onUpdated;
|
|
3582
3789
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3583
3790
|
}
|
|
@@ -3587,25 +3794,25 @@ function resolveInterface(propInfo, ctx) {
|
|
|
3587
3794
|
if (!lang.startsWith("ts")) {
|
|
3588
3795
|
return;
|
|
3589
3796
|
}
|
|
3590
|
-
const propType = propInfo.type ||
|
|
3591
|
-
const propSignature =
|
|
3592
|
-
|
|
3593
|
-
|
|
3797
|
+
const propType = propInfo.type || t31.tsAnyKeyword();
|
|
3798
|
+
const propSignature = t31.tsPropertySignature(
|
|
3799
|
+
t31.isValidIdentifier(name) ? t31.identifier(name) : t31.stringLiteral(name),
|
|
3800
|
+
t31.tsTypeAnnotation(propType)
|
|
3594
3801
|
);
|
|
3595
3802
|
propSignature.optional = !required;
|
|
3596
|
-
const emitArg =
|
|
3597
|
-
emitArg.typeAnnotation =
|
|
3598
|
-
const emitSignature =
|
|
3599
|
-
|
|
3600
|
-
|
|
3803
|
+
const emitArg = t31.identifier("arg");
|
|
3804
|
+
emitArg.typeAnnotation = t31.tsTypeAnnotation(propType);
|
|
3805
|
+
const emitSignature = t31.tsPropertySignature(
|
|
3806
|
+
t31.isValidIdentifier(updateEventName) ? t31.identifier(updateEventName) : t31.stringLiteral(updateEventName),
|
|
3807
|
+
t31.tsTypeAnnotation(t31.tsFunctionType(null, [emitArg], t31.tsTypeAnnotation(t31.tsVoidKeyword())))
|
|
3601
3808
|
);
|
|
3602
3809
|
emitSignature.optional = true;
|
|
3603
3810
|
const appendToTypeLiteral = (list, member) => {
|
|
3604
|
-
const existing = list.find((item) =>
|
|
3811
|
+
const existing = list.find((item) => t31.isTSTypeLiteral(item));
|
|
3605
3812
|
if (existing) {
|
|
3606
3813
|
existing.members.push(member);
|
|
3607
3814
|
} else {
|
|
3608
|
-
list.push(
|
|
3815
|
+
list.push(t31.tsTypeLiteral([member]));
|
|
3609
3816
|
}
|
|
3610
3817
|
};
|
|
3611
3818
|
appendToTypeLiteral(propsTSIface.propsTypes, propSignature);
|
|
@@ -3640,7 +3847,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3640
3847
|
CallExpression(path8) {
|
|
3641
3848
|
const { node } = path8;
|
|
3642
3849
|
const { filename, templateData, scriptData } = ctx;
|
|
3643
|
-
if (!
|
|
3850
|
+
if (!t32.isIdentifier(node.callee)) return;
|
|
3644
3851
|
const { name } = node.callee;
|
|
3645
3852
|
const checkIfFromDefineEmits = () => {
|
|
3646
3853
|
let result = false;
|
|
@@ -3652,7 +3859,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3652
3859
|
const binding = path8.scope.getBinding(name);
|
|
3653
3860
|
if (binding) {
|
|
3654
3861
|
const parent = binding.path.node;
|
|
3655
|
-
if (
|
|
3862
|
+
if (t32.isVariableDeclarator(parent) && t32.isCallExpression(parent.init) && t32.isIdentifier(parent.init.callee)) {
|
|
3656
3863
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
3657
3864
|
}
|
|
3658
3865
|
}
|
|
@@ -3662,9 +3869,9 @@ function resolveEmitCalls(ctx) {
|
|
|
3662
3869
|
if (!checkIfFromDefineEmits()) return;
|
|
3663
3870
|
const [callee, ...args] = node.arguments;
|
|
3664
3871
|
let propCall;
|
|
3665
|
-
if (
|
|
3872
|
+
if (t32.isStringLiteral(callee)) {
|
|
3666
3873
|
const eventName = formatEmitEventName(callee.value);
|
|
3667
|
-
propCall = createPropCall(ctx.propField,
|
|
3874
|
+
propCall = createPropCall(ctx.propField, t32.identifier(eventName), args);
|
|
3668
3875
|
} else {
|
|
3669
3876
|
propCall = createPropCall(ctx.propField, callee, args, true);
|
|
3670
3877
|
logger.error(
|
|
@@ -3672,7 +3879,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3672
3879
|
{
|
|
3673
3880
|
file: filename,
|
|
3674
3881
|
source: scriptData.source,
|
|
3675
|
-
loc: _optionalChain([callee, 'optionalAccess',
|
|
3882
|
+
loc: _optionalChain([callee, 'optionalAccess', _121 => _121.loc])
|
|
3676
3883
|
}
|
|
3677
3884
|
);
|
|
3678
3885
|
}
|
|
@@ -3681,8 +3888,8 @@ function resolveEmitCalls(ctx) {
|
|
|
3681
3888
|
};
|
|
3682
3889
|
}
|
|
3683
3890
|
function createPropCall(rootName, callee, args, computed = false) {
|
|
3684
|
-
return
|
|
3685
|
-
|
|
3891
|
+
return t32.optionalCallExpression(
|
|
3892
|
+
t32.memberExpression(t32.identifier(rootName), callee, computed),
|
|
3686
3893
|
args,
|
|
3687
3894
|
true
|
|
3688
3895
|
);
|
|
@@ -3698,21 +3905,21 @@ function createPropCall(rootName, callee, args, computed = false) {
|
|
|
3698
3905
|
|
|
3699
3906
|
function cloneCallableParams(params) {
|
|
3700
3907
|
const cloneCallableParam = (param, index) => {
|
|
3701
|
-
if (
|
|
3908
|
+
if (t33.isRestElement(param)) {
|
|
3702
3909
|
const arg = param.argument;
|
|
3703
|
-
const name =
|
|
3704
|
-
const rest =
|
|
3705
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
3910
|
+
const name = t33.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
3911
|
+
const rest = t33.restElement(t33.identifier(name));
|
|
3912
|
+
rest.typeAnnotation = param.typeAnnotation || (t33.isIdentifier(arg) ? arg.typeAnnotation : null) || t33.tsTypeAnnotation(t33.tsArrayType(t33.tsAnyKeyword()));
|
|
3706
3913
|
return rest;
|
|
3707
3914
|
}
|
|
3708
|
-
if (
|
|
3709
|
-
const id =
|
|
3915
|
+
if (t33.isIdentifier(param)) {
|
|
3916
|
+
const id = t33.identifier(param.name || `arg${index}`);
|
|
3710
3917
|
id.optional = param.optional;
|
|
3711
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
3918
|
+
id.typeAnnotation = param.typeAnnotation || t33.tsTypeAnnotation(t33.tsAnyKeyword());
|
|
3712
3919
|
return id;
|
|
3713
3920
|
}
|
|
3714
|
-
const fallback =
|
|
3715
|
-
fallback.typeAnnotation =
|
|
3921
|
+
const fallback = t33.identifier(`arg${index}`);
|
|
3922
|
+
fallback.typeAnnotation = t33.tsTypeAnnotation(t33.tsAnyKeyword());
|
|
3716
3923
|
return fallback;
|
|
3717
3924
|
};
|
|
3718
3925
|
return params.map(cloneCallableParam);
|
|
@@ -3722,18 +3929,18 @@ function cloneCallableParams(params) {
|
|
|
3722
3929
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
3723
3930
|
return {
|
|
3724
3931
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3725
|
-
if (!
|
|
3932
|
+
if (!t34.isProgram(path8.parent)) return;
|
|
3726
3933
|
const { node } = path8;
|
|
3727
|
-
if (
|
|
3728
|
-
const typeLiteral =
|
|
3934
|
+
if (t34.isTSInterfaceDeclaration(node)) {
|
|
3935
|
+
const typeLiteral = t34.tsTypeLiteral(node.body.body);
|
|
3729
3936
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
3730
3937
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
3731
|
-
if (resolved &&
|
|
3938
|
+
if (resolved && t34.isTSTypeLiteral(resolved)) {
|
|
3732
3939
|
node.body.body = resolved.members;
|
|
3733
3940
|
}
|
|
3734
3941
|
return;
|
|
3735
3942
|
}
|
|
3736
|
-
if (
|
|
3943
|
+
if (t34.isTSTypeAliasDeclaration(node)) {
|
|
3737
3944
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
3738
3945
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
3739
3946
|
if (resolved) {
|
|
@@ -3744,55 +3951,55 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
3744
3951
|
};
|
|
3745
3952
|
}
|
|
3746
3953
|
function resolveTopLevelEmitType(tsType) {
|
|
3747
|
-
if (
|
|
3954
|
+
if (t34.isTSParenthesizedType(tsType)) {
|
|
3748
3955
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
3749
3956
|
}
|
|
3750
|
-
if (
|
|
3957
|
+
if (t34.isTSTypeReference(tsType)) {
|
|
3751
3958
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3752
3959
|
return tsType;
|
|
3753
3960
|
}
|
|
3754
3961
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
3755
|
-
return
|
|
3962
|
+
return t34.tsTypeReference(
|
|
3756
3963
|
tsType.typeName,
|
|
3757
|
-
|
|
3964
|
+
t34.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3758
3965
|
);
|
|
3759
3966
|
}
|
|
3760
|
-
if (
|
|
3967
|
+
if (t34.isTSIntersectionType(tsType)) {
|
|
3761
3968
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3762
3969
|
if (!types.length) return null;
|
|
3763
3970
|
if (types.length === 1) return types[0];
|
|
3764
|
-
return
|
|
3971
|
+
return t34.tsIntersectionType(types);
|
|
3765
3972
|
}
|
|
3766
|
-
if (
|
|
3973
|
+
if (t34.isTSUnionType(tsType)) {
|
|
3767
3974
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3768
3975
|
if (!types.length) return null;
|
|
3769
3976
|
if (types.length === 1) return types[0];
|
|
3770
|
-
return
|
|
3977
|
+
return t34.tsUnionType(types);
|
|
3771
3978
|
}
|
|
3772
|
-
if (
|
|
3979
|
+
if (t34.isTSTypeLiteral(tsType)) {
|
|
3773
3980
|
const members = [];
|
|
3774
3981
|
for (const member of tsType.members) {
|
|
3775
|
-
if (
|
|
3982
|
+
if (t34.isTSCallSignatureDeclaration(member)) {
|
|
3776
3983
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3777
3984
|
continue;
|
|
3778
3985
|
}
|
|
3779
3986
|
members.push(member);
|
|
3780
3987
|
}
|
|
3781
3988
|
if (!members.length) return null;
|
|
3782
|
-
return
|
|
3989
|
+
return t34.tsTypeLiteral(members);
|
|
3783
3990
|
}
|
|
3784
|
-
if (
|
|
3991
|
+
if (t34.isTSFunctionType(tsType)) {
|
|
3785
3992
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3786
3993
|
if (!props.length) return null;
|
|
3787
|
-
return
|
|
3994
|
+
return t34.tsTypeLiteral(props);
|
|
3788
3995
|
}
|
|
3789
3996
|
return tsType;
|
|
3790
3997
|
}
|
|
3791
3998
|
function resolveDefineEmitsIface(path8, ctx) {
|
|
3792
3999
|
const { node } = path8;
|
|
3793
4000
|
const [runtimeArg] = node.arguments;
|
|
3794
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3795
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
4001
|
+
const tsParams = _optionalChain([node, 'access', _122 => _122.typeParameters, 'optionalAccess', _123 => _123.params]);
|
|
4002
|
+
if (_optionalChain([tsParams, 'optionalAccess', _124 => _124.length])) {
|
|
3796
4003
|
processExplicitType(ctx, tsParams);
|
|
3797
4004
|
return;
|
|
3798
4005
|
}
|
|
@@ -3805,41 +4012,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
3805
4012
|
propsTSIface: { emitTypes }
|
|
3806
4013
|
} = ctx.scriptData;
|
|
3807
4014
|
const members = [];
|
|
3808
|
-
if (
|
|
4015
|
+
if (t34.isArrayExpression(runtimeArg)) {
|
|
3809
4016
|
for (const element of runtimeArg.elements) {
|
|
3810
|
-
if (!element || !
|
|
4017
|
+
if (!element || !t34.isStringLiteral(element)) continue;
|
|
3811
4018
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
3812
4019
|
const key = buildKey(handlerName);
|
|
3813
|
-
const fnType =
|
|
4020
|
+
const fnType = t34.tsFunctionType(
|
|
3814
4021
|
null,
|
|
3815
4022
|
[createRestAnyParam("args")],
|
|
3816
|
-
|
|
4023
|
+
t34.tsTypeAnnotation(t34.tsAnyKeyword())
|
|
3817
4024
|
);
|
|
3818
|
-
const prop =
|
|
4025
|
+
const prop = t34.tsPropertySignature(key, t34.tsTypeAnnotation(fnType));
|
|
3819
4026
|
prop.optional = true;
|
|
3820
4027
|
members.push(prop);
|
|
3821
4028
|
}
|
|
3822
4029
|
if (members.length) {
|
|
3823
|
-
emitTypes.push(
|
|
4030
|
+
emitTypes.push(t34.tsTypeLiteral(members));
|
|
3824
4031
|
}
|
|
3825
4032
|
return;
|
|
3826
4033
|
}
|
|
3827
|
-
if (
|
|
4034
|
+
if (t34.isObjectExpression(runtimeArg)) {
|
|
3828
4035
|
for (const prop of runtimeArg.properties) {
|
|
3829
|
-
if (!
|
|
3830
|
-
if (
|
|
4036
|
+
if (!t34.isObjectProperty(prop)) continue;
|
|
4037
|
+
if (t34.isSpreadElement(prop)) continue;
|
|
3831
4038
|
const rawName = resolvePropName(prop.key);
|
|
3832
4039
|
if (!rawName) continue;
|
|
3833
4040
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3834
4041
|
const key = buildKey(handlerName);
|
|
3835
|
-
const params =
|
|
3836
|
-
const fnType =
|
|
3837
|
-
const propSig =
|
|
4042
|
+
const params = t34.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
4043
|
+
const fnType = t34.tsFunctionType(null, params, t34.tsTypeAnnotation(t34.tsAnyKeyword()));
|
|
4044
|
+
const propSig = t34.tsPropertySignature(key, t34.tsTypeAnnotation(fnType));
|
|
3838
4045
|
propSig.optional = true;
|
|
3839
4046
|
members.push(propSig);
|
|
3840
4047
|
}
|
|
3841
4048
|
if (members.length) {
|
|
3842
|
-
emitTypes.push(
|
|
4049
|
+
emitTypes.push(t34.tsTypeLiteral(members));
|
|
3843
4050
|
}
|
|
3844
4051
|
}
|
|
3845
4052
|
}
|
|
@@ -3860,129 +4067,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
3860
4067
|
return `on${name}`;
|
|
3861
4068
|
}
|
|
3862
4069
|
function resolvePropName(key) {
|
|
3863
|
-
if (
|
|
3864
|
-
if (
|
|
3865
|
-
if (
|
|
4070
|
+
if (t34.isIdentifier(key)) return key.name;
|
|
4071
|
+
if (t34.isStringLiteral(key)) return key.value;
|
|
4072
|
+
if (t34.isNumericLiteral(key)) return String(key.value);
|
|
3866
4073
|
return null;
|
|
3867
4074
|
}
|
|
3868
4075
|
function buildKey(name) {
|
|
3869
|
-
return
|
|
4076
|
+
return t34.isValidIdentifier(name) ? t34.identifier(name) : t34.stringLiteral(name);
|
|
3870
4077
|
}
|
|
3871
4078
|
function createRestAnyParam(name) {
|
|
3872
|
-
const id =
|
|
3873
|
-
const rest =
|
|
3874
|
-
rest.typeAnnotation =
|
|
4079
|
+
const id = t34.identifier(name);
|
|
4080
|
+
const rest = t34.restElement(id);
|
|
4081
|
+
rest.typeAnnotation = t34.tsTypeAnnotation(t34.tsArrayType(t34.tsAnyKeyword()));
|
|
3875
4082
|
return rest;
|
|
3876
4083
|
}
|
|
3877
4084
|
function resolveRuntimeTupleParams(value) {
|
|
3878
4085
|
const params = [];
|
|
3879
4086
|
value.elements.forEach((element, index) => {
|
|
3880
4087
|
if (!element) return;
|
|
3881
|
-
if (
|
|
4088
|
+
if (t34.isSpreadElement(element)) {
|
|
3882
4089
|
params.push(createRestAnyParam(`args${index}`));
|
|
3883
4090
|
return;
|
|
3884
4091
|
}
|
|
3885
|
-
if (
|
|
3886
|
-
const id =
|
|
3887
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
4092
|
+
if (t34.isIdentifier(element)) {
|
|
4093
|
+
const id = t34.identifier(element.name);
|
|
4094
|
+
id.typeAnnotation = element.typeAnnotation || t34.tsTypeAnnotation(t34.tsAnyKeyword());
|
|
3888
4095
|
params.push(id);
|
|
3889
4096
|
return;
|
|
3890
4097
|
}
|
|
3891
|
-
if (
|
|
3892
|
-
const id =
|
|
3893
|
-
id.typeAnnotation =
|
|
4098
|
+
if (t34.isTSAsExpression(element)) {
|
|
4099
|
+
const id = t34.identifier(`arg${index}`);
|
|
4100
|
+
id.typeAnnotation = t34.tsTypeAnnotation(element.typeAnnotation);
|
|
3894
4101
|
params.push(id);
|
|
3895
4102
|
return;
|
|
3896
4103
|
}
|
|
3897
|
-
const fallback =
|
|
3898
|
-
fallback.typeAnnotation =
|
|
4104
|
+
const fallback = t34.identifier(`arg${index}`);
|
|
4105
|
+
fallback.typeAnnotation = t34.tsTypeAnnotation(t34.tsAnyKeyword());
|
|
3899
4106
|
params.push(fallback);
|
|
3900
4107
|
});
|
|
3901
4108
|
return params;
|
|
3902
4109
|
}
|
|
3903
4110
|
function resolveExplicitEmitType(tsType) {
|
|
3904
|
-
if (
|
|
4111
|
+
if (t34.isTSParenthesizedType(tsType)) {
|
|
3905
4112
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
3906
4113
|
}
|
|
3907
|
-
if (
|
|
4114
|
+
if (t34.isTSTypeReference(tsType)) {
|
|
3908
4115
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3909
4116
|
return tsType;
|
|
3910
4117
|
}
|
|
3911
4118
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
3912
|
-
return
|
|
4119
|
+
return t34.tsTypeReference(
|
|
3913
4120
|
tsType.typeName,
|
|
3914
|
-
|
|
4121
|
+
t34.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3915
4122
|
);
|
|
3916
4123
|
}
|
|
3917
|
-
if (
|
|
4124
|
+
if (t34.isTSIntersectionType(tsType)) {
|
|
3918
4125
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3919
4126
|
if (!types.length) return null;
|
|
3920
4127
|
if (types.length === 1) return types[0];
|
|
3921
|
-
return
|
|
4128
|
+
return t34.tsIntersectionType(types);
|
|
3922
4129
|
}
|
|
3923
|
-
if (
|
|
4130
|
+
if (t34.isTSUnionType(tsType)) {
|
|
3924
4131
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3925
4132
|
if (!types.length) return null;
|
|
3926
4133
|
if (types.length === 1) return types[0];
|
|
3927
|
-
return
|
|
4134
|
+
return t34.tsUnionType(types);
|
|
3928
4135
|
}
|
|
3929
|
-
if (
|
|
4136
|
+
if (t34.isTSTypeLiteral(tsType)) {
|
|
3930
4137
|
const members = [];
|
|
3931
4138
|
for (const member of tsType.members) {
|
|
3932
|
-
if (
|
|
4139
|
+
if (t34.isTSPropertySignature(member)) {
|
|
3933
4140
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
3934
4141
|
if (prop) members.push(prop);
|
|
3935
4142
|
continue;
|
|
3936
4143
|
}
|
|
3937
|
-
if (
|
|
4144
|
+
if (t34.isTSCallSignatureDeclaration(member)) {
|
|
3938
4145
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3939
4146
|
continue;
|
|
3940
4147
|
}
|
|
3941
4148
|
}
|
|
3942
4149
|
if (!members.length) return null;
|
|
3943
|
-
return
|
|
4150
|
+
return t34.tsTypeLiteral(members);
|
|
3944
4151
|
}
|
|
3945
|
-
if (
|
|
4152
|
+
if (t34.isTSFunctionType(tsType)) {
|
|
3946
4153
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3947
4154
|
if (!props.length) return null;
|
|
3948
|
-
return
|
|
4155
|
+
return t34.tsTypeLiteral(props);
|
|
3949
4156
|
}
|
|
3950
4157
|
return tsType;
|
|
3951
4158
|
}
|
|
3952
4159
|
function hasEmitsSignatureInType(tsType) {
|
|
3953
|
-
if (
|
|
4160
|
+
if (t34.isTSParenthesizedType(tsType)) {
|
|
3954
4161
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
3955
4162
|
}
|
|
3956
|
-
if (
|
|
4163
|
+
if (t34.isTSTypeReference(tsType)) {
|
|
3957
4164
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3958
4165
|
return false;
|
|
3959
4166
|
}
|
|
3960
4167
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
3961
4168
|
}
|
|
3962
|
-
if (
|
|
4169
|
+
if (t34.isTSIntersectionType(tsType) || t34.isTSUnionType(tsType)) {
|
|
3963
4170
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
3964
4171
|
}
|
|
3965
|
-
if (
|
|
4172
|
+
if (t34.isTSTypeLiteral(tsType)) {
|
|
3966
4173
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
3967
4174
|
}
|
|
3968
|
-
if (
|
|
4175
|
+
if (t34.isTSFunctionType(tsType)) {
|
|
3969
4176
|
return isEmitsCallable(tsType.parameters);
|
|
3970
4177
|
}
|
|
3971
4178
|
return false;
|
|
3972
4179
|
}
|
|
3973
4180
|
function hasEmitsSignatureInMember(member) {
|
|
3974
|
-
if (
|
|
4181
|
+
if (t34.isTSCallSignatureDeclaration(member)) {
|
|
3975
4182
|
return isEmitsCallable(member.parameters);
|
|
3976
4183
|
}
|
|
3977
4184
|
return false;
|
|
3978
4185
|
}
|
|
3979
4186
|
function isEmitsCallable(parameters) {
|
|
3980
4187
|
const [eventParam] = parameters;
|
|
3981
|
-
if (!eventParam || !
|
|
4188
|
+
if (!eventParam || !t34.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3982
4189
|
return false;
|
|
3983
4190
|
}
|
|
3984
4191
|
const { typeAnnotation } = eventParam;
|
|
3985
|
-
if (
|
|
4192
|
+
if (t34.isNoop(typeAnnotation)) return false;
|
|
3986
4193
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
3987
4194
|
}
|
|
3988
4195
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -3990,21 +4197,21 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3990
4197
|
if (!rawName) return null;
|
|
3991
4198
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3992
4199
|
const key = buildKey(handlerName);
|
|
3993
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
4200
|
+
const typeAnnotation = _optionalChain([member, 'access', _125 => _125.typeAnnotation, 'optionalAccess', _126 => _126.typeAnnotation]);
|
|
3994
4201
|
let params = [];
|
|
3995
|
-
let returnType =
|
|
3996
|
-
if (typeAnnotation &&
|
|
4202
|
+
let returnType = t34.tsAnyKeyword();
|
|
4203
|
+
if (typeAnnotation && t34.isTSFunctionType(typeAnnotation)) {
|
|
3997
4204
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3998
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
3999
|
-
} else if (typeAnnotation &&
|
|
4205
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _127 => _127.typeAnnotation, 'optionalAccess', _128 => _128.typeAnnotation]), () => ( returnType));
|
|
4206
|
+
} else if (typeAnnotation && t34.isTSTupleType(typeAnnotation)) {
|
|
4000
4207
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
4001
4208
|
} else if (typeAnnotation) {
|
|
4002
|
-
const id =
|
|
4003
|
-
id.typeAnnotation =
|
|
4209
|
+
const id = t34.identifier("value");
|
|
4210
|
+
id.typeAnnotation = t34.tsTypeAnnotation(typeAnnotation);
|
|
4004
4211
|
params = [id];
|
|
4005
4212
|
}
|
|
4006
|
-
const fnType =
|
|
4007
|
-
const prop =
|
|
4213
|
+
const fnType = t34.tsFunctionType(null, params, t34.tsTypeAnnotation(returnType));
|
|
4214
|
+
const prop = t34.tsPropertySignature(key, t34.tsTypeAnnotation(fnType));
|
|
4008
4215
|
prop.optional = !!member.optional;
|
|
4009
4216
|
return prop;
|
|
4010
4217
|
}
|
|
@@ -4013,32 +4220,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
4013
4220
|
}
|
|
4014
4221
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
4015
4222
|
const [eventParam, ...restParams] = parameters;
|
|
4016
|
-
if (!eventParam || !
|
|
4223
|
+
if (!eventParam || !t34.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
4017
4224
|
return [];
|
|
4018
4225
|
}
|
|
4019
4226
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
4020
|
-
if (
|
|
4227
|
+
if (t34.isNoop(paramTypeAnnotation)) return [];
|
|
4021
4228
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
4022
4229
|
if (!eventNames.length) return [];
|
|
4023
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
4230
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _129 => _129.typeAnnotation]), () => ( t34.tsAnyKeyword()));
|
|
4024
4231
|
return eventNames.map((eventName) => {
|
|
4025
4232
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
4026
4233
|
const key = buildKey(handlerName);
|
|
4027
4234
|
const params = cloneCallableParams(restParams);
|
|
4028
|
-
const fnType =
|
|
4029
|
-
const prop =
|
|
4235
|
+
const fnType = t34.tsFunctionType(null, params, t34.tsTypeAnnotation(returnType));
|
|
4236
|
+
const prop = t34.tsPropertySignature(key, t34.tsTypeAnnotation(fnType));
|
|
4030
4237
|
prop.optional = true;
|
|
4031
4238
|
return prop;
|
|
4032
4239
|
});
|
|
4033
4240
|
}
|
|
4034
4241
|
function resolveEventNames(type) {
|
|
4035
|
-
if (
|
|
4242
|
+
if (t34.isTSLiteralType(type) && t34.isStringLiteral(type.literal)) {
|
|
4036
4243
|
return [type.literal.value];
|
|
4037
4244
|
}
|
|
4038
|
-
if (
|
|
4245
|
+
if (t34.isTSUnionType(type)) {
|
|
4039
4246
|
return type.types.flatMap(resolveEventNames);
|
|
4040
4247
|
}
|
|
4041
|
-
if (
|
|
4248
|
+
if (t34.isTSParenthesizedType(type)) {
|
|
4042
4249
|
return resolveEventNames(type.typeAnnotation);
|
|
4043
4250
|
}
|
|
4044
4251
|
return [];
|
|
@@ -4051,39 +4258,39 @@ function resolveTupleTypeParams(tuple) {
|
|
|
4051
4258
|
return params;
|
|
4052
4259
|
}
|
|
4053
4260
|
function resolveTupleElementParam(element, index) {
|
|
4054
|
-
const isNamedTuple = typeof
|
|
4261
|
+
const isNamedTuple = typeof t34.isTSNamedTupleMember === "function" && t34.isTSNamedTupleMember(element);
|
|
4055
4262
|
if (isNamedTuple) {
|
|
4056
4263
|
const tupleMember = element;
|
|
4057
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
4264
|
+
const name = _optionalChain([tupleMember, 'access', _130 => _130.label, 'optionalAccess', _131 => _131.name]) || `arg${index}`;
|
|
4058
4265
|
let innerType = tupleMember.elementType;
|
|
4059
4266
|
let optional = tupleMember.optional;
|
|
4060
|
-
if (
|
|
4267
|
+
if (t34.isTSOptionalType(innerType)) {
|
|
4061
4268
|
optional = true;
|
|
4062
4269
|
innerType = innerType.typeAnnotation;
|
|
4063
4270
|
}
|
|
4064
|
-
if (
|
|
4065
|
-
const rest =
|
|
4066
|
-
rest.typeAnnotation =
|
|
4271
|
+
if (t34.isTSRestType(innerType)) {
|
|
4272
|
+
const rest = t34.restElement(t34.identifier(name));
|
|
4273
|
+
rest.typeAnnotation = t34.tsTypeAnnotation(innerType.typeAnnotation);
|
|
4067
4274
|
return rest;
|
|
4068
4275
|
}
|
|
4069
|
-
const id2 =
|
|
4276
|
+
const id2 = t34.identifier(name);
|
|
4070
4277
|
id2.optional = optional;
|
|
4071
|
-
id2.typeAnnotation =
|
|
4278
|
+
id2.typeAnnotation = t34.tsTypeAnnotation(innerType);
|
|
4072
4279
|
return id2;
|
|
4073
4280
|
}
|
|
4074
|
-
if (
|
|
4075
|
-
const rest =
|
|
4076
|
-
rest.typeAnnotation =
|
|
4281
|
+
if (t34.isTSRestType(element)) {
|
|
4282
|
+
const rest = t34.restElement(t34.identifier(`args${index}`));
|
|
4283
|
+
rest.typeAnnotation = t34.tsTypeAnnotation(element.typeAnnotation);
|
|
4077
4284
|
return rest;
|
|
4078
4285
|
}
|
|
4079
|
-
if (
|
|
4080
|
-
const id2 =
|
|
4286
|
+
if (t34.isTSOptionalType(element)) {
|
|
4287
|
+
const id2 = t34.identifier(`arg${index}`);
|
|
4081
4288
|
id2.optional = true;
|
|
4082
|
-
id2.typeAnnotation =
|
|
4289
|
+
id2.typeAnnotation = t34.tsTypeAnnotation(element.typeAnnotation);
|
|
4083
4290
|
return id2;
|
|
4084
4291
|
}
|
|
4085
|
-
const id =
|
|
4086
|
-
id.typeAnnotation =
|
|
4292
|
+
const id = t34.identifier(`arg${index}`);
|
|
4293
|
+
id.typeAnnotation = t34.tsTypeAnnotation(element);
|
|
4087
4294
|
return id;
|
|
4088
4295
|
}
|
|
4089
4296
|
|
|
@@ -4092,8 +4299,8 @@ function resolveTupleElementParam(element, index) {
|
|
|
4092
4299
|
function resolveDefinePropsIface(path8, ctx) {
|
|
4093
4300
|
const { node } = path8;
|
|
4094
4301
|
const [runtimeArg] = node.arguments;
|
|
4095
|
-
const tsParams = _optionalChain([node, 'access',
|
|
4096
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
4302
|
+
const tsParams = _optionalChain([node, 'access', _132 => _132.typeParameters, 'optionalAccess', _133 => _133.params]);
|
|
4303
|
+
if (_optionalChain([tsParams, 'optionalAccess', _134 => _134.length])) {
|
|
4097
4304
|
const { propsTSIface } = ctx.scriptData;
|
|
4098
4305
|
propsTSIface.propsTypes = tsParams;
|
|
4099
4306
|
return;
|
|
@@ -4108,38 +4315,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
4108
4315
|
} = scriptData;
|
|
4109
4316
|
if (!runtimeArg) return;
|
|
4110
4317
|
const members = [];
|
|
4111
|
-
if (
|
|
4318
|
+
if (t35.isArrayExpression(runtimeArg)) {
|
|
4112
4319
|
for (const element of runtimeArg.elements) {
|
|
4113
|
-
if (!element || !
|
|
4114
|
-
const key =
|
|
4115
|
-
const prop =
|
|
4320
|
+
if (!element || !t35.isStringLiteral(element)) continue;
|
|
4321
|
+
const key = t35.isValidIdentifier(element.value) ? t35.identifier(element.value) : t35.stringLiteral(element.value);
|
|
4322
|
+
const prop = t35.tsPropertySignature(key, t35.tsTypeAnnotation(t35.tsAnyKeyword()));
|
|
4116
4323
|
prop.optional = true;
|
|
4117
4324
|
members.push(prop);
|
|
4118
4325
|
}
|
|
4119
4326
|
if (members.length) {
|
|
4120
|
-
propsTypes.push(
|
|
4327
|
+
propsTypes.push(t35.tsTypeLiteral(members));
|
|
4121
4328
|
}
|
|
4122
4329
|
return;
|
|
4123
4330
|
}
|
|
4124
|
-
if (
|
|
4331
|
+
if (t35.isObjectExpression(runtimeArg)) {
|
|
4125
4332
|
for (const prop of runtimeArg.properties) {
|
|
4126
|
-
if (!
|
|
4127
|
-
if (
|
|
4333
|
+
if (!t35.isObjectProperty(prop)) continue;
|
|
4334
|
+
if (t35.isSpreadElement(prop)) continue;
|
|
4128
4335
|
const key = prop.key;
|
|
4129
4336
|
let propName = null;
|
|
4130
|
-
if (
|
|
4131
|
-
if (
|
|
4132
|
-
if (
|
|
4337
|
+
if (t35.isIdentifier(key)) propName = key.name;
|
|
4338
|
+
if (t35.isStringLiteral(key)) propName = key.value;
|
|
4339
|
+
if (t35.isNumericLiteral(key)) propName = String(key.value);
|
|
4133
4340
|
if (!propName) continue;
|
|
4134
4341
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
4135
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
4136
|
-
const tsKey =
|
|
4137
|
-
const tsProp =
|
|
4342
|
+
const tsType = _nullishCoalesce(type, () => ( t35.tsAnyKeyword()));
|
|
4343
|
+
const tsKey = t35.isValidIdentifier(propName) ? t35.identifier(propName) : t35.stringLiteral(propName);
|
|
4344
|
+
const tsProp = t35.tsPropertySignature(tsKey, t35.tsTypeAnnotation(tsType));
|
|
4138
4345
|
tsProp.optional = !required;
|
|
4139
4346
|
members.push(tsProp);
|
|
4140
4347
|
}
|
|
4141
4348
|
if (members.length) {
|
|
4142
|
-
propsTypes.push(
|
|
4349
|
+
propsTypes.push(t35.tsTypeLiteral(members));
|
|
4143
4350
|
}
|
|
4144
4351
|
return;
|
|
4145
4352
|
}
|
|
@@ -4148,47 +4355,47 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
4148
4355
|
{
|
|
4149
4356
|
source,
|
|
4150
4357
|
file: filename,
|
|
4151
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
4358
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _135 => _135.loc])
|
|
4152
4359
|
}
|
|
4153
4360
|
);
|
|
4154
4361
|
}
|
|
4155
4362
|
function resolveRuntimePropMeta(value) {
|
|
4156
|
-
if (
|
|
4363
|
+
if (t35.isIdentifier(value)) {
|
|
4157
4364
|
return {
|
|
4158
4365
|
type: mapRuntimeTypeToTSType(value),
|
|
4159
4366
|
required: false
|
|
4160
4367
|
};
|
|
4161
4368
|
}
|
|
4162
|
-
if (
|
|
4369
|
+
if (t35.isArrayExpression(value)) {
|
|
4163
4370
|
return {
|
|
4164
4371
|
type: resolveRuntimeUnionType(value),
|
|
4165
4372
|
required: false
|
|
4166
4373
|
};
|
|
4167
4374
|
}
|
|
4168
|
-
if (!
|
|
4375
|
+
if (!t35.isObjectExpression(value)) {
|
|
4169
4376
|
return { required: false };
|
|
4170
4377
|
}
|
|
4171
4378
|
let type;
|
|
4172
4379
|
let required = false;
|
|
4173
4380
|
for (const prop of value.properties) {
|
|
4174
|
-
if (!
|
|
4175
|
-
if (
|
|
4381
|
+
if (!t35.isObjectProperty(prop)) continue;
|
|
4382
|
+
if (t35.isSpreadElement(prop)) continue;
|
|
4176
4383
|
const key = prop.key;
|
|
4177
|
-
const propName =
|
|
4384
|
+
const propName = t35.isIdentifier(key) ? key.name : t35.isStringLiteral(key) ? key.value : null;
|
|
4178
4385
|
if (!propName) continue;
|
|
4179
4386
|
if (propName === "type") {
|
|
4180
4387
|
const valueNode = prop.value;
|
|
4181
|
-
if (
|
|
4388
|
+
if (t35.isArrayExpression(valueNode)) {
|
|
4182
4389
|
type = resolveRuntimeUnionType(valueNode);
|
|
4183
4390
|
continue;
|
|
4184
4391
|
}
|
|
4185
|
-
if (
|
|
4392
|
+
if (t35.isIdentifier(valueNode)) {
|
|
4186
4393
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
4187
4394
|
continue;
|
|
4188
4395
|
}
|
|
4189
4396
|
}
|
|
4190
4397
|
if (propName === "required") {
|
|
4191
|
-
if (
|
|
4398
|
+
if (t35.isBooleanLiteral(prop.value)) {
|
|
4192
4399
|
required = prop.value.value;
|
|
4193
4400
|
}
|
|
4194
4401
|
}
|
|
@@ -4198,13 +4405,13 @@ function resolveRuntimePropMeta(value) {
|
|
|
4198
4405
|
function resolveRuntimeUnionType(value) {
|
|
4199
4406
|
const types = [];
|
|
4200
4407
|
for (const element of value.elements) {
|
|
4201
|
-
if (!element || !
|
|
4408
|
+
if (!element || !t35.isIdentifier(element)) continue;
|
|
4202
4409
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
4203
4410
|
if (resolved) types.push(resolved);
|
|
4204
4411
|
}
|
|
4205
|
-
if (!types.length) return
|
|
4412
|
+
if (!types.length) return t35.tsAnyKeyword();
|
|
4206
4413
|
if (types.length === 1) return types[0];
|
|
4207
|
-
return
|
|
4414
|
+
return t35.tsUnionType(types);
|
|
4208
4415
|
}
|
|
4209
4416
|
|
|
4210
4417
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
@@ -4217,34 +4424,34 @@ var SLOT_CHILDREN_NAME = "children";
|
|
|
4217
4424
|
var SLOT_FN_PARAM_NAME = "props";
|
|
4218
4425
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
4219
4426
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
4220
|
-
const key =
|
|
4221
|
-
const reactNodeType =
|
|
4222
|
-
|
|
4427
|
+
const key = t36.isValidIdentifier(propName) ? t36.identifier(propName) : t36.stringLiteral(propName);
|
|
4428
|
+
const reactNodeType = t36.tsTypeAnnotation(
|
|
4429
|
+
t36.tsTypeReference(t36.identifier(REACT_API_MAP.ReactNode))
|
|
4223
4430
|
);
|
|
4224
4431
|
let typeAnnotation;
|
|
4225
4432
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
4226
4433
|
typeAnnotation = reactNodeType;
|
|
4227
4434
|
} else {
|
|
4228
|
-
const fnType =
|
|
4229
|
-
typeAnnotation =
|
|
4435
|
+
const fnType = t36.tsFunctionType(null, params, reactNodeType);
|
|
4436
|
+
typeAnnotation = t36.tsTypeAnnotation(fnType);
|
|
4230
4437
|
}
|
|
4231
|
-
const prop =
|
|
4438
|
+
const prop = t36.tsPropertySignature(key, typeAnnotation);
|
|
4232
4439
|
prop.optional = optional;
|
|
4233
4440
|
return prop;
|
|
4234
4441
|
}
|
|
4235
4442
|
function createSlotScopeParam(props, ctx) {
|
|
4236
|
-
const paramId =
|
|
4443
|
+
const paramId = t36.identifier(SLOT_FN_PARAM_NAME);
|
|
4237
4444
|
const propsSigns = [];
|
|
4238
4445
|
const { reactiveBindings } = ctx.templateData;
|
|
4239
4446
|
props.forEach(({ prop, tsType }) => {
|
|
4240
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
4447
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _136 => _136[prop], 'optionalAccess', _137 => _137.value]);
|
|
4241
4448
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
4242
|
-
const typeAnnotation = foundBindingTypes ?
|
|
4243
|
-
const key =
|
|
4244
|
-
const propSign =
|
|
4449
|
+
const typeAnnotation = foundBindingTypes ? t36.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
4450
|
+
const key = t36.isValidIdentifier(prop) ? t36.identifier(prop) : t36.stringLiteral(prop);
|
|
4451
|
+
const propSign = t36.tsPropertySignature(key, typeAnnotation);
|
|
4245
4452
|
propsSigns.push(propSign);
|
|
4246
4453
|
});
|
|
4247
|
-
paramId.typeAnnotation =
|
|
4454
|
+
paramId.typeAnnotation = t36.tsTypeAnnotation(t36.tsTypeLiteral(propsSigns));
|
|
4248
4455
|
return paramId;
|
|
4249
4456
|
}
|
|
4250
4457
|
|
|
@@ -4265,38 +4472,38 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4265
4472
|
return declarations;
|
|
4266
4473
|
}
|
|
4267
4474
|
for (const statement of programPath.node.body) {
|
|
4268
|
-
if (
|
|
4475
|
+
if (t37.isTSInterfaceDeclaration(statement)) {
|
|
4269
4476
|
declarations.set(statement.id.name, {
|
|
4270
|
-
type:
|
|
4477
|
+
type: t37.tsTypeLiteral(statement.body.body),
|
|
4271
4478
|
// 将接口体转换为类型字面量
|
|
4272
|
-
hasTypeParameters: !!_optionalChain([statement, 'access',
|
|
4479
|
+
hasTypeParameters: !!_optionalChain([statement, 'access', _138 => _138.typeParameters, 'optionalAccess', _139 => _139.params, 'access', _140 => _140.length])
|
|
4273
4480
|
// 检查是否有泛型参数
|
|
4274
4481
|
});
|
|
4275
4482
|
continue;
|
|
4276
4483
|
}
|
|
4277
|
-
if (
|
|
4484
|
+
if (t37.isTSTypeAliasDeclaration(statement)) {
|
|
4278
4485
|
declarations.set(statement.id.name, {
|
|
4279
4486
|
type: statement.typeAnnotation,
|
|
4280
4487
|
// 直接使用类型注解
|
|
4281
|
-
hasTypeParameters: !!_optionalChain([statement, 'access',
|
|
4488
|
+
hasTypeParameters: !!_optionalChain([statement, 'access', _141 => _141.typeParameters, 'optionalAccess', _142 => _142.params, 'access', _143 => _143.length])
|
|
4282
4489
|
// 检查是否有泛型参数
|
|
4283
4490
|
});
|
|
4284
4491
|
continue;
|
|
4285
4492
|
}
|
|
4286
|
-
if (
|
|
4493
|
+
if (t37.isExportNamedDeclaration(statement) && statement.declaration) {
|
|
4287
4494
|
const declaration = statement.declaration;
|
|
4288
|
-
if (
|
|
4495
|
+
if (t37.isTSInterfaceDeclaration(declaration)) {
|
|
4289
4496
|
declarations.set(declaration.id.name, {
|
|
4290
|
-
type:
|
|
4497
|
+
type: t37.tsTypeLiteral(declaration.body.body),
|
|
4291
4498
|
// 将接口体转换为类型字面量
|
|
4292
|
-
hasTypeParameters: !!_optionalChain([declaration, 'access',
|
|
4499
|
+
hasTypeParameters: !!_optionalChain([declaration, 'access', _144 => _144.typeParameters, 'optionalAccess', _145 => _145.params, 'access', _146 => _146.length])
|
|
4293
4500
|
// 检查是否有泛型参数
|
|
4294
4501
|
});
|
|
4295
|
-
} else if (
|
|
4502
|
+
} else if (t37.isTSTypeAliasDeclaration(declaration)) {
|
|
4296
4503
|
declarations.set(declaration.id.name, {
|
|
4297
4504
|
type: declaration.typeAnnotation,
|
|
4298
4505
|
// 直接使用类型注解
|
|
4299
|
-
hasTypeParameters: !!_optionalChain([declaration, 'access',
|
|
4506
|
+
hasTypeParameters: !!_optionalChain([declaration, 'access', _147 => _147.typeParameters, 'optionalAccess', _148 => _148.params, 'access', _149 => _149.length])
|
|
4300
4507
|
// 检查是否有泛型参数
|
|
4301
4508
|
});
|
|
4302
4509
|
}
|
|
@@ -4305,22 +4512,22 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4305
4512
|
return declarations;
|
|
4306
4513
|
}
|
|
4307
4514
|
function resolvePropName2(key) {
|
|
4308
|
-
if (
|
|
4515
|
+
if (t37.isIdentifier(key)) {
|
|
4309
4516
|
return key.name;
|
|
4310
4517
|
}
|
|
4311
|
-
if (
|
|
4518
|
+
if (t37.isStringLiteral(key)) {
|
|
4312
4519
|
return key.value;
|
|
4313
4520
|
}
|
|
4314
|
-
if (
|
|
4521
|
+
if (t37.isNumericLiteral(key)) {
|
|
4315
4522
|
return String(key.value);
|
|
4316
4523
|
}
|
|
4317
4524
|
return null;
|
|
4318
4525
|
}
|
|
4319
4526
|
function resolveCallableType(tsType) {
|
|
4320
|
-
if (
|
|
4527
|
+
if (t37.isTSFunctionType(tsType)) {
|
|
4321
4528
|
return tsType;
|
|
4322
4529
|
}
|
|
4323
|
-
if (
|
|
4530
|
+
if (t37.isTSParenthesizedType(tsType)) {
|
|
4324
4531
|
return resolveCallableType(tsType.typeAnnotation);
|
|
4325
4532
|
}
|
|
4326
4533
|
return null;
|
|
@@ -4329,12 +4536,12 @@ function resolveCallableType(tsType) {
|
|
|
4329
4536
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
4330
4537
|
var SLOT_DEFAULT_NAME2 = "default";
|
|
4331
4538
|
function resolveSlotType(tsType, options) {
|
|
4332
|
-
if (
|
|
4539
|
+
if (t38.isTSParenthesizedType(tsType)) {
|
|
4333
4540
|
return resolveSlotType(tsType.typeAnnotation, options);
|
|
4334
4541
|
}
|
|
4335
|
-
if (
|
|
4542
|
+
if (t38.isTSTypeReference(tsType)) {
|
|
4336
4543
|
let shouldRecordReactNode = false;
|
|
4337
|
-
if (_optionalChain([tsType, 'access',
|
|
4544
|
+
if (_optionalChain([tsType, 'access', _150 => _150.typeParameters, 'optionalAccess', _151 => _151.params, 'access', _152 => _152.length])) {
|
|
4338
4545
|
const params = [];
|
|
4339
4546
|
for (const param of tsType.typeParameters.params) {
|
|
4340
4547
|
const resolved2 = resolveSlotType(param, options);
|
|
@@ -4348,11 +4555,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4348
4555
|
};
|
|
4349
4556
|
}
|
|
4350
4557
|
return {
|
|
4351
|
-
type:
|
|
4558
|
+
type: t38.tsTypeReference(tsType.typeName, t38.tsTypeParameterInstantiation(params)),
|
|
4352
4559
|
shouldRecordReactNode
|
|
4353
4560
|
};
|
|
4354
4561
|
}
|
|
4355
|
-
if (!
|
|
4562
|
+
if (!t38.isIdentifier(tsType.typeName)) {
|
|
4356
4563
|
return {
|
|
4357
4564
|
type: tsType,
|
|
4358
4565
|
shouldRecordReactNode: false
|
|
@@ -4383,7 +4590,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4383
4590
|
}
|
|
4384
4591
|
return resolved;
|
|
4385
4592
|
}
|
|
4386
|
-
if (
|
|
4593
|
+
if (t38.isTSIntersectionType(tsType)) {
|
|
4387
4594
|
const types = [];
|
|
4388
4595
|
let shouldRecordReactNode = false;
|
|
4389
4596
|
for (const item of tsType.types) {
|
|
@@ -4406,11 +4613,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4406
4613
|
};
|
|
4407
4614
|
}
|
|
4408
4615
|
return {
|
|
4409
|
-
type:
|
|
4616
|
+
type: t38.tsIntersectionType(types),
|
|
4410
4617
|
shouldRecordReactNode
|
|
4411
4618
|
};
|
|
4412
4619
|
}
|
|
4413
|
-
if (
|
|
4620
|
+
if (t38.isTSUnionType(tsType)) {
|
|
4414
4621
|
const types = [];
|
|
4415
4622
|
let shouldRecordReactNode = false;
|
|
4416
4623
|
for (const item of tsType.types) {
|
|
@@ -4433,11 +4640,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4433
4640
|
};
|
|
4434
4641
|
}
|
|
4435
4642
|
return {
|
|
4436
|
-
type:
|
|
4643
|
+
type: t38.tsUnionType(types),
|
|
4437
4644
|
shouldRecordReactNode
|
|
4438
4645
|
};
|
|
4439
4646
|
}
|
|
4440
|
-
if (
|
|
4647
|
+
if (t38.isTSTypeLiteral(tsType)) {
|
|
4441
4648
|
const members = [];
|
|
4442
4649
|
let shouldRecordReactNode = false;
|
|
4443
4650
|
for (const item of tsType.members) {
|
|
@@ -4452,11 +4659,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4452
4659
|
};
|
|
4453
4660
|
}
|
|
4454
4661
|
return {
|
|
4455
|
-
type:
|
|
4662
|
+
type: t38.tsTypeLiteral(members),
|
|
4456
4663
|
shouldRecordReactNode
|
|
4457
4664
|
};
|
|
4458
4665
|
}
|
|
4459
|
-
if (
|
|
4666
|
+
if (t38.isTSFunctionType(tsType)) {
|
|
4460
4667
|
const props = buildSlotPropSignature(
|
|
4461
4668
|
SLOT_DEFAULT_NAME2,
|
|
4462
4669
|
cloneCallableParams(tsType.parameters),
|
|
@@ -4464,7 +4671,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4464
4671
|
// 默认插槽不是可选的
|
|
4465
4672
|
);
|
|
4466
4673
|
return {
|
|
4467
|
-
type:
|
|
4674
|
+
type: t38.tsTypeLiteral([props]),
|
|
4468
4675
|
shouldRecordReactNode: true
|
|
4469
4676
|
// 函数类型总是需要记录 ReactNode
|
|
4470
4677
|
};
|
|
@@ -4475,7 +4682,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4475
4682
|
};
|
|
4476
4683
|
}
|
|
4477
4684
|
function resolveSlotPropFromMember(member) {
|
|
4478
|
-
if (
|
|
4685
|
+
if (t38.isTSMethodSignature(member)) {
|
|
4479
4686
|
const rawName = resolvePropName2(member.key);
|
|
4480
4687
|
if (!rawName) {
|
|
4481
4688
|
return {
|
|
@@ -4490,7 +4697,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4490
4697
|
// 方法签名总是可调用,需要记录 ReactNode
|
|
4491
4698
|
};
|
|
4492
4699
|
}
|
|
4493
|
-
if (
|
|
4700
|
+
if (t38.isTSPropertySignature(member)) {
|
|
4494
4701
|
const rawName = resolvePropName2(member.key);
|
|
4495
4702
|
if (!rawName) {
|
|
4496
4703
|
return {
|
|
@@ -4498,7 +4705,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4498
4705
|
shouldRecordReactNode: false
|
|
4499
4706
|
};
|
|
4500
4707
|
}
|
|
4501
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
4708
|
+
const typeAnnotation = _optionalChain([member, 'access', _153 => _153.typeAnnotation, 'optionalAccess', _154 => _154.typeAnnotation]);
|
|
4502
4709
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
4503
4710
|
if (!callable) {
|
|
4504
4711
|
return {
|
|
@@ -4513,7 +4720,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4513
4720
|
// 可调用属性需要记录 ReactNode
|
|
4514
4721
|
};
|
|
4515
4722
|
}
|
|
4516
|
-
if (
|
|
4723
|
+
if (t38.isTSCallSignatureDeclaration(member)) {
|
|
4517
4724
|
const params = cloneCallableParams(member.parameters);
|
|
4518
4725
|
return {
|
|
4519
4726
|
member: buildSlotPropSignature(SLOT_DEFAULT_NAME2, params, true),
|
|
@@ -4530,8 +4737,8 @@ function resolveSlotPropFromMember(member) {
|
|
|
4530
4737
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/define-slots.ts
|
|
4531
4738
|
function resolveDefineSlotsIface(path8, ctx) {
|
|
4532
4739
|
const { node } = path8;
|
|
4533
|
-
const tsParams = _optionalChain([node, 'access',
|
|
4534
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
4740
|
+
const tsParams = _optionalChain([node, 'access', _155 => _155.typeParameters, 'optionalAccess', _156 => _156.params]);
|
|
4741
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _157 => _157.length])) return;
|
|
4535
4742
|
const {
|
|
4536
4743
|
propsTSIface: { slotTypes }
|
|
4537
4744
|
} = ctx.scriptData;
|
|
@@ -4571,7 +4778,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
4571
4778
|
}
|
|
4572
4779
|
if (tsMembers.length) {
|
|
4573
4780
|
recordReactNode(ctx);
|
|
4574
|
-
slotTypes.push(
|
|
4781
|
+
slotTypes.push(t39.tsTypeLiteral(tsMembers));
|
|
4575
4782
|
}
|
|
4576
4783
|
}
|
|
4577
4784
|
|
|
@@ -4623,9 +4830,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4623
4830
|
}
|
|
4624
4831
|
const n = declaredOptions.name || "Comp";
|
|
4625
4832
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
4626
|
-
const typeNode =
|
|
4627
|
-
const typeAliasDecl =
|
|
4628
|
-
const exportDecl =
|
|
4833
|
+
const typeNode = t40.tsIntersectionType(tsTypes);
|
|
4834
|
+
const typeAliasDecl = t40.tsTypeAliasDeclaration(t40.identifier(ns), null, typeNode);
|
|
4835
|
+
const exportDecl = t40.exportNamedDeclaration(typeAliasDecl);
|
|
4629
4836
|
propsTSIface.name = ns;
|
|
4630
4837
|
const scriptIR = getScriptIR(ctx);
|
|
4631
4838
|
scriptIR.exports.push(exportDecl);
|
|
@@ -4640,8 +4847,8 @@ function resolveUseAttrs(ctx) {
|
|
|
4640
4847
|
const { init, id } = path8.node;
|
|
4641
4848
|
if (!init) return;
|
|
4642
4849
|
const initPath = path8.get("init");
|
|
4643
|
-
const propsIdentifier =
|
|
4644
|
-
if (
|
|
4850
|
+
const propsIdentifier = t41.identifier(ctx.propField);
|
|
4851
|
+
if (t41.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
|
|
4645
4852
|
const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
|
|
4646
4853
|
replaceNode(initPath, typeAssertion, init);
|
|
4647
4854
|
return;
|
|
@@ -4652,13 +4859,13 @@ function resolveUseAttrs(ctx) {
|
|
|
4652
4859
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
4653
4860
|
if (isTS) {
|
|
4654
4861
|
let typeAnnotation = null;
|
|
4655
|
-
if (
|
|
4862
|
+
if (t41.isIdentifier(id) && t41.isTSTypeAnnotation(id.typeAnnotation)) {
|
|
4656
4863
|
typeAnnotation = id.typeAnnotation.typeAnnotation;
|
|
4657
4864
|
id.typeAnnotation = null;
|
|
4658
4865
|
} else {
|
|
4659
|
-
typeAnnotation =
|
|
4660
|
-
|
|
4661
|
-
|
|
4866
|
+
typeAnnotation = t41.tsTypeReference(
|
|
4867
|
+
t41.identifier("Record"),
|
|
4868
|
+
t41.tsTypeParameterInstantiation([t41.tsStringKeyword(), t41.tsUnknownKeyword()])
|
|
4662
4869
|
);
|
|
4663
4870
|
}
|
|
4664
4871
|
const propsTypeAssertion = createPropsTypeAssertion(propsIdentifier, typeAnnotation);
|
|
@@ -4670,10 +4877,10 @@ function resolveUseAttrs(ctx) {
|
|
|
4670
4877
|
};
|
|
4671
4878
|
}
|
|
4672
4879
|
function isUseAttrsCall(expr) {
|
|
4673
|
-
return
|
|
4880
|
+
return t41.isCallExpression(expr) && isCalleeNamed(expr, VUE_API_MAP.useAttrs);
|
|
4674
4881
|
}
|
|
4675
4882
|
function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
4676
|
-
return
|
|
4883
|
+
return t41.tsAsExpression(propsIdentifier, typeAnnotation);
|
|
4677
4884
|
}
|
|
4678
4885
|
|
|
4679
4886
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -4696,7 +4903,7 @@ function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
|
4696
4903
|
}
|
|
4697
4904
|
function isReactiveBinding(node) {
|
|
4698
4905
|
if (!node) return false;
|
|
4699
|
-
return !!_optionalChain([getScriptNodeMeta, 'call',
|
|
4906
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _158 => _158(node), 'optionalAccess', _159 => _159.is_reactive]);
|
|
4700
4907
|
}
|
|
4701
4908
|
|
|
4702
4909
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-checker.ts
|
|
@@ -4709,40 +4916,40 @@ function isEligibleBindingSource(binding) {
|
|
|
4709
4916
|
const bindingPath = binding.path;
|
|
4710
4917
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4711
4918
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4712
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess',
|
|
4713
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
4714
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
4715
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
4716
|
-
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess',
|
|
4919
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _160 => _160.node, 'access', _161 => _161.init]);
|
|
4920
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t42.isCallExpression(nodeInit) && t42.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4921
|
+
const isHookCallVarBinding = !!declaratorPath && t42.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4922
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t42.isArrowFunctionExpression(nodeInit) || t42.isFunctionExpression(nodeInit));
|
|
4923
|
+
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _162 => _162.node])) || isReactiveBinding(bindingPath.node));
|
|
4717
4924
|
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4718
4925
|
}
|
|
4719
4926
|
function isReactValidDependencyExpr(node) {
|
|
4720
|
-
if (
|
|
4927
|
+
if (t42.isIdentifier(node)) {
|
|
4721
4928
|
return true;
|
|
4722
4929
|
}
|
|
4723
|
-
if (
|
|
4930
|
+
if (t42.isMemberExpression(node) || t42.isOptionalMemberExpression(node)) {
|
|
4724
4931
|
return isStaticMemberChain(node);
|
|
4725
4932
|
}
|
|
4726
4933
|
return false;
|
|
4727
4934
|
}
|
|
4728
4935
|
function isStaticMemberChain(node) {
|
|
4729
4936
|
let current = node;
|
|
4730
|
-
while (
|
|
4731
|
-
if (!current.computed && !
|
|
4937
|
+
while (t42.isMemberExpression(current) || t42.isOptionalMemberExpression(current)) {
|
|
4938
|
+
if (!current.computed && !t42.isIdentifier(current.property)) {
|
|
4732
4939
|
return false;
|
|
4733
4940
|
}
|
|
4734
|
-
if (current.computed && !
|
|
4941
|
+
if (current.computed && !t42.isStringLiteral(current.property) && !t42.isNumericLiteral(current.property)) {
|
|
4735
4942
|
return false;
|
|
4736
4943
|
}
|
|
4737
4944
|
current = current.object;
|
|
4738
4945
|
}
|
|
4739
|
-
return
|
|
4946
|
+
return t42.isIdentifier(current);
|
|
4740
4947
|
}
|
|
4741
4948
|
function isHookLikeCallee(callee) {
|
|
4742
|
-
if (
|
|
4949
|
+
if (t42.isIdentifier(callee)) {
|
|
4743
4950
|
return callee.name.startsWith("use");
|
|
4744
4951
|
}
|
|
4745
|
-
if (
|
|
4952
|
+
if (t42.isMemberExpression(callee) && !callee.computed && t42.isIdentifier(callee.property)) {
|
|
4746
4953
|
return callee.property.name.startsWith("use");
|
|
4747
4954
|
}
|
|
4748
4955
|
return false;
|
|
@@ -4751,16 +4958,16 @@ function isHookLikeCallee(callee) {
|
|
|
4751
4958
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
|
|
4752
4959
|
|
|
4753
4960
|
function getDependencyKey(exp) {
|
|
4754
|
-
if (
|
|
4961
|
+
if (t43.isIdentifier(exp)) {
|
|
4755
4962
|
return exp.name;
|
|
4756
4963
|
}
|
|
4757
|
-
if (
|
|
4964
|
+
if (t43.isMemberExpression(exp) || t43.isOptionalMemberExpression(exp)) {
|
|
4758
4965
|
const objectKey = getDependencyKey(exp.object);
|
|
4759
4966
|
const opt = exp.optional ? "?" : "";
|
|
4760
|
-
if (!exp.computed &&
|
|
4967
|
+
if (!exp.computed && t43.isIdentifier(exp.property)) {
|
|
4761
4968
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4762
4969
|
}
|
|
4763
|
-
if (
|
|
4970
|
+
if (t43.isStringLiteral(exp.property) || t43.isNumericLiteral(exp.property)) {
|
|
4764
4971
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4765
4972
|
}
|
|
4766
4973
|
return `${objectKey}${opt}[*]`;
|
|
@@ -4771,38 +4978,38 @@ function getDependencyKey(exp) {
|
|
|
4771
4978
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
|
|
4772
4979
|
|
|
4773
4980
|
function normalizeDependencyExpr(path8, rootName, ctx) {
|
|
4774
|
-
if (
|
|
4775
|
-
return
|
|
4981
|
+
if (t44.isIdentifier(path8.node)) {
|
|
4982
|
+
return t44.identifier(path8.node.name);
|
|
4776
4983
|
}
|
|
4777
|
-
if (
|
|
4984
|
+
if (t44.isMemberExpression(path8.node) || t44.isOptionalMemberExpression(path8.node)) {
|
|
4778
4985
|
if (rootName === ctx.propField) {
|
|
4779
4986
|
const safePropsExp = ensureOptionalForMemberChain(path8.node);
|
|
4780
4987
|
if (isReactValidDependencyExpr(safePropsExp)) {
|
|
4781
|
-
return
|
|
4988
|
+
return t44.cloneNode(safePropsExp, true);
|
|
4782
4989
|
}
|
|
4783
|
-
return
|
|
4990
|
+
return t44.identifier(rootName);
|
|
4784
4991
|
}
|
|
4785
4992
|
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
4786
|
-
const safeExp =
|
|
4993
|
+
const safeExp = t44.isMemberExpression(normalizedExp) || t44.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
4787
4994
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4788
|
-
return
|
|
4995
|
+
return t44.cloneNode(safeExp, true);
|
|
4789
4996
|
}
|
|
4790
|
-
return
|
|
4997
|
+
return t44.identifier(rootName);
|
|
4791
4998
|
}
|
|
4792
4999
|
return null;
|
|
4793
5000
|
}
|
|
4794
5001
|
function normalizeSourcedDependency(exp) {
|
|
4795
|
-
if (
|
|
4796
|
-
return
|
|
5002
|
+
if (t44.isIdentifier(exp)) {
|
|
5003
|
+
return t44.identifier(exp.name);
|
|
4797
5004
|
}
|
|
4798
|
-
if (
|
|
5005
|
+
if (t44.isMemberExpression(exp) || t44.isOptionalMemberExpression(exp)) {
|
|
4799
5006
|
const root = findRootIdentifier(exp);
|
|
4800
5007
|
if (!root) return null;
|
|
4801
|
-
const safeExp =
|
|
5008
|
+
const safeExp = t44.isMemberExpression(exp) || t44.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4802
5009
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4803
|
-
return
|
|
5010
|
+
return t44.cloneNode(safeExp, true);
|
|
4804
5011
|
}
|
|
4805
|
-
return
|
|
5012
|
+
return t44.identifier(root.name);
|
|
4806
5013
|
}
|
|
4807
5014
|
return null;
|
|
4808
5015
|
}
|
|
@@ -4812,7 +5019,7 @@ function normalizeMemberForCallSite(path8, node) {
|
|
|
4812
5019
|
if (!isDirectCallee) {
|
|
4813
5020
|
return node;
|
|
4814
5021
|
}
|
|
4815
|
-
if (!
|
|
5022
|
+
if (!t44.isExpression(node.object)) {
|
|
4816
5023
|
return node;
|
|
4817
5024
|
}
|
|
4818
5025
|
return node.object;
|
|
@@ -4824,20 +5031,20 @@ function ensureOptionalForMemberChain(node) {
|
|
|
4824
5031
|
const rebuildWithOptionalChain = (node2) => {
|
|
4825
5032
|
const safeObject = ensureOptionalForMemberChain(node2.object);
|
|
4826
5033
|
if (safeObject !== node2.object) {
|
|
4827
|
-
const property =
|
|
4828
|
-
return
|
|
5034
|
+
const property = t44.cloneNode(node2.property, true);
|
|
5035
|
+
return t44.optionalMemberExpression(safeObject, property, node2.computed, true);
|
|
4829
5036
|
}
|
|
4830
|
-
if (
|
|
4831
|
-
const object =
|
|
4832
|
-
const property =
|
|
4833
|
-
return
|
|
5037
|
+
if (t44.isMemberExpression(node2)) {
|
|
5038
|
+
const object = t44.cloneNode(node2.object, true);
|
|
5039
|
+
const property = t44.cloneNode(node2.property, true);
|
|
5040
|
+
return t44.optionalMemberExpression(object, property, node2.computed, true);
|
|
4834
5041
|
}
|
|
4835
5042
|
return node2;
|
|
4836
5043
|
};
|
|
4837
5044
|
return rebuildWithOptionalChain(node);
|
|
4838
5045
|
}
|
|
4839
5046
|
function hasTrailingMemberAccess(node) {
|
|
4840
|
-
return
|
|
5047
|
+
return t44.isMemberExpression(node.object) || t44.isOptionalMemberExpression(node.object);
|
|
4841
5048
|
}
|
|
4842
5049
|
|
|
4843
5050
|
// src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
|
|
@@ -4864,7 +5071,7 @@ function traceBindingSource(binding, seen, depth) {
|
|
|
4864
5071
|
}
|
|
4865
5072
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4866
5073
|
if (depth <= 0) return null;
|
|
4867
|
-
if (
|
|
5074
|
+
if (t45.isIdentifier(exp)) {
|
|
4868
5075
|
const sourceBinding = scope.getBinding(exp.name);
|
|
4869
5076
|
if (!sourceBinding) return null;
|
|
4870
5077
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -4872,13 +5079,13 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4872
5079
|
}
|
|
4873
5080
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4874
5081
|
}
|
|
4875
|
-
if (
|
|
5082
|
+
if (t45.isMemberExpression(exp) || t45.isOptionalMemberExpression(exp)) {
|
|
4876
5083
|
const root = findRootIdentifier(exp);
|
|
4877
5084
|
if (!root) return null;
|
|
4878
5085
|
const sourceBinding = scope.getBinding(root.name);
|
|
4879
5086
|
if (!sourceBinding) return null;
|
|
4880
5087
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
4881
|
-
return
|
|
5088
|
+
return t45.cloneNode(exp);
|
|
4882
5089
|
}
|
|
4883
5090
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4884
5091
|
if (sourcedRoot) {
|
|
@@ -4886,17 +5093,17 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4886
5093
|
if (rebuilt) {
|
|
4887
5094
|
return rebuilt;
|
|
4888
5095
|
}
|
|
4889
|
-
return
|
|
5096
|
+
return t45.cloneNode(sourcedRoot, true);
|
|
4890
5097
|
}
|
|
4891
5098
|
}
|
|
4892
5099
|
return null;
|
|
4893
5100
|
}
|
|
4894
5101
|
function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
4895
5102
|
const replacedObject = (() => {
|
|
4896
|
-
if (
|
|
4897
|
-
return
|
|
5103
|
+
if (t45.isIdentifier(node.object)) {
|
|
5104
|
+
return t45.cloneNode(nextRoot, true);
|
|
4898
5105
|
}
|
|
4899
|
-
if (
|
|
5106
|
+
if (t45.isMemberExpression(node.object) || t45.isOptionalMemberExpression(node.object)) {
|
|
4900
5107
|
return rebuildMemberWithNewRoot(node.object, nextRoot);
|
|
4901
5108
|
}
|
|
4902
5109
|
return null;
|
|
@@ -4904,15 +5111,15 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4904
5111
|
if (!replacedObject) {
|
|
4905
5112
|
return null;
|
|
4906
5113
|
}
|
|
4907
|
-
const property =
|
|
4908
|
-
if (
|
|
4909
|
-
return
|
|
5114
|
+
const property = t45.cloneNode(node.property, true);
|
|
5115
|
+
if (t45.isMemberExpression(node)) {
|
|
5116
|
+
return t45.memberExpression(
|
|
4910
5117
|
replacedObject,
|
|
4911
5118
|
property,
|
|
4912
5119
|
node.computed
|
|
4913
5120
|
);
|
|
4914
5121
|
}
|
|
4915
|
-
return
|
|
5122
|
+
return t45.optionalMemberExpression(
|
|
4916
5123
|
replacedObject,
|
|
4917
5124
|
property,
|
|
4918
5125
|
node.computed,
|
|
@@ -4923,9 +5130,9 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4923
5130
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4924
5131
|
function analyzeDeps(node, ctx, parentPath) {
|
|
4925
5132
|
if (!parentPath) {
|
|
4926
|
-
return
|
|
5133
|
+
return t46.arrayExpression([]);
|
|
4927
5134
|
}
|
|
4928
|
-
const isFnExpr =
|
|
5135
|
+
const isFnExpr = t46.isArrowFunctionExpression(node) || t46.isFunctionExpression(node);
|
|
4929
5136
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
4930
5137
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
4931
5138
|
const deps = /* @__PURE__ */ new Map();
|
|
@@ -4935,13 +5142,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4935
5142
|
}
|
|
4936
5143
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
4937
5144
|
if (analyzeTargetPath) {
|
|
4938
|
-
if (
|
|
5145
|
+
if (t46.isMemberExpression(analyzeTarget) || t46.isOptionalMemberExpression(analyzeTarget)) {
|
|
4939
5146
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
4940
5147
|
if (rootId) {
|
|
4941
5148
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
4942
5149
|
processedIdentifiers.add(rootId);
|
|
4943
5150
|
}
|
|
4944
|
-
} else if (
|
|
5151
|
+
} else if (t46.isIdentifier(analyzeTarget)) {
|
|
4945
5152
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
4946
5153
|
}
|
|
4947
5154
|
}
|
|
@@ -4993,55 +5200,54 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4993
5200
|
}
|
|
4994
5201
|
}
|
|
4995
5202
|
}
|
|
4996
|
-
return
|
|
5203
|
+
return t46.arrayExpression(Array.from(deps.values()));
|
|
4997
5204
|
}
|
|
4998
5205
|
|
|
4999
|
-
// src/core/transform/sfc/script/syntax-processor/process/resolve-
|
|
5000
|
-
|
|
5206
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
5207
|
+
|
|
5208
|
+
function resolveRenameAdapter(ctx) {
|
|
5001
5209
|
return {
|
|
5002
5210
|
"CallExpression|Identifier"(path8) {
|
|
5003
5211
|
const node = path8.node;
|
|
5004
|
-
const
|
|
5005
|
-
|
|
5006
|
-
if (
|
|
5212
|
+
const isCallNode = t47.isCallExpression(node);
|
|
5213
|
+
let apiName = "";
|
|
5214
|
+
if (t47.isIdentifier(node)) {
|
|
5215
|
+
apiName = node.name;
|
|
5216
|
+
} else if (isCallNode && t47.isIdentifier(node.callee)) {
|
|
5217
|
+
apiName = node.callee.name;
|
|
5218
|
+
}
|
|
5219
|
+
if (!apiName) {
|
|
5220
|
+
return;
|
|
5221
|
+
}
|
|
5222
|
+
const runtimeAdapter = ADAPTER_RULES.runtime[apiName];
|
|
5223
|
+
const routerAdapter = ADAPTER_RULES.router[apiName];
|
|
5224
|
+
const adapter = runtimeAdapter || routerAdapter;
|
|
5225
|
+
if (!adapter || adapter.type !== "rename") {
|
|
5007
5226
|
return;
|
|
5008
5227
|
}
|
|
5009
5228
|
if (!isVueApiReference(path8, apiName)) {
|
|
5010
5229
|
return;
|
|
5011
5230
|
}
|
|
5012
|
-
if (
|
|
5013
|
-
|
|
5231
|
+
if (adapter.isTrackable) {
|
|
5232
|
+
const reactiveType = getReactiveType(apiName);
|
|
5233
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
5234
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _163 => _163.node]), {
|
|
5235
|
+
is_reactive: true,
|
|
5236
|
+
reactive_type: reactiveType
|
|
5237
|
+
});
|
|
5238
|
+
}
|
|
5239
|
+
if (isCallNode) {
|
|
5240
|
+
replaceCallName(node, adapter.target);
|
|
5014
5241
|
} else {
|
|
5015
5242
|
replaceIdName(node, adapter.target);
|
|
5016
5243
|
}
|
|
5244
|
+
if (adapter.package === PACKAGE_NAME.router && !ctx.route) {
|
|
5245
|
+
ctx.route = true;
|
|
5246
|
+
}
|
|
5017
5247
|
recordImport(ctx, adapter.package, adapter.target);
|
|
5018
5248
|
}
|
|
5019
5249
|
};
|
|
5020
5250
|
}
|
|
5021
|
-
function getApiName(node) {
|
|
5022
|
-
const isCallNode = t45.isCallExpression(node);
|
|
5023
|
-
let apiName = "";
|
|
5024
|
-
if (t45.isIdentifier(node)) {
|
|
5025
|
-
apiName = node.name;
|
|
5026
|
-
} else if (isCallNode && t45.isIdentifier(node.callee)) {
|
|
5027
|
-
apiName = node.callee.name;
|
|
5028
|
-
}
|
|
5029
|
-
return apiName;
|
|
5030
|
-
}
|
|
5031
|
-
function resolveCallNode(path8, adapter, ctx) {
|
|
5032
|
-
const { node } = path8;
|
|
5033
|
-
const { arguments: args } = node;
|
|
5034
|
-
if (!args.length) return;
|
|
5035
|
-
const fn = args[0];
|
|
5036
|
-
if (!t45.isArrowFunctionExpression(fn) && !t45.isFunctionExpression(fn)) {
|
|
5037
|
-
return;
|
|
5038
|
-
}
|
|
5039
|
-
const fnPath = path8.get("arguments")[0];
|
|
5040
|
-
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
5041
|
-
args.push(deps);
|
|
5042
|
-
replaceCallName(node, adapter.target);
|
|
5043
|
-
recordImport(ctx, adapter.package, adapter.target);
|
|
5044
|
-
}
|
|
5045
5251
|
function isVueApiReference(path8, apiName) {
|
|
5046
5252
|
if (path8.isIdentifier()) {
|
|
5047
5253
|
if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
|
|
@@ -5051,12 +5257,11 @@ function isVueApiReference(path8, apiName) {
|
|
|
5051
5257
|
return false;
|
|
5052
5258
|
}
|
|
5053
5259
|
}
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
return isVueImportBinding(callee.scope.getBinding(apiName));
|
|
5260
|
+
const binding = path8.isCallExpression() ? path8.get("callee").scope.getBinding(apiName) : path8.scope.getBinding(apiName);
|
|
5261
|
+
if (binding) {
|
|
5262
|
+
return isVueImportBinding(binding);
|
|
5058
5263
|
}
|
|
5059
|
-
return
|
|
5264
|
+
return AUTO_IMPORTED_APIS.has(apiName);
|
|
5060
5265
|
}
|
|
5061
5266
|
function isVueImportBinding(binding) {
|
|
5062
5267
|
if (!binding) return false;
|
|
@@ -5064,8 +5269,8 @@ function isVueImportBinding(binding) {
|
|
|
5064
5269
|
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
5065
5270
|
return false;
|
|
5066
5271
|
}
|
|
5067
|
-
const parent = _optionalChain([bindingPath, 'access',
|
|
5068
|
-
if (!parent || !
|
|
5272
|
+
const parent = _optionalChain([bindingPath, 'access', _164 => _164.parentPath, 'optionalAccess', _165 => _165.node]);
|
|
5273
|
+
if (!parent || !t47.isImportDeclaration(parent)) {
|
|
5069
5274
|
return false;
|
|
5070
5275
|
}
|
|
5071
5276
|
const source = parent.source.value.toLowerCase();
|
|
@@ -5078,6 +5283,53 @@ function isVueImportBinding(binding) {
|
|
|
5078
5283
|
return VUE_PACKAGES.some((name) => source === name || source.startsWith(`${name}/`));
|
|
5079
5284
|
}
|
|
5080
5285
|
|
|
5286
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
5287
|
+
function resolveAnalysisOnlyAdapter(ctx) {
|
|
5288
|
+
return {
|
|
5289
|
+
"CallExpression|Identifier"(path8) {
|
|
5290
|
+
const node = path8.node;
|
|
5291
|
+
const apiName = getApiName(node);
|
|
5292
|
+
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
5293
|
+
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
5294
|
+
return;
|
|
5295
|
+
}
|
|
5296
|
+
if (!isVueApiReference(path8, apiName)) {
|
|
5297
|
+
return;
|
|
5298
|
+
}
|
|
5299
|
+
if (t48.isCallExpression(node)) {
|
|
5300
|
+
resolveCallNode(path8, adapter, ctx);
|
|
5301
|
+
} else {
|
|
5302
|
+
replaceIdName(node, adapter.target);
|
|
5303
|
+
}
|
|
5304
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
5305
|
+
}
|
|
5306
|
+
};
|
|
5307
|
+
}
|
|
5308
|
+
function getApiName(node) {
|
|
5309
|
+
const isCallNode = t48.isCallExpression(node);
|
|
5310
|
+
let apiName = "";
|
|
5311
|
+
if (t48.isIdentifier(node)) {
|
|
5312
|
+
apiName = node.name;
|
|
5313
|
+
} else if (isCallNode && t48.isIdentifier(node.callee)) {
|
|
5314
|
+
apiName = node.callee.name;
|
|
5315
|
+
}
|
|
5316
|
+
return apiName;
|
|
5317
|
+
}
|
|
5318
|
+
function resolveCallNode(path8, adapter, ctx) {
|
|
5319
|
+
const { node } = path8;
|
|
5320
|
+
const { arguments: args } = node;
|
|
5321
|
+
if (!args.length) return;
|
|
5322
|
+
const fn = args[0];
|
|
5323
|
+
if (!t48.isArrowFunctionExpression(fn) && !t48.isFunctionExpression(fn)) {
|
|
5324
|
+
return;
|
|
5325
|
+
}
|
|
5326
|
+
const fnPath = path8.get("arguments")[0];
|
|
5327
|
+
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
5328
|
+
args.push(deps);
|
|
5329
|
+
replaceCallName(node, adapter.target);
|
|
5330
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
5331
|
+
}
|
|
5332
|
+
|
|
5081
5333
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
|
|
5082
5334
|
function resolveArrowFnDeps(ctx, ast) {
|
|
5083
5335
|
return {
|
|
@@ -5091,7 +5343,7 @@ function resolveArrowFnDeps(ctx, ast) {
|
|
|
5091
5343
|
const newNode = createUseCallback(node, deps);
|
|
5092
5344
|
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
5093
5345
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
5094
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
5346
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _166 => _166.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
5095
5347
|
replaceNode(path8, newNode, node);
|
|
5096
5348
|
}
|
|
5097
5349
|
};
|
|
@@ -5150,15 +5402,15 @@ function resolveElementRef(ctx) {
|
|
|
5150
5402
|
return;
|
|
5151
5403
|
}
|
|
5152
5404
|
if (isCompRefBindings) {
|
|
5153
|
-
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
5154
|
-
if (!
|
|
5405
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _167 => _167(path8), 'optionalAccess', _168 => _168.node]);
|
|
5406
|
+
if (!t49.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _169 => _169.id]))) {
|
|
5155
5407
|
return;
|
|
5156
5408
|
}
|
|
5157
5409
|
const varName = varDeclaratorPath.id.name;
|
|
5158
5410
|
const compRef = refBindings.componentRefs[varName];
|
|
5159
5411
|
if (!compRef) return;
|
|
5160
5412
|
}
|
|
5161
|
-
node.arguments[0] =
|
|
5413
|
+
node.arguments[0] = t49.identifier("null");
|
|
5162
5414
|
resolveTypeParameters(ctx, path8);
|
|
5163
5415
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
5164
5416
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
@@ -5174,7 +5426,7 @@ function resolveTypeParameters(ctx, path8) {
|
|
|
5174
5426
|
scriptData
|
|
5175
5427
|
} = ctx;
|
|
5176
5428
|
const { node } = path8;
|
|
5177
|
-
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
5429
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _170 => _170(path8), 'optionalAccess', _171 => _171.node]);
|
|
5178
5430
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
5179
5431
|
return;
|
|
5180
5432
|
}
|
|
@@ -5183,20 +5435,20 @@ function resolveTypeParameters(ctx, path8) {
|
|
|
5183
5435
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
5184
5436
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
5185
5437
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
5186
|
-
node.typeParameters =
|
|
5438
|
+
node.typeParameters = t49.tsTypeParameterInstantiation([t49.tsTypeReference(t49.identifier(type))]);
|
|
5187
5439
|
}
|
|
5188
5440
|
}
|
|
5189
5441
|
function resolveRefValueToCurrent(path8) {
|
|
5190
5442
|
const { node } = path8;
|
|
5191
|
-
if (node.computed || !
|
|
5443
|
+
if (node.computed || !t49.isIdentifier(node.property) || node.property.name !== "value") {
|
|
5192
5444
|
return;
|
|
5193
5445
|
}
|
|
5194
5446
|
const rootPath = findRootVariablePath(path8);
|
|
5195
|
-
if (!_optionalChain([rootPath, 'optionalAccess',
|
|
5447
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _172 => _172.node]) || !t49.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
5196
5448
|
return;
|
|
5197
5449
|
}
|
|
5198
5450
|
const rootId = findRootIdentifier(node);
|
|
5199
|
-
if (!
|
|
5451
|
+
if (!t49.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _173 => _173.name])) {
|
|
5200
5452
|
return;
|
|
5201
5453
|
}
|
|
5202
5454
|
node.property.name = "current";
|
|
@@ -5215,11 +5467,11 @@ function resolveExprMemo(ctx, ast) {
|
|
|
5215
5467
|
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
5216
5468
|
return false;
|
|
5217
5469
|
}
|
|
5218
|
-
if (!
|
|
5470
|
+
if (!t50.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
|
|
5219
5471
|
return false;
|
|
5220
5472
|
}
|
|
5221
|
-
if (
|
|
5222
|
-
if (
|
|
5473
|
+
if (t50.isFunction(init)) return false;
|
|
5474
|
+
if (t50.isCallExpression(init) && t50.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
5223
5475
|
return false;
|
|
5224
5476
|
}
|
|
5225
5477
|
return true;
|
|
@@ -5244,10 +5496,10 @@ function resolveLintRules(ctx, ast) {
|
|
|
5244
5496
|
return {
|
|
5245
5497
|
CallExpression(path8) {
|
|
5246
5498
|
const { node, parentPath } = path8;
|
|
5247
|
-
if (!
|
|
5499
|
+
if (!t51.isIdentifier(node.callee)) return;
|
|
5248
5500
|
const { name: callName } = node.callee;
|
|
5249
|
-
const addLog = (
|
|
5250
|
-
logger.error(
|
|
5501
|
+
const addLog = (t56) => {
|
|
5502
|
+
logger.error(t56, {
|
|
5251
5503
|
file: ctx.filename,
|
|
5252
5504
|
source: ctx.scriptData.source,
|
|
5253
5505
|
loc: node.loc
|
|
@@ -5309,7 +5561,7 @@ function resolveProvide(ctx) {
|
|
|
5309
5561
|
});
|
|
5310
5562
|
return;
|
|
5311
5563
|
}
|
|
5312
|
-
const providerTarget = _optionalChain([ADAPTER_RULES, 'access',
|
|
5564
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _174 => _174.runtime, 'access', _175 => _175[VUE_API_MAP.provide], 'optionalAccess', _176 => _176.target]);
|
|
5313
5565
|
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
5314
5566
|
if (!isProvideCall) return;
|
|
5315
5567
|
const { provide } = scriptData;
|
|
@@ -5327,7 +5579,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
5327
5579
|
return root;
|
|
5328
5580
|
}
|
|
5329
5581
|
let cur = root.provide;
|
|
5330
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
5582
|
+
while (_optionalChain([cur, 'optionalAccess', _177 => _177.isOccupied])) {
|
|
5331
5583
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
5332
5584
|
}
|
|
5333
5585
|
return cur || (root.provide = {});
|
|
@@ -5335,13 +5587,13 @@ function findOrCreateCtxProvider(root) {
|
|
|
5335
5587
|
function assignProviderValue(target, key, value) {
|
|
5336
5588
|
const getRawExp = (exp) => {
|
|
5337
5589
|
if (!exp) return "''";
|
|
5338
|
-
if (
|
|
5590
|
+
if (t52.isStringLiteral(exp)) {
|
|
5339
5591
|
return JSON.stringify(exp.value);
|
|
5340
5592
|
}
|
|
5341
|
-
if (
|
|
5593
|
+
if (t52.isNumericLiteral(exp)) {
|
|
5342
5594
|
return exp.value.toString();
|
|
5343
5595
|
}
|
|
5344
|
-
if (
|
|
5596
|
+
if (t52.isIdentifier(exp)) {
|
|
5345
5597
|
return exp.name;
|
|
5346
5598
|
}
|
|
5347
5599
|
try {
|
|
@@ -5356,96 +5608,13 @@ function assignProviderValue(target, key, value) {
|
|
|
5356
5608
|
target.provide = {};
|
|
5357
5609
|
}
|
|
5358
5610
|
|
|
5359
|
-
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
5360
|
-
|
|
5361
|
-
function resolveRenameAdapter(ctx) {
|
|
5362
|
-
return {
|
|
5363
|
-
"CallExpression|Identifier"(path8) {
|
|
5364
|
-
const node = path8.node;
|
|
5365
|
-
const isCallNode = t50.isCallExpression(node);
|
|
5366
|
-
let apiName = "";
|
|
5367
|
-
if (t50.isIdentifier(node)) {
|
|
5368
|
-
apiName = node.name;
|
|
5369
|
-
} else if (isCallNode && t50.isIdentifier(node.callee)) {
|
|
5370
|
-
apiName = node.callee.name;
|
|
5371
|
-
}
|
|
5372
|
-
if (!apiName) {
|
|
5373
|
-
return;
|
|
5374
|
-
}
|
|
5375
|
-
const runtimeAdapter = ADAPTER_RULES.runtime[apiName];
|
|
5376
|
-
const routerAdapter = ADAPTER_RULES.router[apiName];
|
|
5377
|
-
const adapter = runtimeAdapter || routerAdapter;
|
|
5378
|
-
if (!adapter || adapter.type !== "rename") {
|
|
5379
|
-
return;
|
|
5380
|
-
}
|
|
5381
|
-
if (!isVueApiReference2(path8, apiName)) {
|
|
5382
|
-
return;
|
|
5383
|
-
}
|
|
5384
|
-
if (adapter.isTrackable) {
|
|
5385
|
-
const reactiveType = getReactiveType(apiName);
|
|
5386
|
-
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
5387
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _173 => _173.node]), {
|
|
5388
|
-
is_reactive: true,
|
|
5389
|
-
reactive_type: reactiveType
|
|
5390
|
-
});
|
|
5391
|
-
}
|
|
5392
|
-
if (isCallNode) {
|
|
5393
|
-
replaceCallName(node, adapter.target);
|
|
5394
|
-
} else {
|
|
5395
|
-
replaceIdName(node, adapter.target);
|
|
5396
|
-
}
|
|
5397
|
-
if (adapter.package === PACKAGE_NAME.router && !ctx.route) {
|
|
5398
|
-
ctx.route = true;
|
|
5399
|
-
}
|
|
5400
|
-
recordImport(ctx, adapter.package, adapter.target);
|
|
5401
|
-
}
|
|
5402
|
-
};
|
|
5403
|
-
}
|
|
5404
|
-
function isVueApiReference2(path8, apiName) {
|
|
5405
|
-
const whitelist = [VUE_API_MAP.defineAsyncComponent];
|
|
5406
|
-
if (whitelist.includes(apiName)) {
|
|
5407
|
-
return true;
|
|
5408
|
-
}
|
|
5409
|
-
if (path8.isIdentifier()) {
|
|
5410
|
-
if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
|
|
5411
|
-
return false;
|
|
5412
|
-
}
|
|
5413
|
-
if (!path8.isReferencedIdentifier()) {
|
|
5414
|
-
return false;
|
|
5415
|
-
}
|
|
5416
|
-
}
|
|
5417
|
-
if (path8.isCallExpression()) {
|
|
5418
|
-
const callee = path8.get("callee");
|
|
5419
|
-
if (!callee.isIdentifier()) return false;
|
|
5420
|
-
return isVueImportBinding2(callee.scope.getBinding(apiName));
|
|
5421
|
-
}
|
|
5422
|
-
return isVueImportBinding2(path8.scope.getBinding(apiName));
|
|
5423
|
-
}
|
|
5424
|
-
function isVueImportBinding2(binding) {
|
|
5425
|
-
if (!binding) return false;
|
|
5426
|
-
const bindingPath = binding.path;
|
|
5427
|
-
if (!bindingPath.isImportSpecifier() && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier()) {
|
|
5428
|
-
return false;
|
|
5429
|
-
}
|
|
5430
|
-
const parent = _optionalChain([bindingPath, 'access', _174 => _174.parentPath, 'optionalAccess', _175 => _175.node]);
|
|
5431
|
-
if (!parent || !t50.isImportDeclaration(parent)) {
|
|
5432
|
-
return false;
|
|
5433
|
-
}
|
|
5434
|
-
const source = parent.source.value.toLowerCase();
|
|
5435
|
-
if (source.startsWith("@vue/")) {
|
|
5436
|
-
return true;
|
|
5437
|
-
}
|
|
5438
|
-
if (source === "vue-router" || source.startsWith("vue-router/")) {
|
|
5439
|
-
return true;
|
|
5440
|
-
}
|
|
5441
|
-
return VUE_PACKAGES.some((name) => source === name || source.startsWith(`${name}/`));
|
|
5442
|
-
}
|
|
5443
|
-
|
|
5444
5611
|
// src/core/transform/sfc/script/syntax-processor/index.ts
|
|
5445
5612
|
function processVueSyntax2(ast, ctx) {
|
|
5446
5613
|
vueSyntaxProcessor2(ast, ctx, {
|
|
5447
5614
|
preprocess: {
|
|
5448
5615
|
applyBabel: [
|
|
5616
|
+
// feature: https://github.com/vureact-js/core/issues/63
|
|
5617
|
+
resolveWithDefaultsOptions,
|
|
5449
5618
|
resolvePropsIface,
|
|
5450
5619
|
resolveEmitsTopLevelTypes,
|
|
5451
5620
|
resolveDefineOptions,
|
|
@@ -5474,6 +5643,8 @@ function processVueSyntax2(ast, ctx) {
|
|
|
5474
5643
|
},
|
|
5475
5644
|
postprocess: {
|
|
5476
5645
|
applyBabel: [
|
|
5646
|
+
// feature: https://github.com/vureact-js/core/issues/63
|
|
5647
|
+
resolveWithDefaults,
|
|
5477
5648
|
// 该 resolver 需确保放在所有类型处理之后,移除之前
|
|
5478
5649
|
resolveVueTypeAsAny,
|
|
5479
5650
|
resolveRuntimeImports,
|
|
@@ -5485,12 +5656,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
5485
5656
|
}
|
|
5486
5657
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
5487
5658
|
const runExcludeThenApply = (cfg) => {
|
|
5488
|
-
_optionalChain([cfg, 'access',
|
|
5489
|
-
_optionalChain([cfg, 'access',
|
|
5659
|
+
_optionalChain([cfg, 'access', _178 => _178.excludeBabel, 'optionalAccess', _179 => _179.forEach, 'call', _180 => _180((fn) => fn(ctx, ast))]);
|
|
5660
|
+
_optionalChain([cfg, 'access', _181 => _181.applyBabel, 'optionalAccess', _182 => _182.forEach, 'call', _183 => _183((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
5490
5661
|
};
|
|
5491
5662
|
const runApplyThenExclude = (cfg) => {
|
|
5492
|
-
_optionalChain([cfg, 'access',
|
|
5493
|
-
_optionalChain([cfg, 'access',
|
|
5663
|
+
_optionalChain([cfg, 'access', _184 => _184.applyBabel, 'optionalAccess', _185 => _185.forEach, 'call', _186 => _186((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
5664
|
+
_optionalChain([cfg, 'access', _187 => _187.excludeBabel, 'optionalAccess', _188 => _188.forEach, 'call', _189 => _189((fn) => fn(ctx, ast))]);
|
|
5494
5665
|
};
|
|
5495
5666
|
runExcludeThenApply(options.preprocess);
|
|
5496
5667
|
runExcludeThenApply(options.process);
|
|
@@ -5576,9 +5747,9 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
5576
5747
|
|
|
5577
5748
|
|
|
5578
5749
|
var strCodeTypes = {
|
|
5579
|
-
isIdentifier:
|
|
5750
|
+
isIdentifier: isIdentifier32,
|
|
5580
5751
|
isSimpleExpression,
|
|
5581
|
-
isStringLiteral:
|
|
5752
|
+
isStringLiteral: isStringLiteral15
|
|
5582
5753
|
};
|
|
5583
5754
|
function isSimpleExpression(code, excludeVar = false) {
|
|
5584
5755
|
let node;
|
|
@@ -5587,38 +5758,38 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
5587
5758
|
} catch (e7) {
|
|
5588
5759
|
return false;
|
|
5589
5760
|
}
|
|
5590
|
-
if (
|
|
5761
|
+
if (t53.isLiteral(node)) {
|
|
5591
5762
|
return true;
|
|
5592
5763
|
}
|
|
5593
|
-
if (!excludeVar &&
|
|
5764
|
+
if (!excludeVar && t53.isIdentifier(node)) {
|
|
5594
5765
|
return true;
|
|
5595
5766
|
}
|
|
5596
|
-
if (
|
|
5597
|
-
return isSimpleExpression(node.object) &&
|
|
5767
|
+
if (t53.isMemberExpression(node)) {
|
|
5768
|
+
return isSimpleExpression(node.object) && t53.isIdentifier(node.property);
|
|
5598
5769
|
}
|
|
5599
|
-
if (
|
|
5770
|
+
if (t53.isObjectExpression(node) || t53.isArrayExpression(node)) {
|
|
5600
5771
|
return false;
|
|
5601
5772
|
}
|
|
5602
|
-
if (
|
|
5773
|
+
if (t53.isCallExpression(node) || t53.isAssignmentExpression(node)) {
|
|
5603
5774
|
return false;
|
|
5604
5775
|
}
|
|
5605
|
-
if (
|
|
5776
|
+
if (t53.isBinaryExpression(node) || t53.isUnaryExpression(node)) {
|
|
5606
5777
|
return true;
|
|
5607
5778
|
}
|
|
5608
5779
|
return false;
|
|
5609
5780
|
}
|
|
5610
|
-
function
|
|
5781
|
+
function isIdentifier32(code) {
|
|
5611
5782
|
try {
|
|
5612
5783
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5613
|
-
return
|
|
5784
|
+
return t53.isIdentifier(node);
|
|
5614
5785
|
} catch (e8) {
|
|
5615
5786
|
return false;
|
|
5616
5787
|
}
|
|
5617
5788
|
}
|
|
5618
|
-
function
|
|
5789
|
+
function isStringLiteral15(code) {
|
|
5619
5790
|
try {
|
|
5620
5791
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5621
|
-
return
|
|
5792
|
+
return t53.isStringLiteral(node);
|
|
5622
5793
|
} catch (e9) {
|
|
5623
5794
|
return false;
|
|
5624
5795
|
}
|
|
@@ -5728,12 +5899,12 @@ function wrapSingleQuotes(content, condition) {
|
|
|
5728
5899
|
return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
|
|
5729
5900
|
}
|
|
5730
5901
|
function checkPropIsDynamicKey(ctx, node) {
|
|
5731
|
-
const isKeyStatic = _optionalChain([node, 'access',
|
|
5902
|
+
const isKeyStatic = _optionalChain([node, 'access', _190 => _190.arg, 'optionalAccess', _191 => _191.isStatic]);
|
|
5732
5903
|
const { source, filename } = ctx;
|
|
5733
5904
|
if (node.rawName === "v-bind" && !node.name) {
|
|
5734
5905
|
logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
|
|
5735
5906
|
source,
|
|
5736
|
-
loc: _optionalChain([node, 'access',
|
|
5907
|
+
loc: _optionalChain([node, 'access', _192 => _192.arg, 'optionalAccess', _193 => _193.loc]),
|
|
5737
5908
|
file: filename
|
|
5738
5909
|
});
|
|
5739
5910
|
return;
|
|
@@ -5741,7 +5912,7 @@ function checkPropIsDynamicKey(ctx, node) {
|
|
|
5741
5912
|
if (isKeyStatic === false) {
|
|
5742
5913
|
logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
|
|
5743
5914
|
source,
|
|
5744
|
-
loc: _optionalChain([node, 'access',
|
|
5915
|
+
loc: _optionalChain([node, 'access', _194 => _194.arg, 'optionalAccess', _195 => _195.loc]),
|
|
5745
5916
|
file: filename
|
|
5746
5917
|
});
|
|
5747
5918
|
}
|
|
@@ -5761,26 +5932,26 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5761
5932
|
const rule = ADAPTER_RULES.runtime;
|
|
5762
5933
|
const setNameIdentifier = (target, valueName) => {
|
|
5763
5934
|
target.content = valueName;
|
|
5764
|
-
target.ast =
|
|
5935
|
+
target.ast = t54.jsxIdentifier(valueName);
|
|
5765
5936
|
};
|
|
5766
|
-
const setValueExpression = (target, content,
|
|
5937
|
+
const setValueExpression = (target, content, isStringLiteral16) => {
|
|
5767
5938
|
target.content = content;
|
|
5768
|
-
target.ast = resolveStringExpr(content, ctx,
|
|
5939
|
+
target.ast = resolveStringExpr(content, ctx, isStringLiteral16);
|
|
5769
5940
|
};
|
|
5770
5941
|
const createRuntimeCall = (fnName, args) => {
|
|
5771
5942
|
const fnArgs = args.filter(Boolean).join(",");
|
|
5772
|
-
const valIsUndef = fnName === rule.dirOn.target && _optionalChain([args, 'optionalAccess',
|
|
5943
|
+
const valIsUndef = fnName === rule.dirOn.target && _optionalChain([args, 'optionalAccess', _196 => _196[1]]) === "undefined";
|
|
5773
5944
|
const isTs = ctx.scriptData.lang.startsWith("ts");
|
|
5774
5945
|
const safeTypeAssertion = isTs ? valIsUndef ? "as never" : "" : "";
|
|
5775
5946
|
return `${fnName}(${fnArgs}) ${safeTypeAssertion}`;
|
|
5776
5947
|
};
|
|
5777
|
-
const applyRuntimeExpression = (expression, setName = false, nameIdentifier,
|
|
5948
|
+
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral16) => {
|
|
5778
5949
|
if (setName && nameIdentifier) {
|
|
5779
5950
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
5780
5951
|
}
|
|
5781
5952
|
const dir = rule.dir;
|
|
5782
5953
|
recordImport(ctx, dir.package, dir.target);
|
|
5783
|
-
setValueExpression(value.babelExp, expression,
|
|
5954
|
+
setValueExpression(value.babelExp, expression, isStringLiteral16);
|
|
5784
5955
|
};
|
|
5785
5956
|
if (ir.isKeyLessVBind) {
|
|
5786
5957
|
const dirKeyless = rule.dirKeyless;
|
|
@@ -5790,19 +5961,19 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5790
5961
|
}
|
|
5791
5962
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
5792
5963
|
const dirCls = rule.dirCls;
|
|
5793
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5964
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _197 => _197.join, 'call', _198 => _198(",")]) || wrapSingleQuotes(valueContent);
|
|
5794
5965
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
5795
5966
|
applyRuntimeExpression(expression, true, name);
|
|
5796
5967
|
return;
|
|
5797
5968
|
}
|
|
5798
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
5969
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _199 => _199.some, 'call', _200 => _200((item) => !isSimpleStyle(item))]))) {
|
|
5799
5970
|
const dirStyle = rule.dirStyle;
|
|
5800
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5971
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _201 => _201.join, 'call', _202 => _202(",")]) || valueContent;
|
|
5801
5972
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
5802
5973
|
applyRuntimeExpression(expression, true, name);
|
|
5803
5974
|
return;
|
|
5804
5975
|
}
|
|
5805
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
5976
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _203 => _203.modifiers, 'optionalAccess', _204 => _204.length])) {
|
|
5806
5977
|
const dirOn = rule.dirOn;
|
|
5807
5978
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
5808
5979
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
@@ -5857,7 +6028,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
5857
6028
|
continue;
|
|
5858
6029
|
}
|
|
5859
6030
|
const nodeIR = child;
|
|
5860
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
6031
|
+
if (_optionalChain([parentIR, 'optionalAccess', _205 => _205.isBuiltIn])) {
|
|
5861
6032
|
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
5862
6033
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
5863
6034
|
}
|
|
@@ -5898,7 +6069,7 @@ function walkElementNodes(node, onElement) {
|
|
|
5898
6069
|
}
|
|
5899
6070
|
function resolveDefaultStyleModuleName(node) {
|
|
5900
6071
|
const { exp } = node;
|
|
5901
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
6072
|
+
if (_optionalChain([exp, 'optionalAccess', _206 => _206.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
5902
6073
|
return;
|
|
5903
6074
|
}
|
|
5904
6075
|
if (exp.content.includes("$style")) {
|
|
@@ -5994,7 +6165,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
5994
6165
|
const oldStyle = oldAttr.value.content;
|
|
5995
6166
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
5996
6167
|
let merged = oldAttr.value.merge;
|
|
5997
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
6168
|
+
if (!_optionalChain([merged, 'optionalAccess', _207 => _207.length])) {
|
|
5998
6169
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
5999
6170
|
} else {
|
|
6000
6171
|
merged.push(newStyle);
|
|
@@ -6024,7 +6195,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
6024
6195
|
const { source, filename } = ctx;
|
|
6025
6196
|
let value = "";
|
|
6026
6197
|
let loc;
|
|
6027
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
6198
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _208 => _208.exp, 'optionalAccess', _209 => _209.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
6028
6199
|
value = node.exp.content;
|
|
6029
6200
|
loc = node.exp.loc;
|
|
6030
6201
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -6078,11 +6249,11 @@ function resolveRefProp(prop, ctx, nodeIR) {
|
|
|
6078
6249
|
} = ctx;
|
|
6079
6250
|
let propIR;
|
|
6080
6251
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
6081
|
-
const tag = _optionalChain([prop, 'access',
|
|
6252
|
+
const tag = _optionalChain([prop, 'access', _210 => _210.value, 'optionalAccess', _211 => _211.content]);
|
|
6082
6253
|
if (!tag) return;
|
|
6083
6254
|
collectComponentRef(tag, ctx);
|
|
6084
6255
|
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
6085
|
-
const refVar = _optionalChain([domRefBinding, 'optionalAccess',
|
|
6256
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _212 => _212.name]) || _optionalChain([refBindings, 'access', _213 => _213.componentRefs, 'access', _214 => _214[tag], 'optionalAccess', _215 => _215.name]);
|
|
6086
6257
|
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
6087
6258
|
} else {
|
|
6088
6259
|
const exp = prop.exp;
|
|
@@ -6134,7 +6305,7 @@ function resolveTemplateNodeKey(templNode, keyContent, ctx) {
|
|
|
6134
6305
|
return;
|
|
6135
6306
|
}
|
|
6136
6307
|
const [firstChild] = children;
|
|
6137
|
-
if (_optionalChain([firstChild, 'optionalAccess',
|
|
6308
|
+
if (_optionalChain([firstChild, 'optionalAccess', _216 => _216.type]) !== _compilercore.NodeTypes.ELEMENT || firstChild.tagType === _compilercore.ElementTypes.TEMPLATE || firstChild.tagType === _compilercore.ElementTypes.SLOT) {
|
|
6138
6309
|
return;
|
|
6139
6310
|
}
|
|
6140
6311
|
const hasKeyProp = firstChild.props.some(
|
|
@@ -6171,8 +6342,8 @@ function createSimpleVueBind(name, value) {
|
|
|
6171
6342
|
function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
6172
6343
|
const arg = directive.arg;
|
|
6173
6344
|
const exp = directive.exp;
|
|
6174
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6175
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6345
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _217 => _217.content]), () => ( ""));
|
|
6346
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _218 => _218.content]), () => ( "true"));
|
|
6176
6347
|
warnUnsupportedVueDollarVar(ctx, directive);
|
|
6177
6348
|
if (name === "is") {
|
|
6178
6349
|
resolveDynamicIsProp(directive, ir, ctx, nodeIR);
|
|
@@ -6187,7 +6358,7 @@ function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
6187
6358
|
return;
|
|
6188
6359
|
}
|
|
6189
6360
|
const propIR = createPropsIR(directive.rawName, name, content);
|
|
6190
|
-
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6361
|
+
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _219 => _219.isStatic]), () => ( true));
|
|
6191
6362
|
checkPropIsDynamicKey(ctx, directive);
|
|
6192
6363
|
resolvePropertyIR(propIR, ir, ctx, nodeIR, true);
|
|
6193
6364
|
}
|
|
@@ -6201,12 +6372,12 @@ function resolvePropertyIR(propsIR, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
6201
6372
|
content = propsIR.value.content = parseStyleString(content);
|
|
6202
6373
|
}
|
|
6203
6374
|
if (isDynamic) {
|
|
6204
|
-
const
|
|
6205
|
-
if (
|
|
6375
|
+
const isStringLiteral16 = strCodeTypes.isStringLiteral(content);
|
|
6376
|
+
if (isStringLiteral16) {
|
|
6206
6377
|
content = normalizeString(content);
|
|
6207
6378
|
propsIR.value.content = content;
|
|
6208
6379
|
}
|
|
6209
|
-
propsIR.value.isStringLiteral =
|
|
6380
|
+
propsIR.value.isStringLiteral = isStringLiteral16;
|
|
6210
6381
|
}
|
|
6211
6382
|
const existing = findSameProp(nodeIR.props, propsIR);
|
|
6212
6383
|
if (existing) {
|
|
@@ -6226,7 +6397,7 @@ function normalizeString(s) {
|
|
|
6226
6397
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
6227
6398
|
function resolveAttributeProp(attribute, ir, ctx, nodeIR) {
|
|
6228
6399
|
const name = attribute.name;
|
|
6229
|
-
const content = _nullishCoalesce(_optionalChain([attribute, 'access',
|
|
6400
|
+
const content = _nullishCoalesce(_optionalChain([attribute, 'access', _220 => _220.value, 'optionalAccess', _221 => _221.content]), () => ( "true"));
|
|
6230
6401
|
if (name === "is") {
|
|
6231
6402
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
6232
6403
|
return;
|
|
@@ -6321,10 +6492,10 @@ function resolveRouterLinkVSlotProp(directive, nodeIR, ctx) {
|
|
|
6321
6492
|
type: 2 /* SLOT */,
|
|
6322
6493
|
name: "customRender",
|
|
6323
6494
|
rawName: _nullishCoalesce(directive.rawName, () => ( "v-slot")),
|
|
6324
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6495
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _222 => _222.isStatic]), () => ( true)),
|
|
6325
6496
|
isScoped: true,
|
|
6326
6497
|
callback: {
|
|
6327
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6498
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _223 => _223.content, 'optionalAccess', _224 => _224.trim, 'call', _225 => _225()]), () => ( "")),
|
|
6328
6499
|
exp: []
|
|
6329
6500
|
}
|
|
6330
6501
|
};
|
|
@@ -6340,10 +6511,10 @@ function resolveVFor(directive, ir, ctx, nodeIR) {
|
|
|
6340
6511
|
};
|
|
6341
6512
|
}
|
|
6342
6513
|
function resolveForResult(forParseResult) {
|
|
6343
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
6344
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
6345
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
6346
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
6514
|
+
const source = _optionalChain([forParseResult, 'access', _226 => _226.source, 'optionalAccess', _227 => _227.content]);
|
|
6515
|
+
const value = _optionalChain([forParseResult, 'access', _228 => _228.value, 'optionalAccess', _229 => _229.content]);
|
|
6516
|
+
const index = _optionalChain([forParseResult, 'access', _230 => _230.index, 'optionalAccess', _231 => _231.content]);
|
|
6517
|
+
const key = _optionalChain([forParseResult, 'access', _232 => _232.key, 'optionalAccess', _233 => _233.content]);
|
|
6347
6518
|
return {
|
|
6348
6519
|
source,
|
|
6349
6520
|
value,
|
|
@@ -6363,7 +6534,7 @@ function resolveVHtml(directive, ir, ctx, nodeIR) {
|
|
|
6363
6534
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
6364
6535
|
function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
6365
6536
|
const name = directive.name === "else-if" ? "elseIf" : directive.name;
|
|
6366
|
-
const value = _nullishCoalesce(_optionalChain([directive, 'access',
|
|
6537
|
+
const value = _nullishCoalesce(_optionalChain([directive, 'access', _234 => _234.exp, 'optionalAccess', _235 => _235.content]), () => ( "true"));
|
|
6367
6538
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
6368
6539
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
6369
6540
|
let hasError = false;
|
|
@@ -6402,7 +6573,7 @@ function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
6402
6573
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
6403
6574
|
function resolveVMemo(directive, _ir, ctx, nodeIR) {
|
|
6404
6575
|
const exp = directive.exp;
|
|
6405
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
6576
|
+
let value = _optionalChain([exp, 'optionalAccess', _236 => _236.content]);
|
|
6406
6577
|
if (value !== void 0) {
|
|
6407
6578
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
6408
6579
|
const { source, filename } = ctx;
|
|
@@ -6442,14 +6613,14 @@ function resolveVModel(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
6442
6613
|
const getterName = exp.content;
|
|
6443
6614
|
const isComponent = vueNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
6444
6615
|
const inputType = resolveHtmlInput(vueNode, isComponent);
|
|
6445
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6616
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _237 => _237.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
6446
6617
|
let valuePropIR;
|
|
6447
6618
|
let eventPropIR;
|
|
6448
6619
|
if (isComponent) {
|
|
6449
6620
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
6450
6621
|
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
6451
6622
|
const eventVueName = `update:${propName}`;
|
|
6452
|
-
const isTS = _optionalChain([ctx, 'access',
|
|
6623
|
+
const isTS = _optionalChain([ctx, 'access', _238 => _238.scriptData, 'optionalAccess', _239 => _239.lang, 'optionalAccess', _240 => _240.startsWith, 'call', _241 => _241("ts")]);
|
|
6453
6624
|
const valueArg = isTS ? "value: any" : "value";
|
|
6454
6625
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
6455
6626
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -6487,7 +6658,7 @@ function getRadioValue(vueNode) {
|
|
|
6487
6658
|
const valueAttr = vueNode.props.find(
|
|
6488
6659
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
6489
6660
|
);
|
|
6490
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
6661
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _242 => _242.value, 'optionalAccess', _243 => _243.content])) return '""';
|
|
6491
6662
|
const content = valueAttr.value.content;
|
|
6492
6663
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
6493
6664
|
}
|
|
@@ -6497,7 +6668,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
6497
6668
|
const typeProp = node.props.find(
|
|
6498
6669
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
6499
6670
|
);
|
|
6500
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
6671
|
+
return _optionalChain([typeProp, 'optionalAccess', _244 => _244.value, 'optionalAccess', _245 => _245.content, 'optionalAccess', _246 => _246.toLowerCase, 'call', _247 => _247()]);
|
|
6501
6672
|
}
|
|
6502
6673
|
function applyValueModifiers(valueExp, modifiers) {
|
|
6503
6674
|
let result = valueExp;
|
|
@@ -6518,7 +6689,7 @@ function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
|
6518
6689
|
const modifiers = directive.modifiers.map((item) => item.content);
|
|
6519
6690
|
const captureIndex = resolveCaptureModifier(modifiers);
|
|
6520
6691
|
const eventName = resolveEventName(arg.content, captureIndex);
|
|
6521
|
-
const handlerContent = _optionalChain([exp, 'optionalAccess',
|
|
6692
|
+
const handlerContent = _optionalChain([exp, 'optionalAccess', _248 => _248.content, 'optionalAccess', _249 => _249.trim, 'call', _250 => _250()]) || "undefined";
|
|
6522
6693
|
const handler = resolveHandler(handlerContent, ctx, modifiers);
|
|
6523
6694
|
const originalVueEventName = modifiers.length ? `${arg.content}.${modifiers.join(".")}` : "";
|
|
6524
6695
|
const eventIR = createPropsIR(directive.rawName, eventName, handler);
|
|
@@ -6569,10 +6740,10 @@ function resolveHandler(handlerContent, ctx, modifiers) {
|
|
|
6569
6740
|
return handler;
|
|
6570
6741
|
}
|
|
6571
6742
|
function isConsoleCall(expr) {
|
|
6572
|
-
return
|
|
6743
|
+
return t55.isCallExpression(expr) && t55.isMemberExpression(expr.callee) && t55.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
|
|
6573
6744
|
}
|
|
6574
6745
|
function isFnReference(expr) {
|
|
6575
|
-
return
|
|
6746
|
+
return t55.isIdentifier(expr) || t55.isMemberExpression(expr) || t55.isFunction(expr);
|
|
6576
6747
|
}
|
|
6577
6748
|
|
|
6578
6749
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
|
|
@@ -6605,7 +6776,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6605
6776
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
6606
6777
|
const content = !isScoped ? [] : void 0;
|
|
6607
6778
|
const callback = isScoped ? {
|
|
6608
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6779
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _251 => _251.content, 'optionalAccess', _252 => _252.trim, 'call', _253 => _253()]), () => ( "")),
|
|
6609
6780
|
exp: []
|
|
6610
6781
|
} : void 0;
|
|
6611
6782
|
checkPropIsDynamicKey(ctx, directive);
|
|
@@ -6613,7 +6784,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6613
6784
|
type: 2 /* SLOT */,
|
|
6614
6785
|
name,
|
|
6615
6786
|
rawName: _nullishCoalesce(directive.rawName, () => ( "default")),
|
|
6616
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6787
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _254 => _254.isStatic]), () => ( true)),
|
|
6617
6788
|
isScoped,
|
|
6618
6789
|
content,
|
|
6619
6790
|
callback
|
|
@@ -6676,7 +6847,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
6676
6847
|
if (routerAdapter) {
|
|
6677
6848
|
if (!ctx.route) ctx.route = true;
|
|
6678
6849
|
nodeIR.isRoute = true;
|
|
6679
|
-
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess',
|
|
6850
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _255 => _255.package]), routerAdapter.target);
|
|
6680
6851
|
}
|
|
6681
6852
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
6682
6853
|
return nodeIR;
|
|
@@ -6820,7 +6991,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6820
6991
|
for (const prop of node.props) {
|
|
6821
6992
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
6822
6993
|
const attr = prop.name;
|
|
6823
|
-
const value = _optionalChain([prop, 'access',
|
|
6994
|
+
const value = _optionalChain([prop, 'access', _256 => _256.value, 'optionalAccess', _257 => _257.content, 'access', _258 => _258.trim, 'call', _259 => _259()]);
|
|
6824
6995
|
if (attr === "name" && value) {
|
|
6825
6996
|
result.name = camelCase(value);
|
|
6826
6997
|
} else {
|
|
@@ -6843,7 +7014,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6843
7014
|
});
|
|
6844
7015
|
}
|
|
6845
7016
|
const key = arg.content;
|
|
6846
|
-
const value = _optionalChain([exp, 'optionalAccess',
|
|
7017
|
+
const value = _optionalChain([exp, 'optionalAccess', _260 => _260.content, 'optionalAccess', _261 => _261.trim, 'call', _262 => _262()]) || "undefined";
|
|
6847
7018
|
if (key === "name") {
|
|
6848
7019
|
result.name = camelCase(value);
|
|
6849
7020
|
} else {
|
|
@@ -6913,19 +7084,19 @@ function resolveTemplate2(root, ctx) {
|
|
|
6913
7084
|
// src/core/transform/sfc/index.ts
|
|
6914
7085
|
function transform(ast, ctx, options) {
|
|
6915
7086
|
const { template, script, style } = ast;
|
|
6916
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
6917
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
7087
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _263 => _263.ast]), ctx);
|
|
7088
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _264 => _264.ast]), ctx);
|
|
6918
7089
|
const result = {
|
|
6919
7090
|
template: templateIR,
|
|
6920
7091
|
script: scriptIR,
|
|
6921
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
7092
|
+
style: _optionalChain([style, 'optionalAccess', _265 => _265.source, 'optionalAccess', _266 => _266.content])
|
|
6922
7093
|
};
|
|
6923
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
7094
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _267 => _267.plugins]), result, ctx);
|
|
6924
7095
|
return result;
|
|
6925
7096
|
}
|
|
6926
7097
|
|
|
6927
7098
|
// package.json
|
|
6928
|
-
var version = "1.
|
|
7099
|
+
var version = "1.10.0";
|
|
6929
7100
|
var bin = {
|
|
6930
7101
|
vureact: "bin/vureact.js"
|
|
6931
7102
|
};
|
|
@@ -7110,7 +7281,7 @@ var Helper = (_class5 = class {
|
|
|
7110
7281
|
__init8() {this.outDir = "react-app"}
|
|
7111
7282
|
constructor(opts) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);
|
|
7112
7283
|
this.compilerOpts = opts;
|
|
7113
|
-
if (_optionalChain([opts, 'access',
|
|
7284
|
+
if (_optionalChain([opts, 'access', _268 => _268.output, 'optionalAccess', _269 => _269.workspace])) {
|
|
7114
7285
|
this.workspaceDir = opts.output.workspace;
|
|
7115
7286
|
}
|
|
7116
7287
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -7140,7 +7311,7 @@ var Helper = (_class5 = class {
|
|
|
7140
7311
|
}
|
|
7141
7312
|
getOutDirName() {
|
|
7142
7313
|
const { output } = this.compilerOpts;
|
|
7143
|
-
return _optionalChain([output, 'optionalAccess',
|
|
7314
|
+
return _optionalChain([output, 'optionalAccess', _270 => _270.outDir]) || this.outDir;
|
|
7144
7315
|
}
|
|
7145
7316
|
getWorkspaceDir() {
|
|
7146
7317
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -7154,7 +7325,7 @@ var Helper = (_class5 = class {
|
|
|
7154
7325
|
}
|
|
7155
7326
|
getIgnoreAssets() {
|
|
7156
7327
|
const { output } = this.compilerOpts;
|
|
7157
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7328
|
+
if (_optionalChain([output, 'optionalAccess', _271 => _271.ignoreAssets])) {
|
|
7158
7329
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
7159
7330
|
}
|
|
7160
7331
|
return /* @__PURE__ */ new Set([
|
|
@@ -7244,12 +7415,12 @@ var Helper = (_class5 = class {
|
|
|
7244
7415
|
*/
|
|
7245
7416
|
async formatCode({ code, fileInfo }) {
|
|
7246
7417
|
const { format } = this.compilerOpts;
|
|
7247
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
7248
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
7418
|
+
if (!_optionalChain([format, 'optionalAccess', _272 => _272.enabled])) return code;
|
|
7419
|
+
if (_optionalChain([format, 'optionalAccess', _273 => _273.formatter]) === "builtin") {
|
|
7249
7420
|
return simpleFormat(code);
|
|
7250
7421
|
}
|
|
7251
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
7252
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
7422
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _274 => _274.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _275 => _275.script])));
|
|
7423
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _276 => _276.prettierOptions]));
|
|
7253
7424
|
}
|
|
7254
7425
|
/**
|
|
7255
7426
|
* 通用的缓存校验工具函数
|
|
@@ -7283,7 +7454,7 @@ var Helper = (_class5 = class {
|
|
|
7283
7454
|
* @param options.lock - 是否启用文件锁(默认false)
|
|
7284
7455
|
*/
|
|
7285
7456
|
async writeFileWithDir(filePath, content, options) {
|
|
7286
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
7457
|
+
if (_optionalChain([options, 'optionalAccess', _277 => _277.lock])) {
|
|
7287
7458
|
await fileLock.updateFile(filePath, async () => content, options);
|
|
7288
7459
|
} else {
|
|
7289
7460
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
@@ -7328,7 +7499,7 @@ var Helper = (_class5 = class {
|
|
|
7328
7499
|
* 获取需要排除编译的文件
|
|
7329
7500
|
*/
|
|
7330
7501
|
getExcludes() {
|
|
7331
|
-
if (!_optionalChain([this, 'access',
|
|
7502
|
+
if (!_optionalChain([this, 'access', _278 => _278.compilerOpts, 'access', _279 => _279.exclude, 'optionalAccess', _280 => _280.length])) {
|
|
7332
7503
|
return PathFilter.withDefaults();
|
|
7333
7504
|
}
|
|
7334
7505
|
return this.compilerOpts.exclude;
|
|
@@ -7419,7 +7590,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
7419
7590
|
ast: void 0
|
|
7420
7591
|
}
|
|
7421
7592
|
};
|
|
7422
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
7593
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _281 => _281.plugins]), result, ctx);
|
|
7423
7594
|
return result;
|
|
7424
7595
|
}
|
|
7425
7596
|
|
|
@@ -7554,16 +7725,16 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7554
7725
|
});
|
|
7555
7726
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
7556
7727
|
const resolveSFCAndScriptFile = () => {
|
|
7557
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7558
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7728
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _282 => _282.parser]) });
|
|
7729
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _283 => _283.transformer]) });
|
|
7559
7730
|
const gen = generate(ir, ctx.data, {
|
|
7560
7731
|
...genOptions,
|
|
7561
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7732
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _284 => _284.codegen])
|
|
7562
7733
|
});
|
|
7563
7734
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
7564
7735
|
};
|
|
7565
7736
|
const resolveStyleFile = () => {
|
|
7566
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7737
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _285 => _285.parser]) });
|
|
7567
7738
|
return this.resolveStyleResult(result, ctx.data);
|
|
7568
7739
|
};
|
|
7569
7740
|
try {
|
|
@@ -7602,9 +7773,9 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7602
7773
|
lang
|
|
7603
7774
|
},
|
|
7604
7775
|
css: {
|
|
7605
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
7606
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
7607
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
7776
|
+
file: _optionalChain([styleData, 'optionalAccess', _286 => _286.filePath]),
|
|
7777
|
+
hash: _optionalChain([styleData, 'optionalAccess', _287 => _287.scopeId]),
|
|
7778
|
+
code: _optionalChain([ir, 'optionalAccess', _288 => _288.style])
|
|
7608
7779
|
}
|
|
7609
7780
|
},
|
|
7610
7781
|
...base
|
|
@@ -7754,12 +7925,12 @@ var CacheManager = (_class9 = class {
|
|
|
7754
7925
|
const meta = { ...unit };
|
|
7755
7926
|
delete meta.source;
|
|
7756
7927
|
if (key === "sfc" /* SFC */) {
|
|
7757
|
-
_optionalChainDelete([meta, 'access',
|
|
7758
|
-
_optionalChainDelete([meta, 'access',
|
|
7928
|
+
_optionalChainDelete([meta, 'access', _289 => _289.output, 'optionalAccess', _290 => _290.jsx, 'access', _291 => delete _291.code]);
|
|
7929
|
+
_optionalChainDelete([meta, 'access', _292 => _292.output, 'optionalAccess', _293 => _293.css, 'access', _294 => delete _294.code]);
|
|
7759
7930
|
} else if (key === "script" /* SCRIPT */) {
|
|
7760
|
-
_optionalChainDelete([meta, 'access',
|
|
7931
|
+
_optionalChainDelete([meta, 'access', _295 => _295.output, 'optionalAccess', _296 => _296.script, 'access', _297 => delete _297.code]);
|
|
7761
7932
|
} else if (key === "style" /* STYLE */) {
|
|
7762
|
-
_optionalChainDelete([meta, 'access',
|
|
7933
|
+
_optionalChainDelete([meta, 'access', _298 => _298.output, 'optionalAccess', _299 => _299.style, 'access', _300 => delete _300.code]);
|
|
7763
7934
|
}
|
|
7764
7935
|
if (!this.pendingUpdates.has(key)) {
|
|
7765
7936
|
this.pendingUpdates.set(key, []);
|
|
@@ -7779,7 +7950,7 @@ var CacheManager = (_class9 = class {
|
|
|
7779
7950
|
}
|
|
7780
7951
|
for (const key of keys) {
|
|
7781
7952
|
const updates = this.pendingUpdates.get(key);
|
|
7782
|
-
if (!_optionalChain([updates, 'optionalAccess',
|
|
7953
|
+
if (!_optionalChain([updates, 'optionalAccess', _301 => _301.length])) continue;
|
|
7783
7954
|
const entries = [...this.cachedData[key] || []];
|
|
7784
7955
|
updates.forEach(({ unit, meta }) => {
|
|
7785
7956
|
const idx = entries.findIndex((c) => c.file === unit.file);
|
|
@@ -7940,7 +8111,7 @@ var CleanupManager = class {
|
|
|
7940
8111
|
const sfcMeta = meta;
|
|
7941
8112
|
const { jsx, css } = sfcMeta.output;
|
|
7942
8113
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
7943
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
8114
|
+
if (_optionalChain([css, 'optionalAccess', _302 => _302.file])) {
|
|
7944
8115
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
7945
8116
|
}
|
|
7946
8117
|
break;
|
|
@@ -7996,7 +8167,7 @@ var CompilationUnitProcessor = class {
|
|
|
7996
8167
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
7997
8168
|
const isStyleFile = key === "style" /* STYLE */;
|
|
7998
8169
|
if (isSFC || isScriptFile) {
|
|
7999
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
8170
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _303 => _303.hasRoute]);
|
|
8000
8171
|
}
|
|
8001
8172
|
const resolveFileInfo = () => {
|
|
8002
8173
|
if (isSFC) {
|
|
@@ -8016,7 +8187,7 @@ var CompilationUnitProcessor = class {
|
|
|
8016
8187
|
const { script } = result.fileInfo;
|
|
8017
8188
|
unit.output = {
|
|
8018
8189
|
script: {
|
|
8019
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
8190
|
+
file: _optionalChain([script, 'optionalAccess', _304 => _304.file]),
|
|
8020
8191
|
code
|
|
8021
8192
|
}
|
|
8022
8193
|
};
|
|
@@ -8093,7 +8264,7 @@ var FileProcessor = (_class10 = class {
|
|
|
8093
8264
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
8094
8265
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
8095
8266
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.cacheManager.loadCache(key);
|
|
8096
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
8267
|
+
const record = _optionalChain([cache, 'optionalAccess', _305 => _305.target, 'access', _306 => _306.find, 'call', _307 => _307((c) => c.file === absPath)]);
|
|
8097
8268
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
8098
8269
|
fileMeta,
|
|
8099
8270
|
record,
|
|
@@ -8115,10 +8286,10 @@ var FileProcessor = (_class10 = class {
|
|
|
8115
8286
|
hash: hash || this.fileCompiler.genHash(source)
|
|
8116
8287
|
};
|
|
8117
8288
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
8118
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
8289
|
+
if (_optionalChain([processed, 'optionalAccess', _308 => _308.output])) {
|
|
8119
8290
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
8120
8291
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
8121
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
8292
|
+
if (_optionalChain([processed, 'optionalAccess', _309 => _309.hasRoute])) {
|
|
8122
8293
|
await this.addRouterToPackageJson();
|
|
8123
8294
|
await this.updateEntryWithRouterProvider();
|
|
8124
8295
|
}
|
|
@@ -8135,13 +8306,13 @@ var FileProcessor = (_class10 = class {
|
|
|
8135
8306
|
*/
|
|
8136
8307
|
async addRouterToPackageJson() {
|
|
8137
8308
|
const { output } = this.fileCompiler.options;
|
|
8138
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
8309
|
+
if (_optionalChain([output, 'optionalAccess', _310 => _310.bootstrapVite]) === false) {
|
|
8139
8310
|
return;
|
|
8140
8311
|
}
|
|
8141
8312
|
const { router } = RUNTIME_PACKAGES;
|
|
8142
8313
|
const filePath = this.fileCompiler.getOutputPkgPath();
|
|
8143
8314
|
const packageJson = await this.fileCompiler.resolvePackageFile(filePath);
|
|
8144
|
-
if (_optionalChain([packageJson, 'optionalAccess',
|
|
8315
|
+
if (_optionalChain([packageJson, 'optionalAccess', _311 => _311.dependencies, 'optionalAccess', _312 => _312[router.name]])) {
|
|
8145
8316
|
return;
|
|
8146
8317
|
}
|
|
8147
8318
|
if (!packageJson.dependencies) {
|
|
@@ -8160,7 +8331,7 @@ var FileProcessor = (_class10 = class {
|
|
|
8160
8331
|
const { exclude, output, router } = this.fileCompiler.options;
|
|
8161
8332
|
const inputPath = this.fileCompiler.getInputPath();
|
|
8162
8333
|
const outputPath = this.fileCompiler.getOuputPath(true);
|
|
8163
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
8334
|
+
if (_optionalChain([output, 'optionalAccess', _313 => _313.bootstrapVite]) === false || _optionalChain([router, 'optionalAccess', _314 => _314.autoUpdateEntry]) === false || !_optionalChain([router, 'optionalAccess', _315 => _315.configFile])) {
|
|
8164
8335
|
return;
|
|
8165
8336
|
}
|
|
8166
8337
|
const getMainFile = async (filename) => {
|
|
@@ -8181,7 +8352,7 @@ var FileProcessor = (_class10 = class {
|
|
|
8181
8352
|
const prepareRouterEntry = () => {
|
|
8182
8353
|
const importPath = this.fileCompiler.resolveRelativePath(inputPath, router.configFile);
|
|
8183
8354
|
let content = fileData.content;
|
|
8184
|
-
if (_optionalChain([exclude, 'optionalAccess',
|
|
8355
|
+
if (_optionalChain([exclude, 'optionalAccess', _316 => _316.includes, 'call', _317 => _317(router.configFile)]) || _optionalChain([exclude, 'optionalAccess', _318 => _318.includes, 'call', _319 => _319(importPath)])) {
|
|
8185
8356
|
return content;
|
|
8186
8357
|
}
|
|
8187
8358
|
const routerModule = "RouterInstance";
|
|
@@ -8288,7 +8459,7 @@ ${routerImport}`);
|
|
|
8288
8459
|
const resolvedPath = normalizePath(fileCompiler.relativePath(input));
|
|
8289
8460
|
const baseName = _path2.default.basename(input).toLowerCase();
|
|
8290
8461
|
const exclusions = fileCompiler.getIgnoreAssets();
|
|
8291
|
-
if (!_optionalChain([fileCompiler, 'access',
|
|
8462
|
+
if (!_optionalChain([fileCompiler, 'access', _320 => _320.options, 'access', _321 => _321.output, 'optionalAccess', _322 => _322.ignoreAssets])) {
|
|
8292
8463
|
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
8293
8464
|
if (pattern.endsWith(".")) {
|
|
8294
8465
|
return baseName.startsWith(pattern);
|
|
@@ -8424,7 +8595,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8424
8595
|
const { output } = this.options;
|
|
8425
8596
|
const workspaceDir = this.fileCompiler.getWorkspaceDir();
|
|
8426
8597
|
await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
|
|
8427
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
8598
|
+
if (_optionalChain([output, 'optionalAccess', _323 => _323.bootstrapVite]) === false) {
|
|
8428
8599
|
return false;
|
|
8429
8600
|
}
|
|
8430
8601
|
if (this.isSingleFile()) {
|
|
@@ -8464,7 +8635,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8464
8635
|
const newDevDeps = resolveDeps(sourcePkg.devDependencies, newPkg.devDependencies, true);
|
|
8465
8636
|
newPkg.dependencies = newDeps;
|
|
8466
8637
|
newPkg.devDependencies = newDevDeps;
|
|
8467
|
-
newPkg = _optionalChain([output, 'optionalAccess',
|
|
8638
|
+
newPkg = _optionalChain([output, 'optionalAccess', _324 => _324.packageJson, 'optionalCall', _325 => _325(newPkg)]) || newPkg;
|
|
8468
8639
|
await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
|
|
8469
8640
|
this.spinner.succeed("Vite React environment initialized");
|
|
8470
8641
|
return true;
|
|
@@ -8475,12 +8646,12 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8475
8646
|
async resolveViteCreateApp() {
|
|
8476
8647
|
const { output } = this.options;
|
|
8477
8648
|
const { viteVersion, template: tmpl } = this.defaultConfig;
|
|
8478
|
-
const bootstrapVite = _optionalChain([output, 'optionalAccess',
|
|
8649
|
+
const bootstrapVite = _optionalChain([output, 'optionalAccess', _326 => _326.bootstrapVite]);
|
|
8479
8650
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
8480
8651
|
const configObject = typeof bootstrapVite === "object" ? bootstrapVite : null;
|
|
8481
|
-
const viteVer = _optionalChain([configObject, 'optionalAccess',
|
|
8482
|
-
const reactVer = _optionalChain([configObject, 'optionalAccess',
|
|
8483
|
-
const template = _optionalChain([configObject, 'optionalAccess',
|
|
8652
|
+
const viteVer = _optionalChain([configObject, 'optionalAccess', _327 => _327.vite]) || viteVersion;
|
|
8653
|
+
const reactVer = _optionalChain([configObject, 'optionalAccess', _328 => _328.react]);
|
|
8654
|
+
const template = _optionalChain([configObject, 'optionalAccess', _329 => _329.template]) || tmpl;
|
|
8484
8655
|
const cmd = `npm create vite${viteVer} ${outDirName} -- --template ${template}`;
|
|
8485
8656
|
_child_process.execSync.call(void 0, cmd, {
|
|
8486
8657
|
cwd: this.fileCompiler.getWorkspaceDir(),
|
|
@@ -8608,15 +8779,17 @@ var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
|
8608
8779
|
startTime = performance.now();
|
|
8609
8780
|
this.updateSpinner("Scanning files...");
|
|
8610
8781
|
const scanFiles = fileProcessor.scanFiles();
|
|
8611
|
-
this.updateSpinner("Compiling
|
|
8782
|
+
this.updateSpinner("Compiling components...");
|
|
8612
8783
|
const sfcCount = await pipelineManager.runSFC(scanFiles.vue, cacheMap);
|
|
8784
|
+
this.updateSpinner("Compiling scripts...");
|
|
8613
8785
|
const scriptCount = await pipelineManager.runScript(scanFiles.script, cacheMap);
|
|
8786
|
+
this.updateSpinner("Compiling styles...");
|
|
8614
8787
|
const styleCount = await pipelineManager.runStyle(scanFiles.style, cacheMap);
|
|
8615
8788
|
this.updateSpinner("Copying assets...");
|
|
8616
8789
|
const assetCount = await assetManager.runAsset(scanFiles.assets, cacheMap);
|
|
8617
8790
|
this.updateSpinner("Almost done...");
|
|
8618
8791
|
await cacheManager.flushAllCache();
|
|
8619
|
-
await _optionalChain([this, 'access',
|
|
8792
|
+
await _optionalChain([this, 'access', _330 => _330.options, 'access', _331 => _331.onSuccess, 'optionalCall', _332 => _332()]);
|
|
8620
8793
|
const endTime = calcElapsedTime(startTime);
|
|
8621
8794
|
this.printCoreLogs();
|
|
8622
8795
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|
|
@@ -8668,7 +8841,7 @@ var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
|
8668
8841
|
return await this.manager.cleanupManager.removeOutputPath(targetPath, type);
|
|
8669
8842
|
}
|
|
8670
8843
|
showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount) {
|
|
8671
|
-
this.spinner.succeed(`
|
|
8844
|
+
this.spinner.succeed(`Vue compiled to React in ${endTime}`);
|
|
8672
8845
|
if (sfcCount || scriptCount || styleCount || assetCount) {
|
|
8673
8846
|
const stats = [];
|
|
8674
8847
|
if (sfcCount) stats.push(`${sfcCount} ${_kleur2.default.dim("SFC(s)")}`);
|