@vureact/compiler-core 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -61
- package/README.zh-CN.md +193 -0
- package/lib/{chunk-R34TQK4X.js → chunk-EH3325ZP.js} +460 -397
- package/lib/{chunk-QPW3RUZH.esm.js → chunk-S6IFUYGO.esm.js} +411 -348
- package/lib/cli.esm.js +2 -2
- package/lib/cli.js +10 -10
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +3 -3
- package/README.en.md +0 -192
|
@@ -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.8.
|
|
2
|
+
* @vureact/compiler-core v1.8.4
|
|
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 t26 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t44 = _interopRequireWildcard(_types); var t43 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types); var t41 = _interopRequireWildcard(_types); var t42 = _interopRequireWildcard(_types); var t45 = _interopRequireWildcard(_types); var t46 = _interopRequireWildcard(_types); var t47 = _interopRequireWildcard(_types); var t48 = _interopRequireWildcard(_types); var t49 = _interopRequireWildcard(_types); var t51 = _interopRequireWildcard(_types); var t50 = _interopRequireWildcard(_types); var t52 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -39,7 +39,7 @@ var RUNTIME_PACKAGES = {
|
|
|
39
39
|
},
|
|
40
40
|
runtime: {
|
|
41
41
|
name: PACKAGE_NAME.runtime,
|
|
42
|
-
version: "^1.1.
|
|
42
|
+
version: "^1.1.1"
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
var STYLE_MODULE_NAME = "$style";
|
|
@@ -311,7 +311,8 @@ var ADAPTER_RULES = {
|
|
|
311
311
|
type: "rename"
|
|
312
312
|
},
|
|
313
313
|
dirOn: {
|
|
314
|
-
|
|
314
|
+
// fix: https://github.com/vureact-js/core/issues/49
|
|
315
|
+
target: "dir.on",
|
|
315
316
|
package: PACKAGE_NAME.runtime,
|
|
316
317
|
type: "rename"
|
|
317
318
|
},
|
|
@@ -568,7 +569,8 @@ function buildJsxChildrenProcessor(nodeIR, ctx, state) {
|
|
|
568
569
|
}
|
|
569
570
|
function buildJsxChildren(children, ctx) {
|
|
570
571
|
const result = [];
|
|
571
|
-
|
|
572
|
+
const normalizedChildren = Array.isArray(children) ? children : [];
|
|
573
|
+
for (const childIR of normalizedChildren) {
|
|
572
574
|
const jsxNode = buildJsxNode(childIR, ctx);
|
|
573
575
|
if (!jsxNode) continue;
|
|
574
576
|
result.push(jsxNode);
|
|
@@ -3220,6 +3222,49 @@ function resolveSfcCssImport(ctx) {
|
|
|
3220
3222
|
scriptIR.imports.push(importDecl);
|
|
3221
3223
|
}
|
|
3222
3224
|
|
|
3225
|
+
// src/core/transform/sfc/script/syntax-processor/postprocess/resolve-vue-type-as-any.ts
|
|
3226
|
+
|
|
3227
|
+
function resolveVueTypeAsAny(ctx) {
|
|
3228
|
+
return {
|
|
3229
|
+
TSTypeReference(path8) {
|
|
3230
|
+
if (isVueTypeRef(path8)) {
|
|
3231
|
+
replaceNode(path8, t25.tsAnyKeyword(), path8.node);
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
function isVueTypeRef(path8) {
|
|
3237
|
+
const id = resolveTypeNameId(path8.node.typeName);
|
|
3238
|
+
return id !== null && isVueImport(id, path8);
|
|
3239
|
+
}
|
|
3240
|
+
function resolveTypeNameId(typeName) {
|
|
3241
|
+
if (t25.isIdentifier(typeName)) {
|
|
3242
|
+
return typeName;
|
|
3243
|
+
}
|
|
3244
|
+
if (t25.isTSQualifiedName(typeName)) {
|
|
3245
|
+
let node = typeName;
|
|
3246
|
+
while (t25.isTSQualifiedName(node)) {
|
|
3247
|
+
node = node.left;
|
|
3248
|
+
}
|
|
3249
|
+
return t25.isIdentifier(node) ? node : null;
|
|
3250
|
+
}
|
|
3251
|
+
return null;
|
|
3252
|
+
}
|
|
3253
|
+
function isVueImport(id, path8) {
|
|
3254
|
+
const binding = path8.scope.getBinding(id.name);
|
|
3255
|
+
if (!binding) return false;
|
|
3256
|
+
const bp = binding.path;
|
|
3257
|
+
if (!bp.isImportSpecifier() && !bp.isImportDefaultSpecifier()) {
|
|
3258
|
+
return false;
|
|
3259
|
+
}
|
|
3260
|
+
const importDecl = bp.parentPath;
|
|
3261
|
+
if (!importDecl.isImportDeclaration()) {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3264
|
+
const moduleName = importDecl.node.source.value;
|
|
3265
|
+
return VUE_PACKAGES.some((pkg) => moduleName.includes(pkg));
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3223
3268
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-async-component.ts
|
|
3224
3269
|
|
|
3225
3270
|
function resolveDefineAsyncComponent(ctx) {
|
|
@@ -3230,11 +3275,11 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3230
3275
|
return;
|
|
3231
3276
|
}
|
|
3232
3277
|
const [arg] = node.arguments;
|
|
3233
|
-
if (!
|
|
3278
|
+
if (!t26.isObjectExpression(arg)) {
|
|
3234
3279
|
return;
|
|
3235
3280
|
}
|
|
3236
3281
|
for (const prop of arg.properties) {
|
|
3237
|
-
if (!
|
|
3282
|
+
if (!t26.isObjectProperty(prop) || !t26.isIdentifier(prop.key) || prop.key.name !== "hydrate") {
|
|
3238
3283
|
continue;
|
|
3239
3284
|
}
|
|
3240
3285
|
logger.warn('Unsupported option "hydrate"', {
|
|
@@ -3254,19 +3299,19 @@ function resolveDefineAsyncComponent(ctx) {
|
|
|
3254
3299
|
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
3255
3300
|
|
|
3256
3301
|
function createUseCallback(body, deps) {
|
|
3257
|
-
return
|
|
3302
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useCallback), [
|
|
3258
3303
|
body,
|
|
3259
|
-
_nullishCoalesce(deps, () => (
|
|
3304
|
+
_nullishCoalesce(deps, () => ( t27.arrayExpression([])))
|
|
3260
3305
|
]);
|
|
3261
3306
|
}
|
|
3262
3307
|
function createUseMemo(body, deps) {
|
|
3263
|
-
return
|
|
3264
|
-
|
|
3265
|
-
_nullishCoalesce(deps, () => (
|
|
3308
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useMemo), [
|
|
3309
|
+
t27.arrowFunctionExpression([], body),
|
|
3310
|
+
_nullishCoalesce(deps, () => ( t27.arrayExpression([])))
|
|
3266
3311
|
]);
|
|
3267
3312
|
}
|
|
3268
3313
|
function createUseImperativeHandle(refId, init) {
|
|
3269
|
-
return
|
|
3314
|
+
return t27.callExpression(t27.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
3270
3315
|
}
|
|
3271
3316
|
|
|
3272
3317
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
@@ -3287,16 +3332,16 @@ function resolveDefineExpose(ctx) {
|
|
|
3287
3332
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
3288
3333
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
3289
3334
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3290
|
-
if (!
|
|
3335
|
+
if (!t28.isObjectExpression(expose) && !t28.isFunction(expose)) {
|
|
3291
3336
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
3292
3337
|
file: filename,
|
|
3293
3338
|
loc: expose.loc,
|
|
3294
3339
|
source: scriptData.source
|
|
3295
3340
|
});
|
|
3296
3341
|
}
|
|
3297
|
-
const init = !
|
|
3342
|
+
const init = !t28.isFunction(expose) ? t28.arrowFunctionExpression([], expose) : expose;
|
|
3298
3343
|
const { forwardRef } = scriptData;
|
|
3299
|
-
const newNode = createUseImperativeHandle(
|
|
3344
|
+
const newNode = createUseImperativeHandle(t28.identifier(forwardRef.refField), init);
|
|
3300
3345
|
forwardRef.enabled = true;
|
|
3301
3346
|
replaceNode(path8, newNode, node);
|
|
3302
3347
|
}
|
|
@@ -3331,7 +3376,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3331
3376
|
CallExpression(path8) {
|
|
3332
3377
|
const { node } = path8;
|
|
3333
3378
|
const { filename, templateData, scriptData } = ctx;
|
|
3334
|
-
if (!
|
|
3379
|
+
if (!t29.isIdentifier(node.callee)) return;
|
|
3335
3380
|
const { name } = node.callee;
|
|
3336
3381
|
const checkIfFromDefineEmits = () => {
|
|
3337
3382
|
let result = false;
|
|
@@ -3343,7 +3388,7 @@ function resolveEmitCalls(ctx) {
|
|
|
3343
3388
|
const binding = path8.scope.getBinding(name);
|
|
3344
3389
|
if (binding) {
|
|
3345
3390
|
const parent = binding.path.node;
|
|
3346
|
-
if (
|
|
3391
|
+
if (t29.isVariableDeclarator(parent) && t29.isCallExpression(parent.init) && t29.isIdentifier(parent.init.callee)) {
|
|
3347
3392
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
3348
3393
|
}
|
|
3349
3394
|
}
|
|
@@ -3353,9 +3398,9 @@ function resolveEmitCalls(ctx) {
|
|
|
3353
3398
|
if (!checkIfFromDefineEmits()) return;
|
|
3354
3399
|
const [callee, ...args] = node.arguments;
|
|
3355
3400
|
let propCall;
|
|
3356
|
-
if (
|
|
3401
|
+
if (t29.isStringLiteral(callee)) {
|
|
3357
3402
|
const eventName = formatEmitEventName(callee.value);
|
|
3358
|
-
propCall = createPropCall(ctx.propField,
|
|
3403
|
+
propCall = createPropCall(ctx.propField, t29.identifier(eventName), args);
|
|
3359
3404
|
} else {
|
|
3360
3405
|
propCall = createPropCall(ctx.propField, callee, args, true);
|
|
3361
3406
|
logger.error(
|
|
@@ -3372,8 +3417,8 @@ function resolveEmitCalls(ctx) {
|
|
|
3372
3417
|
};
|
|
3373
3418
|
}
|
|
3374
3419
|
function createPropCall(rootName, callee, args, computed = false) {
|
|
3375
|
-
return
|
|
3376
|
-
|
|
3420
|
+
return t29.optionalCallExpression(
|
|
3421
|
+
t29.memberExpression(t29.identifier(rootName), callee, computed),
|
|
3377
3422
|
args,
|
|
3378
3423
|
true
|
|
3379
3424
|
);
|
|
@@ -3389,21 +3434,21 @@ function createPropCall(rootName, callee, args, computed = false) {
|
|
|
3389
3434
|
|
|
3390
3435
|
function cloneCallableParams(params) {
|
|
3391
3436
|
const cloneCallableParam = (param, index) => {
|
|
3392
|
-
if (
|
|
3437
|
+
if (t30.isRestElement(param)) {
|
|
3393
3438
|
const arg = param.argument;
|
|
3394
|
-
const name =
|
|
3395
|
-
const rest =
|
|
3396
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
3439
|
+
const name = t30.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
3440
|
+
const rest = t30.restElement(t30.identifier(name));
|
|
3441
|
+
rest.typeAnnotation = param.typeAnnotation || (t30.isIdentifier(arg) ? arg.typeAnnotation : null) || t30.tsTypeAnnotation(t30.tsArrayType(t30.tsAnyKeyword()));
|
|
3397
3442
|
return rest;
|
|
3398
3443
|
}
|
|
3399
|
-
if (
|
|
3400
|
-
const id =
|
|
3444
|
+
if (t30.isIdentifier(param)) {
|
|
3445
|
+
const id = t30.identifier(param.name || `arg${index}`);
|
|
3401
3446
|
id.optional = param.optional;
|
|
3402
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
3447
|
+
id.typeAnnotation = param.typeAnnotation || t30.tsTypeAnnotation(t30.tsAnyKeyword());
|
|
3403
3448
|
return id;
|
|
3404
3449
|
}
|
|
3405
|
-
const fallback =
|
|
3406
|
-
fallback.typeAnnotation =
|
|
3450
|
+
const fallback = t30.identifier(`arg${index}`);
|
|
3451
|
+
fallback.typeAnnotation = t30.tsTypeAnnotation(t30.tsAnyKeyword());
|
|
3407
3452
|
return fallback;
|
|
3408
3453
|
};
|
|
3409
3454
|
return params.map(cloneCallableParam);
|
|
@@ -3413,18 +3458,18 @@ function cloneCallableParams(params) {
|
|
|
3413
3458
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
3414
3459
|
return {
|
|
3415
3460
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3416
|
-
if (!
|
|
3461
|
+
if (!t31.isProgram(path8.parent)) return;
|
|
3417
3462
|
const { node } = path8;
|
|
3418
|
-
if (
|
|
3419
|
-
const typeLiteral =
|
|
3463
|
+
if (t31.isTSInterfaceDeclaration(node)) {
|
|
3464
|
+
const typeLiteral = t31.tsTypeLiteral(node.body.body);
|
|
3420
3465
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
3421
3466
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
3422
|
-
if (resolved &&
|
|
3467
|
+
if (resolved && t31.isTSTypeLiteral(resolved)) {
|
|
3423
3468
|
node.body.body = resolved.members;
|
|
3424
3469
|
}
|
|
3425
3470
|
return;
|
|
3426
3471
|
}
|
|
3427
|
-
if (
|
|
3472
|
+
if (t31.isTSTypeAliasDeclaration(node)) {
|
|
3428
3473
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
3429
3474
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
3430
3475
|
if (resolved) {
|
|
@@ -3435,47 +3480,47 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
3435
3480
|
};
|
|
3436
3481
|
}
|
|
3437
3482
|
function resolveTopLevelEmitType(tsType) {
|
|
3438
|
-
if (
|
|
3483
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3439
3484
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
3440
3485
|
}
|
|
3441
|
-
if (
|
|
3486
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3442
3487
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3443
3488
|
return tsType;
|
|
3444
3489
|
}
|
|
3445
3490
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
3446
|
-
return
|
|
3491
|
+
return t31.tsTypeReference(
|
|
3447
3492
|
tsType.typeName,
|
|
3448
|
-
|
|
3493
|
+
t31.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3449
3494
|
);
|
|
3450
3495
|
}
|
|
3451
|
-
if (
|
|
3496
|
+
if (t31.isTSIntersectionType(tsType)) {
|
|
3452
3497
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3453
3498
|
if (!types.length) return null;
|
|
3454
3499
|
if (types.length === 1) return types[0];
|
|
3455
|
-
return
|
|
3500
|
+
return t31.tsIntersectionType(types);
|
|
3456
3501
|
}
|
|
3457
|
-
if (
|
|
3502
|
+
if (t31.isTSUnionType(tsType)) {
|
|
3458
3503
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
3459
3504
|
if (!types.length) return null;
|
|
3460
3505
|
if (types.length === 1) return types[0];
|
|
3461
|
-
return
|
|
3506
|
+
return t31.tsUnionType(types);
|
|
3462
3507
|
}
|
|
3463
|
-
if (
|
|
3508
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3464
3509
|
const members = [];
|
|
3465
3510
|
for (const member of tsType.members) {
|
|
3466
|
-
if (
|
|
3511
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3467
3512
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3468
3513
|
continue;
|
|
3469
3514
|
}
|
|
3470
3515
|
members.push(member);
|
|
3471
3516
|
}
|
|
3472
3517
|
if (!members.length) return null;
|
|
3473
|
-
return
|
|
3518
|
+
return t31.tsTypeLiteral(members);
|
|
3474
3519
|
}
|
|
3475
|
-
if (
|
|
3520
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3476
3521
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3477
3522
|
if (!props.length) return null;
|
|
3478
|
-
return
|
|
3523
|
+
return t31.tsTypeLiteral(props);
|
|
3479
3524
|
}
|
|
3480
3525
|
return tsType;
|
|
3481
3526
|
}
|
|
@@ -3496,41 +3541,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
3496
3541
|
propsTSIface: { emitTypes }
|
|
3497
3542
|
} = ctx.scriptData;
|
|
3498
3543
|
const members = [];
|
|
3499
|
-
if (
|
|
3544
|
+
if (t31.isArrayExpression(runtimeArg)) {
|
|
3500
3545
|
for (const element of runtimeArg.elements) {
|
|
3501
|
-
if (!element || !
|
|
3546
|
+
if (!element || !t31.isStringLiteral(element)) continue;
|
|
3502
3547
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
3503
3548
|
const key = buildKey(handlerName);
|
|
3504
|
-
const fnType =
|
|
3549
|
+
const fnType = t31.tsFunctionType(
|
|
3505
3550
|
null,
|
|
3506
3551
|
[createRestAnyParam("args")],
|
|
3507
|
-
|
|
3552
|
+
t31.tsTypeAnnotation(t31.tsAnyKeyword())
|
|
3508
3553
|
);
|
|
3509
|
-
const prop =
|
|
3554
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3510
3555
|
prop.optional = true;
|
|
3511
3556
|
members.push(prop);
|
|
3512
3557
|
}
|
|
3513
3558
|
if (members.length) {
|
|
3514
|
-
emitTypes.push(
|
|
3559
|
+
emitTypes.push(t31.tsTypeLiteral(members));
|
|
3515
3560
|
}
|
|
3516
3561
|
return;
|
|
3517
3562
|
}
|
|
3518
|
-
if (
|
|
3563
|
+
if (t31.isObjectExpression(runtimeArg)) {
|
|
3519
3564
|
for (const prop of runtimeArg.properties) {
|
|
3520
|
-
if (!
|
|
3521
|
-
if (
|
|
3565
|
+
if (!t31.isObjectProperty(prop)) continue;
|
|
3566
|
+
if (t31.isSpreadElement(prop)) continue;
|
|
3522
3567
|
const rawName = resolvePropName(prop.key);
|
|
3523
3568
|
if (!rawName) continue;
|
|
3524
3569
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
3525
3570
|
const key = buildKey(handlerName);
|
|
3526
|
-
const params =
|
|
3527
|
-
const fnType =
|
|
3528
|
-
const propSig =
|
|
3571
|
+
const params = t31.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
3572
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(t31.tsAnyKeyword()));
|
|
3573
|
+
const propSig = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3529
3574
|
propSig.optional = true;
|
|
3530
3575
|
members.push(propSig);
|
|
3531
3576
|
}
|
|
3532
3577
|
if (members.length) {
|
|
3533
|
-
emitTypes.push(
|
|
3578
|
+
emitTypes.push(t31.tsTypeLiteral(members));
|
|
3534
3579
|
}
|
|
3535
3580
|
}
|
|
3536
3581
|
}
|
|
@@ -3551,129 +3596,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
3551
3596
|
return `on${name}`;
|
|
3552
3597
|
}
|
|
3553
3598
|
function resolvePropName(key) {
|
|
3554
|
-
if (
|
|
3555
|
-
if (
|
|
3556
|
-
if (
|
|
3599
|
+
if (t31.isIdentifier(key)) return key.name;
|
|
3600
|
+
if (t31.isStringLiteral(key)) return key.value;
|
|
3601
|
+
if (t31.isNumericLiteral(key)) return String(key.value);
|
|
3557
3602
|
return null;
|
|
3558
3603
|
}
|
|
3559
3604
|
function buildKey(name) {
|
|
3560
|
-
return
|
|
3605
|
+
return t31.isValidIdentifier(name) ? t31.identifier(name) : t31.stringLiteral(name);
|
|
3561
3606
|
}
|
|
3562
3607
|
function createRestAnyParam(name) {
|
|
3563
|
-
const id =
|
|
3564
|
-
const rest =
|
|
3565
|
-
rest.typeAnnotation =
|
|
3608
|
+
const id = t31.identifier(name);
|
|
3609
|
+
const rest = t31.restElement(id);
|
|
3610
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(t31.tsArrayType(t31.tsAnyKeyword()));
|
|
3566
3611
|
return rest;
|
|
3567
3612
|
}
|
|
3568
3613
|
function resolveRuntimeTupleParams(value) {
|
|
3569
3614
|
const params = [];
|
|
3570
3615
|
value.elements.forEach((element, index) => {
|
|
3571
3616
|
if (!element) return;
|
|
3572
|
-
if (
|
|
3617
|
+
if (t31.isSpreadElement(element)) {
|
|
3573
3618
|
params.push(createRestAnyParam(`args${index}`));
|
|
3574
3619
|
return;
|
|
3575
3620
|
}
|
|
3576
|
-
if (
|
|
3577
|
-
const id =
|
|
3578
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
3621
|
+
if (t31.isIdentifier(element)) {
|
|
3622
|
+
const id = t31.identifier(element.name);
|
|
3623
|
+
id.typeAnnotation = element.typeAnnotation || t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3579
3624
|
params.push(id);
|
|
3580
3625
|
return;
|
|
3581
3626
|
}
|
|
3582
|
-
if (
|
|
3583
|
-
const id =
|
|
3584
|
-
id.typeAnnotation =
|
|
3627
|
+
if (t31.isTSAsExpression(element)) {
|
|
3628
|
+
const id = t31.identifier(`arg${index}`);
|
|
3629
|
+
id.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3585
3630
|
params.push(id);
|
|
3586
3631
|
return;
|
|
3587
3632
|
}
|
|
3588
|
-
const fallback =
|
|
3589
|
-
fallback.typeAnnotation =
|
|
3633
|
+
const fallback = t31.identifier(`arg${index}`);
|
|
3634
|
+
fallback.typeAnnotation = t31.tsTypeAnnotation(t31.tsAnyKeyword());
|
|
3590
3635
|
params.push(fallback);
|
|
3591
3636
|
});
|
|
3592
3637
|
return params;
|
|
3593
3638
|
}
|
|
3594
3639
|
function resolveExplicitEmitType(tsType) {
|
|
3595
|
-
if (
|
|
3640
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3596
3641
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
3597
3642
|
}
|
|
3598
|
-
if (
|
|
3643
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3599
3644
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3600
3645
|
return tsType;
|
|
3601
3646
|
}
|
|
3602
3647
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
3603
|
-
return
|
|
3648
|
+
return t31.tsTypeReference(
|
|
3604
3649
|
tsType.typeName,
|
|
3605
|
-
|
|
3650
|
+
t31.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3606
3651
|
);
|
|
3607
3652
|
}
|
|
3608
|
-
if (
|
|
3653
|
+
if (t31.isTSIntersectionType(tsType)) {
|
|
3609
3654
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3610
3655
|
if (!types.length) return null;
|
|
3611
3656
|
if (types.length === 1) return types[0];
|
|
3612
|
-
return
|
|
3657
|
+
return t31.tsIntersectionType(types);
|
|
3613
3658
|
}
|
|
3614
|
-
if (
|
|
3659
|
+
if (t31.isTSUnionType(tsType)) {
|
|
3615
3660
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
3616
3661
|
if (!types.length) return null;
|
|
3617
3662
|
if (types.length === 1) return types[0];
|
|
3618
|
-
return
|
|
3663
|
+
return t31.tsUnionType(types);
|
|
3619
3664
|
}
|
|
3620
|
-
if (
|
|
3665
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3621
3666
|
const members = [];
|
|
3622
3667
|
for (const member of tsType.members) {
|
|
3623
|
-
if (
|
|
3668
|
+
if (t31.isTSPropertySignature(member)) {
|
|
3624
3669
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
3625
3670
|
if (prop) members.push(prop);
|
|
3626
3671
|
continue;
|
|
3627
3672
|
}
|
|
3628
|
-
if (
|
|
3673
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3629
3674
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
3630
3675
|
continue;
|
|
3631
3676
|
}
|
|
3632
3677
|
}
|
|
3633
3678
|
if (!members.length) return null;
|
|
3634
|
-
return
|
|
3679
|
+
return t31.tsTypeLiteral(members);
|
|
3635
3680
|
}
|
|
3636
|
-
if (
|
|
3681
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3637
3682
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
3638
3683
|
if (!props.length) return null;
|
|
3639
|
-
return
|
|
3684
|
+
return t31.tsTypeLiteral(props);
|
|
3640
3685
|
}
|
|
3641
3686
|
return tsType;
|
|
3642
3687
|
}
|
|
3643
3688
|
function hasEmitsSignatureInType(tsType) {
|
|
3644
|
-
if (
|
|
3689
|
+
if (t31.isTSParenthesizedType(tsType)) {
|
|
3645
3690
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
3646
3691
|
}
|
|
3647
|
-
if (
|
|
3692
|
+
if (t31.isTSTypeReference(tsType)) {
|
|
3648
3693
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3649
3694
|
return false;
|
|
3650
3695
|
}
|
|
3651
3696
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
3652
3697
|
}
|
|
3653
|
-
if (
|
|
3698
|
+
if (t31.isTSIntersectionType(tsType) || t31.isTSUnionType(tsType)) {
|
|
3654
3699
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
3655
3700
|
}
|
|
3656
|
-
if (
|
|
3701
|
+
if (t31.isTSTypeLiteral(tsType)) {
|
|
3657
3702
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
3658
3703
|
}
|
|
3659
|
-
if (
|
|
3704
|
+
if (t31.isTSFunctionType(tsType)) {
|
|
3660
3705
|
return isEmitsCallable(tsType.parameters);
|
|
3661
3706
|
}
|
|
3662
3707
|
return false;
|
|
3663
3708
|
}
|
|
3664
3709
|
function hasEmitsSignatureInMember(member) {
|
|
3665
|
-
if (
|
|
3710
|
+
if (t31.isTSCallSignatureDeclaration(member)) {
|
|
3666
3711
|
return isEmitsCallable(member.parameters);
|
|
3667
3712
|
}
|
|
3668
3713
|
return false;
|
|
3669
3714
|
}
|
|
3670
3715
|
function isEmitsCallable(parameters) {
|
|
3671
3716
|
const [eventParam] = parameters;
|
|
3672
|
-
if (!eventParam || !
|
|
3717
|
+
if (!eventParam || !t31.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3673
3718
|
return false;
|
|
3674
3719
|
}
|
|
3675
3720
|
const { typeAnnotation } = eventParam;
|
|
3676
|
-
if (
|
|
3721
|
+
if (t31.isNoop(typeAnnotation)) return false;
|
|
3677
3722
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
3678
3723
|
}
|
|
3679
3724
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -3683,19 +3728,19 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
3683
3728
|
const key = buildKey(handlerName);
|
|
3684
3729
|
const typeAnnotation = _optionalChain([member, 'access', _110 => _110.typeAnnotation, 'optionalAccess', _111 => _111.typeAnnotation]);
|
|
3685
3730
|
let params = [];
|
|
3686
|
-
let returnType =
|
|
3687
|
-
if (typeAnnotation &&
|
|
3731
|
+
let returnType = t31.tsAnyKeyword();
|
|
3732
|
+
if (typeAnnotation && t31.isTSFunctionType(typeAnnotation)) {
|
|
3688
3733
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
3689
3734
|
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _112 => _112.typeAnnotation, 'optionalAccess', _113 => _113.typeAnnotation]), () => ( returnType));
|
|
3690
|
-
} else if (typeAnnotation &&
|
|
3735
|
+
} else if (typeAnnotation && t31.isTSTupleType(typeAnnotation)) {
|
|
3691
3736
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
3692
3737
|
} else if (typeAnnotation) {
|
|
3693
|
-
const id =
|
|
3694
|
-
id.typeAnnotation =
|
|
3738
|
+
const id = t31.identifier("value");
|
|
3739
|
+
id.typeAnnotation = t31.tsTypeAnnotation(typeAnnotation);
|
|
3695
3740
|
params = [id];
|
|
3696
3741
|
}
|
|
3697
|
-
const fnType =
|
|
3698
|
-
const prop =
|
|
3742
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(returnType));
|
|
3743
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3699
3744
|
prop.optional = !!member.optional;
|
|
3700
3745
|
return prop;
|
|
3701
3746
|
}
|
|
@@ -3704,32 +3749,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
3704
3749
|
}
|
|
3705
3750
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
3706
3751
|
const [eventParam, ...restParams] = parameters;
|
|
3707
|
-
if (!eventParam || !
|
|
3752
|
+
if (!eventParam || !t31.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
3708
3753
|
return [];
|
|
3709
3754
|
}
|
|
3710
3755
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
3711
|
-
if (
|
|
3756
|
+
if (t31.isNoop(paramTypeAnnotation)) return [];
|
|
3712
3757
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
3713
3758
|
if (!eventNames.length) return [];
|
|
3714
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _114 => _114.typeAnnotation]), () => (
|
|
3759
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _114 => _114.typeAnnotation]), () => ( t31.tsAnyKeyword()));
|
|
3715
3760
|
return eventNames.map((eventName) => {
|
|
3716
3761
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
3717
3762
|
const key = buildKey(handlerName);
|
|
3718
3763
|
const params = cloneCallableParams(restParams);
|
|
3719
|
-
const fnType =
|
|
3720
|
-
const prop =
|
|
3764
|
+
const fnType = t31.tsFunctionType(null, params, t31.tsTypeAnnotation(returnType));
|
|
3765
|
+
const prop = t31.tsPropertySignature(key, t31.tsTypeAnnotation(fnType));
|
|
3721
3766
|
prop.optional = true;
|
|
3722
3767
|
return prop;
|
|
3723
3768
|
});
|
|
3724
3769
|
}
|
|
3725
3770
|
function resolveEventNames(type) {
|
|
3726
|
-
if (
|
|
3771
|
+
if (t31.isTSLiteralType(type) && t31.isStringLiteral(type.literal)) {
|
|
3727
3772
|
return [type.literal.value];
|
|
3728
3773
|
}
|
|
3729
|
-
if (
|
|
3774
|
+
if (t31.isTSUnionType(type)) {
|
|
3730
3775
|
return type.types.flatMap(resolveEventNames);
|
|
3731
3776
|
}
|
|
3732
|
-
if (
|
|
3777
|
+
if (t31.isTSParenthesizedType(type)) {
|
|
3733
3778
|
return resolveEventNames(type.typeAnnotation);
|
|
3734
3779
|
}
|
|
3735
3780
|
return [];
|
|
@@ -3742,39 +3787,39 @@ function resolveTupleTypeParams(tuple) {
|
|
|
3742
3787
|
return params;
|
|
3743
3788
|
}
|
|
3744
3789
|
function resolveTupleElementParam(element, index) {
|
|
3745
|
-
const isNamedTuple = typeof
|
|
3790
|
+
const isNamedTuple = typeof t31.isTSNamedTupleMember === "function" && t31.isTSNamedTupleMember(element);
|
|
3746
3791
|
if (isNamedTuple) {
|
|
3747
3792
|
const tupleMember = element;
|
|
3748
3793
|
const name = _optionalChain([tupleMember, 'access', _115 => _115.label, 'optionalAccess', _116 => _116.name]) || `arg${index}`;
|
|
3749
3794
|
let innerType = tupleMember.elementType;
|
|
3750
3795
|
let optional = tupleMember.optional;
|
|
3751
|
-
if (
|
|
3796
|
+
if (t31.isTSOptionalType(innerType)) {
|
|
3752
3797
|
optional = true;
|
|
3753
3798
|
innerType = innerType.typeAnnotation;
|
|
3754
3799
|
}
|
|
3755
|
-
if (
|
|
3756
|
-
const rest =
|
|
3757
|
-
rest.typeAnnotation =
|
|
3800
|
+
if (t31.isTSRestType(innerType)) {
|
|
3801
|
+
const rest = t31.restElement(t31.identifier(name));
|
|
3802
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(innerType.typeAnnotation);
|
|
3758
3803
|
return rest;
|
|
3759
3804
|
}
|
|
3760
|
-
const id2 =
|
|
3805
|
+
const id2 = t31.identifier(name);
|
|
3761
3806
|
id2.optional = optional;
|
|
3762
|
-
id2.typeAnnotation =
|
|
3807
|
+
id2.typeAnnotation = t31.tsTypeAnnotation(innerType);
|
|
3763
3808
|
return id2;
|
|
3764
3809
|
}
|
|
3765
|
-
if (
|
|
3766
|
-
const rest =
|
|
3767
|
-
rest.typeAnnotation =
|
|
3810
|
+
if (t31.isTSRestType(element)) {
|
|
3811
|
+
const rest = t31.restElement(t31.identifier(`args${index}`));
|
|
3812
|
+
rest.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3768
3813
|
return rest;
|
|
3769
3814
|
}
|
|
3770
|
-
if (
|
|
3771
|
-
const id2 =
|
|
3815
|
+
if (t31.isTSOptionalType(element)) {
|
|
3816
|
+
const id2 = t31.identifier(`arg${index}`);
|
|
3772
3817
|
id2.optional = true;
|
|
3773
|
-
id2.typeAnnotation =
|
|
3818
|
+
id2.typeAnnotation = t31.tsTypeAnnotation(element.typeAnnotation);
|
|
3774
3819
|
return id2;
|
|
3775
3820
|
}
|
|
3776
|
-
const id =
|
|
3777
|
-
id.typeAnnotation =
|
|
3821
|
+
const id = t31.identifier(`arg${index}`);
|
|
3822
|
+
id.typeAnnotation = t31.tsTypeAnnotation(element);
|
|
3778
3823
|
return id;
|
|
3779
3824
|
}
|
|
3780
3825
|
|
|
@@ -3799,38 +3844,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3799
3844
|
} = scriptData;
|
|
3800
3845
|
if (!runtimeArg) return;
|
|
3801
3846
|
const members = [];
|
|
3802
|
-
if (
|
|
3847
|
+
if (t32.isArrayExpression(runtimeArg)) {
|
|
3803
3848
|
for (const element of runtimeArg.elements) {
|
|
3804
|
-
if (!element || !
|
|
3805
|
-
const key =
|
|
3806
|
-
const prop =
|
|
3849
|
+
if (!element || !t32.isStringLiteral(element)) continue;
|
|
3850
|
+
const key = t32.isValidIdentifier(element.value) ? t32.identifier(element.value) : t32.stringLiteral(element.value);
|
|
3851
|
+
const prop = t32.tsPropertySignature(key, t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3807
3852
|
prop.optional = true;
|
|
3808
3853
|
members.push(prop);
|
|
3809
3854
|
}
|
|
3810
3855
|
if (members.length) {
|
|
3811
|
-
propsTypes.push(
|
|
3856
|
+
propsTypes.push(t32.tsTypeLiteral(members));
|
|
3812
3857
|
}
|
|
3813
3858
|
return;
|
|
3814
3859
|
}
|
|
3815
|
-
if (
|
|
3860
|
+
if (t32.isObjectExpression(runtimeArg)) {
|
|
3816
3861
|
for (const prop of runtimeArg.properties) {
|
|
3817
|
-
if (!
|
|
3818
|
-
if (
|
|
3862
|
+
if (!t32.isObjectProperty(prop)) continue;
|
|
3863
|
+
if (t32.isSpreadElement(prop)) continue;
|
|
3819
3864
|
const key = prop.key;
|
|
3820
3865
|
let propName = null;
|
|
3821
|
-
if (
|
|
3822
|
-
if (
|
|
3823
|
-
if (
|
|
3866
|
+
if (t32.isIdentifier(key)) propName = key.name;
|
|
3867
|
+
if (t32.isStringLiteral(key)) propName = key.value;
|
|
3868
|
+
if (t32.isNumericLiteral(key)) propName = String(key.value);
|
|
3824
3869
|
if (!propName) continue;
|
|
3825
3870
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
3826
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
3827
|
-
const tsKey =
|
|
3828
|
-
const tsProp =
|
|
3871
|
+
const tsType = _nullishCoalesce(type, () => ( t32.tsAnyKeyword()));
|
|
3872
|
+
const tsKey = t32.isValidIdentifier(propName) ? t32.identifier(propName) : t32.stringLiteral(propName);
|
|
3873
|
+
const tsProp = t32.tsPropertySignature(tsKey, t32.tsTypeAnnotation(tsType));
|
|
3829
3874
|
tsProp.optional = !required;
|
|
3830
3875
|
members.push(tsProp);
|
|
3831
3876
|
}
|
|
3832
3877
|
if (members.length) {
|
|
3833
|
-
propsTypes.push(
|
|
3878
|
+
propsTypes.push(t32.tsTypeLiteral(members));
|
|
3834
3879
|
}
|
|
3835
3880
|
return;
|
|
3836
3881
|
}
|
|
@@ -3844,42 +3889,42 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
3844
3889
|
);
|
|
3845
3890
|
}
|
|
3846
3891
|
function resolveRuntimePropMeta(value) {
|
|
3847
|
-
if (
|
|
3892
|
+
if (t32.isIdentifier(value)) {
|
|
3848
3893
|
return {
|
|
3849
3894
|
type: mapRuntimeTypeToTSType(value),
|
|
3850
3895
|
required: false
|
|
3851
3896
|
};
|
|
3852
3897
|
}
|
|
3853
|
-
if (
|
|
3898
|
+
if (t32.isArrayExpression(value)) {
|
|
3854
3899
|
return {
|
|
3855
3900
|
type: resolveRuntimeUnionType(value),
|
|
3856
3901
|
required: false
|
|
3857
3902
|
};
|
|
3858
3903
|
}
|
|
3859
|
-
if (!
|
|
3904
|
+
if (!t32.isObjectExpression(value)) {
|
|
3860
3905
|
return { required: false };
|
|
3861
3906
|
}
|
|
3862
3907
|
let type;
|
|
3863
3908
|
let required = false;
|
|
3864
3909
|
for (const prop of value.properties) {
|
|
3865
|
-
if (!
|
|
3866
|
-
if (
|
|
3910
|
+
if (!t32.isObjectProperty(prop)) continue;
|
|
3911
|
+
if (t32.isSpreadElement(prop)) continue;
|
|
3867
3912
|
const key = prop.key;
|
|
3868
|
-
const propName =
|
|
3913
|
+
const propName = t32.isIdentifier(key) ? key.name : t32.isStringLiteral(key) ? key.value : null;
|
|
3869
3914
|
if (!propName) continue;
|
|
3870
3915
|
if (propName === "type") {
|
|
3871
3916
|
const valueNode = prop.value;
|
|
3872
|
-
if (
|
|
3917
|
+
if (t32.isArrayExpression(valueNode)) {
|
|
3873
3918
|
type = resolveRuntimeUnionType(valueNode);
|
|
3874
3919
|
continue;
|
|
3875
3920
|
}
|
|
3876
|
-
if (
|
|
3921
|
+
if (t32.isIdentifier(valueNode)) {
|
|
3877
3922
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3878
3923
|
continue;
|
|
3879
3924
|
}
|
|
3880
3925
|
}
|
|
3881
3926
|
if (propName === "required") {
|
|
3882
|
-
if (
|
|
3927
|
+
if (t32.isBooleanLiteral(prop.value)) {
|
|
3883
3928
|
required = prop.value.value;
|
|
3884
3929
|
}
|
|
3885
3930
|
}
|
|
@@ -3889,34 +3934,34 @@ function resolveRuntimePropMeta(value) {
|
|
|
3889
3934
|
function resolveRuntimeUnionType(value) {
|
|
3890
3935
|
const types = [];
|
|
3891
3936
|
for (const element of value.elements) {
|
|
3892
|
-
if (!element || !
|
|
3937
|
+
if (!element || !t32.isIdentifier(element)) continue;
|
|
3893
3938
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3894
3939
|
if (resolved) types.push(resolved);
|
|
3895
3940
|
}
|
|
3896
|
-
if (!types.length) return
|
|
3941
|
+
if (!types.length) return t32.tsAnyKeyword();
|
|
3897
3942
|
if (types.length === 1) return types[0];
|
|
3898
|
-
return
|
|
3943
|
+
return t32.tsUnionType(types);
|
|
3899
3944
|
}
|
|
3900
3945
|
function mapRuntimeTypeToTSType(value) {
|
|
3901
3946
|
switch (value.name) {
|
|
3902
3947
|
case "String":
|
|
3903
|
-
return
|
|
3948
|
+
return t32.tsStringKeyword();
|
|
3904
3949
|
case "Number":
|
|
3905
|
-
return
|
|
3950
|
+
return t32.tsNumberKeyword();
|
|
3906
3951
|
case "Boolean":
|
|
3907
|
-
return
|
|
3952
|
+
return t32.tsBooleanKeyword();
|
|
3908
3953
|
case "Object":
|
|
3909
|
-
return
|
|
3954
|
+
return t32.tsTypeLiteral([]);
|
|
3910
3955
|
case "Array":
|
|
3911
|
-
return
|
|
3956
|
+
return t32.tsArrayType(t32.tsAnyKeyword());
|
|
3912
3957
|
case "Function":
|
|
3913
|
-
return
|
|
3958
|
+
return t32.tsFunctionType(null, [], t32.tsTypeAnnotation(t32.tsAnyKeyword()));
|
|
3914
3959
|
case "Symbol":
|
|
3915
|
-
return
|
|
3960
|
+
return t32.tsSymbolKeyword();
|
|
3916
3961
|
case "BigInt":
|
|
3917
|
-
return
|
|
3962
|
+
return t32.tsBigIntKeyword();
|
|
3918
3963
|
default:
|
|
3919
|
-
return
|
|
3964
|
+
return t32.tsAnyKeyword();
|
|
3920
3965
|
}
|
|
3921
3966
|
}
|
|
3922
3967
|
|
|
@@ -3930,34 +3975,34 @@ var SLOT_CHILDREN_NAME = "children";
|
|
|
3930
3975
|
var SLOT_FN_PARAM_NAME = "props";
|
|
3931
3976
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3932
3977
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3933
|
-
const key =
|
|
3934
|
-
const reactNodeType =
|
|
3935
|
-
|
|
3978
|
+
const key = t33.isValidIdentifier(propName) ? t33.identifier(propName) : t33.stringLiteral(propName);
|
|
3979
|
+
const reactNodeType = t33.tsTypeAnnotation(
|
|
3980
|
+
t33.tsTypeReference(t33.identifier(REACT_API_MAP.ReactNode))
|
|
3936
3981
|
);
|
|
3937
3982
|
let typeAnnotation;
|
|
3938
3983
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3939
3984
|
typeAnnotation = reactNodeType;
|
|
3940
3985
|
} else {
|
|
3941
|
-
const fnType =
|
|
3942
|
-
typeAnnotation =
|
|
3986
|
+
const fnType = t33.tsFunctionType(null, params, reactNodeType);
|
|
3987
|
+
typeAnnotation = t33.tsTypeAnnotation(fnType);
|
|
3943
3988
|
}
|
|
3944
|
-
const prop =
|
|
3989
|
+
const prop = t33.tsPropertySignature(key, typeAnnotation);
|
|
3945
3990
|
prop.optional = optional;
|
|
3946
3991
|
return prop;
|
|
3947
3992
|
}
|
|
3948
3993
|
function createSlotScopeParam(props, ctx) {
|
|
3949
|
-
const paramId =
|
|
3994
|
+
const paramId = t33.identifier(SLOT_FN_PARAM_NAME);
|
|
3950
3995
|
const propsSigns = [];
|
|
3951
3996
|
const { reactiveBindings } = ctx.templateData;
|
|
3952
3997
|
props.forEach(({ prop, tsType }) => {
|
|
3953
3998
|
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _121 => _121[prop], 'optionalAccess', _122 => _122.value]);
|
|
3954
3999
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3955
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3956
|
-
const key =
|
|
3957
|
-
const propSign =
|
|
4000
|
+
const typeAnnotation = foundBindingTypes ? t33.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
4001
|
+
const key = t33.isValidIdentifier(prop) ? t33.identifier(prop) : t33.stringLiteral(prop);
|
|
4002
|
+
const propSign = t33.tsPropertySignature(key, typeAnnotation);
|
|
3958
4003
|
propsSigns.push(propSign);
|
|
3959
4004
|
});
|
|
3960
|
-
paramId.typeAnnotation =
|
|
4005
|
+
paramId.typeAnnotation = t33.tsTypeAnnotation(t33.tsTypeLiteral(propsSigns));
|
|
3961
4006
|
return paramId;
|
|
3962
4007
|
}
|
|
3963
4008
|
|
|
@@ -3978,16 +4023,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
3978
4023
|
return declarations;
|
|
3979
4024
|
}
|
|
3980
4025
|
for (const statement of programPath.node.body) {
|
|
3981
|
-
if (
|
|
4026
|
+
if (t34.isTSInterfaceDeclaration(statement)) {
|
|
3982
4027
|
declarations.set(statement.id.name, {
|
|
3983
|
-
type:
|
|
4028
|
+
type: t34.tsTypeLiteral(statement.body.body),
|
|
3984
4029
|
// 将接口体转换为类型字面量
|
|
3985
4030
|
hasTypeParameters: !!_optionalChain([statement, 'access', _123 => _123.typeParameters, 'optionalAccess', _124 => _124.params, 'access', _125 => _125.length])
|
|
3986
4031
|
// 检查是否有泛型参数
|
|
3987
4032
|
});
|
|
3988
4033
|
continue;
|
|
3989
4034
|
}
|
|
3990
|
-
if (
|
|
4035
|
+
if (t34.isTSTypeAliasDeclaration(statement)) {
|
|
3991
4036
|
declarations.set(statement.id.name, {
|
|
3992
4037
|
type: statement.typeAnnotation,
|
|
3993
4038
|
// 直接使用类型注解
|
|
@@ -3996,16 +4041,16 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
3996
4041
|
});
|
|
3997
4042
|
continue;
|
|
3998
4043
|
}
|
|
3999
|
-
if (
|
|
4044
|
+
if (t34.isExportNamedDeclaration(statement) && statement.declaration) {
|
|
4000
4045
|
const declaration = statement.declaration;
|
|
4001
|
-
if (
|
|
4046
|
+
if (t34.isTSInterfaceDeclaration(declaration)) {
|
|
4002
4047
|
declarations.set(declaration.id.name, {
|
|
4003
|
-
type:
|
|
4048
|
+
type: t34.tsTypeLiteral(declaration.body.body),
|
|
4004
4049
|
// 将接口体转换为类型字面量
|
|
4005
4050
|
hasTypeParameters: !!_optionalChain([declaration, 'access', _129 => _129.typeParameters, 'optionalAccess', _130 => _130.params, 'access', _131 => _131.length])
|
|
4006
4051
|
// 检查是否有泛型参数
|
|
4007
4052
|
});
|
|
4008
|
-
} else if (
|
|
4053
|
+
} else if (t34.isTSTypeAliasDeclaration(declaration)) {
|
|
4009
4054
|
declarations.set(declaration.id.name, {
|
|
4010
4055
|
type: declaration.typeAnnotation,
|
|
4011
4056
|
// 直接使用类型注解
|
|
@@ -4018,22 +4063,22 @@ function collectLocalTypeDeclarations(path8) {
|
|
|
4018
4063
|
return declarations;
|
|
4019
4064
|
}
|
|
4020
4065
|
function resolvePropName2(key) {
|
|
4021
|
-
if (
|
|
4066
|
+
if (t34.isIdentifier(key)) {
|
|
4022
4067
|
return key.name;
|
|
4023
4068
|
}
|
|
4024
|
-
if (
|
|
4069
|
+
if (t34.isStringLiteral(key)) {
|
|
4025
4070
|
return key.value;
|
|
4026
4071
|
}
|
|
4027
|
-
if (
|
|
4072
|
+
if (t34.isNumericLiteral(key)) {
|
|
4028
4073
|
return String(key.value);
|
|
4029
4074
|
}
|
|
4030
4075
|
return null;
|
|
4031
4076
|
}
|
|
4032
4077
|
function resolveCallableType(tsType) {
|
|
4033
|
-
if (
|
|
4078
|
+
if (t34.isTSFunctionType(tsType)) {
|
|
4034
4079
|
return tsType;
|
|
4035
4080
|
}
|
|
4036
|
-
if (
|
|
4081
|
+
if (t34.isTSParenthesizedType(tsType)) {
|
|
4037
4082
|
return resolveCallableType(tsType.typeAnnotation);
|
|
4038
4083
|
}
|
|
4039
4084
|
return null;
|
|
@@ -4042,10 +4087,10 @@ function resolveCallableType(tsType) {
|
|
|
4042
4087
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/type-resolver.ts
|
|
4043
4088
|
var SLOT_DEFAULT_NAME2 = "default";
|
|
4044
4089
|
function resolveSlotType(tsType, options) {
|
|
4045
|
-
if (
|
|
4090
|
+
if (t35.isTSParenthesizedType(tsType)) {
|
|
4046
4091
|
return resolveSlotType(tsType.typeAnnotation, options);
|
|
4047
4092
|
}
|
|
4048
|
-
if (
|
|
4093
|
+
if (t35.isTSTypeReference(tsType)) {
|
|
4049
4094
|
let shouldRecordReactNode = false;
|
|
4050
4095
|
if (_optionalChain([tsType, 'access', _135 => _135.typeParameters, 'optionalAccess', _136 => _136.params, 'access', _137 => _137.length])) {
|
|
4051
4096
|
const params = [];
|
|
@@ -4061,11 +4106,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4061
4106
|
};
|
|
4062
4107
|
}
|
|
4063
4108
|
return {
|
|
4064
|
-
type:
|
|
4109
|
+
type: t35.tsTypeReference(tsType.typeName, t35.tsTypeParameterInstantiation(params)),
|
|
4065
4110
|
shouldRecordReactNode
|
|
4066
4111
|
};
|
|
4067
4112
|
}
|
|
4068
|
-
if (!
|
|
4113
|
+
if (!t35.isIdentifier(tsType.typeName)) {
|
|
4069
4114
|
return {
|
|
4070
4115
|
type: tsType,
|
|
4071
4116
|
shouldRecordReactNode: false
|
|
@@ -4096,7 +4141,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4096
4141
|
}
|
|
4097
4142
|
return resolved;
|
|
4098
4143
|
}
|
|
4099
|
-
if (
|
|
4144
|
+
if (t35.isTSIntersectionType(tsType)) {
|
|
4100
4145
|
const types = [];
|
|
4101
4146
|
let shouldRecordReactNode = false;
|
|
4102
4147
|
for (const item of tsType.types) {
|
|
@@ -4119,11 +4164,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4119
4164
|
};
|
|
4120
4165
|
}
|
|
4121
4166
|
return {
|
|
4122
|
-
type:
|
|
4167
|
+
type: t35.tsIntersectionType(types),
|
|
4123
4168
|
shouldRecordReactNode
|
|
4124
4169
|
};
|
|
4125
4170
|
}
|
|
4126
|
-
if (
|
|
4171
|
+
if (t35.isTSUnionType(tsType)) {
|
|
4127
4172
|
const types = [];
|
|
4128
4173
|
let shouldRecordReactNode = false;
|
|
4129
4174
|
for (const item of tsType.types) {
|
|
@@ -4146,11 +4191,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4146
4191
|
};
|
|
4147
4192
|
}
|
|
4148
4193
|
return {
|
|
4149
|
-
type:
|
|
4194
|
+
type: t35.tsUnionType(types),
|
|
4150
4195
|
shouldRecordReactNode
|
|
4151
4196
|
};
|
|
4152
4197
|
}
|
|
4153
|
-
if (
|
|
4198
|
+
if (t35.isTSTypeLiteral(tsType)) {
|
|
4154
4199
|
const members = [];
|
|
4155
4200
|
let shouldRecordReactNode = false;
|
|
4156
4201
|
for (const item of tsType.members) {
|
|
@@ -4165,11 +4210,11 @@ function resolveSlotType(tsType, options) {
|
|
|
4165
4210
|
};
|
|
4166
4211
|
}
|
|
4167
4212
|
return {
|
|
4168
|
-
type:
|
|
4213
|
+
type: t35.tsTypeLiteral(members),
|
|
4169
4214
|
shouldRecordReactNode
|
|
4170
4215
|
};
|
|
4171
4216
|
}
|
|
4172
|
-
if (
|
|
4217
|
+
if (t35.isTSFunctionType(tsType)) {
|
|
4173
4218
|
const props = buildSlotPropSignature(
|
|
4174
4219
|
SLOT_DEFAULT_NAME2,
|
|
4175
4220
|
cloneCallableParams(tsType.parameters),
|
|
@@ -4177,7 +4222,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4177
4222
|
// 默认插槽不是可选的
|
|
4178
4223
|
);
|
|
4179
4224
|
return {
|
|
4180
|
-
type:
|
|
4225
|
+
type: t35.tsTypeLiteral([props]),
|
|
4181
4226
|
shouldRecordReactNode: true
|
|
4182
4227
|
// 函数类型总是需要记录 ReactNode
|
|
4183
4228
|
};
|
|
@@ -4188,7 +4233,7 @@ function resolveSlotType(tsType, options) {
|
|
|
4188
4233
|
};
|
|
4189
4234
|
}
|
|
4190
4235
|
function resolveSlotPropFromMember(member) {
|
|
4191
|
-
if (
|
|
4236
|
+
if (t35.isTSMethodSignature(member)) {
|
|
4192
4237
|
const rawName = resolvePropName2(member.key);
|
|
4193
4238
|
if (!rawName) {
|
|
4194
4239
|
return {
|
|
@@ -4203,7 +4248,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4203
4248
|
// 方法签名总是可调用,需要记录 ReactNode
|
|
4204
4249
|
};
|
|
4205
4250
|
}
|
|
4206
|
-
if (
|
|
4251
|
+
if (t35.isTSPropertySignature(member)) {
|
|
4207
4252
|
const rawName = resolvePropName2(member.key);
|
|
4208
4253
|
if (!rawName) {
|
|
4209
4254
|
return {
|
|
@@ -4226,7 +4271,7 @@ function resolveSlotPropFromMember(member) {
|
|
|
4226
4271
|
// 可调用属性需要记录 ReactNode
|
|
4227
4272
|
};
|
|
4228
4273
|
}
|
|
4229
|
-
if (
|
|
4274
|
+
if (t35.isTSCallSignatureDeclaration(member)) {
|
|
4230
4275
|
const params = cloneCallableParams(member.parameters);
|
|
4231
4276
|
return {
|
|
4232
4277
|
member: buildSlotPropSignature(SLOT_DEFAULT_NAME2, params, true),
|
|
@@ -4284,7 +4329,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
4284
4329
|
}
|
|
4285
4330
|
if (tsMembers.length) {
|
|
4286
4331
|
recordReactNode(ctx);
|
|
4287
|
-
slotTypes.push(
|
|
4332
|
+
slotTypes.push(t36.tsTypeLiteral(tsMembers));
|
|
4288
4333
|
}
|
|
4289
4334
|
}
|
|
4290
4335
|
|
|
@@ -4336,9 +4381,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
4336
4381
|
}
|
|
4337
4382
|
const n = declaredOptions.name || "Comp";
|
|
4338
4383
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
4339
|
-
const typeNode =
|
|
4340
|
-
const typeAliasDecl =
|
|
4341
|
-
const exportDecl =
|
|
4384
|
+
const typeNode = t37.tsIntersectionType(tsTypes);
|
|
4385
|
+
const typeAliasDecl = t37.tsTypeAliasDeclaration(t37.identifier(ns), null, typeNode);
|
|
4386
|
+
const exportDecl = t37.exportNamedDeclaration(typeAliasDecl);
|
|
4342
4387
|
propsTSIface.name = ns;
|
|
4343
4388
|
const scriptIR = getScriptIR(ctx);
|
|
4344
4389
|
scriptIR.exports.push(exportDecl);
|
|
@@ -4353,8 +4398,8 @@ function resolveUseAttrs(ctx) {
|
|
|
4353
4398
|
const { init, id } = path8.node;
|
|
4354
4399
|
if (!init) return;
|
|
4355
4400
|
const initPath = path8.get("init");
|
|
4356
|
-
const propsIdentifier =
|
|
4357
|
-
if (
|
|
4401
|
+
const propsIdentifier = t38.identifier(ctx.propField);
|
|
4402
|
+
if (t38.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
|
|
4358
4403
|
const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
|
|
4359
4404
|
replaceNode(initPath, typeAssertion, init);
|
|
4360
4405
|
return;
|
|
@@ -4365,13 +4410,13 @@ function resolveUseAttrs(ctx) {
|
|
|
4365
4410
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
4366
4411
|
if (isTS) {
|
|
4367
4412
|
let typeAnnotation = null;
|
|
4368
|
-
if (
|
|
4413
|
+
if (t38.isIdentifier(id) && t38.isTSTypeAnnotation(id.typeAnnotation)) {
|
|
4369
4414
|
typeAnnotation = id.typeAnnotation.typeAnnotation;
|
|
4370
4415
|
id.typeAnnotation = null;
|
|
4371
4416
|
} else {
|
|
4372
|
-
typeAnnotation =
|
|
4373
|
-
|
|
4374
|
-
|
|
4417
|
+
typeAnnotation = t38.tsTypeReference(
|
|
4418
|
+
t38.identifier("Record"),
|
|
4419
|
+
t38.tsTypeParameterInstantiation([t38.tsStringKeyword(), t38.tsUnknownKeyword()])
|
|
4375
4420
|
);
|
|
4376
4421
|
}
|
|
4377
4422
|
const propsTypeAssertion = createPropsTypeAssertion(propsIdentifier, typeAnnotation);
|
|
@@ -4383,10 +4428,10 @@ function resolveUseAttrs(ctx) {
|
|
|
4383
4428
|
};
|
|
4384
4429
|
}
|
|
4385
4430
|
function isUseAttrsCall(expr) {
|
|
4386
|
-
return
|
|
4431
|
+
return t38.isCallExpression(expr) && isCalleeNamed(expr, VUE_API_MAP.useAttrs);
|
|
4387
4432
|
}
|
|
4388
4433
|
function createPropsTypeAssertion(propsIdentifier, typeAnnotation) {
|
|
4389
|
-
return
|
|
4434
|
+
return t38.tsAsExpression(propsIdentifier, typeAnnotation);
|
|
4390
4435
|
}
|
|
4391
4436
|
|
|
4392
4437
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -4423,39 +4468,39 @@ function isEligibleBindingSource(binding) {
|
|
|
4423
4468
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
4424
4469
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
4425
4470
|
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _145 => _145.node, 'access', _146 => _146.init]);
|
|
4426
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
4427
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
4428
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
4471
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t39.isCallExpression(nodeInit) && t39.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
4472
|
+
const isHookCallVarBinding = !!declaratorPath && t39.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
4473
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t39.isArrowFunctionExpression(nodeInit) || t39.isFunctionExpression(nodeInit));
|
|
4429
4474
|
const isReactiveFunctionBinding = isFunctionBinding && (isReactiveBinding(_optionalChain([declaratorPath, 'optionalAccess', _147 => _147.node])) || isReactiveBinding(bindingPath.node));
|
|
4430
4475
|
return isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isReactiveFunctionBinding;
|
|
4431
4476
|
}
|
|
4432
4477
|
function isReactValidDependencyExpr(node) {
|
|
4433
|
-
if (
|
|
4478
|
+
if (t39.isIdentifier(node)) {
|
|
4434
4479
|
return true;
|
|
4435
4480
|
}
|
|
4436
|
-
if (
|
|
4481
|
+
if (t39.isMemberExpression(node) || t39.isOptionalMemberExpression(node)) {
|
|
4437
4482
|
return isStaticMemberChain(node);
|
|
4438
4483
|
}
|
|
4439
4484
|
return false;
|
|
4440
4485
|
}
|
|
4441
4486
|
function isStaticMemberChain(node) {
|
|
4442
4487
|
let current = node;
|
|
4443
|
-
while (
|
|
4444
|
-
if (!current.computed && !
|
|
4488
|
+
while (t39.isMemberExpression(current) || t39.isOptionalMemberExpression(current)) {
|
|
4489
|
+
if (!current.computed && !t39.isIdentifier(current.property)) {
|
|
4445
4490
|
return false;
|
|
4446
4491
|
}
|
|
4447
|
-
if (current.computed && !
|
|
4492
|
+
if (current.computed && !t39.isStringLiteral(current.property) && !t39.isNumericLiteral(current.property)) {
|
|
4448
4493
|
return false;
|
|
4449
4494
|
}
|
|
4450
4495
|
current = current.object;
|
|
4451
4496
|
}
|
|
4452
|
-
return
|
|
4497
|
+
return t39.isIdentifier(current);
|
|
4453
4498
|
}
|
|
4454
4499
|
function isHookLikeCallee(callee) {
|
|
4455
|
-
if (
|
|
4500
|
+
if (t39.isIdentifier(callee)) {
|
|
4456
4501
|
return callee.name.startsWith("use");
|
|
4457
4502
|
}
|
|
4458
|
-
if (
|
|
4503
|
+
if (t39.isMemberExpression(callee) && !callee.computed && t39.isIdentifier(callee.property)) {
|
|
4459
4504
|
return callee.property.name.startsWith("use");
|
|
4460
4505
|
}
|
|
4461
4506
|
return false;
|
|
@@ -4464,16 +4509,16 @@ function isHookLikeCallee(callee) {
|
|
|
4464
4509
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-key.ts
|
|
4465
4510
|
|
|
4466
4511
|
function getDependencyKey(exp) {
|
|
4467
|
-
if (
|
|
4512
|
+
if (t40.isIdentifier(exp)) {
|
|
4468
4513
|
return exp.name;
|
|
4469
4514
|
}
|
|
4470
|
-
if (
|
|
4515
|
+
if (t40.isMemberExpression(exp) || t40.isOptionalMemberExpression(exp)) {
|
|
4471
4516
|
const objectKey = getDependencyKey(exp.object);
|
|
4472
4517
|
const opt = exp.optional ? "?" : "";
|
|
4473
|
-
if (!exp.computed &&
|
|
4518
|
+
if (!exp.computed && t40.isIdentifier(exp.property)) {
|
|
4474
4519
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
4475
4520
|
}
|
|
4476
|
-
if (
|
|
4521
|
+
if (t40.isStringLiteral(exp.property) || t40.isNumericLiteral(exp.property)) {
|
|
4477
4522
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
4478
4523
|
}
|
|
4479
4524
|
return `${objectKey}${opt}[*]`;
|
|
@@ -4484,38 +4529,38 @@ function getDependencyKey(exp) {
|
|
|
4484
4529
|
// src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
|
|
4485
4530
|
|
|
4486
4531
|
function normalizeDependencyExpr(path8, rootName, ctx) {
|
|
4487
|
-
if (
|
|
4488
|
-
return
|
|
4532
|
+
if (t41.isIdentifier(path8.node)) {
|
|
4533
|
+
return t41.identifier(path8.node.name);
|
|
4489
4534
|
}
|
|
4490
|
-
if (
|
|
4535
|
+
if (t41.isMemberExpression(path8.node) || t41.isOptionalMemberExpression(path8.node)) {
|
|
4491
4536
|
if (rootName === ctx.propField) {
|
|
4492
4537
|
const safePropsExp = ensureOptionalForMemberChain(path8.node);
|
|
4493
4538
|
if (isReactValidDependencyExpr(safePropsExp)) {
|
|
4494
|
-
return
|
|
4539
|
+
return t41.cloneNode(safePropsExp, true);
|
|
4495
4540
|
}
|
|
4496
|
-
return
|
|
4541
|
+
return t41.identifier(rootName);
|
|
4497
4542
|
}
|
|
4498
4543
|
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
4499
|
-
const safeExp =
|
|
4544
|
+
const safeExp = t41.isMemberExpression(normalizedExp) || t41.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
|
|
4500
4545
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4501
|
-
return
|
|
4546
|
+
return t41.cloneNode(safeExp, true);
|
|
4502
4547
|
}
|
|
4503
|
-
return
|
|
4548
|
+
return t41.identifier(rootName);
|
|
4504
4549
|
}
|
|
4505
4550
|
return null;
|
|
4506
4551
|
}
|
|
4507
4552
|
function normalizeSourcedDependency(exp) {
|
|
4508
|
-
if (
|
|
4509
|
-
return
|
|
4553
|
+
if (t41.isIdentifier(exp)) {
|
|
4554
|
+
return t41.identifier(exp.name);
|
|
4510
4555
|
}
|
|
4511
|
-
if (
|
|
4556
|
+
if (t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp)) {
|
|
4512
4557
|
const root = findRootIdentifier(exp);
|
|
4513
4558
|
if (!root) return null;
|
|
4514
|
-
const safeExp =
|
|
4559
|
+
const safeExp = t41.isMemberExpression(exp) || t41.isOptionalMemberExpression(exp) ? ensureOptionalForMemberChain(exp) : exp;
|
|
4515
4560
|
if (isReactValidDependencyExpr(safeExp)) {
|
|
4516
|
-
return
|
|
4561
|
+
return t41.cloneNode(safeExp, true);
|
|
4517
4562
|
}
|
|
4518
|
-
return
|
|
4563
|
+
return t41.identifier(root.name);
|
|
4519
4564
|
}
|
|
4520
4565
|
return null;
|
|
4521
4566
|
}
|
|
@@ -4525,7 +4570,7 @@ function normalizeMemberForCallSite(path8, node) {
|
|
|
4525
4570
|
if (!isDirectCallee) {
|
|
4526
4571
|
return node;
|
|
4527
4572
|
}
|
|
4528
|
-
if (!
|
|
4573
|
+
if (!t41.isExpression(node.object)) {
|
|
4529
4574
|
return node;
|
|
4530
4575
|
}
|
|
4531
4576
|
return node.object;
|
|
@@ -4534,15 +4579,23 @@ function ensureOptionalForMemberChain(node) {
|
|
|
4534
4579
|
if (!hasTrailingMemberAccess(node)) {
|
|
4535
4580
|
return node;
|
|
4536
4581
|
}
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4582
|
+
const rebuildWithOptionalChain = (node2) => {
|
|
4583
|
+
const safeObject = ensureOptionalForMemberChain(node2.object);
|
|
4584
|
+
if (safeObject !== node2.object) {
|
|
4585
|
+
const property = t41.cloneNode(node2.property, true);
|
|
4586
|
+
return t41.optionalMemberExpression(safeObject, property, node2.computed, true);
|
|
4587
|
+
}
|
|
4588
|
+
if (t41.isMemberExpression(node2)) {
|
|
4589
|
+
const object = t41.cloneNode(node2.object, true);
|
|
4590
|
+
const property = t41.cloneNode(node2.property, true);
|
|
4591
|
+
return t41.optionalMemberExpression(object, property, node2.computed, true);
|
|
4592
|
+
}
|
|
4593
|
+
return node2;
|
|
4594
|
+
};
|
|
4595
|
+
return rebuildWithOptionalChain(node);
|
|
4543
4596
|
}
|
|
4544
4597
|
function hasTrailingMemberAccess(node) {
|
|
4545
|
-
return
|
|
4598
|
+
return t41.isMemberExpression(node.object) || t41.isOptionalMemberExpression(node.object);
|
|
4546
4599
|
}
|
|
4547
4600
|
|
|
4548
4601
|
// src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
|
|
@@ -4569,7 +4622,7 @@ function traceBindingSource(binding, seen, depth) {
|
|
|
4569
4622
|
}
|
|
4570
4623
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
4571
4624
|
if (depth <= 0) return null;
|
|
4572
|
-
if (
|
|
4625
|
+
if (t42.isIdentifier(exp)) {
|
|
4573
4626
|
const sourceBinding = scope.getBinding(exp.name);
|
|
4574
4627
|
if (!sourceBinding) return null;
|
|
4575
4628
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -4577,13 +4630,13 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4577
4630
|
}
|
|
4578
4631
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4579
4632
|
}
|
|
4580
|
-
if (
|
|
4633
|
+
if (t42.isMemberExpression(exp) || t42.isOptionalMemberExpression(exp)) {
|
|
4581
4634
|
const root = findRootIdentifier(exp);
|
|
4582
4635
|
if (!root) return null;
|
|
4583
4636
|
const sourceBinding = scope.getBinding(root.name);
|
|
4584
4637
|
if (!sourceBinding) return null;
|
|
4585
4638
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
4586
|
-
return
|
|
4639
|
+
return t42.cloneNode(exp);
|
|
4587
4640
|
}
|
|
4588
4641
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
4589
4642
|
if (sourcedRoot) {
|
|
@@ -4591,17 +4644,17 @@ function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
|
4591
4644
|
if (rebuilt) {
|
|
4592
4645
|
return rebuilt;
|
|
4593
4646
|
}
|
|
4594
|
-
return
|
|
4647
|
+
return t42.cloneNode(sourcedRoot, true);
|
|
4595
4648
|
}
|
|
4596
4649
|
}
|
|
4597
4650
|
return null;
|
|
4598
4651
|
}
|
|
4599
4652
|
function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
4600
4653
|
const replacedObject = (() => {
|
|
4601
|
-
if (
|
|
4602
|
-
return
|
|
4654
|
+
if (t42.isIdentifier(node.object)) {
|
|
4655
|
+
return t42.cloneNode(nextRoot, true);
|
|
4603
4656
|
}
|
|
4604
|
-
if (
|
|
4657
|
+
if (t42.isMemberExpression(node.object) || t42.isOptionalMemberExpression(node.object)) {
|
|
4605
4658
|
return rebuildMemberWithNewRoot(node.object, nextRoot);
|
|
4606
4659
|
}
|
|
4607
4660
|
return null;
|
|
@@ -4609,15 +4662,15 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4609
4662
|
if (!replacedObject) {
|
|
4610
4663
|
return null;
|
|
4611
4664
|
}
|
|
4612
|
-
const property =
|
|
4613
|
-
if (
|
|
4614
|
-
return
|
|
4665
|
+
const property = t42.cloneNode(node.property, true);
|
|
4666
|
+
if (t42.isMemberExpression(node)) {
|
|
4667
|
+
return t42.memberExpression(
|
|
4615
4668
|
replacedObject,
|
|
4616
4669
|
property,
|
|
4617
4670
|
node.computed
|
|
4618
4671
|
);
|
|
4619
4672
|
}
|
|
4620
|
-
return
|
|
4673
|
+
return t42.optionalMemberExpression(
|
|
4621
4674
|
replacedObject,
|
|
4622
4675
|
property,
|
|
4623
4676
|
node.computed,
|
|
@@ -4628,9 +4681,9 @@ function rebuildMemberWithNewRoot(node, nextRoot) {
|
|
|
4628
4681
|
// src/core/transform/sfc/script/shared/dependency-analyzer/index.ts
|
|
4629
4682
|
function analyzeDeps(node, ctx, parentPath) {
|
|
4630
4683
|
if (!parentPath) {
|
|
4631
|
-
return
|
|
4684
|
+
return t43.arrayExpression([]);
|
|
4632
4685
|
}
|
|
4633
|
-
const isFnExpr =
|
|
4686
|
+
const isFnExpr = t43.isArrowFunctionExpression(node) || t43.isFunctionExpression(node);
|
|
4634
4687
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
4635
4688
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
4636
4689
|
const deps = /* @__PURE__ */ new Map();
|
|
@@ -4640,13 +4693,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4640
4693
|
}
|
|
4641
4694
|
const analyzeTargetPath = parentPath && parentPath.node === analyzeTarget ? parentPath : null;
|
|
4642
4695
|
if (analyzeTargetPath) {
|
|
4643
|
-
if (
|
|
4696
|
+
if (t43.isMemberExpression(analyzeTarget) || t43.isOptionalMemberExpression(analyzeTarget)) {
|
|
4644
4697
|
const rootId = findRootIdentifier(analyzeTarget);
|
|
4645
4698
|
if (rootId) {
|
|
4646
4699
|
tryAddDependency(analyzeTargetPath, rootId.name, analyzeTargetPath.scope);
|
|
4647
4700
|
processedIdentifiers.add(rootId);
|
|
4648
4701
|
}
|
|
4649
|
-
} else if (
|
|
4702
|
+
} else if (t43.isIdentifier(analyzeTarget)) {
|
|
4650
4703
|
tryAddDependency(analyzeTargetPath, analyzeTarget.name, analyzeTargetPath.scope);
|
|
4651
4704
|
}
|
|
4652
4705
|
}
|
|
@@ -4698,7 +4751,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
4698
4751
|
}
|
|
4699
4752
|
}
|
|
4700
4753
|
}
|
|
4701
|
-
return
|
|
4754
|
+
return t43.arrayExpression(Array.from(deps.values()));
|
|
4702
4755
|
}
|
|
4703
4756
|
|
|
4704
4757
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
@@ -4714,7 +4767,7 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4714
4767
|
if (!isVueApiReference(path8, apiName)) {
|
|
4715
4768
|
return;
|
|
4716
4769
|
}
|
|
4717
|
-
if (
|
|
4770
|
+
if (t44.isCallExpression(node)) {
|
|
4718
4771
|
resolveCallNode(path8, adapter, ctx);
|
|
4719
4772
|
} else {
|
|
4720
4773
|
replaceIdName(node, adapter.target);
|
|
@@ -4724,11 +4777,11 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
4724
4777
|
};
|
|
4725
4778
|
}
|
|
4726
4779
|
function getApiName(node) {
|
|
4727
|
-
const isCallNode =
|
|
4780
|
+
const isCallNode = t44.isCallExpression(node);
|
|
4728
4781
|
let apiName = "";
|
|
4729
|
-
if (
|
|
4782
|
+
if (t44.isIdentifier(node)) {
|
|
4730
4783
|
apiName = node.name;
|
|
4731
|
-
} else if (isCallNode &&
|
|
4784
|
+
} else if (isCallNode && t44.isIdentifier(node.callee)) {
|
|
4732
4785
|
apiName = node.callee.name;
|
|
4733
4786
|
}
|
|
4734
4787
|
return apiName;
|
|
@@ -4738,7 +4791,7 @@ function resolveCallNode(path8, adapter, ctx) {
|
|
|
4738
4791
|
const { arguments: args } = node;
|
|
4739
4792
|
if (!args.length) return;
|
|
4740
4793
|
const fn = args[0];
|
|
4741
|
-
if (!
|
|
4794
|
+
if (!t44.isArrowFunctionExpression(fn) && !t44.isFunctionExpression(fn)) {
|
|
4742
4795
|
return;
|
|
4743
4796
|
}
|
|
4744
4797
|
const fnPath = path8.get("arguments")[0];
|
|
@@ -4770,7 +4823,7 @@ function isVueImportBinding(binding) {
|
|
|
4770
4823
|
return false;
|
|
4771
4824
|
}
|
|
4772
4825
|
const parent = _optionalChain([bindingPath, 'access', _148 => _148.parentPath, 'optionalAccess', _149 => _149.node]);
|
|
4773
|
-
if (!parent || !
|
|
4826
|
+
if (!parent || !t44.isImportDeclaration(parent)) {
|
|
4774
4827
|
return false;
|
|
4775
4828
|
}
|
|
4776
4829
|
const source = parent.source.value.toLowerCase();
|
|
@@ -4856,14 +4909,14 @@ function resolveElementRef(ctx) {
|
|
|
4856
4909
|
}
|
|
4857
4910
|
if (isCompRefBindings) {
|
|
4858
4911
|
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _151 => _151(path8), 'optionalAccess', _152 => _152.node]);
|
|
4859
|
-
if (!
|
|
4912
|
+
if (!t45.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _153 => _153.id]))) {
|
|
4860
4913
|
return;
|
|
4861
4914
|
}
|
|
4862
4915
|
const varName = varDeclaratorPath.id.name;
|
|
4863
4916
|
const compRef = refBindings.componentRefs[varName];
|
|
4864
4917
|
if (!compRef) return;
|
|
4865
4918
|
}
|
|
4866
|
-
node.arguments[0] =
|
|
4919
|
+
node.arguments[0] = t45.identifier("null");
|
|
4867
4920
|
resolveTypeParameters(ctx, path8);
|
|
4868
4921
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
4869
4922
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
@@ -4888,20 +4941,20 @@ function resolveTypeParameters(ctx, path8) {
|
|
|
4888
4941
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
4889
4942
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
4890
4943
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
4891
|
-
node.typeParameters =
|
|
4944
|
+
node.typeParameters = t45.tsTypeParameterInstantiation([t45.tsTypeReference(t45.identifier(type))]);
|
|
4892
4945
|
}
|
|
4893
4946
|
}
|
|
4894
4947
|
function resolveRefValueToCurrent(path8) {
|
|
4895
4948
|
const { node } = path8;
|
|
4896
|
-
if (node.computed || !
|
|
4949
|
+
if (node.computed || !t45.isIdentifier(node.property) || node.property.name !== "value") {
|
|
4897
4950
|
return;
|
|
4898
4951
|
}
|
|
4899
4952
|
const rootPath = findRootVariablePath(path8);
|
|
4900
|
-
if (!_optionalChain([rootPath, 'optionalAccess', _156 => _156.node]) || !
|
|
4953
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _156 => _156.node]) || !t45.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
4901
4954
|
return;
|
|
4902
4955
|
}
|
|
4903
4956
|
const rootId = findRootIdentifier(node);
|
|
4904
|
-
if (!
|
|
4957
|
+
if (!t45.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _157 => _157.name])) {
|
|
4905
4958
|
return;
|
|
4906
4959
|
}
|
|
4907
4960
|
node.property.name = "current";
|
|
@@ -4920,11 +4973,11 @@ function resolveExprMemo(ctx, ast) {
|
|
|
4920
4973
|
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
4921
4974
|
return false;
|
|
4922
4975
|
}
|
|
4923
|
-
if (!
|
|
4976
|
+
if (!t46.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
|
|
4924
4977
|
return false;
|
|
4925
4978
|
}
|
|
4926
|
-
if (
|
|
4927
|
-
if (
|
|
4979
|
+
if (t46.isFunction(init)) return false;
|
|
4980
|
+
if (t46.isCallExpression(init) && t46.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
4928
4981
|
return false;
|
|
4929
4982
|
}
|
|
4930
4983
|
return true;
|
|
@@ -4949,10 +5002,10 @@ function resolveLintRules(ctx, ast) {
|
|
|
4949
5002
|
return {
|
|
4950
5003
|
CallExpression(path8) {
|
|
4951
5004
|
const { node, parentPath } = path8;
|
|
4952
|
-
if (!
|
|
5005
|
+
if (!t47.isIdentifier(node.callee)) return;
|
|
4953
5006
|
const { name: callName } = node.callee;
|
|
4954
|
-
const addLog = (
|
|
4955
|
-
logger.error(
|
|
5007
|
+
const addLog = (t53) => {
|
|
5008
|
+
logger.error(t53, {
|
|
4956
5009
|
file: ctx.filename,
|
|
4957
5010
|
source: ctx.scriptData.source,
|
|
4958
5011
|
loc: node.loc
|
|
@@ -5029,13 +5082,13 @@ function findOrCreateCtxProvider(root) {
|
|
|
5029
5082
|
function assignProviderValue(target, key, value) {
|
|
5030
5083
|
const getRawExp = (exp) => {
|
|
5031
5084
|
if (!exp) return "''";
|
|
5032
|
-
if (
|
|
5085
|
+
if (t48.isStringLiteral(exp)) {
|
|
5033
5086
|
return JSON.stringify(exp.value);
|
|
5034
5087
|
}
|
|
5035
|
-
if (
|
|
5088
|
+
if (t48.isNumericLiteral(exp)) {
|
|
5036
5089
|
return exp.value.toString();
|
|
5037
5090
|
}
|
|
5038
|
-
if (
|
|
5091
|
+
if (t48.isIdentifier(exp)) {
|
|
5039
5092
|
return exp.name;
|
|
5040
5093
|
}
|
|
5041
5094
|
try {
|
|
@@ -5056,11 +5109,11 @@ function resolveRenameAdapter(ctx) {
|
|
|
5056
5109
|
return {
|
|
5057
5110
|
"CallExpression|Identifier"(path8) {
|
|
5058
5111
|
const node = path8.node;
|
|
5059
|
-
const isCallNode =
|
|
5112
|
+
const isCallNode = t49.isCallExpression(node);
|
|
5060
5113
|
let apiName = "";
|
|
5061
|
-
if (
|
|
5114
|
+
if (t49.isIdentifier(node)) {
|
|
5062
5115
|
apiName = node.name;
|
|
5063
|
-
} else if (isCallNode &&
|
|
5116
|
+
} else if (isCallNode && t49.isIdentifier(node.callee)) {
|
|
5064
5117
|
apiName = node.callee.name;
|
|
5065
5118
|
}
|
|
5066
5119
|
if (!apiName) {
|
|
@@ -5122,7 +5175,7 @@ function isVueImportBinding2(binding) {
|
|
|
5122
5175
|
return false;
|
|
5123
5176
|
}
|
|
5124
5177
|
const parent = _optionalChain([bindingPath, 'access', _163 => _163.parentPath, 'optionalAccess', _164 => _164.node]);
|
|
5125
|
-
if (!parent || !
|
|
5178
|
+
if (!parent || !t49.isImportDeclaration(parent)) {
|
|
5126
5179
|
return false;
|
|
5127
5180
|
}
|
|
5128
5181
|
const source = parent.source.value.toLowerCase();
|
|
@@ -5166,7 +5219,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
5166
5219
|
excludeBabel: [resolveTemplateSlotIface, resolveCompIProps]
|
|
5167
5220
|
},
|
|
5168
5221
|
postprocess: {
|
|
5169
|
-
applyBabel: [
|
|
5222
|
+
applyBabel: [
|
|
5223
|
+
// 该 resolver 需确保放在所有类型处理之后,移除之前
|
|
5224
|
+
resolveVueTypeAsAny,
|
|
5225
|
+
resolveRuntimeImports,
|
|
5226
|
+
resolveASTChunks
|
|
5227
|
+
],
|
|
5170
5228
|
excludeBabel: [resolveSfcCssImport]
|
|
5171
5229
|
}
|
|
5172
5230
|
});
|
|
@@ -5265,7 +5323,7 @@ function isRouterLinkBooleanCustomProp(prop) {
|
|
|
5265
5323
|
|
|
5266
5324
|
|
|
5267
5325
|
var strCodeTypes = {
|
|
5268
|
-
isIdentifier:
|
|
5326
|
+
isIdentifier: isIdentifier29,
|
|
5269
5327
|
isSimpleExpression,
|
|
5270
5328
|
isStringLiteral: isStringLiteral13
|
|
5271
5329
|
};
|
|
@@ -5276,30 +5334,30 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
5276
5334
|
} catch (e7) {
|
|
5277
5335
|
return false;
|
|
5278
5336
|
}
|
|
5279
|
-
if (
|
|
5337
|
+
if (t50.isLiteral(node)) {
|
|
5280
5338
|
return true;
|
|
5281
5339
|
}
|
|
5282
|
-
if (!excludeVar &&
|
|
5340
|
+
if (!excludeVar && t50.isIdentifier(node)) {
|
|
5283
5341
|
return true;
|
|
5284
5342
|
}
|
|
5285
|
-
if (
|
|
5286
|
-
return isSimpleExpression(node.object) &&
|
|
5343
|
+
if (t50.isMemberExpression(node)) {
|
|
5344
|
+
return isSimpleExpression(node.object) && t50.isIdentifier(node.property);
|
|
5287
5345
|
}
|
|
5288
|
-
if (
|
|
5346
|
+
if (t50.isObjectExpression(node) || t50.isArrayExpression(node)) {
|
|
5289
5347
|
return false;
|
|
5290
5348
|
}
|
|
5291
|
-
if (
|
|
5349
|
+
if (t50.isCallExpression(node) || t50.isAssignmentExpression(node)) {
|
|
5292
5350
|
return false;
|
|
5293
5351
|
}
|
|
5294
|
-
if (
|
|
5352
|
+
if (t50.isBinaryExpression(node) || t50.isUnaryExpression(node)) {
|
|
5295
5353
|
return true;
|
|
5296
5354
|
}
|
|
5297
5355
|
return false;
|
|
5298
5356
|
}
|
|
5299
|
-
function
|
|
5357
|
+
function isIdentifier29(code) {
|
|
5300
5358
|
try {
|
|
5301
5359
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5302
|
-
return
|
|
5360
|
+
return t50.isIdentifier(node);
|
|
5303
5361
|
} catch (e8) {
|
|
5304
5362
|
return false;
|
|
5305
5363
|
}
|
|
@@ -5307,7 +5365,7 @@ function isIdentifier28(code) {
|
|
|
5307
5365
|
function isStringLiteral13(code) {
|
|
5308
5366
|
try {
|
|
5309
5367
|
const node = _parser.parseExpression.call(void 0, code);
|
|
5310
|
-
return
|
|
5368
|
+
return t50.isStringLiteral(node);
|
|
5311
5369
|
} catch (e9) {
|
|
5312
5370
|
return false;
|
|
5313
5371
|
}
|
|
@@ -5447,9 +5505,10 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5447
5505
|
const value = ir.value;
|
|
5448
5506
|
const valueContent = value.content;
|
|
5449
5507
|
const mergedItems = value.merge;
|
|
5508
|
+
const rule = ADAPTER_RULES.runtime;
|
|
5450
5509
|
const setNameIdentifier = (target, valueName) => {
|
|
5451
5510
|
target.content = valueName;
|
|
5452
|
-
target.ast =
|
|
5511
|
+
target.ast = t51.jsxIdentifier(valueName);
|
|
5453
5512
|
};
|
|
5454
5513
|
const setValueExpression = (target, content, isStringLiteral14) => {
|
|
5455
5514
|
target.content = content;
|
|
@@ -5457,38 +5516,41 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
5457
5516
|
};
|
|
5458
5517
|
const createRuntimeCall = (fnName, args) => {
|
|
5459
5518
|
const fnArgs = args.filter(Boolean).join(",");
|
|
5460
|
-
|
|
5519
|
+
const valIsUndef = fnName === rule.dirOn.target && _optionalChain([args, 'optionalAccess', _183 => _183[1]]) === "undefined";
|
|
5520
|
+
const isTs = ctx.scriptData.lang.startsWith("ts");
|
|
5521
|
+
const safeTypeAssertion = isTs ? valIsUndef ? "as never" : "" : "";
|
|
5522
|
+
return `${fnName}(${fnArgs}) ${safeTypeAssertion}`;
|
|
5461
5523
|
};
|
|
5462
5524
|
const applyRuntimeExpression = (expression, setName = false, nameIdentifier, isStringLiteral14) => {
|
|
5463
5525
|
if (setName && nameIdentifier) {
|
|
5464
5526
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
5465
5527
|
}
|
|
5466
|
-
const dir =
|
|
5528
|
+
const dir = rule.dir;
|
|
5467
5529
|
recordImport(ctx, dir.package, dir.target);
|
|
5468
5530
|
setValueExpression(value.babelExp, expression, isStringLiteral14);
|
|
5469
5531
|
};
|
|
5470
5532
|
if (ir.isKeyLessVBind) {
|
|
5471
|
-
const dirKeyless =
|
|
5533
|
+
const dirKeyless = rule.dirKeyless;
|
|
5472
5534
|
const expression = createRuntimeCall(dirKeyless.target, [valueContent]);
|
|
5473
5535
|
applyRuntimeExpression(expression, false);
|
|
5474
5536
|
return;
|
|
5475
5537
|
}
|
|
5476
5538
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
5477
|
-
const dirCls =
|
|
5478
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5539
|
+
const dirCls = rule.dirCls;
|
|
5540
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _184 => _184.join, 'call', _185 => _185(",")]) || wrapSingleQuotes(valueContent);
|
|
5479
5541
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
5480
5542
|
applyRuntimeExpression(expression, true, name);
|
|
5481
5543
|
return;
|
|
5482
5544
|
}
|
|
5483
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
5484
|
-
const dirStyle =
|
|
5485
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
5545
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _186 => _186.some, 'call', _187 => _187((item) => !isSimpleStyle(item))]))) {
|
|
5546
|
+
const dirStyle = rule.dirStyle;
|
|
5547
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _188 => _188.join, 'call', _189 => _189(",")]) || valueContent;
|
|
5486
5548
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
5487
5549
|
applyRuntimeExpression(expression, true, name);
|
|
5488
5550
|
return;
|
|
5489
5551
|
}
|
|
5490
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
5491
|
-
const dirOn =
|
|
5552
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _190 => _190.modifiers, 'optionalAccess', _191 => _191.length])) {
|
|
5553
|
+
const dirOn = rule.dirOn;
|
|
5492
5554
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
5493
5555
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
5494
5556
|
applyRuntimeExpression(expression, true, name);
|
|
@@ -5542,7 +5604,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
5542
5604
|
continue;
|
|
5543
5605
|
}
|
|
5544
5606
|
const nodeIR = child;
|
|
5545
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
5607
|
+
if (_optionalChain([parentIR, 'optionalAccess', _192 => _192.isBuiltIn])) {
|
|
5546
5608
|
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
5547
5609
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
5548
5610
|
}
|
|
@@ -5583,7 +5645,7 @@ function walkElementNodes(node, onElement) {
|
|
|
5583
5645
|
}
|
|
5584
5646
|
function resolveDefaultStyleModuleName(node) {
|
|
5585
5647
|
const { exp } = node;
|
|
5586
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
5648
|
+
if (_optionalChain([exp, 'optionalAccess', _193 => _193.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
5587
5649
|
return;
|
|
5588
5650
|
}
|
|
5589
5651
|
if (exp.content.includes("$style")) {
|
|
@@ -5679,7 +5741,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
5679
5741
|
const oldStyle = oldAttr.value.content;
|
|
5680
5742
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
5681
5743
|
let merged = oldAttr.value.merge;
|
|
5682
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
5744
|
+
if (!_optionalChain([merged, 'optionalAccess', _194 => _194.length])) {
|
|
5683
5745
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
5684
5746
|
} else {
|
|
5685
5747
|
merged.push(newStyle);
|
|
@@ -5709,7 +5771,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
5709
5771
|
const { source, filename } = ctx;
|
|
5710
5772
|
let value = "";
|
|
5711
5773
|
let loc;
|
|
5712
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
5774
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _195 => _195.exp, 'optionalAccess', _196 => _196.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
5713
5775
|
value = node.exp.content;
|
|
5714
5776
|
loc = node.exp.loc;
|
|
5715
5777
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -5763,11 +5825,11 @@ function resolveRefProp(prop, ctx, nodeIR) {
|
|
|
5763
5825
|
} = ctx;
|
|
5764
5826
|
let propIR;
|
|
5765
5827
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5766
|
-
const tag = _optionalChain([prop, 'access',
|
|
5828
|
+
const tag = _optionalChain([prop, 'access', _197 => _197.value, 'optionalAccess', _198 => _198.content]);
|
|
5767
5829
|
if (!tag) return;
|
|
5768
5830
|
collectComponentRef(tag, ctx);
|
|
5769
5831
|
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
5770
|
-
const refVar = _optionalChain([domRefBinding, 'optionalAccess',
|
|
5832
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _199 => _199.name]) || _optionalChain([refBindings, 'access', _200 => _200.componentRefs, 'access', _201 => _201[tag], 'optionalAccess', _202 => _202.name]);
|
|
5771
5833
|
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
5772
5834
|
} else {
|
|
5773
5835
|
const exp = prop.exp;
|
|
@@ -5819,7 +5881,7 @@ function resolveTemplateNodeKey(templNode, keyContent, ctx) {
|
|
|
5819
5881
|
return;
|
|
5820
5882
|
}
|
|
5821
5883
|
const [firstChild] = children;
|
|
5822
|
-
if (_optionalChain([firstChild, 'optionalAccess',
|
|
5884
|
+
if (_optionalChain([firstChild, 'optionalAccess', _203 => _203.type]) !== _compilercore.NodeTypes.ELEMENT || firstChild.tagType === _compilercore.ElementTypes.TEMPLATE || firstChild.tagType === _compilercore.ElementTypes.SLOT) {
|
|
5823
5885
|
return;
|
|
5824
5886
|
}
|
|
5825
5887
|
const hasKeyProp = firstChild.props.some(
|
|
@@ -5856,8 +5918,8 @@ function createSimpleVueBind(name, value) {
|
|
|
5856
5918
|
function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
5857
5919
|
const arg = directive.arg;
|
|
5858
5920
|
const exp = directive.exp;
|
|
5859
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5860
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
5921
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _204 => _204.content]), () => ( ""));
|
|
5922
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _205 => _205.content]), () => ( "true"));
|
|
5861
5923
|
warnUnsupportedVueDollarVar(ctx, directive);
|
|
5862
5924
|
if (name === "is") {
|
|
5863
5925
|
resolveDynamicIsProp(directive, ir, ctx, nodeIR);
|
|
@@ -5872,7 +5934,7 @@ function resolveDynamicAttributeProp(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
5872
5934
|
return;
|
|
5873
5935
|
}
|
|
5874
5936
|
const propIR = createPropsIR(directive.rawName, name, content);
|
|
5875
|
-
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5937
|
+
propIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _206 => _206.isStatic]), () => ( true));
|
|
5876
5938
|
checkPropIsDynamicKey(ctx, directive);
|
|
5877
5939
|
resolvePropertyIR(propIR, ir, ctx, nodeIR, true);
|
|
5878
5940
|
}
|
|
@@ -5911,7 +5973,7 @@ function normalizeString(s) {
|
|
|
5911
5973
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
5912
5974
|
function resolveAttributeProp(attribute, ir, ctx, nodeIR) {
|
|
5913
5975
|
const name = attribute.name;
|
|
5914
|
-
const content = _nullishCoalesce(_optionalChain([attribute, 'access',
|
|
5976
|
+
const content = _nullishCoalesce(_optionalChain([attribute, 'access', _207 => _207.value, 'optionalAccess', _208 => _208.content]), () => ( "true"));
|
|
5915
5977
|
if (name === "is") {
|
|
5916
5978
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
5917
5979
|
return;
|
|
@@ -6006,10 +6068,10 @@ function resolveRouterLinkVSlotProp(directive, nodeIR, ctx) {
|
|
|
6006
6068
|
type: 2 /* SLOT */,
|
|
6007
6069
|
name: "customRender",
|
|
6008
6070
|
rawName: _nullishCoalesce(directive.rawName, () => ( "v-slot")),
|
|
6009
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6071
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _209 => _209.isStatic]), () => ( true)),
|
|
6010
6072
|
isScoped: true,
|
|
6011
6073
|
callback: {
|
|
6012
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6074
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _210 => _210.content, 'optionalAccess', _211 => _211.trim, 'call', _212 => _212()]), () => ( "")),
|
|
6013
6075
|
exp: []
|
|
6014
6076
|
}
|
|
6015
6077
|
};
|
|
@@ -6025,10 +6087,10 @@ function resolveVFor(directive, ir, ctx, nodeIR) {
|
|
|
6025
6087
|
};
|
|
6026
6088
|
}
|
|
6027
6089
|
function resolveForResult(forParseResult) {
|
|
6028
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
6029
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
6030
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
6031
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
6090
|
+
const source = _optionalChain([forParseResult, 'access', _213 => _213.source, 'optionalAccess', _214 => _214.content]);
|
|
6091
|
+
const value = _optionalChain([forParseResult, 'access', _215 => _215.value, 'optionalAccess', _216 => _216.content]);
|
|
6092
|
+
const index = _optionalChain([forParseResult, 'access', _217 => _217.index, 'optionalAccess', _218 => _218.content]);
|
|
6093
|
+
const key = _optionalChain([forParseResult, 'access', _219 => _219.key, 'optionalAccess', _220 => _220.content]);
|
|
6032
6094
|
return {
|
|
6033
6095
|
source,
|
|
6034
6096
|
value,
|
|
@@ -6048,7 +6110,7 @@ function resolveVHtml(directive, ir, ctx, nodeIR) {
|
|
|
6048
6110
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
6049
6111
|
function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
6050
6112
|
const name = directive.name === "else-if" ? "elseIf" : directive.name;
|
|
6051
|
-
const value = _nullishCoalesce(_optionalChain([directive, 'access',
|
|
6113
|
+
const value = _nullishCoalesce(_optionalChain([directive, 'access', _221 => _221.exp, 'optionalAccess', _222 => _222.content]), () => ( "true"));
|
|
6052
6114
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
6053
6115
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
6054
6116
|
let hasError = false;
|
|
@@ -6087,7 +6149,7 @@ function resolveVIf(directive, ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
6087
6149
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
6088
6150
|
function resolveVMemo(directive, _ir, ctx, nodeIR) {
|
|
6089
6151
|
const exp = directive.exp;
|
|
6090
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
6152
|
+
let value = _optionalChain([exp, 'optionalAccess', _223 => _223.content]);
|
|
6091
6153
|
if (value !== void 0) {
|
|
6092
6154
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
6093
6155
|
const { source, filename } = ctx;
|
|
@@ -6127,14 +6189,14 @@ function resolveVModel(directive, ir, ctx, vueNode, nodeIR) {
|
|
|
6127
6189
|
const getterName = exp.content;
|
|
6128
6190
|
const isComponent = vueNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
6129
6191
|
const inputType = resolveHtmlInput(vueNode, isComponent);
|
|
6130
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6192
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _224 => _224.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
6131
6193
|
let valuePropIR;
|
|
6132
6194
|
let eventPropIR;
|
|
6133
6195
|
if (isComponent) {
|
|
6134
6196
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
6135
6197
|
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
6136
6198
|
const eventVueName = `update:${propName}`;
|
|
6137
|
-
const isTS = _optionalChain([ctx, 'access',
|
|
6199
|
+
const isTS = _optionalChain([ctx, 'access', _225 => _225.scriptData, 'optionalAccess', _226 => _226.lang, 'optionalAccess', _227 => _227.startsWith, 'call', _228 => _228("ts")]);
|
|
6138
6200
|
const valueArg = isTS ? "value: any" : "value";
|
|
6139
6201
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
6140
6202
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -6172,7 +6234,7 @@ function getRadioValue(vueNode) {
|
|
|
6172
6234
|
const valueAttr = vueNode.props.find(
|
|
6173
6235
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
6174
6236
|
);
|
|
6175
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
6237
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _229 => _229.value, 'optionalAccess', _230 => _230.content])) return '""';
|
|
6176
6238
|
const content = valueAttr.value.content;
|
|
6177
6239
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
6178
6240
|
}
|
|
@@ -6182,7 +6244,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
6182
6244
|
const typeProp = node.props.find(
|
|
6183
6245
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
6184
6246
|
);
|
|
6185
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
6247
|
+
return _optionalChain([typeProp, 'optionalAccess', _231 => _231.value, 'optionalAccess', _232 => _232.content, 'optionalAccess', _233 => _233.toLowerCase, 'call', _234 => _234()]);
|
|
6186
6248
|
}
|
|
6187
6249
|
function applyValueModifiers(valueExp, modifiers) {
|
|
6188
6250
|
let result = valueExp;
|
|
@@ -6203,7 +6265,8 @@ function resolveVOn(directive, ir, ctx, nodeIR) {
|
|
|
6203
6265
|
const modifiers = directive.modifiers.map((item) => item.content);
|
|
6204
6266
|
const captureIndex = resolveCaptureModifier(modifiers);
|
|
6205
6267
|
const eventName = resolveEventName(arg.content, captureIndex);
|
|
6206
|
-
const
|
|
6268
|
+
const handlerContent = _optionalChain([exp, 'optionalAccess', _235 => _235.content, 'optionalAccess', _236 => _236.trim, 'call', _237 => _237()]) || "undefined";
|
|
6269
|
+
const handler = resolveHandler(handlerContent, ctx, modifiers);
|
|
6207
6270
|
const originalVueEventName = modifiers.length ? `${arg.content}.${modifiers.join(".")}` : "";
|
|
6208
6271
|
const eventIR = createPropsIR(directive.rawName, eventName, handler);
|
|
6209
6272
|
eventIR.type = 3 /* EVENT */;
|
|
@@ -6253,10 +6316,10 @@ function resolveHandler(handlerContent, ctx, modifiers) {
|
|
|
6253
6316
|
return handler;
|
|
6254
6317
|
}
|
|
6255
6318
|
function isConsoleCall(expr) {
|
|
6256
|
-
return
|
|
6319
|
+
return t52.isCallExpression(expr) && t52.isMemberExpression(expr.callee) && t52.isIdentifier(expr.callee.object) && expr.callee.object.name === "console";
|
|
6257
6320
|
}
|
|
6258
6321
|
function isFnReference(expr) {
|
|
6259
|
-
return
|
|
6322
|
+
return t52.isIdentifier(expr) || t52.isMemberExpression(expr) || t52.isFunction(expr);
|
|
6260
6323
|
}
|
|
6261
6324
|
|
|
6262
6325
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-show.ts
|
|
@@ -6289,7 +6352,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6289
6352
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
6290
6353
|
const content = !isScoped ? [] : void 0;
|
|
6291
6354
|
const callback = isScoped ? {
|
|
6292
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
6355
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _238 => _238.content, 'optionalAccess', _239 => _239.trim, 'call', _240 => _240()]), () => ( "")),
|
|
6293
6356
|
exp: []
|
|
6294
6357
|
} : void 0;
|
|
6295
6358
|
checkPropIsDynamicKey(ctx, directive);
|
|
@@ -6297,7 +6360,7 @@ function resolveVSlotProp(directive, ir, ctx) {
|
|
|
6297
6360
|
type: 2 /* SLOT */,
|
|
6298
6361
|
name,
|
|
6299
6362
|
rawName: _nullishCoalesce(directive.rawName, () => ( "default")),
|
|
6300
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
6363
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _241 => _241.isStatic]), () => ( true)),
|
|
6301
6364
|
isScoped,
|
|
6302
6365
|
content,
|
|
6303
6366
|
callback
|
|
@@ -6360,7 +6423,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
6360
6423
|
if (routerAdapter) {
|
|
6361
6424
|
if (!ctx.route) ctx.route = true;
|
|
6362
6425
|
nodeIR.isRoute = true;
|
|
6363
|
-
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess',
|
|
6426
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _242 => _242.package]), routerAdapter.target);
|
|
6364
6427
|
}
|
|
6365
6428
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
6366
6429
|
return nodeIR;
|
|
@@ -6488,11 +6551,8 @@ function resolveSlotOutletNode(node, nodeIR, ctx, parentIR, childrenIR) {
|
|
|
6488
6551
|
function resolveSlotProps(node, ctx) {
|
|
6489
6552
|
const result = {
|
|
6490
6553
|
name: "children",
|
|
6491
|
-
// 默认插槽名为'children'
|
|
6492
6554
|
isScope: false,
|
|
6493
|
-
// 默认非作用域插槽
|
|
6494
6555
|
props: []
|
|
6495
|
-
// 作用域参数列表
|
|
6496
6556
|
};
|
|
6497
6557
|
const { source, filename } = ctx;
|
|
6498
6558
|
const addSlotProp = (key, value) => {
|
|
@@ -6507,7 +6567,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6507
6567
|
for (const prop of node.props) {
|
|
6508
6568
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
6509
6569
|
const attr = prop.name;
|
|
6510
|
-
const value = _optionalChain([prop, 'access',
|
|
6570
|
+
const value = _optionalChain([prop, 'access', _243 => _243.value, 'optionalAccess', _244 => _244.content, 'access', _245 => _245.trim, 'call', _246 => _246()]);
|
|
6511
6571
|
if (attr === "name" && value) {
|
|
6512
6572
|
result.name = camelCase(value);
|
|
6513
6573
|
} else {
|
|
@@ -6516,9 +6576,12 @@ function resolveSlotProps(node, ctx) {
|
|
|
6516
6576
|
continue;
|
|
6517
6577
|
}
|
|
6518
6578
|
if (prop.type === _compilercore.NodeTypes.DIRECTIVE) {
|
|
6579
|
+
warnUnsupportedVueDollarVar(ctx, prop);
|
|
6580
|
+
if (!prop.arg) {
|
|
6581
|
+
continue;
|
|
6582
|
+
}
|
|
6519
6583
|
const arg = prop.arg;
|
|
6520
6584
|
const exp = prop.exp;
|
|
6521
|
-
warnUnsupportedVueDollarVar(ctx, prop);
|
|
6522
6585
|
if (!arg.isStatic) {
|
|
6523
6586
|
logger.warn("Avoid using dynamic slot names, as they may lead to unexpected behavior.", {
|
|
6524
6587
|
source,
|
|
@@ -6527,7 +6590,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
6527
6590
|
});
|
|
6528
6591
|
}
|
|
6529
6592
|
const key = arg.content;
|
|
6530
|
-
const value = exp.content.trim();
|
|
6593
|
+
const value = _optionalChain([exp, 'optionalAccess', _247 => _247.content, 'optionalAccess', _248 => _248.trim, 'call', _249 => _249()]) || "undefined";
|
|
6531
6594
|
if (key === "name") {
|
|
6532
6595
|
result.name = camelCase(value);
|
|
6533
6596
|
} else {
|
|
@@ -6597,19 +6660,19 @@ function resolveTemplate2(root, ctx) {
|
|
|
6597
6660
|
// src/core/transform/sfc/index.ts
|
|
6598
6661
|
function transform(ast, ctx, options) {
|
|
6599
6662
|
const { template, script, style } = ast;
|
|
6600
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
6601
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
6663
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _250 => _250.ast]), ctx);
|
|
6664
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _251 => _251.ast]), ctx);
|
|
6602
6665
|
const result = {
|
|
6603
6666
|
template: templateIR,
|
|
6604
6667
|
script: scriptIR,
|
|
6605
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
6668
|
+
style: _optionalChain([style, 'optionalAccess', _252 => _252.source, 'optionalAccess', _253 => _253.content])
|
|
6606
6669
|
};
|
|
6607
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
6670
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _254 => _254.plugins]), result, ctx);
|
|
6608
6671
|
return result;
|
|
6609
6672
|
}
|
|
6610
6673
|
|
|
6611
6674
|
// package.json
|
|
6612
|
-
var version = "1.8.
|
|
6675
|
+
var version = "1.8.4";
|
|
6613
6676
|
var bin = {
|
|
6614
6677
|
vureact: "bin/vureact.js"
|
|
6615
6678
|
};
|
|
@@ -6794,7 +6857,7 @@ var Helper = (_class5 = class {
|
|
|
6794
6857
|
__init8() {this.outDir = "react-app"}
|
|
6795
6858
|
constructor(opts) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);
|
|
6796
6859
|
this.compilerOpts = opts;
|
|
6797
|
-
if (_optionalChain([opts, 'access',
|
|
6860
|
+
if (_optionalChain([opts, 'access', _255 => _255.output, 'optionalAccess', _256 => _256.workspace])) {
|
|
6798
6861
|
this.workspaceDir = opts.output.workspace;
|
|
6799
6862
|
}
|
|
6800
6863
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -6824,7 +6887,7 @@ var Helper = (_class5 = class {
|
|
|
6824
6887
|
}
|
|
6825
6888
|
getOutDirName() {
|
|
6826
6889
|
const { output } = this.compilerOpts;
|
|
6827
|
-
return _optionalChain([output, 'optionalAccess',
|
|
6890
|
+
return _optionalChain([output, 'optionalAccess', _257 => _257.outDir]) || this.outDir;
|
|
6828
6891
|
}
|
|
6829
6892
|
getWorkspaceDir() {
|
|
6830
6893
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -6838,7 +6901,7 @@ var Helper = (_class5 = class {
|
|
|
6838
6901
|
}
|
|
6839
6902
|
getIgnoreAssets() {
|
|
6840
6903
|
const { output } = this.compilerOpts;
|
|
6841
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
6904
|
+
if (_optionalChain([output, 'optionalAccess', _258 => _258.ignoreAssets])) {
|
|
6842
6905
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
6843
6906
|
}
|
|
6844
6907
|
return /* @__PURE__ */ new Set([
|
|
@@ -6928,12 +6991,12 @@ var Helper = (_class5 = class {
|
|
|
6928
6991
|
*/
|
|
6929
6992
|
async formatCode({ code, fileInfo }) {
|
|
6930
6993
|
const { format } = this.compilerOpts;
|
|
6931
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
6932
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
6994
|
+
if (!_optionalChain([format, 'optionalAccess', _259 => _259.enabled])) return code;
|
|
6995
|
+
if (_optionalChain([format, 'optionalAccess', _260 => _260.formatter]) === "builtin") {
|
|
6933
6996
|
return simpleFormat(code);
|
|
6934
6997
|
}
|
|
6935
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
6936
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
6998
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _261 => _261.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _262 => _262.script])));
|
|
6999
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _263 => _263.prettierOptions]));
|
|
6937
7000
|
}
|
|
6938
7001
|
/**
|
|
6939
7002
|
* 通用的缓存校验工具函数
|
|
@@ -6967,7 +7030,7 @@ var Helper = (_class5 = class {
|
|
|
6967
7030
|
* @param options.lock - 是否启用文件锁(默认false)
|
|
6968
7031
|
*/
|
|
6969
7032
|
async writeFileWithDir(filePath, content, options) {
|
|
6970
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
7033
|
+
if (_optionalChain([options, 'optionalAccess', _264 => _264.lock])) {
|
|
6971
7034
|
await fileLock.updateFile(filePath, async () => content, options);
|
|
6972
7035
|
} else {
|
|
6973
7036
|
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
@@ -7012,7 +7075,7 @@ var Helper = (_class5 = class {
|
|
|
7012
7075
|
* 获取需要排除编译的文件
|
|
7013
7076
|
*/
|
|
7014
7077
|
getExcludes() {
|
|
7015
|
-
if (!_optionalChain([this, 'access',
|
|
7078
|
+
if (!_optionalChain([this, 'access', _265 => _265.compilerOpts, 'access', _266 => _266.exclude, 'optionalAccess', _267 => _267.length])) {
|
|
7016
7079
|
return PathFilter.withDefaults();
|
|
7017
7080
|
}
|
|
7018
7081
|
return this.compilerOpts.exclude;
|
|
@@ -7103,7 +7166,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
7103
7166
|
ast: void 0
|
|
7104
7167
|
}
|
|
7105
7168
|
};
|
|
7106
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
7169
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _268 => _268.plugins]), result, ctx);
|
|
7107
7170
|
return result;
|
|
7108
7171
|
}
|
|
7109
7172
|
|
|
@@ -7237,16 +7300,16 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7237
7300
|
});
|
|
7238
7301
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
7239
7302
|
const resolveSFCAndScriptFile = () => {
|
|
7240
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7241
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7303
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _269 => _269.parser]) });
|
|
7304
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _270 => _270.transformer]) });
|
|
7242
7305
|
const gen = generate(ir, ctx.data, {
|
|
7243
7306
|
...genOptions,
|
|
7244
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7307
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _271 => _271.codegen])
|
|
7245
7308
|
});
|
|
7246
7309
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
7247
7310
|
};
|
|
7248
7311
|
const resolveStyleFile = () => {
|
|
7249
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
7312
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _272 => _272.parser]) });
|
|
7250
7313
|
return this.resolveStyleResult(result, ctx.data);
|
|
7251
7314
|
};
|
|
7252
7315
|
try {
|
|
@@ -7285,9 +7348,9 @@ var BaseCompiler = (_class7 = class extends Helper {
|
|
|
7285
7348
|
lang
|
|
7286
7349
|
},
|
|
7287
7350
|
css: {
|
|
7288
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
7289
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
7290
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
7351
|
+
file: _optionalChain([styleData, 'optionalAccess', _273 => _273.filePath]),
|
|
7352
|
+
hash: _optionalChain([styleData, 'optionalAccess', _274 => _274.scopeId]),
|
|
7353
|
+
code: _optionalChain([ir, 'optionalAccess', _275 => _275.style])
|
|
7291
7354
|
}
|
|
7292
7355
|
},
|
|
7293
7356
|
...base
|
|
@@ -7437,12 +7500,12 @@ var CacheManager = (_class9 = class {
|
|
|
7437
7500
|
const meta = { ...unit };
|
|
7438
7501
|
delete meta.source;
|
|
7439
7502
|
if (key === "sfc" /* SFC */) {
|
|
7440
|
-
_optionalChainDelete([meta, 'access',
|
|
7441
|
-
_optionalChainDelete([meta, 'access',
|
|
7503
|
+
_optionalChainDelete([meta, 'access', _276 => _276.output, 'optionalAccess', _277 => _277.jsx, 'access', _278 => delete _278.code]);
|
|
7504
|
+
_optionalChainDelete([meta, 'access', _279 => _279.output, 'optionalAccess', _280 => _280.css, 'access', _281 => delete _281.code]);
|
|
7442
7505
|
} else if (key === "script" /* SCRIPT */) {
|
|
7443
|
-
_optionalChainDelete([meta, 'access',
|
|
7506
|
+
_optionalChainDelete([meta, 'access', _282 => _282.output, 'optionalAccess', _283 => _283.script, 'access', _284 => delete _284.code]);
|
|
7444
7507
|
} else if (key === "style" /* STYLE */) {
|
|
7445
|
-
_optionalChainDelete([meta, 'access',
|
|
7508
|
+
_optionalChainDelete([meta, 'access', _285 => _285.output, 'optionalAccess', _286 => _286.style, 'access', _287 => delete _287.code]);
|
|
7446
7509
|
}
|
|
7447
7510
|
if (!this.pendingUpdates.has(key)) {
|
|
7448
7511
|
this.pendingUpdates.set(key, []);
|
|
@@ -7462,7 +7525,7 @@ var CacheManager = (_class9 = class {
|
|
|
7462
7525
|
}
|
|
7463
7526
|
for (const key of keys) {
|
|
7464
7527
|
const updates = this.pendingUpdates.get(key);
|
|
7465
|
-
if (!_optionalChain([updates, 'optionalAccess',
|
|
7528
|
+
if (!_optionalChain([updates, 'optionalAccess', _288 => _288.length])) continue;
|
|
7466
7529
|
const entries = [...this.cachedData[key] || []];
|
|
7467
7530
|
updates.forEach(({ unit, meta }) => {
|
|
7468
7531
|
const idx = entries.findIndex((c) => c.file === unit.file);
|
|
@@ -7623,7 +7686,7 @@ var CleanupManager = class {
|
|
|
7623
7686
|
const sfcMeta = meta;
|
|
7624
7687
|
const { jsx, css } = sfcMeta.output;
|
|
7625
7688
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
7626
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
7689
|
+
if (_optionalChain([css, 'optionalAccess', _289 => _289.file])) {
|
|
7627
7690
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
7628
7691
|
}
|
|
7629
7692
|
break;
|
|
@@ -7679,7 +7742,7 @@ var CompilationUnitProcessor = class {
|
|
|
7679
7742
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
7680
7743
|
const isStyleFile = key === "style" /* STYLE */;
|
|
7681
7744
|
if (isSFC || isScriptFile) {
|
|
7682
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
7745
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _290 => _290.hasRoute]);
|
|
7683
7746
|
}
|
|
7684
7747
|
const resolveFileInfo = () => {
|
|
7685
7748
|
if (isSFC) {
|
|
@@ -7699,7 +7762,7 @@ var CompilationUnitProcessor = class {
|
|
|
7699
7762
|
const { script } = result.fileInfo;
|
|
7700
7763
|
unit.output = {
|
|
7701
7764
|
script: {
|
|
7702
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
7765
|
+
file: _optionalChain([script, 'optionalAccess', _291 => _291.file]),
|
|
7703
7766
|
code
|
|
7704
7767
|
}
|
|
7705
7768
|
};
|
|
@@ -7776,7 +7839,7 @@ var FileProcessor = (_class10 = class {
|
|
|
7776
7839
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
7777
7840
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
7778
7841
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.cacheManager.loadCache(key);
|
|
7779
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
7842
|
+
const record = _optionalChain([cache, 'optionalAccess', _292 => _292.target, 'access', _293 => _293.find, 'call', _294 => _294((c) => c.file === absPath)]);
|
|
7780
7843
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
7781
7844
|
fileMeta,
|
|
7782
7845
|
record,
|
|
@@ -7798,10 +7861,10 @@ var FileProcessor = (_class10 = class {
|
|
|
7798
7861
|
hash: hash || this.fileCompiler.genHash(source)
|
|
7799
7862
|
};
|
|
7800
7863
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
7801
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
7864
|
+
if (_optionalChain([processed, 'optionalAccess', _295 => _295.output])) {
|
|
7802
7865
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
7803
7866
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
7804
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
7867
|
+
if (_optionalChain([processed, 'optionalAccess', _296 => _296.hasRoute])) {
|
|
7805
7868
|
await this.addRouterToPackageJson();
|
|
7806
7869
|
await this.updateEntryWithRouterProvider();
|
|
7807
7870
|
}
|
|
@@ -7818,13 +7881,13 @@ var FileProcessor = (_class10 = class {
|
|
|
7818
7881
|
*/
|
|
7819
7882
|
async addRouterToPackageJson() {
|
|
7820
7883
|
const { output } = this.fileCompiler.options;
|
|
7821
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7884
|
+
if (_optionalChain([output, 'optionalAccess', _297 => _297.bootstrapVite]) === false) {
|
|
7822
7885
|
return;
|
|
7823
7886
|
}
|
|
7824
7887
|
const { router } = RUNTIME_PACKAGES;
|
|
7825
7888
|
const filePath = this.fileCompiler.getOutputPkgPath();
|
|
7826
7889
|
const packageJson = await this.fileCompiler.resolvePackageFile(filePath);
|
|
7827
|
-
if (_optionalChain([packageJson, 'optionalAccess',
|
|
7890
|
+
if (_optionalChain([packageJson, 'optionalAccess', _298 => _298.dependencies, 'optionalAccess', _299 => _299[router.name]])) {
|
|
7828
7891
|
return;
|
|
7829
7892
|
}
|
|
7830
7893
|
if (!packageJson.dependencies) {
|
|
@@ -7843,7 +7906,7 @@ var FileProcessor = (_class10 = class {
|
|
|
7843
7906
|
const { exclude, output, router } = this.fileCompiler.options;
|
|
7844
7907
|
const inputPath = this.fileCompiler.getInputPath();
|
|
7845
7908
|
const outputPath = this.fileCompiler.getOuputPath(true);
|
|
7846
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
7909
|
+
if (_optionalChain([output, 'optionalAccess', _300 => _300.bootstrapVite]) === false || _optionalChain([router, 'optionalAccess', _301 => _301.autoUpdateEntry]) === false || !_optionalChain([router, 'optionalAccess', _302 => _302.configFile])) {
|
|
7847
7910
|
return;
|
|
7848
7911
|
}
|
|
7849
7912
|
const getMainFile = async (filename) => {
|
|
@@ -7864,7 +7927,7 @@ var FileProcessor = (_class10 = class {
|
|
|
7864
7927
|
const prepareRouterEntry = () => {
|
|
7865
7928
|
const importPath = this.fileCompiler.resolveRelativePath(inputPath, router.configFile);
|
|
7866
7929
|
let content = fileData.content;
|
|
7867
|
-
if (_optionalChain([exclude, 'optionalAccess',
|
|
7930
|
+
if (_optionalChain([exclude, 'optionalAccess', _303 => _303.includes, 'call', _304 => _304(router.configFile)]) || _optionalChain([exclude, 'optionalAccess', _305 => _305.includes, 'call', _306 => _306(importPath)])) {
|
|
7868
7931
|
return content;
|
|
7869
7932
|
}
|
|
7870
7933
|
const routerModule = "RouterInstance";
|
|
@@ -7971,7 +8034,7 @@ ${routerImport}`);
|
|
|
7971
8034
|
const resolvedPath = normalizePath(fileCompiler.relativePath(input));
|
|
7972
8035
|
const baseName = _path2.default.basename(input).toLowerCase();
|
|
7973
8036
|
const exclusions = fileCompiler.getIgnoreAssets();
|
|
7974
|
-
if (!_optionalChain([fileCompiler, 'access',
|
|
8037
|
+
if (!_optionalChain([fileCompiler, 'access', _307 => _307.options, 'access', _308 => _308.output, 'optionalAccess', _309 => _309.ignoreAssets])) {
|
|
7975
8038
|
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
7976
8039
|
if (pattern.endsWith(".")) {
|
|
7977
8040
|
return baseName.startsWith(pattern);
|
|
@@ -8107,7 +8170,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8107
8170
|
const { output } = this.options;
|
|
8108
8171
|
const workspaceDir = this.fileCompiler.getWorkspaceDir();
|
|
8109
8172
|
await _fs2.default.promises.mkdir(workspaceDir, { recursive: true });
|
|
8110
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
8173
|
+
if (_optionalChain([output, 'optionalAccess', _310 => _310.bootstrapVite]) === false) {
|
|
8111
8174
|
return false;
|
|
8112
8175
|
}
|
|
8113
8176
|
if (this.isSingleFile()) {
|
|
@@ -8147,7 +8210,7 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8147
8210
|
const newDevDeps = resolveDeps(sourcePkg.devDependencies, newPkg.devDependencies, true);
|
|
8148
8211
|
newPkg.dependencies = newDeps;
|
|
8149
8212
|
newPkg.devDependencies = newDevDeps;
|
|
8150
|
-
newPkg = _optionalChain([output, 'optionalAccess',
|
|
8213
|
+
newPkg = _optionalChain([output, 'optionalAccess', _311 => _311.packageJson, 'optionalCall', _312 => _312(newPkg)]) || newPkg;
|
|
8151
8214
|
await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
|
|
8152
8215
|
this.spinner.succeed("Vite React environment initialized");
|
|
8153
8216
|
return true;
|
|
@@ -8158,12 +8221,12 @@ var ViteBootstrapper = (_class12 = class {
|
|
|
8158
8221
|
async resolveViteCreateApp() {
|
|
8159
8222
|
const { output } = this.options;
|
|
8160
8223
|
const { viteVersion, template: tmpl } = this.defaultConfig;
|
|
8161
|
-
const bootstrapVite = _optionalChain([output, 'optionalAccess',
|
|
8224
|
+
const bootstrapVite = _optionalChain([output, 'optionalAccess', _313 => _313.bootstrapVite]);
|
|
8162
8225
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
8163
8226
|
const configObject = typeof bootstrapVite === "object" ? bootstrapVite : null;
|
|
8164
|
-
const viteVer = _optionalChain([configObject, 'optionalAccess',
|
|
8165
|
-
const reactVer = _optionalChain([configObject, 'optionalAccess',
|
|
8166
|
-
const template = _optionalChain([configObject, 'optionalAccess',
|
|
8227
|
+
const viteVer = _optionalChain([configObject, 'optionalAccess', _314 => _314.vite]) || viteVersion;
|
|
8228
|
+
const reactVer = _optionalChain([configObject, 'optionalAccess', _315 => _315.react]);
|
|
8229
|
+
const template = _optionalChain([configObject, 'optionalAccess', _316 => _316.template]) || tmpl;
|
|
8167
8230
|
const cmd = `npm create vite${viteVer} ${outDirName} -- --template ${template}`;
|
|
8168
8231
|
_child_process.execSync.call(void 0, cmd, {
|
|
8169
8232
|
cwd: this.fileCompiler.getWorkspaceDir(),
|
|
@@ -8299,7 +8362,7 @@ var FileCompiler = (_class13 = class extends BaseCompiler {
|
|
|
8299
8362
|
const assetCount = await assetManager.runAsset(scanFiles.assets, cacheMap);
|
|
8300
8363
|
this.updateSpinner("Almost done...");
|
|
8301
8364
|
await cacheManager.flushAllCache();
|
|
8302
|
-
await _optionalChain([this, 'access',
|
|
8365
|
+
await _optionalChain([this, 'access', _317 => _317.options, 'access', _318 => _318.onSuccess, 'optionalCall', _319 => _319()]);
|
|
8303
8366
|
const endTime = calcElapsedTime(startTime);
|
|
8304
8367
|
this.printCoreLogs();
|
|
8305
8368
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|