@vureact/compiler-core 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{chunk-FCLIDEIZ.js → chunk-7LBUUA24.js} +986 -861
- package/lib/{chunk-UJZGDNNB.esm.js → chunk-CUCUXW56.esm.js} +887 -762
- package/lib/cli.d.cts +1 -2
- package/lib/cli.d.ts +1 -2
- package/lib/cli.esm.js +47 -2
- package/lib/cli.js +54 -9
- package/lib/compiler-core.d.cts +9 -0
- package/lib/compiler-core.d.ts +9 -0
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +13 -5
- package/templates/route-setup-notes.md +192 -0
- package/templates/route-setup-notes.zh.md +192 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
|
|
2
|
+
* @vureact/compiler-core v1.3.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,7 +24,7 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var
|
|
27
|
+
var _types = require('@babel/types'); var t11 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
29
|
// src/consts/other.ts
|
|
30
30
|
var PACKAGE_NAME = {
|
|
@@ -312,11 +312,27 @@ var ADAPTER_RULES = {
|
|
|
312
312
|
package: PACKAGE_NAME.router,
|
|
313
313
|
type: "rename"
|
|
314
314
|
},
|
|
315
|
+
// =============== Methods ===============
|
|
315
316
|
createRouter: {
|
|
316
317
|
target: "createRouter",
|
|
317
318
|
package: PACKAGE_NAME.router,
|
|
318
319
|
type: "rename"
|
|
319
320
|
},
|
|
321
|
+
createWebHistory: {
|
|
322
|
+
target: "createWebHistory",
|
|
323
|
+
package: PACKAGE_NAME.router,
|
|
324
|
+
type: "rename"
|
|
325
|
+
},
|
|
326
|
+
createWebHashHistory: {
|
|
327
|
+
target: "createWebHashHistory",
|
|
328
|
+
package: PACKAGE_NAME.router,
|
|
329
|
+
type: "rename"
|
|
330
|
+
},
|
|
331
|
+
createMemoryHistory: {
|
|
332
|
+
target: "createMemoryHistory",
|
|
333
|
+
package: PACKAGE_NAME.router,
|
|
334
|
+
type: "rename"
|
|
335
|
+
},
|
|
320
336
|
// =============== Hooks ===============
|
|
321
337
|
useRoute: {
|
|
322
338
|
target: "useRoute",
|
|
@@ -369,6 +385,56 @@ var VUE_API_MAP = {
|
|
|
369
385
|
RouterLink: "RouterLink"
|
|
370
386
|
};
|
|
371
387
|
|
|
388
|
+
// src/shared/babel-utils.ts
|
|
389
|
+
var _parser = require('@babel/parser');
|
|
390
|
+
function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
391
|
+
const baseOptions = {
|
|
392
|
+
sourceType: "module",
|
|
393
|
+
sourceFilename: _nullishCoalesce(filename, () => ( "anonymous")),
|
|
394
|
+
errorRecovery: true
|
|
395
|
+
// 容错模式
|
|
396
|
+
};
|
|
397
|
+
const plugins = [];
|
|
398
|
+
if (lang.includes("ts")) {
|
|
399
|
+
plugins.push("typescript");
|
|
400
|
+
}
|
|
401
|
+
if (lang.endsWith("sx")) {
|
|
402
|
+
if (lang.startsWith("t")) plugins.push("typescript");
|
|
403
|
+
plugins.push("jsx");
|
|
404
|
+
}
|
|
405
|
+
if (context === "vueTemplate") {
|
|
406
|
+
plugins.push("decorators-legacy");
|
|
407
|
+
} else if (context === "expression") {
|
|
408
|
+
baseOptions.sourceType = "script";
|
|
409
|
+
baseOptions.allowReturnOutsideFunction = true;
|
|
410
|
+
baseOptions.allowSuperOutsideMethod = true;
|
|
411
|
+
}
|
|
412
|
+
plugins.push("classProperties", "objectRestSpread", "asyncGenerators");
|
|
413
|
+
return {
|
|
414
|
+
...baseOptions,
|
|
415
|
+
plugins: [...new Set(plugins)]
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function stringToExpr(input, lang, filename = "") {
|
|
419
|
+
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
420
|
+
}
|
|
421
|
+
function atComponentOrHookRoot(path8, rootScope, inScriptFile = false) {
|
|
422
|
+
const { parentPath, scope } = path8;
|
|
423
|
+
const parentBlock = scope.block;
|
|
424
|
+
if (!parentPath) return !inScriptFile;
|
|
425
|
+
if (parentBlock === rootScope) {
|
|
426
|
+
if (inScriptFile) return false;
|
|
427
|
+
if (parentPath.isBlockStatement() && parentPath.node !== rootScope) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (parentPath.isCallExpression() || parentPath.isNewExpression()) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|
|
372
438
|
// src/core/codegen/component/jsx/utils/jsx-element-utils.ts
|
|
373
439
|
|
|
374
440
|
function createJsxElement(tag, props, children, selfClosing) {
|
|
@@ -479,6 +545,81 @@ function buildJsxChildren(children, ctx) {
|
|
|
479
545
|
|
|
480
546
|
// src/core/codegen/component/jsx/syntax-processor/process/build-loop-node.ts
|
|
481
547
|
|
|
548
|
+
|
|
549
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
// src/utils/camelCase.ts
|
|
553
|
+
var camelCase = (str) => {
|
|
554
|
+
if (str.includes("-")) {
|
|
555
|
+
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
556
|
+
}
|
|
557
|
+
return str;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/utils/capitalize.ts
|
|
561
|
+
var capitalize = (str) => {
|
|
562
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/special-expressions.ts
|
|
566
|
+
function resolveSpecialExpressions(input, ctx) {
|
|
567
|
+
input = resolveEmitsCalls(input, ctx);
|
|
568
|
+
input = resolveRefVariable(input, ctx);
|
|
569
|
+
return input;
|
|
570
|
+
}
|
|
571
|
+
function resolveEmitsCalls(input, ctx) {
|
|
572
|
+
const result = matchEmitCalls(input, ctx);
|
|
573
|
+
if (!result) return input;
|
|
574
|
+
const [, , eventName, args] = result;
|
|
575
|
+
const callee = eventName.split(/[:\-]/).map((part) => capitalize(camelCase(part))).join("");
|
|
576
|
+
const event = args ? `on${callee}?.(${args})` : `on${callee}?.()`;
|
|
577
|
+
return `${ctx.propField}?.${event}`;
|
|
578
|
+
}
|
|
579
|
+
function matchEmitCalls(input, ctx) {
|
|
580
|
+
const { reactiveBindings } = ctx.templateData;
|
|
581
|
+
const macroBinding = Object.values(reactiveBindings).find((b) => b.source === "defineEmits");
|
|
582
|
+
if (!macroBinding) return null;
|
|
583
|
+
const escapedName = macroBinding.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
584
|
+
const regex = new RegExp(
|
|
585
|
+
`${escapedName}\\s*\\(\\s*(['"\`])([^\\1]*?)\\1\\s*(?:,\\s*(.*?))?\\s*\\)$`,
|
|
586
|
+
// 可选的第二个参数
|
|
587
|
+
"s"
|
|
588
|
+
// s 标志让 . 匹配换行符
|
|
589
|
+
);
|
|
590
|
+
return input.trim().match(regex);
|
|
591
|
+
}
|
|
592
|
+
function resolveRefVariable(input, ctx) {
|
|
593
|
+
const { reactiveBindings } = ctx.templateData;
|
|
594
|
+
const addValueProperty = (input2, varName) => {
|
|
595
|
+
const escapedVarName = varName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
596
|
+
const regex = new RegExp(
|
|
597
|
+
`(?<![a-zA-Z0-9_\\.])${escapedVarName}(?![a-zA-Z0-9_])(?!\\.value)`,
|
|
598
|
+
"g"
|
|
599
|
+
);
|
|
600
|
+
return input2.replace(regex, `${varName}.value`);
|
|
601
|
+
};
|
|
602
|
+
for (const name in reactiveBindings) {
|
|
603
|
+
const binding = reactiveBindings[name];
|
|
604
|
+
if (_optionalChain([binding, 'optionalAccess', _6 => _6.reactiveType]) !== "ref") continue;
|
|
605
|
+
input = addValueProperty(input, name);
|
|
606
|
+
}
|
|
607
|
+
return input;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
611
|
+
function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
612
|
+
if (toStrLiteral) return t5.stringLiteral(input);
|
|
613
|
+
const { filename, scriptData } = ctx;
|
|
614
|
+
const newContent = resolveSpecialExpressions(input, ctx);
|
|
615
|
+
try {
|
|
616
|
+
return stringToExpr(newContent, scriptData.lang, filename);
|
|
617
|
+
} catch (e2) {
|
|
618
|
+
return t5.identifier(newContent);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/core/codegen/component/jsx/syntax-processor/process/build-loop-node.ts
|
|
482
623
|
function buildLoopNode(nodeIR, ctx) {
|
|
483
624
|
const loop = nodeIR.meta.loop;
|
|
484
625
|
loop.isHandled = true;
|
|
@@ -488,15 +629,15 @@ function buildLoopNode(nodeIR, ctx) {
|
|
|
488
629
|
function buildArrayLoopNode(nodeIR, ctx) {
|
|
489
630
|
const loop = nodeIR.meta.loop;
|
|
490
631
|
const { source, value, index, key } = loop.value;
|
|
491
|
-
const
|
|
492
|
-
const params = [
|
|
632
|
+
const sourceExpression = resolveStringExpr(source, ctx);
|
|
633
|
+
const params = [t6.identifier(value)];
|
|
493
634
|
if (_nullishCoalesce(index, () => ( key))) {
|
|
494
|
-
params.push(
|
|
635
|
+
params.push(t6.identifier(_nullishCoalesce(index, () => ( key))));
|
|
495
636
|
}
|
|
496
|
-
const mapCallExpression =
|
|
497
|
-
|
|
637
|
+
const mapCallExpression = t6.callExpression(
|
|
638
|
+
t6.memberExpression(sourceExpression, t6.identifier("map")),
|
|
498
639
|
[
|
|
499
|
-
|
|
640
|
+
t6.arrowFunctionExpression(
|
|
500
641
|
params,
|
|
501
642
|
convertJsxChildToExpression(buildElementNode(nodeIR, ctx))
|
|
502
643
|
)
|
|
@@ -507,21 +648,21 @@ function buildArrayLoopNode(nodeIR, ctx) {
|
|
|
507
648
|
function buildObjectLoopNode(nodeIR, ctx) {
|
|
508
649
|
const loop = nodeIR.meta.loop;
|
|
509
650
|
const { source, value, key, index } = loop.value;
|
|
510
|
-
const
|
|
511
|
-
const objectEntriesCallExpression =
|
|
512
|
-
|
|
513
|
-
[
|
|
651
|
+
const sourceExpression = resolveStringExpr(source, ctx);
|
|
652
|
+
const objectEntriesCallExpression = t6.callExpression(
|
|
653
|
+
t6.memberExpression(t6.identifier("Object"), t6.identifier("entries")),
|
|
654
|
+
[sourceExpression]
|
|
514
655
|
);
|
|
515
656
|
const params = [
|
|
516
|
-
|
|
657
|
+
t6.arrayPattern([t6.identifier(key || "key"), t6.identifier(value)])
|
|
517
658
|
];
|
|
518
659
|
if (index) {
|
|
519
|
-
params.push(
|
|
660
|
+
params.push(t6.identifier(index));
|
|
520
661
|
}
|
|
521
|
-
const mapCallExpression =
|
|
522
|
-
|
|
662
|
+
const mapCallExpression = t6.callExpression(
|
|
663
|
+
t6.memberExpression(objectEntriesCallExpression, t6.identifier("map")),
|
|
523
664
|
[
|
|
524
|
-
|
|
665
|
+
t6.arrowFunctionExpression(
|
|
525
666
|
params,
|
|
526
667
|
convertJsxChildToExpression(buildElementNode(nodeIR, ctx))
|
|
527
668
|
)
|
|
@@ -537,8 +678,8 @@ function buildMemoNode(nodeIR, ctx) {
|
|
|
537
678
|
memo.isHandled = true;
|
|
538
679
|
const depsExpression = memo.babelExp.ast;
|
|
539
680
|
const bodyExpression = convertJsxChildToExpression(buildElementNode(nodeIR, ctx));
|
|
540
|
-
const useMemoCallExpression =
|
|
541
|
-
|
|
681
|
+
const useMemoCallExpression = t7.callExpression(t7.identifier("useMemo"), [
|
|
682
|
+
t7.arrowFunctionExpression([], bodyExpression),
|
|
542
683
|
depsExpression
|
|
543
684
|
]);
|
|
544
685
|
return buildJsxExpressionNode(useMemoCallExpression);
|
|
@@ -548,7 +689,7 @@ function buildMemoNode(nodeIR, ctx) {
|
|
|
548
689
|
|
|
549
690
|
|
|
550
691
|
// src/core/codegen/component/jsx/syntax-processor/process/build-slot-prop.ts
|
|
551
|
-
|
|
692
|
+
|
|
552
693
|
|
|
553
694
|
|
|
554
695
|
// src/shared/logger.ts
|
|
@@ -558,6 +699,9 @@ var _parser = require('@babel/parser');
|
|
|
558
699
|
var _minimatch = require('minimatch');
|
|
559
700
|
var _url = require('url');
|
|
560
701
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
702
|
+
function getDirname(metaUrl) {
|
|
703
|
+
return _path2.default.dirname(_url.fileURLToPath.call(void 0, metaUrl));
|
|
704
|
+
}
|
|
561
705
|
var PathFilter = (_class = class {
|
|
562
706
|
__init() {this.patterns = []}
|
|
563
707
|
|
|
@@ -626,7 +770,7 @@ function normalizePath(filePath) {
|
|
|
626
770
|
if (fp.startsWith("file:")) {
|
|
627
771
|
fp = _url.fileURLToPath.call(void 0, fp);
|
|
628
772
|
}
|
|
629
|
-
} catch (
|
|
773
|
+
} catch (e3) {
|
|
630
774
|
}
|
|
631
775
|
fp = fp.replace(/\\/g, "/").replace(/\/\/+/, "/");
|
|
632
776
|
return fp;
|
|
@@ -659,8 +803,8 @@ var Logger = (_class2 = class {constructor() { _class2.prototype.__init2.call(th
|
|
|
659
803
|
level,
|
|
660
804
|
message,
|
|
661
805
|
file: file ? normalizePath(relativePath(file)) : void 0,
|
|
662
|
-
line: _optionalChain([loc, 'optionalAccess',
|
|
663
|
-
column: _optionalChain([loc, 'optionalAccess',
|
|
806
|
+
line: _optionalChain([loc, 'optionalAccess', _7 => _7.start, 'optionalAccess', _8 => _8.line]),
|
|
807
|
+
column: _optionalChain([loc, 'optionalAccess', _9 => _9.start, 'optionalAccess', _10 => _10.column]),
|
|
664
808
|
source,
|
|
665
809
|
contextLines
|
|
666
810
|
};
|
|
@@ -746,9 +890,9 @@ var Logger = (_class2 = class {constructor() { _class2.prototype.__init2.call(th
|
|
|
746
890
|
return result.join("\n");
|
|
747
891
|
}
|
|
748
892
|
getOrderedLogs(opts) {
|
|
749
|
-
const errorLogs = _optionalChain([opts, 'optionalAccess',
|
|
750
|
-
const warnLogs = _optionalChain([opts, 'optionalAccess',
|
|
751
|
-
const infoLogs = _optionalChain([opts, 'optionalAccess',
|
|
893
|
+
const errorLogs = _optionalChain([opts, 'optionalAccess', _11 => _11.errors]) === false ? [] : this.logs.filter((l) => l.level === "error");
|
|
894
|
+
const warnLogs = _optionalChain([opts, 'optionalAccess', _12 => _12.warnings]) === false ? [] : this.logs.filter((l) => l.level === "warning");
|
|
895
|
+
const infoLogs = _optionalChain([opts, 'optionalAccess', _13 => _13.info]) === false ? [] : this.logs.filter((l) => l.level === "info");
|
|
752
896
|
return [...errorLogs, ...warnLogs, ...infoLogs];
|
|
753
897
|
}
|
|
754
898
|
printSummary() {
|
|
@@ -798,16 +942,16 @@ var logger = new Logger();
|
|
|
798
942
|
|
|
799
943
|
// src/core/codegen/component/jsx/syntax-processor/process/build-slot-prop.ts
|
|
800
944
|
function buildSlotProp(nodeIR, ctx) {
|
|
801
|
-
const slotKey =
|
|
802
|
-
const childrenNodeIR = !nodeIR.isScoped ? nodeIR.content : _optionalChain([nodeIR, 'access',
|
|
803
|
-
if (!_optionalChain([childrenNodeIR, 'optionalAccess',
|
|
945
|
+
const slotKey = t8.jsxIdentifier(nodeIR.name);
|
|
946
|
+
const childrenNodeIR = !nodeIR.isScoped ? nodeIR.content : _optionalChain([nodeIR, 'access', _14 => _14.callback, 'optionalAccess', _15 => _15.exp]);
|
|
947
|
+
if (!_optionalChain([childrenNodeIR, 'optionalAccess', _16 => _16.length])) {
|
|
804
948
|
return null;
|
|
805
949
|
}
|
|
806
950
|
const jsxChild = childrenNodeIR.length > 1 ? buildFragmentNode(buildJsxChildren(childrenNodeIR, ctx)) : buildJsxNode(childrenNodeIR[0], ctx);
|
|
807
951
|
if (!jsxChild) {
|
|
808
952
|
return null;
|
|
809
953
|
}
|
|
810
|
-
const slotValue = nodeIR.isScoped ?
|
|
954
|
+
const slotValue = nodeIR.isScoped ? t8.arrowFunctionExpression(
|
|
811
955
|
buildSlotCallbackParams(nodeIR, ctx),
|
|
812
956
|
convertJsxChildToExpression(jsxChild)
|
|
813
957
|
) : jsxChild;
|
|
@@ -816,32 +960,32 @@ function buildSlotProp(nodeIR, ctx) {
|
|
|
816
960
|
}
|
|
817
961
|
if (!nodeIR.isStatic) {
|
|
818
962
|
const dynamicSlotKey = _parser.parseExpression.call(void 0, nodeIR.name);
|
|
819
|
-
const spreadObject =
|
|
820
|
-
|
|
963
|
+
const spreadObject = t8.objectExpression([
|
|
964
|
+
t8.objectProperty(dynamicSlotKey, convertSlotValueToExpression(slotValue), true)
|
|
821
965
|
]);
|
|
822
|
-
return
|
|
966
|
+
return t8.jsxSpreadAttribute(spreadObject);
|
|
823
967
|
}
|
|
824
|
-
return
|
|
968
|
+
return t8.jsxAttribute(slotKey, buildJsxExpressionNode(convertSlotValueToExpression(slotValue)));
|
|
825
969
|
}
|
|
826
970
|
function convertSlotValueToExpression(nodeIR) {
|
|
827
|
-
if (
|
|
971
|
+
if (t8.isArrowFunctionExpression(nodeIR)) {
|
|
828
972
|
return nodeIR;
|
|
829
973
|
}
|
|
830
974
|
return convertJsxChildToExpression(nodeIR);
|
|
831
975
|
}
|
|
832
976
|
function buildSlotCallbackParams(nodeIR, ctx) {
|
|
833
|
-
const rawArg = _optionalChain([nodeIR, 'access',
|
|
977
|
+
const rawArg = _optionalChain([nodeIR, 'access', _17 => _17.callback, 'optionalAccess', _18 => _18.arg, 'optionalAccess', _19 => _19.trim, 'call', _20 => _20()]);
|
|
834
978
|
if (!rawArg) {
|
|
835
979
|
return [];
|
|
836
980
|
}
|
|
837
981
|
const source = rawArg.startsWith("(") ? `${rawArg} => null` : `(${rawArg}) => null`;
|
|
838
982
|
try {
|
|
839
983
|
const expression = _parser.parseExpression.call(void 0, source);
|
|
840
|
-
if (!
|
|
984
|
+
if (!t8.isArrowFunctionExpression(expression)) {
|
|
841
985
|
return [];
|
|
842
986
|
}
|
|
843
987
|
return expression.params;
|
|
844
|
-
} catch (
|
|
988
|
+
} catch (e4) {
|
|
845
989
|
logger.warn(`Failed to parse slot params "${rawArg}". Falling back to no-arg slot function.`, {
|
|
846
990
|
file: ctx.filename
|
|
847
991
|
});
|
|
@@ -880,13 +1024,13 @@ function buildStandardProp(nodeIR) {
|
|
|
880
1024
|
}
|
|
881
1025
|
} = nodeIR;
|
|
882
1026
|
if (!isStatic || isKeyLessVBind) {
|
|
883
|
-
return
|
|
1027
|
+
return t9.jsxSpreadAttribute(valueAST);
|
|
884
1028
|
}
|
|
885
1029
|
let value;
|
|
886
1030
|
if (content !== "true") {
|
|
887
|
-
value = isStringLiteral13 ?
|
|
1031
|
+
value = isStringLiteral13 ? t9.stringLiteral(content) : buildJsxExpressionNode(valueAST);
|
|
888
1032
|
}
|
|
889
|
-
return
|
|
1033
|
+
return t9.jsxAttribute(keyAST, value);
|
|
890
1034
|
}
|
|
891
1035
|
|
|
892
1036
|
// src/core/codegen/component/jsx/syntax-processor/process/build-element-node.ts
|
|
@@ -896,13 +1040,13 @@ function buildElementNode(nodeIR, ctx) {
|
|
|
896
1040
|
return null;
|
|
897
1041
|
}
|
|
898
1042
|
const meta = nodeIR.meta;
|
|
899
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1043
|
+
if (_optionalChain([meta, 'optionalAccess', _21 => _21.condition]) && !meta.condition.isHandled) {
|
|
900
1044
|
return buildConditionNode(nodeIR, ctx);
|
|
901
1045
|
}
|
|
902
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1046
|
+
if (_optionalChain([meta, 'optionalAccess', _22 => _22.memo, 'optionalAccess', _23 => _23.isMemo]) && !meta.memo.isHandled) {
|
|
903
1047
|
return buildMemoNode(nodeIR, ctx);
|
|
904
1048
|
}
|
|
905
|
-
if (_optionalChain([meta, 'optionalAccess',
|
|
1049
|
+
if (_optionalChain([meta, 'optionalAccess', _24 => _24.loop, 'optionalAccess', _25 => _25.isLoop]) && !meta.loop.isHandled) {
|
|
906
1050
|
return buildLoopNode(nodeIR, ctx);
|
|
907
1051
|
}
|
|
908
1052
|
const props = buildProps(nodeIR, ctx);
|
|
@@ -932,8 +1076,8 @@ function buildConditionNode(nodeIR, ctx) {
|
|
|
932
1076
|
}
|
|
933
1077
|
const testExpression = condition.babelExp.ast;
|
|
934
1078
|
const trueBranchExpression = convertJsxChildToExpression(buildCurrentNode());
|
|
935
|
-
const falseBranchExpression = nextNodeIR ? convertJsxChildToExpression(buildElementNode(nextNodeIR, ctx)) :
|
|
936
|
-
const conditionalExpression2 =
|
|
1079
|
+
const falseBranchExpression = nextNodeIR ? convertJsxChildToExpression(buildElementNode(nextNodeIR, ctx)) : t10.nullLiteral();
|
|
1080
|
+
const conditionalExpression2 = t10.conditionalExpression(
|
|
937
1081
|
testExpression,
|
|
938
1082
|
// 条件测试部分
|
|
939
1083
|
trueBranchExpression,
|
|
@@ -949,20 +1093,28 @@ function buildConditionNode(nodeIR, ctx) {
|
|
|
949
1093
|
function buildCtxProviderNode(nodeIR, ctx, children) {
|
|
950
1094
|
const { name, value, provide: nextProvide } = nodeIR;
|
|
951
1095
|
let childNodes = children;
|
|
952
|
-
if (_optionalChain([nextProvide, 'optionalAccess',
|
|
1096
|
+
if (_optionalChain([nextProvide, 'optionalAccess', _26 => _26.isOccupied])) {
|
|
953
1097
|
childNodes = [buildCtxProviderNode(nextProvide, ctx, children)];
|
|
954
1098
|
}
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
1099
|
+
const parseProviderExpr = (raw) => {
|
|
1100
|
+
if (!raw) return t11.stringLiteral("");
|
|
1101
|
+
try {
|
|
1102
|
+
return stringToExpr(raw, ctx.scriptData.lang, ctx.filename);
|
|
1103
|
+
} catch (e5) {
|
|
1104
|
+
return t11.stringLiteral(raw);
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
const nameProp = t11.jsxAttribute(
|
|
1108
|
+
t11.jsxIdentifier("name"),
|
|
1109
|
+
buildJsxExpressionNode(parseProviderExpr(name))
|
|
958
1110
|
);
|
|
959
|
-
const valueProp =
|
|
960
|
-
|
|
961
|
-
buildJsxExpressionNode(
|
|
1111
|
+
const valueProp = t11.jsxAttribute(
|
|
1112
|
+
t11.jsxIdentifier("value"),
|
|
1113
|
+
buildJsxExpressionNode(parseProviderExpr(value))
|
|
962
1114
|
);
|
|
963
1115
|
void ctx;
|
|
964
1116
|
const adpater = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
965
|
-
return createJsxElement(adpater.target, [
|
|
1117
|
+
return createJsxElement(adpater.target, [nameProp, valueProp], childNodes);
|
|
966
1118
|
}
|
|
967
1119
|
|
|
968
1120
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-root-jsx.ts
|
|
@@ -1004,7 +1156,7 @@ function jsxBuilder(nodeIR, ctx, state, options) {
|
|
|
1004
1156
|
|
|
1005
1157
|
// src/core/codegen/component/jsx/index.ts
|
|
1006
1158
|
function buildJSX(nodeIR, ctx) {
|
|
1007
|
-
if (!_optionalChain([nodeIR, 'optionalAccess',
|
|
1159
|
+
if (!_optionalChain([nodeIR, 'optionalAccess', _27 => _27.children, 'access', _28 => _28.length])) {
|
|
1008
1160
|
return null;
|
|
1009
1161
|
}
|
|
1010
1162
|
return buildJSXChild(nodeIR, ctx);
|
|
@@ -1018,16 +1170,16 @@ function buildJSX(nodeIR, ctx) {
|
|
|
1018
1170
|
function buildProgramNode(nodeIR, ctx, state) {
|
|
1019
1171
|
const statements = [...state.preambleStatements];
|
|
1020
1172
|
if (!state.component) {
|
|
1021
|
-
state.result =
|
|
1173
|
+
state.result = t12.program(statements, void 0, "module");
|
|
1022
1174
|
return;
|
|
1023
1175
|
}
|
|
1024
1176
|
statements.push(state.component);
|
|
1025
1177
|
if (state.expose) {
|
|
1026
1178
|
const [declarator] = state.component.declarations;
|
|
1027
1179
|
const { name } = declarator.id;
|
|
1028
|
-
statements.push(
|
|
1180
|
+
statements.push(t12.exportDefaultDeclaration(t12.identifier(name)));
|
|
1029
1181
|
}
|
|
1030
|
-
state.result =
|
|
1182
|
+
state.result = t12.program(statements, void 0, "module");
|
|
1031
1183
|
void nodeIR;
|
|
1032
1184
|
void ctx;
|
|
1033
1185
|
}
|
|
@@ -1047,19 +1199,6 @@ var REACT_API_MAP = {
|
|
|
1047
1199
|
useImperativeHandle: "useImperativeHandle"
|
|
1048
1200
|
};
|
|
1049
1201
|
|
|
1050
|
-
// src/utils/camelCase.ts
|
|
1051
|
-
var camelCase = (str) => {
|
|
1052
|
-
if (str.includes("-")) {
|
|
1053
|
-
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
1054
|
-
}
|
|
1055
|
-
return str;
|
|
1056
|
-
};
|
|
1057
|
-
|
|
1058
|
-
// src/utils/capitalize.ts
|
|
1059
|
-
var capitalize = (str) => {
|
|
1060
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1061
|
-
};
|
|
1062
|
-
|
|
1063
1202
|
// src/utils/hash.ts
|
|
1064
1203
|
var _xxhashjs = require('xxhashjs'); var _xxhashjs2 = _interopRequireDefault(_xxhashjs);
|
|
1065
1204
|
function genHashByXXH(str) {
|
|
@@ -1083,7 +1222,7 @@ function buildComponent(scriptIR, ctx, state) {
|
|
|
1083
1222
|
} = ctx;
|
|
1084
1223
|
const hasProps = getHasProps(propsTSIface.propsTypes) || getHasProps(propsTSIface.emitTypes) || getHasProps(propsTSIface.slotTypes);
|
|
1085
1224
|
const shouldMemo = scriptIR !== null || hasProps;
|
|
1086
|
-
const jsxStatement =
|
|
1225
|
+
const jsxStatement = t13.returnStatement(state.jsx || t13.nullLiteral());
|
|
1087
1226
|
const component = !shouldMemo ? resolvePureUIComponent(jsxStatement, ctx) : resolveMemoComponent(scriptIR.statement.local, jsxStatement, ctx);
|
|
1088
1227
|
state.component = component;
|
|
1089
1228
|
}
|
|
@@ -1091,24 +1230,24 @@ function getHasProps(list) {
|
|
|
1091
1230
|
return list.length > 0;
|
|
1092
1231
|
}
|
|
1093
1232
|
function resolvePureUIComponent(jsxStmt, ctx) {
|
|
1094
|
-
return
|
|
1095
|
-
|
|
1233
|
+
return t13.variableDeclaration("const", [
|
|
1234
|
+
t13.variableDeclarator(
|
|
1096
1235
|
resolveComponentName(ctx),
|
|
1097
|
-
|
|
1236
|
+
t13.arrowFunctionExpression([], t13.blockStatement([jsxStmt]))
|
|
1098
1237
|
)
|
|
1099
1238
|
]);
|
|
1100
1239
|
}
|
|
1101
1240
|
function resolveMemoComponent(local, jsxStmt, ctx) {
|
|
1102
1241
|
const name = resolveComponentName(ctx);
|
|
1103
1242
|
const param = resolvePropsParam(ctx);
|
|
1104
|
-
const body =
|
|
1243
|
+
const body = t13.blockStatement(resolveLocalStatements(local, jsxStmt));
|
|
1105
1244
|
const component = resolveComponent(param, body, ctx);
|
|
1106
1245
|
let compFn = component;
|
|
1107
1246
|
if (ctx.scriptData.forwardRef.enabled) {
|
|
1108
1247
|
compFn = resolveForwardRef(body, ctx);
|
|
1109
1248
|
}
|
|
1110
|
-
const memoCall =
|
|
1111
|
-
return
|
|
1249
|
+
const memoCall = t13.callExpression(t13.identifier(REACT_API_MAP.memo), [compFn]);
|
|
1250
|
+
return t13.variableDeclaration("const", [t13.variableDeclarator(name, memoCall)]);
|
|
1112
1251
|
}
|
|
1113
1252
|
function resolveComponentName(ctx) {
|
|
1114
1253
|
const { filename, compName } = ctx;
|
|
@@ -1122,14 +1261,14 @@ function resolveComponentName(ctx) {
|
|
|
1122
1261
|
file: filename
|
|
1123
1262
|
});
|
|
1124
1263
|
}
|
|
1125
|
-
return
|
|
1264
|
+
return t13.identifier(name);
|
|
1126
1265
|
}
|
|
1127
1266
|
function resolveLocalStatements(local, jsx) {
|
|
1128
1267
|
const stmts = [jsx];
|
|
1129
1268
|
if (!local) return stmts;
|
|
1130
1269
|
if (typeof local === "object" && "program" in local) {
|
|
1131
1270
|
const program3 = local.program;
|
|
1132
|
-
if (_optionalChain([program3, 'optionalAccess',
|
|
1271
|
+
if (_optionalChain([program3, 'optionalAccess', _29 => _29.body, 'optionalAccess', _30 => _30.length])) {
|
|
1133
1272
|
return [...program3.body, jsx];
|
|
1134
1273
|
}
|
|
1135
1274
|
}
|
|
@@ -1142,7 +1281,7 @@ function resolveComponent(param, body, ctx) {
|
|
|
1142
1281
|
if (forwardRef.enabled) {
|
|
1143
1282
|
return resolveForwardRef(body, ctx);
|
|
1144
1283
|
}
|
|
1145
|
-
const baseComponent =
|
|
1284
|
+
const baseComponent = t13.arrowFunctionExpression(!param ? [] : [param], body);
|
|
1146
1285
|
return baseComponent;
|
|
1147
1286
|
}
|
|
1148
1287
|
function resolveForwardRef(body, ctx) {
|
|
@@ -1150,18 +1289,18 @@ function resolveForwardRef(body, ctx) {
|
|
|
1150
1289
|
propField,
|
|
1151
1290
|
scriptData: { forwardRef, lang }
|
|
1152
1291
|
} = ctx;
|
|
1153
|
-
const params = [
|
|
1292
|
+
const params = [t13.identifier(forwardRef.refField)];
|
|
1154
1293
|
const propsId = resolvePropsParam(ctx);
|
|
1155
|
-
const callExpr =
|
|
1156
|
-
|
|
1294
|
+
const callExpr = t13.callExpression(t13.identifier(REACT_API_MAP.forwardRef), [
|
|
1295
|
+
t13.arrowFunctionExpression(params, body)
|
|
1157
1296
|
]);
|
|
1158
1297
|
if (lang.startsWith("ts")) {
|
|
1159
|
-
const types = [
|
|
1298
|
+
const types = [t13.tsAnyKeyword()];
|
|
1160
1299
|
if (propsId) {
|
|
1161
|
-
const propsType = _optionalChain([propsId, 'optionalAccess',
|
|
1162
|
-
types.push(propsType ||
|
|
1300
|
+
const propsType = _optionalChain([propsId, 'optionalAccess', _31 => _31.typeAnnotation, 'optionalAccess', _32 => _32.typeAnnotation]);
|
|
1301
|
+
types.push(propsType || t13.tsAnyKeyword());
|
|
1163
1302
|
}
|
|
1164
|
-
callExpr.typeParameters =
|
|
1303
|
+
callExpr.typeParameters = t13.tsTypeParameterInstantiation(types);
|
|
1165
1304
|
}
|
|
1166
1305
|
if (propsId) {
|
|
1167
1306
|
propsId.typeAnnotation = null;
|
|
@@ -1172,7 +1311,7 @@ function resolveForwardRef(body, ctx) {
|
|
|
1172
1311
|
function resolvePropsParam(ctx) {
|
|
1173
1312
|
const { propField, scriptData } = ctx;
|
|
1174
1313
|
const { propsTSIface } = scriptData;
|
|
1175
|
-
const propsIdentifier =
|
|
1314
|
+
const propsIdentifier = t13.identifier(propField);
|
|
1176
1315
|
if (scriptData.lang.startsWith("js")) {
|
|
1177
1316
|
if (propsTSIface.hasPropsInJsEnv) {
|
|
1178
1317
|
return propsIdentifier;
|
|
@@ -1182,14 +1321,14 @@ function resolvePropsParam(ctx) {
|
|
|
1182
1321
|
if (!propsTSIface.name) {
|
|
1183
1322
|
return;
|
|
1184
1323
|
}
|
|
1185
|
-
const typeIdentifier =
|
|
1186
|
-
propsIdentifier.typeAnnotation =
|
|
1324
|
+
const typeIdentifier = t13.identifier(propsTSIface.name);
|
|
1325
|
+
propsIdentifier.typeAnnotation = t13.tsTypeAnnotation(t13.tsTypeReference(typeIdentifier));
|
|
1187
1326
|
return propsIdentifier;
|
|
1188
1327
|
}
|
|
1189
1328
|
|
|
1190
1329
|
// src/core/codegen/component/script/syntax-processor/process/build-program-preamble.ts
|
|
1191
1330
|
function buildProgramPreamble(nodeIR, ctx, state) {
|
|
1192
|
-
const statements = [_optionalChain([nodeIR, 'optionalAccess',
|
|
1331
|
+
const statements = [_optionalChain([nodeIR, 'optionalAccess', _33 => _33.imports]), _optionalChain([nodeIR, 'optionalAccess', _34 => _34.tsTypes]), _optionalChain([nodeIR, 'optionalAccess', _35 => _35.exports]), _optionalChain([nodeIR, 'optionalAccess', _36 => _36.statement, 'access', _37 => _37.global])].flat().filter(Boolean);
|
|
1193
1332
|
state.preambleStatements = statements;
|
|
1194
1333
|
void ctx;
|
|
1195
1334
|
}
|
|
@@ -1208,7 +1347,7 @@ function buildScriptSyntax(nodeIR, ctx, jsx, expose = true) {
|
|
|
1208
1347
|
process: [buildProgramPreamble, buildComponent],
|
|
1209
1348
|
postprocess: [buildProgramNode]
|
|
1210
1349
|
});
|
|
1211
|
-
return state.result ||
|
|
1350
|
+
return state.result || t14.program([], void 0, "module");
|
|
1212
1351
|
}
|
|
1213
1352
|
function scriptSyntaxProcessor(nodeIR, ctx, state, options) {
|
|
1214
1353
|
const run = (p) => {
|
|
@@ -1244,7 +1383,7 @@ function generateComponent(ir, ctx, options) {
|
|
|
1244
1383
|
code,
|
|
1245
1384
|
source: ctx.source
|
|
1246
1385
|
};
|
|
1247
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1386
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _38 => _38.plugins]), result, ctx);
|
|
1248
1387
|
return result;
|
|
1249
1388
|
}
|
|
1250
1389
|
|
|
@@ -1258,7 +1397,7 @@ function generateOnlyScript(ir, ctx, options) {
|
|
|
1258
1397
|
code,
|
|
1259
1398
|
source: ctx.source
|
|
1260
1399
|
};
|
|
1261
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1400
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _39 => _39.plugins]), result, ctx);
|
|
1262
1401
|
return result;
|
|
1263
1402
|
}
|
|
1264
1403
|
|
|
@@ -1270,58 +1409,6 @@ function generate(ir, ctx, options) {
|
|
|
1270
1409
|
|
|
1271
1410
|
// src/core/parse/script-only.ts
|
|
1272
1411
|
|
|
1273
|
-
|
|
1274
|
-
// src/shared/babel-utils.ts
|
|
1275
|
-
|
|
1276
|
-
function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
1277
|
-
const baseOptions = {
|
|
1278
|
-
sourceType: "module",
|
|
1279
|
-
sourceFilename: _nullishCoalesce(filename, () => ( "anonymous")),
|
|
1280
|
-
errorRecovery: true
|
|
1281
|
-
// 容错模式
|
|
1282
|
-
};
|
|
1283
|
-
const plugins = [];
|
|
1284
|
-
if (lang.includes("ts")) {
|
|
1285
|
-
plugins.push("typescript");
|
|
1286
|
-
}
|
|
1287
|
-
if (lang.endsWith("sx")) {
|
|
1288
|
-
if (lang.startsWith("t")) plugins.push("typescript");
|
|
1289
|
-
plugins.push("jsx");
|
|
1290
|
-
}
|
|
1291
|
-
if (context === "vueTemplate") {
|
|
1292
|
-
plugins.push("decorators-legacy");
|
|
1293
|
-
} else if (context === "expression") {
|
|
1294
|
-
baseOptions.sourceType = "script";
|
|
1295
|
-
baseOptions.allowReturnOutsideFunction = true;
|
|
1296
|
-
baseOptions.allowSuperOutsideMethod = true;
|
|
1297
|
-
}
|
|
1298
|
-
plugins.push("classProperties", "objectRestSpread", "asyncGenerators");
|
|
1299
|
-
return {
|
|
1300
|
-
...baseOptions,
|
|
1301
|
-
plugins: [...new Set(plugins)]
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
|
-
function stringToExpr(input, lang, filename = "") {
|
|
1305
|
-
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
1306
|
-
}
|
|
1307
|
-
function atComponentOrHookRoot(path7, rootScope, inScriptFile = false) {
|
|
1308
|
-
const { parentPath, scope } = path7;
|
|
1309
|
-
const parentBlock = scope.block;
|
|
1310
|
-
if (!parentPath) return !inScriptFile;
|
|
1311
|
-
if (parentBlock === rootScope) {
|
|
1312
|
-
if (inScriptFile) return false;
|
|
1313
|
-
if (parentPath.isBlockStatement() && parentPath.node !== rootScope) {
|
|
1314
|
-
return false;
|
|
1315
|
-
}
|
|
1316
|
-
if (parentPath.isCallExpression() || parentPath.isNewExpression()) {
|
|
1317
|
-
return false;
|
|
1318
|
-
}
|
|
1319
|
-
return true;
|
|
1320
|
-
}
|
|
1321
|
-
return false;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
// src/core/parse/script-only.ts
|
|
1325
1412
|
function parseOnlyScript(source, ctx, options) {
|
|
1326
1413
|
const lang = ctx.inputType.split("-")[1];
|
|
1327
1414
|
const ast = _parser.parse.call(void 0, source, getBabelParseOptions(lang, "script", ctx.filename));
|
|
@@ -1343,7 +1430,7 @@ function parseOnlyScript(source, ctx, options) {
|
|
|
1343
1430
|
};
|
|
1344
1431
|
ctx.scriptData.lang = lang;
|
|
1345
1432
|
ctx.scriptData.source = source;
|
|
1346
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1433
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _40 => _40.plugins]), result, ctx);
|
|
1347
1434
|
return result;
|
|
1348
1435
|
}
|
|
1349
1436
|
|
|
@@ -1378,8 +1465,8 @@ function resolveScript(descriptor, ctx, pResult) {
|
|
|
1378
1465
|
} else {
|
|
1379
1466
|
result.ast = _parser.parse.call(void 0, result.source.content, options);
|
|
1380
1467
|
}
|
|
1381
|
-
if (_optionalChain([scriptBlock, 'optionalAccess',
|
|
1382
|
-
_optionalChain([scriptBlock, 'optionalAccess',
|
|
1468
|
+
if (_optionalChain([scriptBlock, 'optionalAccess', _41 => _41.warnings])) {
|
|
1469
|
+
_optionalChain([scriptBlock, 'optionalAccess', _42 => _42.warnings, 'access', _43 => _43.forEach, 'call', _44 => _44((msg) => {
|
|
1383
1470
|
logger.warn(msg, { file: ctx.filename });
|
|
1384
1471
|
})]);
|
|
1385
1472
|
}
|
|
@@ -1397,41 +1484,41 @@ function extractSetupBodyToTopLevel(content, options) {
|
|
|
1397
1484
|
const otherTopLevel = [];
|
|
1398
1485
|
let setupStatements = [];
|
|
1399
1486
|
for (const node of ast.program.body) {
|
|
1400
|
-
if (
|
|
1487
|
+
if (t15.isImportDeclaration(node)) {
|
|
1401
1488
|
importNodes.push(node);
|
|
1402
1489
|
continue;
|
|
1403
1490
|
}
|
|
1404
|
-
if (
|
|
1491
|
+
if (t15.isExportDefaultDeclaration(node)) {
|
|
1405
1492
|
const decl = node.declaration;
|
|
1406
|
-
if (decl &&
|
|
1493
|
+
if (decl && t15.isObjectExpression(decl)) {
|
|
1407
1494
|
const nameProp = decl.properties.find((p) => {
|
|
1408
|
-
if (
|
|
1495
|
+
if (t15.isObjectProperty(p)) {
|
|
1409
1496
|
const key = p.key;
|
|
1410
|
-
return
|
|
1497
|
+
return t15.isIdentifier(key) && key.name === "name" || t15.isStringLiteral(key) && key.value === "name";
|
|
1411
1498
|
}
|
|
1412
1499
|
return false;
|
|
1413
1500
|
});
|
|
1414
|
-
if (nameProp &&
|
|
1415
|
-
if (
|
|
1501
|
+
if (nameProp && t15.isObjectProperty(nameProp)) {
|
|
1502
|
+
if (t15.isStringLiteral(nameProp.value)) {
|
|
1416
1503
|
name = nameProp.value.value;
|
|
1417
1504
|
}
|
|
1418
1505
|
}
|
|
1419
1506
|
const setupProp = decl.properties.find((p) => {
|
|
1420
|
-
if (
|
|
1507
|
+
if (t15.isObjectMethod(p)) {
|
|
1421
1508
|
return p.key && p.key.name === "setup";
|
|
1422
1509
|
}
|
|
1423
|
-
if (
|
|
1510
|
+
if (t15.isObjectProperty(p)) {
|
|
1424
1511
|
const key = p.key;
|
|
1425
|
-
return
|
|
1512
|
+
return t15.isIdentifier(key) && key.name === "setup" || t15.isStringLiteral(key) && key.value === "setup";
|
|
1426
1513
|
}
|
|
1427
1514
|
return false;
|
|
1428
1515
|
});
|
|
1429
1516
|
if (setupProp) {
|
|
1430
|
-
const value =
|
|
1431
|
-
if (value && (
|
|
1432
|
-
const fnBody =
|
|
1517
|
+
const value = t15.isObjectMethod(setupProp) ? setupProp : t15.isObjectProperty(setupProp) ? setupProp.value : null;
|
|
1518
|
+
if (value && (t15.isFunction(value) || t15.isObjectMethod(value))) {
|
|
1519
|
+
const fnBody = t15.isBlockStatement(value.body) ? value.body.body : [];
|
|
1433
1520
|
for (const stmt of fnBody) {
|
|
1434
|
-
if (
|
|
1521
|
+
if (t15.isReturnStatement(stmt)) continue;
|
|
1435
1522
|
setupStatements.push(stmt);
|
|
1436
1523
|
}
|
|
1437
1524
|
}
|
|
@@ -1454,7 +1541,7 @@ function extractSetupBodyToTopLevel(content, options) {
|
|
|
1454
1541
|
}
|
|
1455
1542
|
function extractCompName(source) {
|
|
1456
1543
|
const nameMatch = source.match(/@vr-name:\s*(\w+)/);
|
|
1457
|
-
return _optionalChain([nameMatch, 'optionalAccess',
|
|
1544
|
+
return _optionalChain([nameMatch, 'optionalAccess', _45 => _45[1], 'optionalAccess', _46 => _46.trim, 'call', _47 => _47()]) || "";
|
|
1458
1545
|
}
|
|
1459
1546
|
|
|
1460
1547
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
@@ -1560,15 +1647,15 @@ function getReactiveStateApis() {
|
|
|
1560
1647
|
|
|
1561
1648
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
1562
1649
|
function resolveScriptMeta(result, ctx) {
|
|
1563
|
-
const scriptAST = _optionalChain([result, 'access',
|
|
1650
|
+
const scriptAST = _optionalChain([result, 'access', _48 => _48.script, 'optionalAccess', _49 => _49.ast]);
|
|
1564
1651
|
if (!scriptAST) return;
|
|
1565
1652
|
_core.traverse.call(void 0, scriptAST, {
|
|
1566
|
-
VariableDeclarator(
|
|
1567
|
-
const { node } =
|
|
1568
|
-
if (!atComponentOrHookRoot(
|
|
1653
|
+
VariableDeclarator(path8) {
|
|
1654
|
+
const { node } = path8;
|
|
1655
|
+
if (!atComponentOrHookRoot(path8, scriptAST.program) || !t16.isIdentifier(node.id)) {
|
|
1569
1656
|
return;
|
|
1570
1657
|
}
|
|
1571
|
-
if (node.init &&
|
|
1658
|
+
if (node.init && t16.isCallExpression(node.init) && t16.isIdentifier(node.init.callee)) {
|
|
1572
1659
|
collectReactiveBindings(node, ctx);
|
|
1573
1660
|
collectRefBindings(node, ctx);
|
|
1574
1661
|
}
|
|
@@ -1600,7 +1687,7 @@ function collectRefBindings(node, ctx) {
|
|
|
1600
1687
|
const callee = init.callee;
|
|
1601
1688
|
if (callee.name !== VUE_API_MAP.useTemplateRef) return;
|
|
1602
1689
|
const idName = node.id.name;
|
|
1603
|
-
const tag = _optionalChain([init, 'access',
|
|
1690
|
+
const tag = _optionalChain([init, 'access', _50 => _50.arguments, 'access', _51 => _51[0], 'optionalAccess', _52 => _52.value]);
|
|
1604
1691
|
refBindings.domRefs[idName] = {
|
|
1605
1692
|
tag,
|
|
1606
1693
|
htmlType: HTML_TAG_TYPES[tag] || "HTMLElement",
|
|
@@ -1774,7 +1861,7 @@ function resolveStyles(descriptor, ctx, result) {
|
|
|
1774
1861
|
var _compilercore = require('@vue/compiler-core');
|
|
1775
1862
|
function resolveTemplate(descriptor, _, result) {
|
|
1776
1863
|
const block = descriptor.template;
|
|
1777
|
-
if (!_optionalChain([block, 'optionalAccess',
|
|
1864
|
+
if (!_optionalChain([block, 'optionalAccess', _53 => _53.content])) return null;
|
|
1778
1865
|
result.template = {
|
|
1779
1866
|
ast: _compilercore.baseParse.call(void 0, block.content),
|
|
1780
1867
|
source: block
|
|
@@ -1791,7 +1878,7 @@ function processVueSyntax(descriptor, ctx, result) {
|
|
|
1791
1878
|
}
|
|
1792
1879
|
function vueSyntaxProcessor(descriptor, ctx, result, options) {
|
|
1793
1880
|
const run = (p, type) => {
|
|
1794
|
-
_optionalChain([p, 'optionalAccess',
|
|
1881
|
+
_optionalChain([p, 'optionalAccess', _54 => _54.forEach, 'call', _55 => _55((handler) => {
|
|
1795
1882
|
if (type === "post") {
|
|
1796
1883
|
handler(result, ctx);
|
|
1797
1884
|
return;
|
|
@@ -1815,7 +1902,7 @@ function parseSFC(source, ctx, options) {
|
|
|
1815
1902
|
};
|
|
1816
1903
|
collectErrs(descriptor, errors);
|
|
1817
1904
|
processVueSyntax(descriptor, ctx, result);
|
|
1818
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1905
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _56 => _56.plugins]), result, ctx);
|
|
1819
1906
|
return result;
|
|
1820
1907
|
}
|
|
1821
1908
|
function collectErrs(descriptor, errors) {
|
|
@@ -1823,7 +1910,7 @@ function collectErrs(descriptor, errors) {
|
|
|
1823
1910
|
logger.error(err.message, {
|
|
1824
1911
|
source: descriptor.source,
|
|
1825
1912
|
file: descriptor.filename,
|
|
1826
|
-
loc: _optionalChain([err, 'optionalAccess',
|
|
1913
|
+
loc: _optionalChain([err, 'optionalAccess', _57 => _57.loc])
|
|
1827
1914
|
});
|
|
1828
1915
|
}
|
|
1829
1916
|
if (descriptor.cssVars.length) {
|
|
@@ -1855,9 +1942,9 @@ function insertCSSImport(ctx) {
|
|
|
1855
1942
|
const scriptIR = getScriptIR(ctx);
|
|
1856
1943
|
const filename = normalizePath(filePath).split("/").pop();
|
|
1857
1944
|
const importPath = `./${filename}`;
|
|
1858
|
-
const importDecl =
|
|
1859
|
-
!moduleName ? [] : [
|
|
1860
|
-
|
|
1945
|
+
const importDecl = t17.importDeclaration(
|
|
1946
|
+
!moduleName ? [] : [t17.importDefaultSpecifier(t17.identifier(moduleName))],
|
|
1947
|
+
t17.stringLiteral(importPath)
|
|
1861
1948
|
);
|
|
1862
1949
|
scriptIR.imports.push(importDecl);
|
|
1863
1950
|
}
|
|
@@ -1868,6 +1955,9 @@ function insertCSSImport(ctx) {
|
|
|
1868
1955
|
// src/core/transform/shared.ts
|
|
1869
1956
|
function recordImport(ctx, pkg, name, onDemand = true) {
|
|
1870
1957
|
const { imports } = ctx;
|
|
1958
|
+
if (isTypeOnlyImport(name)) {
|
|
1959
|
+
name = `type ${name}`;
|
|
1960
|
+
}
|
|
1871
1961
|
if (imports.has(pkg)) {
|
|
1872
1962
|
const list = imports.get(pkg);
|
|
1873
1963
|
const foundItem = list.find((item) => item.name === name);
|
|
@@ -1878,6 +1968,10 @@ function recordImport(ctx, pkg, name, onDemand = true) {
|
|
|
1878
1968
|
}
|
|
1879
1969
|
imports.set(pkg, [{ name, onDemand }]);
|
|
1880
1970
|
}
|
|
1971
|
+
function isTypeOnlyImport(name) {
|
|
1972
|
+
const arr = [REACT_API_MAP.ReactNode];
|
|
1973
|
+
return arr.includes(name);
|
|
1974
|
+
}
|
|
1881
1975
|
|
|
1882
1976
|
// src/core/transform/sfc/script/shared/replace-vue-suffix.ts
|
|
1883
1977
|
function replaceVueSuffix(ctx, node) {
|
|
@@ -1892,36 +1986,36 @@ function insertRequiredImports(ctx) {
|
|
|
1892
1986
|
const processedModules = /* @__PURE__ */ new Set();
|
|
1893
1987
|
let hasProcessedImports = false;
|
|
1894
1988
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
|
|
1895
|
-
function resolveRequiredImport(
|
|
1896
|
-
const { node } =
|
|
1989
|
+
function resolveRequiredImport(path8) {
|
|
1990
|
+
const { node } = path8;
|
|
1897
1991
|
const moduleName = node.source.value.toLowerCase();
|
|
1898
1992
|
const isVueLike = isVueEcosystemPackage(moduleName);
|
|
1899
1993
|
mergeImports(node, ctx);
|
|
1900
|
-
if (processedModules.has(moduleName) && !
|
|
1901
|
-
|
|
1994
|
+
if (processedModules.has(moduleName) && !path8.removed) {
|
|
1995
|
+
path8.remove();
|
|
1902
1996
|
return;
|
|
1903
1997
|
}
|
|
1904
1998
|
processedModules.add(moduleName);
|
|
1905
1999
|
if (!hasProcessedImports) {
|
|
1906
2000
|
const required = createRequiredImports(ctx);
|
|
1907
2001
|
if (isVueLike) {
|
|
1908
|
-
|
|
2002
|
+
path8.replaceWithMultiple(required);
|
|
1909
2003
|
} else if (moduleName === PACKAGE_NAME.react) {
|
|
1910
|
-
|
|
2004
|
+
path8.insertAfter(required);
|
|
1911
2005
|
} else {
|
|
1912
|
-
|
|
2006
|
+
path8.insertBefore(required);
|
|
1913
2007
|
}
|
|
1914
2008
|
hasProcessedImports = true;
|
|
1915
2009
|
}
|
|
1916
|
-
if (isVueLike && !
|
|
1917
|
-
|
|
2010
|
+
if (isVueLike && !path8.removed) {
|
|
2011
|
+
path8.remove();
|
|
1918
2012
|
return;
|
|
1919
2013
|
}
|
|
1920
2014
|
replaceVueSuffix(ctx, node.source);
|
|
1921
2015
|
}
|
|
1922
|
-
function resolveStyleFileExt(
|
|
2016
|
+
function resolveStyleFileExt(path8) {
|
|
1923
2017
|
if (!ctx.preprocessStyles) return;
|
|
1924
|
-
const { node } =
|
|
2018
|
+
const { node } = path8;
|
|
1925
2019
|
if (!node || !node.source || !node.source.value) return;
|
|
1926
2020
|
const importSource = node.source.value;
|
|
1927
2021
|
if (typeof importSource !== "string") return;
|
|
@@ -1933,16 +2027,16 @@ function insertRequiredImports(ctx) {
|
|
|
1933
2027
|
return {
|
|
1934
2028
|
// 增加 Program.exit 兜底注入 required imports(处理无 ImportDeclaration 的 SFC)
|
|
1935
2029
|
Program: {
|
|
1936
|
-
exit(
|
|
2030
|
+
exit(path8) {
|
|
1937
2031
|
if (hasProcessedImports) return;
|
|
1938
2032
|
const required = createRequiredImports(ctx);
|
|
1939
|
-
|
|
2033
|
+
path8.unshiftContainer("body", required);
|
|
1940
2034
|
hasProcessedImports = true;
|
|
1941
2035
|
}
|
|
1942
2036
|
},
|
|
1943
|
-
ImportDeclaration(
|
|
1944
|
-
resolveRequiredImport(
|
|
1945
|
-
resolveStyleFileExt(
|
|
2037
|
+
ImportDeclaration(path8) {
|
|
2038
|
+
resolveRequiredImport(path8);
|
|
2039
|
+
resolveStyleFileExt(path8);
|
|
1946
2040
|
}
|
|
1947
2041
|
};
|
|
1948
2042
|
}
|
|
@@ -1961,22 +2055,22 @@ function isVueEcosystemPackage(moduleName) {
|
|
|
1961
2055
|
function mergeImports(currentNode, ctx) {
|
|
1962
2056
|
const moduleName = currentNode.source.value.toLowerCase();
|
|
1963
2057
|
const ctxImportItems = ctx.imports.get(moduleName);
|
|
1964
|
-
if (!_optionalChain([ctxImportItems, 'optionalAccess',
|
|
2058
|
+
if (!_optionalChain([ctxImportItems, 'optionalAccess', _58 => _58.length])) {
|
|
1965
2059
|
return;
|
|
1966
2060
|
}
|
|
1967
2061
|
const currentImports = /* @__PURE__ */ new Set();
|
|
1968
2062
|
for (const spec of currentNode.specifiers) {
|
|
1969
|
-
if (
|
|
2063
|
+
if (t18.isImportSpecifier(spec) && t18.isIdentifier(spec.imported)) {
|
|
1970
2064
|
currentImports.add(spec.imported.name);
|
|
1971
2065
|
}
|
|
1972
|
-
if (
|
|
2066
|
+
if (t18.isImportDefaultSpecifier(spec) && t18.isIdentifier(spec.local)) {
|
|
1973
2067
|
currentImports.add(spec.local.name);
|
|
1974
2068
|
}
|
|
1975
2069
|
}
|
|
1976
2070
|
for (const item of ctxImportItems) {
|
|
1977
2071
|
if (currentImports.has(item.name)) return;
|
|
1978
|
-
const local =
|
|
1979
|
-
const newNode = !item.onDemand ?
|
|
2072
|
+
const local = t18.identifier(item.name);
|
|
2073
|
+
const newNode = !item.onDemand ? t18.importDefaultSpecifier(local) : t18.importSpecifier(local, local);
|
|
1980
2074
|
currentNode.specifiers.push(newNode);
|
|
1981
2075
|
}
|
|
1982
2076
|
ctx.imports.delete(moduleName);
|
|
@@ -1987,18 +2081,18 @@ function createRequiredImports(ctx) {
|
|
|
1987
2081
|
ctx.imports.forEach((items, moduleName) => {
|
|
1988
2082
|
const specifier = [];
|
|
1989
2083
|
for (const item of items) {
|
|
1990
|
-
const local =
|
|
2084
|
+
const local = t18.identifier(item.name);
|
|
1991
2085
|
if (!item.onDemand) {
|
|
1992
|
-
specifier.push(
|
|
2086
|
+
specifier.push(t18.importDefaultSpecifier(local));
|
|
1993
2087
|
} else {
|
|
1994
|
-
specifier.push(
|
|
2088
|
+
specifier.push(t18.importSpecifier(local, local));
|
|
1995
2089
|
}
|
|
1996
2090
|
}
|
|
1997
2091
|
importMap[moduleName] = specifier;
|
|
1998
2092
|
});
|
|
1999
2093
|
for (const name in importMap) {
|
|
2000
2094
|
const specifiers = importMap[name];
|
|
2001
|
-
const importDecl =
|
|
2095
|
+
const importDecl = t18.importDeclaration(specifiers, t18.stringLiteral(name));
|
|
2002
2096
|
if (name === PACKAGE_NAME.react) {
|
|
2003
2097
|
result.unshift(importDecl);
|
|
2004
2098
|
} else {
|
|
@@ -2013,29 +2107,29 @@ function createRequiredImports(ctx) {
|
|
|
2013
2107
|
|
|
2014
2108
|
// src/core/transform/sfc/script/shared/babel-utils.ts
|
|
2015
2109
|
|
|
2016
|
-
function findRootVariablePath(
|
|
2017
|
-
const rootId = findRootIdentifier(
|
|
2018
|
-
if (!_optionalChain([rootId, 'optionalAccess',
|
|
2019
|
-
const binding =
|
|
2110
|
+
function findRootVariablePath(path8) {
|
|
2111
|
+
const rootId = findRootIdentifier(path8.node);
|
|
2112
|
+
if (!_optionalChain([rootId, 'optionalAccess', _59 => _59.name])) return null;
|
|
2113
|
+
const binding = path8.scope.getBinding(rootId.name);
|
|
2020
2114
|
if (!binding) return null;
|
|
2021
2115
|
const rootPath = getVariableDeclaratorPath(binding.path);
|
|
2022
2116
|
return rootPath;
|
|
2023
2117
|
}
|
|
2024
2118
|
function findRootIdentifier(node) {
|
|
2025
2119
|
let current = node.object;
|
|
2026
|
-
while (
|
|
2120
|
+
while (t19.isMemberExpression(current) || t19.isOptionalMemberExpression(current)) {
|
|
2027
2121
|
current = current.object;
|
|
2028
2122
|
}
|
|
2029
|
-
return
|
|
2123
|
+
return t19.isIdentifier(current) ? current : null;
|
|
2030
2124
|
}
|
|
2031
|
-
function getVariableDeclaratorPath(
|
|
2032
|
-
if (
|
|
2033
|
-
return
|
|
2125
|
+
function getVariableDeclaratorPath(path8) {
|
|
2126
|
+
if (path8.isVariableDeclarator()) {
|
|
2127
|
+
return path8;
|
|
2034
2128
|
}
|
|
2035
|
-
return
|
|
2129
|
+
return path8.findParent((p) => p.isVariableDeclarator());
|
|
2036
2130
|
}
|
|
2037
|
-
function isVariableDeclTopLevel(
|
|
2038
|
-
const variableDeclaratorPath =
|
|
2131
|
+
function isVariableDeclTopLevel(path8) {
|
|
2132
|
+
const variableDeclaratorPath = path8;
|
|
2039
2133
|
const variableDeclarationPath = variableDeclaratorPath.parentPath;
|
|
2040
2134
|
if (!variableDeclarationPath) {
|
|
2041
2135
|
return false;
|
|
@@ -2049,75 +2143,75 @@ function isVariableDeclTopLevel(path7) {
|
|
|
2049
2143
|
}
|
|
2050
2144
|
return false;
|
|
2051
2145
|
}
|
|
2052
|
-
function isRealVariableAccess(
|
|
2053
|
-
return isIdentifierAccess(
|
|
2146
|
+
function isRealVariableAccess(path8) {
|
|
2147
|
+
return isIdentifierAccess(path8) && !isPropertyName(path8);
|
|
2054
2148
|
}
|
|
2055
|
-
function isIdentifierAccess(
|
|
2056
|
-
if (isIdentifierDeclaration(
|
|
2149
|
+
function isIdentifierAccess(path8) {
|
|
2150
|
+
if (isIdentifierDeclaration(path8)) {
|
|
2057
2151
|
return false;
|
|
2058
2152
|
}
|
|
2059
|
-
const binding =
|
|
2153
|
+
const binding = path8.scope.getBinding(path8.node.name);
|
|
2060
2154
|
if (!binding) {
|
|
2061
2155
|
return true;
|
|
2062
2156
|
}
|
|
2063
|
-
return binding.identifier !==
|
|
2157
|
+
return binding.identifier !== path8.node;
|
|
2064
2158
|
}
|
|
2065
|
-
function isIdentifierDeclaration(
|
|
2066
|
-
const parent =
|
|
2159
|
+
function isIdentifierDeclaration(path8) {
|
|
2160
|
+
const parent = path8.parentPath;
|
|
2067
2161
|
if (!parent) return false;
|
|
2068
|
-
if (parent.isVariableDeclarator() && parent.node.id ===
|
|
2162
|
+
if (parent.isVariableDeclarator() && parent.node.id === path8.node) {
|
|
2069
2163
|
return true;
|
|
2070
2164
|
}
|
|
2071
|
-
if (parent.isFunctionDeclaration() && parent.node.id ===
|
|
2165
|
+
if (parent.isFunctionDeclaration() && parent.node.id === path8.node) {
|
|
2072
2166
|
return true;
|
|
2073
2167
|
}
|
|
2074
|
-
if (parent.isFunctionExpression() && parent.node.id ===
|
|
2168
|
+
if (parent.isFunctionExpression() && parent.node.id === path8.node) {
|
|
2075
2169
|
return true;
|
|
2076
2170
|
}
|
|
2077
|
-
if (parent.isClassDeclaration() && parent.node.id ===
|
|
2171
|
+
if (parent.isClassDeclaration() && parent.node.id === path8.node) {
|
|
2078
2172
|
return true;
|
|
2079
2173
|
}
|
|
2080
|
-
if (parent.isImportSpecifier() && parent.node.local ===
|
|
2174
|
+
if (parent.isImportSpecifier() && parent.node.local === path8.node) {
|
|
2081
2175
|
return true;
|
|
2082
2176
|
}
|
|
2083
|
-
if (parent.isImportDefaultSpecifier() && parent.node.local ===
|
|
2177
|
+
if (parent.isImportDefaultSpecifier() && parent.node.local === path8.node) {
|
|
2084
2178
|
return true;
|
|
2085
2179
|
}
|
|
2086
|
-
if (parent.isImportNamespaceSpecifier() && parent.node.local ===
|
|
2180
|
+
if (parent.isImportNamespaceSpecifier() && parent.node.local === path8.node) {
|
|
2087
2181
|
return true;
|
|
2088
2182
|
}
|
|
2089
|
-
if (parent.isFunction() && parent.node.params.includes(
|
|
2183
|
+
if (parent.isFunction() && parent.node.params.includes(path8.node)) {
|
|
2090
2184
|
return true;
|
|
2091
2185
|
}
|
|
2092
|
-
if (parent.isCatchClause() && parent.node.param ===
|
|
2186
|
+
if (parent.isCatchClause() && parent.node.param === path8.node) {
|
|
2093
2187
|
return true;
|
|
2094
2188
|
}
|
|
2095
2189
|
return false;
|
|
2096
2190
|
}
|
|
2097
|
-
function isPropertyName(
|
|
2098
|
-
const parent =
|
|
2191
|
+
function isPropertyName(path8) {
|
|
2192
|
+
const parent = path8.parentPath;
|
|
2099
2193
|
if (!parent) return false;
|
|
2100
|
-
if (parent.isObjectProperty() && parent.node.key ===
|
|
2194
|
+
if (parent.isObjectProperty() && parent.node.key === path8.node) {
|
|
2101
2195
|
return true;
|
|
2102
2196
|
}
|
|
2103
|
-
if (parent.isClassProperty() && parent.node.key ===
|
|
2197
|
+
if (parent.isClassProperty() && parent.node.key === path8.node) {
|
|
2104
2198
|
return true;
|
|
2105
2199
|
}
|
|
2106
|
-
if (parent.isMemberExpression() && parent.node.property ===
|
|
2200
|
+
if (parent.isMemberExpression() && parent.node.property === path8.node) {
|
|
2107
2201
|
return true;
|
|
2108
2202
|
}
|
|
2109
2203
|
return false;
|
|
2110
2204
|
}
|
|
2111
2205
|
function replaceCallName(callExp, identifierName) {
|
|
2112
2206
|
const { callee } = callExp;
|
|
2113
|
-
if (!
|
|
2207
|
+
if (!t19.isIdentifier(callee)) return;
|
|
2114
2208
|
callee.name = identifierName;
|
|
2115
2209
|
if (callee.loc) {
|
|
2116
2210
|
callee.loc.identifierName = identifierName;
|
|
2117
2211
|
}
|
|
2118
2212
|
}
|
|
2119
2213
|
function replaceIdName(id, newName) {
|
|
2120
|
-
if (!
|
|
2214
|
+
if (!t19.isIdentifier(id)) return;
|
|
2121
2215
|
id.name = newName;
|
|
2122
2216
|
if (id.loc) {
|
|
2123
2217
|
id.loc.identifierName = newName;
|
|
@@ -2127,65 +2221,65 @@ function stringValueToTSType(ctx, input, tsTypeAnnotation7) {
|
|
|
2127
2221
|
const { filename, scriptData } = ctx;
|
|
2128
2222
|
const exp = stringToExpr(input, scriptData.lang, filename);
|
|
2129
2223
|
const ts = expressionToTSType(exp);
|
|
2130
|
-
return tsTypeAnnotation7 ?
|
|
2224
|
+
return tsTypeAnnotation7 ? t19.tsTypeAnnotation(ts) : ts;
|
|
2131
2225
|
}
|
|
2132
2226
|
function expressionToTSType(exp) {
|
|
2133
|
-
if (
|
|
2134
|
-
if (
|
|
2135
|
-
if (
|
|
2136
|
-
if (
|
|
2137
|
-
if (
|
|
2227
|
+
if (t19.isStringLiteral(exp)) return t19.tsStringKeyword();
|
|
2228
|
+
if (t19.isNumericLiteral(exp)) return t19.tsNumberKeyword();
|
|
2229
|
+
if (t19.isBooleanLiteral(exp)) return t19.tsBooleanKeyword();
|
|
2230
|
+
if (t19.isArrayExpression(exp)) return t19.tsArrayType(t19.tsAnyKeyword());
|
|
2231
|
+
if (t19.isObjectExpression(exp)) {
|
|
2138
2232
|
const members = [];
|
|
2139
2233
|
for (const p of exp.properties) {
|
|
2140
|
-
if (!
|
|
2234
|
+
if (!t19.isObjectProperty(p)) continue;
|
|
2141
2235
|
let key;
|
|
2142
|
-
if (
|
|
2143
|
-
else if (
|
|
2236
|
+
if (t19.isIdentifier(p.key)) key = p.key.name;
|
|
2237
|
+
else if (t19.isStringLiteral(p.key)) key = p.key.value;
|
|
2144
2238
|
if (!key) continue;
|
|
2145
|
-
if (
|
|
2239
|
+
if (t19.isExpression(p.value)) {
|
|
2146
2240
|
members.push(
|
|
2147
|
-
|
|
2241
|
+
t19.tsPropertySignature(t19.identifier(key), t19.tsTypeAnnotation(expressionToTSType(p.value)))
|
|
2148
2242
|
);
|
|
2149
2243
|
} else {
|
|
2150
2244
|
members.push(
|
|
2151
|
-
|
|
2245
|
+
t19.tsPropertySignature(t19.identifier(key), t19.tsTypeAnnotation(t19.tsAnyKeyword()))
|
|
2152
2246
|
);
|
|
2153
2247
|
}
|
|
2154
2248
|
}
|
|
2155
|
-
return
|
|
2249
|
+
return t19.tsTypeLiteral(members);
|
|
2156
2250
|
}
|
|
2157
|
-
if (
|
|
2251
|
+
if (t19.isArrowFunctionExpression(exp) || t19.isFunctionExpression(exp)) {
|
|
2158
2252
|
const params = exp.params.map((p, i) => {
|
|
2159
|
-
const id =
|
|
2160
|
-
id.typeAnnotation =
|
|
2253
|
+
const id = t19.isIdentifier(p) ? t19.identifier(p.name) : t19.identifier(`arg${i}`);
|
|
2254
|
+
id.typeAnnotation = t19.tsTypeAnnotation(t19.tsAnyKeyword());
|
|
2161
2255
|
return id;
|
|
2162
2256
|
});
|
|
2163
|
-
let returnType =
|
|
2164
|
-
if (
|
|
2257
|
+
let returnType = t19.tsAnyKeyword();
|
|
2258
|
+
if (t19.isBlockStatement(exp.body)) {
|
|
2165
2259
|
for (const stmt of exp.body.body) {
|
|
2166
|
-
if (
|
|
2167
|
-
if (
|
|
2260
|
+
if (t19.isReturnStatement(stmt) && stmt.argument) {
|
|
2261
|
+
if (t19.isExpression(stmt.argument)) {
|
|
2168
2262
|
returnType = expressionToTSType(stmt.argument);
|
|
2169
2263
|
break;
|
|
2170
2264
|
}
|
|
2171
2265
|
}
|
|
2172
2266
|
}
|
|
2173
|
-
} else if (
|
|
2267
|
+
} else if (t19.isExpression(exp.body)) {
|
|
2174
2268
|
returnType = expressionToTSType(exp.body);
|
|
2175
2269
|
}
|
|
2176
|
-
return
|
|
2270
|
+
return t19.tsFunctionType(null, params, t19.tsTypeAnnotation(returnType));
|
|
2177
2271
|
}
|
|
2178
|
-
return
|
|
2272
|
+
return t19.tsAnyKeyword();
|
|
2179
2273
|
}
|
|
2180
2274
|
function isCalleeNamed(node, name) {
|
|
2181
|
-
if (!
|
|
2275
|
+
if (!t19.isIdentifier(node.callee)) {
|
|
2182
2276
|
return false;
|
|
2183
2277
|
}
|
|
2184
2278
|
return node.callee.name === name;
|
|
2185
2279
|
}
|
|
2186
2280
|
function isSimpleLiteral(node) {
|
|
2187
2281
|
if (!node) return false;
|
|
2188
|
-
if (
|
|
2282
|
+
if (t19.isStringLiteral(node) || t19.isNumericLiteral(node) || t19.isBooleanLiteral(node) || t19.isNullLiteral(node) || t19.isRegExpLiteral(node) || t19.isBigIntLiteral(node) || t19.isDecimalLiteral(node)) {
|
|
2189
2283
|
return true;
|
|
2190
2284
|
}
|
|
2191
2285
|
return false;
|
|
@@ -2214,26 +2308,26 @@ function resolveStaticHoisting(ctx) {
|
|
|
2214
2308
|
return {};
|
|
2215
2309
|
}
|
|
2216
2310
|
return {
|
|
2217
|
-
"ImportDeclaration|ExportDeclaration"(
|
|
2218
|
-
if (
|
|
2219
|
-
scriptIR.imports.push(
|
|
2220
|
-
} else if (
|
|
2221
|
-
scriptIR.exports.push(
|
|
2311
|
+
"ImportDeclaration|ExportDeclaration"(path8) {
|
|
2312
|
+
if (t20.isImportDeclaration(path8.node)) {
|
|
2313
|
+
scriptIR.imports.push(path8.node);
|
|
2314
|
+
} else if (t20.isExportDeclaration(path8.node)) {
|
|
2315
|
+
scriptIR.exports.push(path8.node);
|
|
2222
2316
|
}
|
|
2223
|
-
|
|
2317
|
+
path8.remove();
|
|
2224
2318
|
},
|
|
2225
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(
|
|
2226
|
-
if (
|
|
2227
|
-
scriptIR.tsTypes.push(
|
|
2228
|
-
|
|
2319
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path8) {
|
|
2320
|
+
if (t20.isProgram(path8.parent)) {
|
|
2321
|
+
scriptIR.tsTypes.push(path8.node);
|
|
2322
|
+
path8.remove();
|
|
2229
2323
|
}
|
|
2230
2324
|
},
|
|
2231
|
-
VariableDeclarator(
|
|
2232
|
-
const { node } =
|
|
2233
|
-
if (!isVariableDeclTopLevel(
|
|
2325
|
+
VariableDeclarator(path8) {
|
|
2326
|
+
const { node } = path8;
|
|
2327
|
+
if (!isVariableDeclTopLevel(path8) || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
|
|
2234
2328
|
return;
|
|
2235
2329
|
}
|
|
2236
|
-
const declarationPath =
|
|
2330
|
+
const declarationPath = path8.findParent((p) => p.isVariableDeclaration());
|
|
2237
2331
|
if (!declarationPath) return;
|
|
2238
2332
|
scriptIR.statement.global.push(declarationPath.node);
|
|
2239
2333
|
declarationPath.remove();
|
|
@@ -2250,24 +2344,24 @@ function collectLocalStatements(ctx, ast) {
|
|
|
2250
2344
|
|
|
2251
2345
|
function resolveDefineAsyncComponent(ctx) {
|
|
2252
2346
|
return {
|
|
2253
|
-
CallExpression(
|
|
2254
|
-
const { node } =
|
|
2347
|
+
CallExpression(path8) {
|
|
2348
|
+
const { node } = path8;
|
|
2255
2349
|
if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
|
|
2256
2350
|
return;
|
|
2257
2351
|
}
|
|
2258
2352
|
const [arg] = node.arguments;
|
|
2259
2353
|
checkIsUnsupported(ctx, arg);
|
|
2260
|
-
pushToGlobalScope(
|
|
2354
|
+
pushToGlobalScope(path8, ctx);
|
|
2261
2355
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.lazy);
|
|
2262
2356
|
}
|
|
2263
2357
|
};
|
|
2264
2358
|
}
|
|
2265
2359
|
function checkIsUnsupported(ctx, arg) {
|
|
2266
|
-
if (
|
|
2360
|
+
if (t21.isFunction(arg)) {
|
|
2267
2361
|
checkIsDynamicImport(ctx, arg);
|
|
2268
|
-
} else if (
|
|
2362
|
+
} else if (t21.isObjectExpression(arg)) {
|
|
2269
2363
|
const { value } = arg.properties.find(
|
|
2270
|
-
(p) =>
|
|
2364
|
+
(p) => t21.isObjectProperty(p) && t21.isIdentifier(p.key) && p.key.name === "loader"
|
|
2271
2365
|
);
|
|
2272
2366
|
checkIsDynamicImport(ctx, value);
|
|
2273
2367
|
if (arg.properties.length > 1) {
|
|
@@ -2278,31 +2372,31 @@ function checkIsUnsupported(ctx, arg) {
|
|
|
2278
2372
|
function checkIsDynamicImport(ctx, node) {
|
|
2279
2373
|
const { scriptData, filename } = ctx;
|
|
2280
2374
|
const warnIsNotImport = (target) => {
|
|
2281
|
-
if (!target || !
|
|
2375
|
+
if (!target || !t21.isImport(target)) {
|
|
2282
2376
|
logger.error(
|
|
2283
2377
|
`Only ES module dynamic imports are supported. You must use and return import('...').`,
|
|
2284
2378
|
{
|
|
2285
2379
|
source: scriptData.source,
|
|
2286
2380
|
file: filename,
|
|
2287
|
-
loc: _optionalChain([target, 'optionalAccess',
|
|
2381
|
+
loc: _optionalChain([target, 'optionalAccess', _60 => _60.loc]) || {}
|
|
2288
2382
|
}
|
|
2289
2383
|
);
|
|
2290
2384
|
}
|
|
2291
2385
|
};
|
|
2292
|
-
if (
|
|
2386
|
+
if (t21.isFunction(node)) {
|
|
2293
2387
|
checkIsDynamicImport(ctx, node.body);
|
|
2294
2388
|
return;
|
|
2295
2389
|
}
|
|
2296
|
-
if (
|
|
2390
|
+
if (t21.isBlockStatement(node)) {
|
|
2297
2391
|
const [returnSmt] = node.body;
|
|
2298
|
-
if (
|
|
2392
|
+
if (t21.isReturnStatement(returnSmt)) {
|
|
2299
2393
|
warnIsNotImport(returnSmt.argument);
|
|
2300
2394
|
}
|
|
2301
2395
|
return;
|
|
2302
2396
|
}
|
|
2303
|
-
if (
|
|
2397
|
+
if (t21.isCallExpression(node)) {
|
|
2304
2398
|
warnIsNotImport(node.callee);
|
|
2305
|
-
if (
|
|
2399
|
+
if (t21.isStringLiteral(node.arguments[0])) {
|
|
2306
2400
|
replaceVueSuffix(ctx, node.arguments[0]);
|
|
2307
2401
|
}
|
|
2308
2402
|
return;
|
|
@@ -2320,15 +2414,15 @@ function warnMultipleOptionsUsed(ctx, node) {
|
|
|
2320
2414
|
}
|
|
2321
2415
|
);
|
|
2322
2416
|
}
|
|
2323
|
-
function pushToGlobalScope(
|
|
2324
|
-
const { node } =
|
|
2417
|
+
function pushToGlobalScope(path8, ctx) {
|
|
2418
|
+
const { node } = path8;
|
|
2325
2419
|
const callee = node.callee;
|
|
2326
2420
|
callee.name = REACT_API_MAP.lazy;
|
|
2327
2421
|
callee.loc.identifierName = REACT_API_MAP.lazy;
|
|
2328
2422
|
if (node.typeParameters) {
|
|
2329
2423
|
node.typeParameters = void 0;
|
|
2330
2424
|
}
|
|
2331
|
-
let declarationPath =
|
|
2425
|
+
let declarationPath = path8.parentPath;
|
|
2332
2426
|
while (declarationPath) {
|
|
2333
2427
|
if (declarationPath.isVariableDeclaration()) {
|
|
2334
2428
|
break;
|
|
@@ -2336,15 +2430,15 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2336
2430
|
declarationPath = declarationPath.parentPath;
|
|
2337
2431
|
}
|
|
2338
2432
|
let fullNode;
|
|
2339
|
-
if (_optionalChain([declarationPath, 'optionalAccess',
|
|
2433
|
+
if (_optionalChain([declarationPath, 'optionalAccess', _61 => _61.isVariableDeclaration, 'call', _62 => _62()])) {
|
|
2340
2434
|
fullNode = declarationPath.node;
|
|
2341
2435
|
declarationPath.remove();
|
|
2342
|
-
} else if (
|
|
2343
|
-
fullNode =
|
|
2344
|
-
|
|
2436
|
+
} else if (path8.parentPath.isVariableDeclarator()) {
|
|
2437
|
+
fullNode = path8.parent;
|
|
2438
|
+
path8.parentPath.remove();
|
|
2345
2439
|
} else {
|
|
2346
|
-
fullNode =
|
|
2347
|
-
|
|
2440
|
+
fullNode = path8.node;
|
|
2441
|
+
path8.remove();
|
|
2348
2442
|
}
|
|
2349
2443
|
const scriptIR = getScriptIR(ctx);
|
|
2350
2444
|
scriptIR.statement.global.push(fullNode);
|
|
@@ -2356,51 +2450,51 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2356
2450
|
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
2357
2451
|
|
|
2358
2452
|
function createUseCallback(body, deps) {
|
|
2359
|
-
return
|
|
2453
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useCallback), [
|
|
2360
2454
|
body,
|
|
2361
|
-
_nullishCoalesce(deps, () => (
|
|
2455
|
+
_nullishCoalesce(deps, () => ( t22.arrayExpression([])))
|
|
2362
2456
|
]);
|
|
2363
2457
|
}
|
|
2364
2458
|
function createUseMemo(body, deps) {
|
|
2365
|
-
return
|
|
2366
|
-
|
|
2367
|
-
_nullishCoalesce(deps, () => (
|
|
2459
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useMemo), [
|
|
2460
|
+
t22.arrowFunctionExpression([], body),
|
|
2461
|
+
_nullishCoalesce(deps, () => ( t22.arrayExpression([])))
|
|
2368
2462
|
]);
|
|
2369
2463
|
}
|
|
2370
2464
|
function createUseImperativeHandle(refId, init) {
|
|
2371
|
-
return
|
|
2465
|
+
return t22.callExpression(t22.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
2372
2466
|
}
|
|
2373
2467
|
|
|
2374
2468
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
2375
2469
|
function resolveDefineExpose(ctx) {
|
|
2376
2470
|
if (ctx.inputType !== "sfc") return {};
|
|
2377
2471
|
return {
|
|
2378
|
-
CallExpression(
|
|
2379
|
-
const { node } =
|
|
2472
|
+
CallExpression(path8) {
|
|
2473
|
+
const { node } = path8;
|
|
2380
2474
|
const { filename, scriptData } = ctx;
|
|
2381
2475
|
if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
|
|
2382
2476
|
return;
|
|
2383
2477
|
}
|
|
2384
2478
|
const [expose] = node.arguments;
|
|
2385
2479
|
if (!expose) {
|
|
2386
|
-
|
|
2480
|
+
path8.remove();
|
|
2387
2481
|
return;
|
|
2388
2482
|
}
|
|
2389
2483
|
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
2390
2484
|
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
2391
2485
|
recordImport(ctx, adapter.package, adapter.target);
|
|
2392
|
-
if (!
|
|
2486
|
+
if (!t23.isObjectExpression(expose) && !t23.isFunction(expose)) {
|
|
2393
2487
|
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
2394
2488
|
file: filename,
|
|
2395
2489
|
loc: expose.loc,
|
|
2396
2490
|
source: scriptData.source
|
|
2397
2491
|
});
|
|
2398
2492
|
}
|
|
2399
|
-
const init = !
|
|
2493
|
+
const init = !t23.isFunction(expose) ? t23.arrowFunctionExpression([], expose) : expose;
|
|
2400
2494
|
const { forwardRef } = scriptData;
|
|
2401
|
-
const newNode = createUseImperativeHandle(
|
|
2495
|
+
const newNode = createUseImperativeHandle(t23.identifier(forwardRef.refField), init);
|
|
2402
2496
|
forwardRef.enabled = true;
|
|
2403
|
-
|
|
2497
|
+
path8.replaceWith(newNode);
|
|
2404
2498
|
}
|
|
2405
2499
|
};
|
|
2406
2500
|
}
|
|
@@ -2409,8 +2503,8 @@ function resolveDefineExpose(ctx) {
|
|
|
2409
2503
|
|
|
2410
2504
|
function resolveDefineOptions(ctx) {
|
|
2411
2505
|
return {
|
|
2412
|
-
CallExpression(
|
|
2413
|
-
const { node } =
|
|
2506
|
+
CallExpression(path8) {
|
|
2507
|
+
const { node } = path8;
|
|
2414
2508
|
if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
|
|
2415
2509
|
return;
|
|
2416
2510
|
}
|
|
@@ -2420,26 +2514,26 @@ function resolveDefineOptions(ctx) {
|
|
|
2420
2514
|
logger.warn("defineOptions was found, but no options were provided.", {
|
|
2421
2515
|
source: scriptData.source,
|
|
2422
2516
|
file: filename,
|
|
2423
|
-
loc: _optionalChain([node, 'optionalAccess',
|
|
2517
|
+
loc: _optionalChain([node, 'optionalAccess', _63 => _63.loc])
|
|
2424
2518
|
});
|
|
2425
|
-
|
|
2519
|
+
path8.remove();
|
|
2426
2520
|
return;
|
|
2427
2521
|
}
|
|
2428
|
-
if (!
|
|
2522
|
+
if (!t24.isObjectExpression(options)) {
|
|
2429
2523
|
logger.warn("Argument for defineOptions must be an object expression.", {
|
|
2430
2524
|
source: scriptData.source,
|
|
2431
2525
|
file: filename,
|
|
2432
|
-
loc: _optionalChain([options, 'optionalAccess',
|
|
2526
|
+
loc: _optionalChain([options, 'optionalAccess', _64 => _64.loc])
|
|
2433
2527
|
});
|
|
2434
2528
|
} else {
|
|
2435
2529
|
for (const prop of options.properties) {
|
|
2436
|
-
if (!
|
|
2530
|
+
if (!t24.isObjectProperty(prop) || !t24.isIdentifier(prop.key)) {
|
|
2437
2531
|
continue;
|
|
2438
2532
|
}
|
|
2439
2533
|
extractName(prop, ctx);
|
|
2440
2534
|
}
|
|
2441
2535
|
}
|
|
2442
|
-
|
|
2536
|
+
path8.remove();
|
|
2443
2537
|
}
|
|
2444
2538
|
};
|
|
2445
2539
|
}
|
|
@@ -2447,14 +2541,14 @@ function extractName(prop, ctx) {
|
|
|
2447
2541
|
if (ctx.compName) return;
|
|
2448
2542
|
const { filename, scriptData } = ctx;
|
|
2449
2543
|
if (!prop.computed && prop.key.name === "name") {
|
|
2450
|
-
if (
|
|
2544
|
+
if (t24.isStringLiteral(prop.value)) {
|
|
2451
2545
|
ctx.compName = prop.value.value;
|
|
2452
2546
|
return;
|
|
2453
2547
|
}
|
|
2454
2548
|
logger.error(`name must be a string type, but got ${prop.value.type}`, {
|
|
2455
2549
|
source: scriptData.source,
|
|
2456
2550
|
file: filename,
|
|
2457
|
-
loc: _optionalChain([prop, 'access',
|
|
2551
|
+
loc: _optionalChain([prop, 'access', _65 => _65.key, 'optionalAccess', _66 => _66.loc])
|
|
2458
2552
|
});
|
|
2459
2553
|
}
|
|
2460
2554
|
}
|
|
@@ -2462,11 +2556,19 @@ function extractName(prop, ctx) {
|
|
|
2462
2556
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-emit-calls.ts
|
|
2463
2557
|
|
|
2464
2558
|
function resolveEmitCalls(ctx) {
|
|
2559
|
+
const formatEmitEventName = (raw) => {
|
|
2560
|
+
if (raw.startsWith("update:")) {
|
|
2561
|
+
const modelKey = raw.slice("update:".length);
|
|
2562
|
+
return `onUpdate${capitalize(camelCase(modelKey))}`;
|
|
2563
|
+
}
|
|
2564
|
+
const normalized = raw.includes(":") ? raw.replace(/:/g, "-") : raw;
|
|
2565
|
+
return `on${capitalize(camelCase(normalized))}`;
|
|
2566
|
+
};
|
|
2465
2567
|
return {
|
|
2466
|
-
CallExpression(
|
|
2467
|
-
const { node } =
|
|
2568
|
+
CallExpression(path8) {
|
|
2569
|
+
const { node } = path8;
|
|
2468
2570
|
const { filename, templateData, scriptData } = ctx;
|
|
2469
|
-
if (!
|
|
2571
|
+
if (!t25.isIdentifier(node.callee)) return;
|
|
2470
2572
|
const { name } = node.callee;
|
|
2471
2573
|
const checkIfFromDefineEmits = () => {
|
|
2472
2574
|
let result = false;
|
|
@@ -2475,10 +2577,10 @@ function resolveEmitCalls(ctx) {
|
|
|
2475
2577
|
result = meta.source === MACRO_API_NAMES.emits;
|
|
2476
2578
|
}
|
|
2477
2579
|
if (!result) {
|
|
2478
|
-
const binding =
|
|
2580
|
+
const binding = path8.scope.getBinding(name);
|
|
2479
2581
|
if (binding) {
|
|
2480
2582
|
const parent = binding.path.node;
|
|
2481
|
-
if (
|
|
2583
|
+
if (t25.isVariableDeclarator(parent) && t25.isCallExpression(parent.init) && t25.isIdentifier(parent.init.callee)) {
|
|
2482
2584
|
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
2483
2585
|
}
|
|
2484
2586
|
}
|
|
@@ -2487,26 +2589,27 @@ function resolveEmitCalls(ctx) {
|
|
|
2487
2589
|
};
|
|
2488
2590
|
if (!checkIfFromDefineEmits()) return;
|
|
2489
2591
|
const [callee, ...args] = node.arguments;
|
|
2490
|
-
const eventName =
|
|
2592
|
+
const eventName = t25.isStringLiteral(callee) ? formatEmitEventName(callee.value) : void 0;
|
|
2491
2593
|
if (!eventName) {
|
|
2492
|
-
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess',
|
|
2594
|
+
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess', _67 => _67.type])}, expression will be removed`, {
|
|
2493
2595
|
file: filename,
|
|
2494
2596
|
source: scriptData.source,
|
|
2495
|
-
loc: _optionalChain([callee, 'optionalAccess',
|
|
2597
|
+
loc: _optionalChain([callee, 'optionalAccess', _68 => _68.loc])
|
|
2496
2598
|
});
|
|
2497
|
-
|
|
2599
|
+
path8.remove();
|
|
2498
2600
|
return;
|
|
2499
2601
|
}
|
|
2500
|
-
const propCall =
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2602
|
+
const propCall = t25.optionalCallExpression(
|
|
2603
|
+
t25.optionalMemberExpression(
|
|
2604
|
+
t25.identifier(ctx.propField),
|
|
2605
|
+
t25.identifier(eventName),
|
|
2504
2606
|
false,
|
|
2505
2607
|
true
|
|
2506
2608
|
),
|
|
2507
|
-
args
|
|
2609
|
+
args,
|
|
2610
|
+
true
|
|
2508
2611
|
);
|
|
2509
|
-
|
|
2612
|
+
path8.replaceWith(propCall);
|
|
2510
2613
|
}
|
|
2511
2614
|
};
|
|
2512
2615
|
}
|
|
@@ -2521,21 +2624,21 @@ function resolveEmitCalls(ctx) {
|
|
|
2521
2624
|
|
|
2522
2625
|
function cloneCallableParams(params) {
|
|
2523
2626
|
const cloneCallableParam = (param, index) => {
|
|
2524
|
-
if (
|
|
2627
|
+
if (t26.isRestElement(param)) {
|
|
2525
2628
|
const arg = param.argument;
|
|
2526
|
-
const name =
|
|
2527
|
-
const rest =
|
|
2528
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
2629
|
+
const name = t26.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
2630
|
+
const rest = t26.restElement(t26.identifier(name));
|
|
2631
|
+
rest.typeAnnotation = param.typeAnnotation || (t26.isIdentifier(arg) ? arg.typeAnnotation : null) || t26.tsTypeAnnotation(t26.tsArrayType(t26.tsAnyKeyword()));
|
|
2529
2632
|
return rest;
|
|
2530
2633
|
}
|
|
2531
|
-
if (
|
|
2532
|
-
const id =
|
|
2634
|
+
if (t26.isIdentifier(param)) {
|
|
2635
|
+
const id = t26.identifier(param.name || `arg${index}`);
|
|
2533
2636
|
id.optional = param.optional;
|
|
2534
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
2637
|
+
id.typeAnnotation = param.typeAnnotation || t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2535
2638
|
return id;
|
|
2536
2639
|
}
|
|
2537
|
-
const fallback =
|
|
2538
|
-
fallback.typeAnnotation =
|
|
2640
|
+
const fallback = t26.identifier(`arg${index}`);
|
|
2641
|
+
fallback.typeAnnotation = t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2539
2642
|
return fallback;
|
|
2540
2643
|
};
|
|
2541
2644
|
return params.map(cloneCallableParam);
|
|
@@ -2544,19 +2647,19 @@ function cloneCallableParams(params) {
|
|
|
2544
2647
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
|
|
2545
2648
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
2546
2649
|
return {
|
|
2547
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(
|
|
2548
|
-
if (!
|
|
2549
|
-
const { node } =
|
|
2550
|
-
if (
|
|
2551
|
-
const typeLiteral =
|
|
2650
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
2651
|
+
if (!t27.isProgram(path8.parent)) return;
|
|
2652
|
+
const { node } = path8;
|
|
2653
|
+
if (t27.isTSInterfaceDeclaration(node)) {
|
|
2654
|
+
const typeLiteral = t27.tsTypeLiteral(node.body.body);
|
|
2552
2655
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
2553
2656
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
2554
|
-
if (resolved &&
|
|
2657
|
+
if (resolved && t27.isTSTypeLiteral(resolved)) {
|
|
2555
2658
|
node.body.body = resolved.members;
|
|
2556
2659
|
}
|
|
2557
2660
|
return;
|
|
2558
2661
|
}
|
|
2559
|
-
if (
|
|
2662
|
+
if (t27.isTSTypeAliasDeclaration(node)) {
|
|
2560
2663
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
2561
2664
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
2562
2665
|
if (resolved) {
|
|
@@ -2567,55 +2670,55 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
2567
2670
|
};
|
|
2568
2671
|
}
|
|
2569
2672
|
function resolveTopLevelEmitType(tsType) {
|
|
2570
|
-
if (
|
|
2673
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2571
2674
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
2572
2675
|
}
|
|
2573
|
-
if (
|
|
2676
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2574
2677
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2575
2678
|
return tsType;
|
|
2576
2679
|
}
|
|
2577
2680
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
2578
|
-
return
|
|
2681
|
+
return t27.tsTypeReference(
|
|
2579
2682
|
tsType.typeName,
|
|
2580
|
-
|
|
2683
|
+
t27.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2581
2684
|
);
|
|
2582
2685
|
}
|
|
2583
|
-
if (
|
|
2686
|
+
if (t27.isTSIntersectionType(tsType)) {
|
|
2584
2687
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2585
2688
|
if (!types.length) return null;
|
|
2586
2689
|
if (types.length === 1) return types[0];
|
|
2587
|
-
return
|
|
2690
|
+
return t27.tsIntersectionType(types);
|
|
2588
2691
|
}
|
|
2589
|
-
if (
|
|
2692
|
+
if (t27.isTSUnionType(tsType)) {
|
|
2590
2693
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2591
2694
|
if (!types.length) return null;
|
|
2592
2695
|
if (types.length === 1) return types[0];
|
|
2593
|
-
return
|
|
2696
|
+
return t27.tsUnionType(types);
|
|
2594
2697
|
}
|
|
2595
|
-
if (
|
|
2698
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2596
2699
|
const members = [];
|
|
2597
2700
|
for (const member of tsType.members) {
|
|
2598
|
-
if (
|
|
2701
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2599
2702
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2600
2703
|
continue;
|
|
2601
2704
|
}
|
|
2602
2705
|
members.push(member);
|
|
2603
2706
|
}
|
|
2604
2707
|
if (!members.length) return null;
|
|
2605
|
-
return
|
|
2708
|
+
return t27.tsTypeLiteral(members);
|
|
2606
2709
|
}
|
|
2607
|
-
if (
|
|
2710
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2608
2711
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2609
2712
|
if (!props.length) return null;
|
|
2610
|
-
return
|
|
2713
|
+
return t27.tsTypeLiteral(props);
|
|
2611
2714
|
}
|
|
2612
2715
|
return tsType;
|
|
2613
2716
|
}
|
|
2614
|
-
function resolveDefineEmitsIface(
|
|
2615
|
-
const { node } =
|
|
2717
|
+
function resolveDefineEmitsIface(path8, ctx) {
|
|
2718
|
+
const { node } = path8;
|
|
2616
2719
|
const [runtimeArg] = node.arguments;
|
|
2617
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2618
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
2720
|
+
const tsParams = _optionalChain([node, 'access', _69 => _69.typeParameters, 'optionalAccess', _70 => _70.params]);
|
|
2721
|
+
if (_optionalChain([tsParams, 'optionalAccess', _71 => _71.length])) {
|
|
2619
2722
|
processExplicitType(ctx, tsParams);
|
|
2620
2723
|
return;
|
|
2621
2724
|
}
|
|
@@ -2628,41 +2731,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
2628
2731
|
propsTSIface: { emitTypes }
|
|
2629
2732
|
} = ctx.scriptData;
|
|
2630
2733
|
const members = [];
|
|
2631
|
-
if (
|
|
2734
|
+
if (t27.isArrayExpression(runtimeArg)) {
|
|
2632
2735
|
for (const element of runtimeArg.elements) {
|
|
2633
|
-
if (!element || !
|
|
2736
|
+
if (!element || !t27.isStringLiteral(element)) continue;
|
|
2634
2737
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
2635
2738
|
const key = buildKey(handlerName);
|
|
2636
|
-
const fnType =
|
|
2739
|
+
const fnType = t27.tsFunctionType(
|
|
2637
2740
|
null,
|
|
2638
2741
|
[createRestAnyParam("args")],
|
|
2639
|
-
|
|
2742
|
+
t27.tsTypeAnnotation(t27.tsAnyKeyword())
|
|
2640
2743
|
);
|
|
2641
|
-
const prop =
|
|
2744
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2642
2745
|
prop.optional = true;
|
|
2643
2746
|
members.push(prop);
|
|
2644
2747
|
}
|
|
2645
2748
|
if (members.length) {
|
|
2646
|
-
emitTypes.push(
|
|
2749
|
+
emitTypes.push(t27.tsTypeLiteral(members));
|
|
2647
2750
|
}
|
|
2648
2751
|
return;
|
|
2649
2752
|
}
|
|
2650
|
-
if (
|
|
2753
|
+
if (t27.isObjectExpression(runtimeArg)) {
|
|
2651
2754
|
for (const prop of runtimeArg.properties) {
|
|
2652
|
-
if (!
|
|
2653
|
-
if (
|
|
2755
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
2756
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
2654
2757
|
const rawName = resolvePropName(prop.key);
|
|
2655
2758
|
if (!rawName) continue;
|
|
2656
2759
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2657
2760
|
const key = buildKey(handlerName);
|
|
2658
|
-
const params =
|
|
2659
|
-
const fnType =
|
|
2660
|
-
const propSig =
|
|
2761
|
+
const params = t27.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
2762
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
2763
|
+
const propSig = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2661
2764
|
propSig.optional = true;
|
|
2662
2765
|
members.push(propSig);
|
|
2663
2766
|
}
|
|
2664
2767
|
if (members.length) {
|
|
2665
|
-
emitTypes.push(
|
|
2768
|
+
emitTypes.push(t27.tsTypeLiteral(members));
|
|
2666
2769
|
}
|
|
2667
2770
|
}
|
|
2668
2771
|
}
|
|
@@ -2683,129 +2786,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
2683
2786
|
return `on${name}`;
|
|
2684
2787
|
}
|
|
2685
2788
|
function resolvePropName(key) {
|
|
2686
|
-
if (
|
|
2687
|
-
if (
|
|
2688
|
-
if (
|
|
2789
|
+
if (t27.isIdentifier(key)) return key.name;
|
|
2790
|
+
if (t27.isStringLiteral(key)) return key.value;
|
|
2791
|
+
if (t27.isNumericLiteral(key)) return String(key.value);
|
|
2689
2792
|
return null;
|
|
2690
2793
|
}
|
|
2691
2794
|
function buildKey(name) {
|
|
2692
|
-
return
|
|
2795
|
+
return t27.isValidIdentifier(name) ? t27.identifier(name) : t27.stringLiteral(name);
|
|
2693
2796
|
}
|
|
2694
2797
|
function createRestAnyParam(name) {
|
|
2695
|
-
const id =
|
|
2696
|
-
const rest =
|
|
2697
|
-
rest.typeAnnotation =
|
|
2798
|
+
const id = t27.identifier(name);
|
|
2799
|
+
const rest = t27.restElement(id);
|
|
2800
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(t27.tsArrayType(t27.tsAnyKeyword()));
|
|
2698
2801
|
return rest;
|
|
2699
2802
|
}
|
|
2700
2803
|
function resolveRuntimeTupleParams(value) {
|
|
2701
2804
|
const params = [];
|
|
2702
2805
|
value.elements.forEach((element, index) => {
|
|
2703
2806
|
if (!element) return;
|
|
2704
|
-
if (
|
|
2807
|
+
if (t27.isSpreadElement(element)) {
|
|
2705
2808
|
params.push(createRestAnyParam(`args${index}`));
|
|
2706
2809
|
return;
|
|
2707
2810
|
}
|
|
2708
|
-
if (
|
|
2709
|
-
const id =
|
|
2710
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
2811
|
+
if (t27.isIdentifier(element)) {
|
|
2812
|
+
const id = t27.identifier(element.name);
|
|
2813
|
+
id.typeAnnotation = element.typeAnnotation || t27.tsTypeAnnotation(t27.tsAnyKeyword());
|
|
2711
2814
|
params.push(id);
|
|
2712
2815
|
return;
|
|
2713
2816
|
}
|
|
2714
|
-
if (
|
|
2715
|
-
const id =
|
|
2716
|
-
id.typeAnnotation =
|
|
2817
|
+
if (t27.isTSAsExpression(element)) {
|
|
2818
|
+
const id = t27.identifier(`arg${index}`);
|
|
2819
|
+
id.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2717
2820
|
params.push(id);
|
|
2718
2821
|
return;
|
|
2719
2822
|
}
|
|
2720
|
-
const fallback =
|
|
2721
|
-
fallback.typeAnnotation =
|
|
2823
|
+
const fallback = t27.identifier(`arg${index}`);
|
|
2824
|
+
fallback.typeAnnotation = t27.tsTypeAnnotation(t27.tsAnyKeyword());
|
|
2722
2825
|
params.push(fallback);
|
|
2723
2826
|
});
|
|
2724
2827
|
return params;
|
|
2725
2828
|
}
|
|
2726
2829
|
function resolveExplicitEmitType(tsType) {
|
|
2727
|
-
if (
|
|
2830
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2728
2831
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
2729
2832
|
}
|
|
2730
|
-
if (
|
|
2833
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2731
2834
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2732
2835
|
return tsType;
|
|
2733
2836
|
}
|
|
2734
2837
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
2735
|
-
return
|
|
2838
|
+
return t27.tsTypeReference(
|
|
2736
2839
|
tsType.typeName,
|
|
2737
|
-
|
|
2840
|
+
t27.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2738
2841
|
);
|
|
2739
2842
|
}
|
|
2740
|
-
if (
|
|
2843
|
+
if (t27.isTSIntersectionType(tsType)) {
|
|
2741
2844
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2742
2845
|
if (!types.length) return null;
|
|
2743
2846
|
if (types.length === 1) return types[0];
|
|
2744
|
-
return
|
|
2847
|
+
return t27.tsIntersectionType(types);
|
|
2745
2848
|
}
|
|
2746
|
-
if (
|
|
2849
|
+
if (t27.isTSUnionType(tsType)) {
|
|
2747
2850
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2748
2851
|
if (!types.length) return null;
|
|
2749
2852
|
if (types.length === 1) return types[0];
|
|
2750
|
-
return
|
|
2853
|
+
return t27.tsUnionType(types);
|
|
2751
2854
|
}
|
|
2752
|
-
if (
|
|
2855
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2753
2856
|
const members = [];
|
|
2754
2857
|
for (const member of tsType.members) {
|
|
2755
|
-
if (
|
|
2858
|
+
if (t27.isTSPropertySignature(member)) {
|
|
2756
2859
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
2757
2860
|
if (prop) members.push(prop);
|
|
2758
2861
|
continue;
|
|
2759
2862
|
}
|
|
2760
|
-
if (
|
|
2863
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2761
2864
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2762
2865
|
continue;
|
|
2763
2866
|
}
|
|
2764
2867
|
}
|
|
2765
2868
|
if (!members.length) return null;
|
|
2766
|
-
return
|
|
2869
|
+
return t27.tsTypeLiteral(members);
|
|
2767
2870
|
}
|
|
2768
|
-
if (
|
|
2871
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2769
2872
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2770
2873
|
if (!props.length) return null;
|
|
2771
|
-
return
|
|
2874
|
+
return t27.tsTypeLiteral(props);
|
|
2772
2875
|
}
|
|
2773
2876
|
return tsType;
|
|
2774
2877
|
}
|
|
2775
2878
|
function hasEmitsSignatureInType(tsType) {
|
|
2776
|
-
if (
|
|
2879
|
+
if (t27.isTSParenthesizedType(tsType)) {
|
|
2777
2880
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
2778
2881
|
}
|
|
2779
|
-
if (
|
|
2882
|
+
if (t27.isTSTypeReference(tsType)) {
|
|
2780
2883
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2781
2884
|
return false;
|
|
2782
2885
|
}
|
|
2783
2886
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
2784
2887
|
}
|
|
2785
|
-
if (
|
|
2888
|
+
if (t27.isTSIntersectionType(tsType) || t27.isTSUnionType(tsType)) {
|
|
2786
2889
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
2787
2890
|
}
|
|
2788
|
-
if (
|
|
2891
|
+
if (t27.isTSTypeLiteral(tsType)) {
|
|
2789
2892
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
2790
2893
|
}
|
|
2791
|
-
if (
|
|
2894
|
+
if (t27.isTSFunctionType(tsType)) {
|
|
2792
2895
|
return isEmitsCallable(tsType.parameters);
|
|
2793
2896
|
}
|
|
2794
2897
|
return false;
|
|
2795
2898
|
}
|
|
2796
2899
|
function hasEmitsSignatureInMember(member) {
|
|
2797
|
-
if (
|
|
2900
|
+
if (t27.isTSCallSignatureDeclaration(member)) {
|
|
2798
2901
|
return isEmitsCallable(member.parameters);
|
|
2799
2902
|
}
|
|
2800
2903
|
return false;
|
|
2801
2904
|
}
|
|
2802
2905
|
function isEmitsCallable(parameters) {
|
|
2803
2906
|
const [eventParam] = parameters;
|
|
2804
|
-
if (!eventParam || !
|
|
2907
|
+
if (!eventParam || !t27.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2805
2908
|
return false;
|
|
2806
2909
|
}
|
|
2807
2910
|
const { typeAnnotation } = eventParam;
|
|
2808
|
-
if (
|
|
2911
|
+
if (t27.isNoop(typeAnnotation)) return false;
|
|
2809
2912
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
2810
2913
|
}
|
|
2811
2914
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -2813,21 +2916,21 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
2813
2916
|
if (!rawName) return null;
|
|
2814
2917
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2815
2918
|
const key = buildKey(handlerName);
|
|
2816
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
2919
|
+
const typeAnnotation = _optionalChain([member, 'access', _72 => _72.typeAnnotation, 'optionalAccess', _73 => _73.typeAnnotation]);
|
|
2817
2920
|
let params = [];
|
|
2818
|
-
let returnType =
|
|
2819
|
-
if (typeAnnotation &&
|
|
2921
|
+
let returnType = t27.tsAnyKeyword();
|
|
2922
|
+
if (typeAnnotation && t27.isTSFunctionType(typeAnnotation)) {
|
|
2820
2923
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
2821
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
2822
|
-
} else if (typeAnnotation &&
|
|
2924
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _74 => _74.typeAnnotation, 'optionalAccess', _75 => _75.typeAnnotation]), () => ( returnType));
|
|
2925
|
+
} else if (typeAnnotation && t27.isTSTupleType(typeAnnotation)) {
|
|
2823
2926
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
2824
2927
|
} else if (typeAnnotation) {
|
|
2825
|
-
const id =
|
|
2826
|
-
id.typeAnnotation =
|
|
2928
|
+
const id = t27.identifier("value");
|
|
2929
|
+
id.typeAnnotation = t27.tsTypeAnnotation(typeAnnotation);
|
|
2827
2930
|
params = [id];
|
|
2828
2931
|
}
|
|
2829
|
-
const fnType =
|
|
2830
|
-
const prop =
|
|
2932
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(returnType));
|
|
2933
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2831
2934
|
prop.optional = !!member.optional;
|
|
2832
2935
|
return prop;
|
|
2833
2936
|
}
|
|
@@ -2836,32 +2939,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
2836
2939
|
}
|
|
2837
2940
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
2838
2941
|
const [eventParam, ...restParams] = parameters;
|
|
2839
|
-
if (!eventParam || !
|
|
2942
|
+
if (!eventParam || !t27.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2840
2943
|
return [];
|
|
2841
2944
|
}
|
|
2842
2945
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
2843
|
-
if (
|
|
2946
|
+
if (t27.isNoop(paramTypeAnnotation)) return [];
|
|
2844
2947
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
2845
2948
|
if (!eventNames.length) return [];
|
|
2846
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
2949
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _76 => _76.typeAnnotation]), () => ( t27.tsAnyKeyword()));
|
|
2847
2950
|
return eventNames.map((eventName) => {
|
|
2848
2951
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
2849
2952
|
const key = buildKey(handlerName);
|
|
2850
2953
|
const params = cloneCallableParams(restParams);
|
|
2851
|
-
const fnType =
|
|
2852
|
-
const prop =
|
|
2954
|
+
const fnType = t27.tsFunctionType(null, params, t27.tsTypeAnnotation(returnType));
|
|
2955
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(fnType));
|
|
2853
2956
|
prop.optional = true;
|
|
2854
2957
|
return prop;
|
|
2855
2958
|
});
|
|
2856
2959
|
}
|
|
2857
2960
|
function resolveEventNames(type) {
|
|
2858
|
-
if (
|
|
2961
|
+
if (t27.isTSLiteralType(type) && t27.isStringLiteral(type.literal)) {
|
|
2859
2962
|
return [type.literal.value];
|
|
2860
2963
|
}
|
|
2861
|
-
if (
|
|
2964
|
+
if (t27.isTSUnionType(type)) {
|
|
2862
2965
|
return type.types.flatMap(resolveEventNames);
|
|
2863
2966
|
}
|
|
2864
|
-
if (
|
|
2967
|
+
if (t27.isTSParenthesizedType(type)) {
|
|
2865
2968
|
return resolveEventNames(type.typeAnnotation);
|
|
2866
2969
|
}
|
|
2867
2970
|
return [];
|
|
@@ -2874,49 +2977,49 @@ function resolveTupleTypeParams(tuple) {
|
|
|
2874
2977
|
return params;
|
|
2875
2978
|
}
|
|
2876
2979
|
function resolveTupleElementParam(element, index) {
|
|
2877
|
-
const isNamedTuple = typeof
|
|
2980
|
+
const isNamedTuple = typeof t27.isTSNamedTupleMember === "function" && t27.isTSNamedTupleMember(element);
|
|
2878
2981
|
if (isNamedTuple) {
|
|
2879
2982
|
const tupleMember = element;
|
|
2880
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
2983
|
+
const name = _optionalChain([tupleMember, 'access', _77 => _77.label, 'optionalAccess', _78 => _78.name]) || `arg${index}`;
|
|
2881
2984
|
let innerType = tupleMember.elementType;
|
|
2882
2985
|
let optional = tupleMember.optional;
|
|
2883
|
-
if (
|
|
2986
|
+
if (t27.isTSOptionalType(innerType)) {
|
|
2884
2987
|
optional = true;
|
|
2885
2988
|
innerType = innerType.typeAnnotation;
|
|
2886
2989
|
}
|
|
2887
|
-
if (
|
|
2888
|
-
const rest =
|
|
2889
|
-
rest.typeAnnotation =
|
|
2990
|
+
if (t27.isTSRestType(innerType)) {
|
|
2991
|
+
const rest = t27.restElement(t27.identifier(name));
|
|
2992
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(innerType.typeAnnotation);
|
|
2890
2993
|
return rest;
|
|
2891
2994
|
}
|
|
2892
|
-
const id2 =
|
|
2995
|
+
const id2 = t27.identifier(name);
|
|
2893
2996
|
id2.optional = optional;
|
|
2894
|
-
id2.typeAnnotation =
|
|
2997
|
+
id2.typeAnnotation = t27.tsTypeAnnotation(innerType);
|
|
2895
2998
|
return id2;
|
|
2896
2999
|
}
|
|
2897
|
-
if (
|
|
2898
|
-
const rest =
|
|
2899
|
-
rest.typeAnnotation =
|
|
3000
|
+
if (t27.isTSRestType(element)) {
|
|
3001
|
+
const rest = t27.restElement(t27.identifier(`args${index}`));
|
|
3002
|
+
rest.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2900
3003
|
return rest;
|
|
2901
3004
|
}
|
|
2902
|
-
if (
|
|
2903
|
-
const id2 =
|
|
3005
|
+
if (t27.isTSOptionalType(element)) {
|
|
3006
|
+
const id2 = t27.identifier(`arg${index}`);
|
|
2904
3007
|
id2.optional = true;
|
|
2905
|
-
id2.typeAnnotation =
|
|
3008
|
+
id2.typeAnnotation = t27.tsTypeAnnotation(element.typeAnnotation);
|
|
2906
3009
|
return id2;
|
|
2907
3010
|
}
|
|
2908
|
-
const id =
|
|
2909
|
-
id.typeAnnotation =
|
|
3011
|
+
const id = t27.identifier(`arg${index}`);
|
|
3012
|
+
id.typeAnnotation = t27.tsTypeAnnotation(element);
|
|
2910
3013
|
return id;
|
|
2911
3014
|
}
|
|
2912
3015
|
|
|
2913
3016
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
|
|
2914
3017
|
|
|
2915
|
-
function resolveDefinePropsIface(
|
|
2916
|
-
const { node } =
|
|
3018
|
+
function resolveDefinePropsIface(path8, ctx) {
|
|
3019
|
+
const { node } = path8;
|
|
2917
3020
|
const [runtimeArg] = node.arguments;
|
|
2918
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2919
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
3021
|
+
const tsParams = _optionalChain([node, 'access', _79 => _79.typeParameters, 'optionalAccess', _80 => _80.params]);
|
|
3022
|
+
if (_optionalChain([tsParams, 'optionalAccess', _81 => _81.length])) {
|
|
2920
3023
|
const { propsTSIface } = ctx.scriptData;
|
|
2921
3024
|
propsTSIface.propsTypes = tsParams;
|
|
2922
3025
|
return;
|
|
@@ -2931,38 +3034,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
2931
3034
|
} = scriptData;
|
|
2932
3035
|
if (!runtimeArg) return;
|
|
2933
3036
|
const members = [];
|
|
2934
|
-
if (
|
|
3037
|
+
if (t28.isArrayExpression(runtimeArg)) {
|
|
2935
3038
|
for (const element of runtimeArg.elements) {
|
|
2936
|
-
if (!element || !
|
|
2937
|
-
const key =
|
|
2938
|
-
const prop =
|
|
3039
|
+
if (!element || !t28.isStringLiteral(element)) continue;
|
|
3040
|
+
const key = t28.isValidIdentifier(element.value) ? t28.identifier(element.value) : t28.stringLiteral(element.value);
|
|
3041
|
+
const prop = t28.tsPropertySignature(key, t28.tsTypeAnnotation(t28.tsAnyKeyword()));
|
|
2939
3042
|
prop.optional = true;
|
|
2940
3043
|
members.push(prop);
|
|
2941
3044
|
}
|
|
2942
3045
|
if (members.length) {
|
|
2943
|
-
propsTypes.push(
|
|
3046
|
+
propsTypes.push(t28.tsTypeLiteral(members));
|
|
2944
3047
|
}
|
|
2945
3048
|
return;
|
|
2946
3049
|
}
|
|
2947
|
-
if (
|
|
3050
|
+
if (t28.isObjectExpression(runtimeArg)) {
|
|
2948
3051
|
for (const prop of runtimeArg.properties) {
|
|
2949
|
-
if (!
|
|
2950
|
-
if (
|
|
3052
|
+
if (!t28.isObjectProperty(prop)) continue;
|
|
3053
|
+
if (t28.isSpreadElement(prop)) continue;
|
|
2951
3054
|
const key = prop.key;
|
|
2952
3055
|
let propName = null;
|
|
2953
|
-
if (
|
|
2954
|
-
if (
|
|
2955
|
-
if (
|
|
3056
|
+
if (t28.isIdentifier(key)) propName = key.name;
|
|
3057
|
+
if (t28.isStringLiteral(key)) propName = key.value;
|
|
3058
|
+
if (t28.isNumericLiteral(key)) propName = String(key.value);
|
|
2956
3059
|
if (!propName) continue;
|
|
2957
3060
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
2958
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
2959
|
-
const tsKey =
|
|
2960
|
-
const tsProp =
|
|
3061
|
+
const tsType = _nullishCoalesce(type, () => ( t28.tsAnyKeyword()));
|
|
3062
|
+
const tsKey = t28.isValidIdentifier(propName) ? t28.identifier(propName) : t28.stringLiteral(propName);
|
|
3063
|
+
const tsProp = t28.tsPropertySignature(tsKey, t28.tsTypeAnnotation(tsType));
|
|
2961
3064
|
tsProp.optional = !required;
|
|
2962
3065
|
members.push(tsProp);
|
|
2963
3066
|
}
|
|
2964
3067
|
if (members.length) {
|
|
2965
|
-
propsTypes.push(
|
|
3068
|
+
propsTypes.push(t28.tsTypeLiteral(members));
|
|
2966
3069
|
}
|
|
2967
3070
|
return;
|
|
2968
3071
|
}
|
|
@@ -2971,47 +3074,47 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
2971
3074
|
{
|
|
2972
3075
|
source,
|
|
2973
3076
|
file: filename,
|
|
2974
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
3077
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _82 => _82.loc])
|
|
2975
3078
|
}
|
|
2976
3079
|
);
|
|
2977
3080
|
}
|
|
2978
3081
|
function resolveRuntimePropMeta(value) {
|
|
2979
|
-
if (
|
|
3082
|
+
if (t28.isIdentifier(value)) {
|
|
2980
3083
|
return {
|
|
2981
3084
|
type: mapRuntimeTypeToTSType(value),
|
|
2982
3085
|
required: false
|
|
2983
3086
|
};
|
|
2984
3087
|
}
|
|
2985
|
-
if (
|
|
3088
|
+
if (t28.isArrayExpression(value)) {
|
|
2986
3089
|
return {
|
|
2987
3090
|
type: resolveRuntimeUnionType(value),
|
|
2988
3091
|
required: false
|
|
2989
3092
|
};
|
|
2990
3093
|
}
|
|
2991
|
-
if (!
|
|
3094
|
+
if (!t28.isObjectExpression(value)) {
|
|
2992
3095
|
return { required: false };
|
|
2993
3096
|
}
|
|
2994
3097
|
let type;
|
|
2995
3098
|
let required = false;
|
|
2996
3099
|
for (const prop of value.properties) {
|
|
2997
|
-
if (!
|
|
2998
|
-
if (
|
|
3100
|
+
if (!t28.isObjectProperty(prop)) continue;
|
|
3101
|
+
if (t28.isSpreadElement(prop)) continue;
|
|
2999
3102
|
const key = prop.key;
|
|
3000
|
-
const propName =
|
|
3103
|
+
const propName = t28.isIdentifier(key) ? key.name : t28.isStringLiteral(key) ? key.value : null;
|
|
3001
3104
|
if (!propName) continue;
|
|
3002
3105
|
if (propName === "type") {
|
|
3003
3106
|
const valueNode = prop.value;
|
|
3004
|
-
if (
|
|
3107
|
+
if (t28.isArrayExpression(valueNode)) {
|
|
3005
3108
|
type = resolveRuntimeUnionType(valueNode);
|
|
3006
3109
|
continue;
|
|
3007
3110
|
}
|
|
3008
|
-
if (
|
|
3111
|
+
if (t28.isIdentifier(valueNode)) {
|
|
3009
3112
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
3010
3113
|
continue;
|
|
3011
3114
|
}
|
|
3012
3115
|
}
|
|
3013
3116
|
if (propName === "required") {
|
|
3014
|
-
if (
|
|
3117
|
+
if (t28.isBooleanLiteral(prop.value)) {
|
|
3015
3118
|
required = prop.value.value;
|
|
3016
3119
|
}
|
|
3017
3120
|
}
|
|
@@ -3021,34 +3124,34 @@ function resolveRuntimePropMeta(value) {
|
|
|
3021
3124
|
function resolveRuntimeUnionType(value) {
|
|
3022
3125
|
const types = [];
|
|
3023
3126
|
for (const element of value.elements) {
|
|
3024
|
-
if (!element || !
|
|
3127
|
+
if (!element || !t28.isIdentifier(element)) continue;
|
|
3025
3128
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
3026
3129
|
if (resolved) types.push(resolved);
|
|
3027
3130
|
}
|
|
3028
|
-
if (!types.length) return
|
|
3131
|
+
if (!types.length) return t28.tsAnyKeyword();
|
|
3029
3132
|
if (types.length === 1) return types[0];
|
|
3030
|
-
return
|
|
3133
|
+
return t28.tsUnionType(types);
|
|
3031
3134
|
}
|
|
3032
3135
|
function mapRuntimeTypeToTSType(value) {
|
|
3033
3136
|
switch (value.name) {
|
|
3034
3137
|
case "String":
|
|
3035
|
-
return
|
|
3138
|
+
return t28.tsStringKeyword();
|
|
3036
3139
|
case "Number":
|
|
3037
|
-
return
|
|
3140
|
+
return t28.tsNumberKeyword();
|
|
3038
3141
|
case "Boolean":
|
|
3039
|
-
return
|
|
3142
|
+
return t28.tsBooleanKeyword();
|
|
3040
3143
|
case "Object":
|
|
3041
|
-
return
|
|
3144
|
+
return t28.tsTypeLiteral([]);
|
|
3042
3145
|
case "Array":
|
|
3043
|
-
return
|
|
3146
|
+
return t28.tsArrayType(t28.tsAnyKeyword());
|
|
3044
3147
|
case "Function":
|
|
3045
|
-
return
|
|
3148
|
+
return t28.tsFunctionType(null, [], t28.tsTypeAnnotation(t28.tsAnyKeyword()));
|
|
3046
3149
|
case "Symbol":
|
|
3047
|
-
return
|
|
3150
|
+
return t28.tsSymbolKeyword();
|
|
3048
3151
|
case "BigInt":
|
|
3049
|
-
return
|
|
3152
|
+
return t28.tsBigIntKeyword();
|
|
3050
3153
|
default:
|
|
3051
|
-
return
|
|
3154
|
+
return t28.tsAnyKeyword();
|
|
3052
3155
|
}
|
|
3053
3156
|
}
|
|
3054
3157
|
|
|
@@ -3059,20 +3162,20 @@ var SLOT_CHILDREN_NAME = "children";
|
|
|
3059
3162
|
var SLOT_FN_PARAM_NAME = "props";
|
|
3060
3163
|
function resolveSlotsTopLevelTypes(ctx) {
|
|
3061
3164
|
return {
|
|
3062
|
-
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(
|
|
3063
|
-
if (!
|
|
3064
|
-
const { node } =
|
|
3065
|
-
if (
|
|
3066
|
-
const typeLiteral =
|
|
3165
|
+
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
|
|
3166
|
+
if (!t29.isProgram(path8.parent)) return;
|
|
3167
|
+
const { node } = path8;
|
|
3168
|
+
if (t29.isTSInterfaceDeclaration(node)) {
|
|
3169
|
+
const typeLiteral = t29.tsTypeLiteral(node.body.body);
|
|
3067
3170
|
if (!hasSlotsSignatureInType(typeLiteral)) return;
|
|
3068
3171
|
const resolved = resolveSlotType(typeLiteral);
|
|
3069
|
-
if (resolved &&
|
|
3172
|
+
if (resolved && t29.isTSTypeLiteral(resolved)) {
|
|
3070
3173
|
node.body.body = resolved.members;
|
|
3071
3174
|
recordReactNode(ctx);
|
|
3072
3175
|
}
|
|
3073
3176
|
return;
|
|
3074
3177
|
}
|
|
3075
|
-
if (
|
|
3178
|
+
if (t29.isTSTypeAliasDeclaration(node)) {
|
|
3076
3179
|
if (!hasSlotsSignatureInType(node.typeAnnotation)) return;
|
|
3077
3180
|
const resolved = resolveSlotType(node.typeAnnotation);
|
|
3078
3181
|
if (resolved) {
|
|
@@ -3083,10 +3186,10 @@ function resolveSlotsTopLevelTypes(ctx) {
|
|
|
3083
3186
|
}
|
|
3084
3187
|
};
|
|
3085
3188
|
}
|
|
3086
|
-
function resolveDefineSlotsIface(
|
|
3087
|
-
const { node } =
|
|
3088
|
-
const tsParams = _optionalChain([node, 'access',
|
|
3089
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
3189
|
+
function resolveDefineSlotsIface(path8, ctx) {
|
|
3190
|
+
const { node } = path8;
|
|
3191
|
+
const tsParams = _optionalChain([node, 'access', _83 => _83.typeParameters, 'optionalAccess', _84 => _84.params]);
|
|
3192
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _85 => _85.length])) return;
|
|
3090
3193
|
const {
|
|
3091
3194
|
propsTSIface: { slotTypes }
|
|
3092
3195
|
} = ctx.scriptData;
|
|
@@ -3117,7 +3220,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
3117
3220
|
}
|
|
3118
3221
|
if (tsMembers.length) {
|
|
3119
3222
|
recordReactNode(ctx);
|
|
3120
|
-
slotTypes.push(
|
|
3223
|
+
slotTypes.push(t29.tsTypeLiteral(tsMembers));
|
|
3121
3224
|
}
|
|
3122
3225
|
}
|
|
3123
3226
|
function recordReactNode(ctx) {
|
|
@@ -3127,32 +3230,32 @@ function recordReactNode(ctx) {
|
|
|
3127
3230
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
|
|
3128
3231
|
}
|
|
3129
3232
|
function resolveSlotType(tsType) {
|
|
3130
|
-
if (
|
|
3233
|
+
if (t29.isTSParenthesizedType(tsType)) {
|
|
3131
3234
|
return resolveSlotType(tsType.typeAnnotation);
|
|
3132
3235
|
}
|
|
3133
|
-
if (
|
|
3236
|
+
if (t29.isTSTypeReference(tsType)) {
|
|
3134
3237
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3135
3238
|
return tsType;
|
|
3136
3239
|
}
|
|
3137
3240
|
const params = tsType.typeParameters.params.map((param) => resolveSlotType(param)).filter(Boolean);
|
|
3138
|
-
return
|
|
3241
|
+
return t29.tsTypeReference(
|
|
3139
3242
|
tsType.typeName,
|
|
3140
|
-
|
|
3243
|
+
t29.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
3141
3244
|
);
|
|
3142
3245
|
}
|
|
3143
|
-
if (
|
|
3246
|
+
if (t29.isTSIntersectionType(tsType)) {
|
|
3144
3247
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3145
3248
|
if (!types.length) return null;
|
|
3146
3249
|
if (types.length === 1) return types[0];
|
|
3147
|
-
return
|
|
3250
|
+
return t29.tsIntersectionType(types);
|
|
3148
3251
|
}
|
|
3149
|
-
if (
|
|
3252
|
+
if (t29.isTSUnionType(tsType)) {
|
|
3150
3253
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
3151
3254
|
if (!types.length) return null;
|
|
3152
3255
|
if (types.length === 1) return types[0];
|
|
3153
|
-
return
|
|
3256
|
+
return t29.tsUnionType(types);
|
|
3154
3257
|
}
|
|
3155
|
-
if (
|
|
3258
|
+
if (t29.isTSTypeLiteral(tsType)) {
|
|
3156
3259
|
const members = [];
|
|
3157
3260
|
for (const member of tsType.members) {
|
|
3158
3261
|
const resolved = resolveSlotPropFromMember(member);
|
|
@@ -3163,110 +3266,111 @@ function resolveSlotType(tsType) {
|
|
|
3163
3266
|
members.push(member);
|
|
3164
3267
|
}
|
|
3165
3268
|
if (!members.length) return null;
|
|
3166
|
-
return
|
|
3269
|
+
return t29.tsTypeLiteral(members);
|
|
3167
3270
|
}
|
|
3168
|
-
if (
|
|
3271
|
+
if (t29.isTSFunctionType(tsType)) {
|
|
3169
3272
|
const props = buildSlotPropSignature(
|
|
3170
3273
|
SLOT_DEFAULT_NAME,
|
|
3171
3274
|
cloneCallableParams(tsType.parameters),
|
|
3172
3275
|
false
|
|
3173
3276
|
);
|
|
3174
|
-
return
|
|
3277
|
+
return t29.tsTypeLiteral([props]);
|
|
3175
3278
|
}
|
|
3176
3279
|
return tsType;
|
|
3177
3280
|
}
|
|
3178
3281
|
function hasSlotsSignatureInType(tsType) {
|
|
3179
|
-
if (
|
|
3282
|
+
if (t29.isTSParenthesizedType(tsType)) {
|
|
3180
3283
|
return hasSlotsSignatureInType(tsType.typeAnnotation);
|
|
3181
3284
|
}
|
|
3182
|
-
if (
|
|
3285
|
+
if (t29.isTSTypeReference(tsType)) {
|
|
3183
3286
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
3184
3287
|
return false;
|
|
3185
3288
|
}
|
|
3186
3289
|
return tsType.typeParameters.params.some(hasSlotsSignatureInType);
|
|
3187
3290
|
}
|
|
3188
|
-
if (
|
|
3291
|
+
if (t29.isTSIntersectionType(tsType) || t29.isTSUnionType(tsType)) {
|
|
3189
3292
|
return tsType.types.some(hasSlotsSignatureInType);
|
|
3190
3293
|
}
|
|
3191
|
-
if (
|
|
3294
|
+
if (t29.isTSTypeLiteral(tsType)) {
|
|
3192
3295
|
return tsType.members.some(hasSlotsSignatureInMember);
|
|
3193
3296
|
}
|
|
3194
|
-
if (
|
|
3297
|
+
if (t29.isTSFunctionType(tsType)) {
|
|
3195
3298
|
return true;
|
|
3196
3299
|
}
|
|
3197
3300
|
return false;
|
|
3198
3301
|
}
|
|
3199
3302
|
function hasSlotsSignatureInMember(member) {
|
|
3200
|
-
if (
|
|
3201
|
-
if (
|
|
3202
|
-
if (
|
|
3203
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3303
|
+
if (t29.isTSMethodSignature(member)) return true;
|
|
3304
|
+
if (t29.isTSCallSignatureDeclaration(member)) return true;
|
|
3305
|
+
if (t29.isTSPropertySignature(member)) {
|
|
3306
|
+
const typeAnnotation = _optionalChain([member, 'access', _86 => _86.typeAnnotation, 'optionalAccess', _87 => _87.typeAnnotation]);
|
|
3204
3307
|
return !!(typeAnnotation && resolveCallableType(typeAnnotation));
|
|
3205
3308
|
}
|
|
3206
3309
|
return false;
|
|
3207
3310
|
}
|
|
3208
3311
|
function resolveSlotPropFromMember(member) {
|
|
3209
|
-
if (
|
|
3312
|
+
if (t29.isTSMethodSignature(member)) {
|
|
3210
3313
|
const rawName = resolvePropName2(member.key);
|
|
3211
3314
|
if (!rawName) return null;
|
|
3212
3315
|
const params = cloneCallableParams(member.parameters);
|
|
3213
3316
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3214
3317
|
}
|
|
3215
|
-
if (
|
|
3318
|
+
if (t29.isTSPropertySignature(member)) {
|
|
3216
3319
|
const rawName = resolvePropName2(member.key);
|
|
3217
3320
|
if (!rawName) return null;
|
|
3218
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3321
|
+
const typeAnnotation = _optionalChain([member, 'access', _88 => _88.typeAnnotation, 'optionalAccess', _89 => _89.typeAnnotation]);
|
|
3219
3322
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
3220
3323
|
if (!callable) return null;
|
|
3221
3324
|
const params = cloneCallableParams(callable.parameters);
|
|
3222
3325
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
3223
3326
|
}
|
|
3224
|
-
if (
|
|
3327
|
+
if (t29.isTSCallSignatureDeclaration(member)) {
|
|
3225
3328
|
const params = cloneCallableParams(member.parameters);
|
|
3226
3329
|
return buildSlotPropSignature(SLOT_DEFAULT_NAME, params, true);
|
|
3227
3330
|
}
|
|
3228
3331
|
return null;
|
|
3229
3332
|
}
|
|
3230
3333
|
function resolveCallableType(tsType) {
|
|
3231
|
-
if (
|
|
3232
|
-
if (
|
|
3334
|
+
if (t29.isTSFunctionType(tsType)) return tsType;
|
|
3335
|
+
if (t29.isTSParenthesizedType(tsType)) return resolveCallableType(tsType.typeAnnotation);
|
|
3233
3336
|
return null;
|
|
3234
3337
|
}
|
|
3235
3338
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
3236
3339
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
3237
|
-
const key =
|
|
3238
|
-
const reactNodeType =
|
|
3239
|
-
|
|
3340
|
+
const key = t29.isValidIdentifier(propName) ? t29.identifier(propName) : t29.stringLiteral(propName);
|
|
3341
|
+
const reactNodeType = t29.tsTypeAnnotation(
|
|
3342
|
+
t29.tsTypeReference(t29.identifier(REACT_API_MAP.ReactNode))
|
|
3240
3343
|
);
|
|
3241
3344
|
let typeAnnotation;
|
|
3242
3345
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
3243
3346
|
typeAnnotation = reactNodeType;
|
|
3244
3347
|
} else {
|
|
3245
|
-
const fnType =
|
|
3246
|
-
typeAnnotation =
|
|
3348
|
+
const fnType = t29.tsFunctionType(null, params, reactNodeType);
|
|
3349
|
+
typeAnnotation = t29.tsTypeAnnotation(fnType);
|
|
3247
3350
|
}
|
|
3248
|
-
const prop =
|
|
3351
|
+
const prop = t29.tsPropertySignature(key, typeAnnotation);
|
|
3249
3352
|
prop.optional = optional;
|
|
3250
3353
|
return prop;
|
|
3251
3354
|
}
|
|
3252
3355
|
function createSlotScopeParam(props, ctx) {
|
|
3253
|
-
const paramId =
|
|
3356
|
+
const paramId = t29.identifier(SLOT_FN_PARAM_NAME);
|
|
3254
3357
|
const propsSigns = [];
|
|
3255
3358
|
const { reactiveBindings } = ctx.templateData;
|
|
3256
3359
|
props.forEach(({ prop, tsType }) => {
|
|
3257
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
3360
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _90 => _90[prop], 'optionalAccess', _91 => _91.value]);
|
|
3258
3361
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3259
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3260
|
-
const
|
|
3362
|
+
const typeAnnotation = foundBindingTypes ? t29.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
3363
|
+
const key = t29.isValidIdentifier(prop) ? t29.identifier(prop) : t29.stringLiteral(prop);
|
|
3364
|
+
const propSign = t29.tsPropertySignature(key, typeAnnotation);
|
|
3261
3365
|
propsSigns.push(propSign);
|
|
3262
3366
|
});
|
|
3263
|
-
paramId.typeAnnotation =
|
|
3367
|
+
paramId.typeAnnotation = t29.tsTypeAnnotation(t29.tsTypeLiteral(propsSigns));
|
|
3264
3368
|
return paramId;
|
|
3265
3369
|
}
|
|
3266
3370
|
function resolvePropName2(key) {
|
|
3267
|
-
if (
|
|
3268
|
-
if (
|
|
3269
|
-
if (
|
|
3371
|
+
if (t29.isIdentifier(key)) return key.name;
|
|
3372
|
+
if (t29.isStringLiteral(key)) return key.value;
|
|
3373
|
+
if (t29.isNumericLiteral(key)) return String(key.value);
|
|
3270
3374
|
return null;
|
|
3271
3375
|
}
|
|
3272
3376
|
|
|
@@ -3274,8 +3378,8 @@ function resolvePropName2(key) {
|
|
|
3274
3378
|
function resolvePropsIface(ctx) {
|
|
3275
3379
|
const isTS = ctx.scriptData.lang.startsWith("ts");
|
|
3276
3380
|
return {
|
|
3277
|
-
CallExpression(
|
|
3278
|
-
const { node, parentPath } =
|
|
3381
|
+
CallExpression(path8) {
|
|
3382
|
+
const { node, parentPath } = path8;
|
|
3279
3383
|
const name = node.callee.name;
|
|
3280
3384
|
if (!isCalleeNamed(node, MACRO_API_NAMES.props) && !isCalleeNamed(node, MACRO_API_NAMES.emits) && !isCalleeNamed(node, MACRO_API_NAMES.slots)) {
|
|
3281
3385
|
return;
|
|
@@ -3284,7 +3388,7 @@ function resolvePropsIface(ctx) {
|
|
|
3284
3388
|
if (parentPath.isVariableDeclaration() || parentPath.isVariableDeclarator()) {
|
|
3285
3389
|
parentPath.remove();
|
|
3286
3390
|
} else {
|
|
3287
|
-
|
|
3391
|
+
path8.remove();
|
|
3288
3392
|
}
|
|
3289
3393
|
};
|
|
3290
3394
|
if (ctx.inputType !== "sfc") {
|
|
@@ -3298,11 +3402,11 @@ function resolvePropsIface(ctx) {
|
|
|
3298
3402
|
propsTSIface.hasPropsInJsEnv = true;
|
|
3299
3403
|
} else {
|
|
3300
3404
|
if (name === MACRO_API_NAMES.props) {
|
|
3301
|
-
resolveDefinePropsIface(
|
|
3405
|
+
resolveDefinePropsIface(path8, ctx);
|
|
3302
3406
|
} else if (name === MACRO_API_NAMES.emits) {
|
|
3303
|
-
resolveDefineEmitsIface(
|
|
3407
|
+
resolveDefineEmitsIface(path8, ctx);
|
|
3304
3408
|
} else if (name === MACRO_API_NAMES.slots) {
|
|
3305
|
-
resolveDefineSlotsIface(
|
|
3409
|
+
resolveDefineSlotsIface(path8, ctx);
|
|
3306
3410
|
}
|
|
3307
3411
|
}
|
|
3308
3412
|
removePath();
|
|
@@ -3318,9 +3422,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3318
3422
|
}
|
|
3319
3423
|
const n = ctx.compName || "Comp";
|
|
3320
3424
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
3321
|
-
const typeNode =
|
|
3322
|
-
const typeAliasDecl =
|
|
3323
|
-
const exportDecl =
|
|
3425
|
+
const typeNode = t30.tsIntersectionType(tsTypes);
|
|
3426
|
+
const typeAliasDecl = t30.tsTypeAliasDeclaration(t30.identifier(ns), null, typeNode);
|
|
3427
|
+
const exportDecl = t30.exportNamedDeclaration(typeAliasDecl);
|
|
3324
3428
|
propsTSIface.name = ns;
|
|
3325
3429
|
const scriptIR = getScriptIR(ctx);
|
|
3326
3430
|
scriptIR.exports.push(exportDecl);
|
|
@@ -3336,9 +3440,9 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3336
3440
|
var TRACE_MAX_DEPTH = 20;
|
|
3337
3441
|
function analyzeDeps(node, ctx, parentPath) {
|
|
3338
3442
|
if (!parentPath) {
|
|
3339
|
-
return
|
|
3443
|
+
return t31.arrayExpression([]);
|
|
3340
3444
|
}
|
|
3341
|
-
const isFnExpr =
|
|
3445
|
+
const isFnExpr = t31.isArrowFunctionExpression(node) || t31.isFunctionExpression(node);
|
|
3342
3446
|
const analyzeTarget = isFnExpr ? node.body : node;
|
|
3343
3447
|
const bindingLocalBoundary = isFnExpr ? node : analyzeTarget;
|
|
3344
3448
|
const reactiveStateApis = getReactiveStateApis();
|
|
@@ -3351,11 +3455,11 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3351
3455
|
analyzeTarget,
|
|
3352
3456
|
{
|
|
3353
3457
|
"MemberExpression|OptionalMemberExpression"(memberPath) {
|
|
3354
|
-
const
|
|
3355
|
-
if (isNestedMemberObject(
|
|
3356
|
-
const rootId = findRootIdentifier(
|
|
3458
|
+
const path8 = memberPath;
|
|
3459
|
+
if (isNestedMemberObject(path8)) return;
|
|
3460
|
+
const rootId = findRootIdentifier(path8.node);
|
|
3357
3461
|
if (!rootId) return;
|
|
3358
|
-
tryAddDependency(
|
|
3462
|
+
tryAddDependency(path8, rootId.name, path8.scope);
|
|
3359
3463
|
processedIdentifiers.add(rootId);
|
|
3360
3464
|
},
|
|
3361
3465
|
Identifier(idPath) {
|
|
@@ -3390,40 +3494,41 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3390
3494
|
addDependency(sourcedExpression);
|
|
3391
3495
|
}
|
|
3392
3496
|
}
|
|
3393
|
-
function normalizeDependencyExpr(
|
|
3394
|
-
if (
|
|
3395
|
-
return
|
|
3497
|
+
function normalizeDependencyExpr(path8, rootName) {
|
|
3498
|
+
if (t31.isIdentifier(path8.node)) {
|
|
3499
|
+
return t31.identifier(path8.node.name);
|
|
3396
3500
|
}
|
|
3397
|
-
if (
|
|
3398
|
-
const normalizedExp = normalizeMemberForCallSite(
|
|
3399
|
-
|
|
3400
|
-
|
|
3501
|
+
if (t31.isMemberExpression(path8.node) || t31.isOptionalMemberExpression(path8.node)) {
|
|
3502
|
+
const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
|
|
3503
|
+
const safeExp = t31.isMemberExpression(normalizedExp) || t31.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForRefValue(normalizedExp) : normalizedExp;
|
|
3504
|
+
if (isReactValidDependencyExpr(safeExp)) {
|
|
3505
|
+
return t31.cloneNode(safeExp, true);
|
|
3401
3506
|
}
|
|
3402
|
-
return
|
|
3507
|
+
return t31.identifier(rootName);
|
|
3403
3508
|
}
|
|
3404
3509
|
return null;
|
|
3405
3510
|
}
|
|
3406
3511
|
function isReactValidDependencyExpr(node2) {
|
|
3407
|
-
if (
|
|
3512
|
+
if (t31.isIdentifier(node2)) {
|
|
3408
3513
|
return true;
|
|
3409
3514
|
}
|
|
3410
|
-
if (
|
|
3515
|
+
if (t31.isMemberExpression(node2) || t31.isOptionalMemberExpression(node2)) {
|
|
3411
3516
|
return isStaticMemberChain(node2);
|
|
3412
3517
|
}
|
|
3413
3518
|
return false;
|
|
3414
3519
|
}
|
|
3415
3520
|
function isStaticMemberChain(node2) {
|
|
3416
3521
|
let current = node2;
|
|
3417
|
-
while (
|
|
3418
|
-
if (!current.computed && !
|
|
3522
|
+
while (t31.isMemberExpression(current) || t31.isOptionalMemberExpression(current)) {
|
|
3523
|
+
if (!current.computed && !t31.isIdentifier(current.property)) {
|
|
3419
3524
|
return false;
|
|
3420
3525
|
}
|
|
3421
|
-
if (current.computed && !
|
|
3526
|
+
if (current.computed && !t31.isStringLiteral(current.property) && !t31.isNumericLiteral(current.property)) {
|
|
3422
3527
|
return false;
|
|
3423
3528
|
}
|
|
3424
3529
|
current = current.object;
|
|
3425
3530
|
}
|
|
3426
|
-
return
|
|
3531
|
+
return t31.isIdentifier(current);
|
|
3427
3532
|
}
|
|
3428
3533
|
function isBindingDeclaredInsideBoundary(binding, boundary) {
|
|
3429
3534
|
let current = binding.path;
|
|
@@ -3435,17 +3540,42 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3435
3540
|
}
|
|
3436
3541
|
return false;
|
|
3437
3542
|
}
|
|
3438
|
-
function normalizeMemberForCallSite(
|
|
3439
|
-
const parent =
|
|
3543
|
+
function normalizeMemberForCallSite(path8, node2) {
|
|
3544
|
+
const parent = path8.parentPath;
|
|
3440
3545
|
const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node2 || parent.isOptionalCallExpression() && parent.node.callee === node2);
|
|
3441
3546
|
if (!isDirectCallee) {
|
|
3442
3547
|
return node2;
|
|
3443
3548
|
}
|
|
3444
|
-
if (!
|
|
3549
|
+
if (!t31.isExpression(node2.object)) {
|
|
3445
3550
|
return node2;
|
|
3446
3551
|
}
|
|
3447
3552
|
return node2.object;
|
|
3448
3553
|
}
|
|
3554
|
+
function ensureOptionalForRefValue(node2) {
|
|
3555
|
+
if (!hasRefValueAccess(node2)) {
|
|
3556
|
+
return node2;
|
|
3557
|
+
}
|
|
3558
|
+
if (t31.isOptionalMemberExpression(node2) && node2.optional) {
|
|
3559
|
+
return node2;
|
|
3560
|
+
}
|
|
3561
|
+
const object = t31.cloneNode(node2.object, true);
|
|
3562
|
+
const property = t31.cloneNode(node2.property, true);
|
|
3563
|
+
return t31.optionalMemberExpression(object, property, node2.computed, true);
|
|
3564
|
+
}
|
|
3565
|
+
function hasRefValueAccess(node2) {
|
|
3566
|
+
let current = node2;
|
|
3567
|
+
while (t31.isMemberExpression(current) || t31.isOptionalMemberExpression(current)) {
|
|
3568
|
+
if (current.computed) {
|
|
3569
|
+
if (t31.isStringLiteral(current.property) && current.property.value === "value") {
|
|
3570
|
+
return true;
|
|
3571
|
+
}
|
|
3572
|
+
} else if (t31.isIdentifier(current.property) && current.property.name === "value") {
|
|
3573
|
+
return true;
|
|
3574
|
+
}
|
|
3575
|
+
current = current.object;
|
|
3576
|
+
}
|
|
3577
|
+
return false;
|
|
3578
|
+
}
|
|
3449
3579
|
function isEligibleBindingSource(binding) {
|
|
3450
3580
|
if (binding.kind === "param") {
|
|
3451
3581
|
return false;
|
|
@@ -3454,20 +3584,20 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3454
3584
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
3455
3585
|
const isImportBinding = bindingPath.isImportSpecifier() || bindingPath.isImportDefaultSpecifier() || bindingPath.isImportNamespaceSpecifier();
|
|
3456
3586
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
3457
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess',
|
|
3458
|
-
const isReactiveApiCallVarBinding = !!declaratorPath &&
|
|
3459
|
-
const isHookCallVarBinding = !!declaratorPath &&
|
|
3460
|
-
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (
|
|
3461
|
-
if (declaratorPath && nodeInit && (
|
|
3587
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _92 => _92.node, 'access', _93 => _93.init]);
|
|
3588
|
+
const isReactiveApiCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && t31.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
3589
|
+
const isHookCallVarBinding = !!declaratorPath && t31.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
3590
|
+
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit));
|
|
3591
|
+
if (declaratorPath && nodeInit && (t31.isArrowFunctionExpression(nodeInit) || t31.isFunctionExpression(nodeInit))) {
|
|
3462
3592
|
markAsAnalyzed(nodeInit, false);
|
|
3463
3593
|
}
|
|
3464
3594
|
return isImportBinding || isReactiveVarBinding || isReactiveApiCallVarBinding || isHookCallVarBinding || isFunctionBinding;
|
|
3465
3595
|
}
|
|
3466
3596
|
function isHookLikeCallee(callee) {
|
|
3467
|
-
if (
|
|
3597
|
+
if (t31.isIdentifier(callee)) {
|
|
3468
3598
|
return callee.name.startsWith("use");
|
|
3469
3599
|
}
|
|
3470
|
-
if (
|
|
3600
|
+
if (t31.isMemberExpression(callee) && !callee.computed && t31.isIdentifier(callee.property)) {
|
|
3471
3601
|
return callee.property.name.startsWith("use");
|
|
3472
3602
|
}
|
|
3473
3603
|
return false;
|
|
@@ -3483,7 +3613,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3483
3613
|
}
|
|
3484
3614
|
function isExpressionSourcedFromEligibleBinding(exp, scope, seen, depth) {
|
|
3485
3615
|
if (depth <= 0) return null;
|
|
3486
|
-
if (
|
|
3616
|
+
if (t31.isIdentifier(exp)) {
|
|
3487
3617
|
const sourceBinding = scope.getBinding(exp.name);
|
|
3488
3618
|
if (!sourceBinding) return null;
|
|
3489
3619
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
@@ -3491,13 +3621,13 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3491
3621
|
}
|
|
3492
3622
|
return traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3493
3623
|
}
|
|
3494
|
-
if (
|
|
3624
|
+
if (t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp)) {
|
|
3495
3625
|
const root = findRootIdentifier(exp);
|
|
3496
3626
|
if (!root) return null;
|
|
3497
3627
|
const sourceBinding = scope.getBinding(root.name);
|
|
3498
3628
|
if (!sourceBinding) return null;
|
|
3499
3629
|
if (isEligibleBindingSource(sourceBinding)) {
|
|
3500
|
-
return
|
|
3630
|
+
return t31.cloneNode(exp);
|
|
3501
3631
|
}
|
|
3502
3632
|
const sourcedRoot = traceBindingSource(sourceBinding, seen, depth - 1);
|
|
3503
3633
|
if (sourcedRoot) {
|
|
@@ -3505,17 +3635,17 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3505
3635
|
if (rebuilt) {
|
|
3506
3636
|
return rebuilt;
|
|
3507
3637
|
}
|
|
3508
|
-
return
|
|
3638
|
+
return t31.cloneNode(sourcedRoot, true);
|
|
3509
3639
|
}
|
|
3510
3640
|
}
|
|
3511
3641
|
return null;
|
|
3512
3642
|
}
|
|
3513
3643
|
function rebuildMemberWithNewRoot(node2, nextRoot) {
|
|
3514
3644
|
const replacedObject = (() => {
|
|
3515
|
-
if (
|
|
3516
|
-
return
|
|
3645
|
+
if (t31.isIdentifier(node2.object)) {
|
|
3646
|
+
return t31.cloneNode(nextRoot, true);
|
|
3517
3647
|
}
|
|
3518
|
-
if (
|
|
3648
|
+
if (t31.isMemberExpression(node2.object) || t31.isOptionalMemberExpression(node2.object)) {
|
|
3519
3649
|
return rebuildMemberWithNewRoot(node2.object, nextRoot);
|
|
3520
3650
|
}
|
|
3521
3651
|
return null;
|
|
@@ -3523,51 +3653,51 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3523
3653
|
if (!replacedObject) {
|
|
3524
3654
|
return null;
|
|
3525
3655
|
}
|
|
3526
|
-
const property =
|
|
3527
|
-
if (
|
|
3528
|
-
return
|
|
3656
|
+
const property = t31.cloneNode(node2.property, true);
|
|
3657
|
+
if (t31.isMemberExpression(node2)) {
|
|
3658
|
+
return t31.memberExpression(
|
|
3529
3659
|
replacedObject,
|
|
3530
3660
|
property,
|
|
3531
3661
|
node2.computed
|
|
3532
3662
|
);
|
|
3533
3663
|
}
|
|
3534
|
-
return
|
|
3664
|
+
return t31.optionalMemberExpression(
|
|
3535
3665
|
replacedObject,
|
|
3536
3666
|
property,
|
|
3537
3667
|
node2.computed,
|
|
3538
3668
|
node2.optional
|
|
3539
3669
|
);
|
|
3540
3670
|
}
|
|
3541
|
-
return
|
|
3671
|
+
return t31.arrayExpression(Array.from(deps.values()));
|
|
3542
3672
|
}
|
|
3543
3673
|
function getDependencyKey(exp) {
|
|
3544
|
-
if (
|
|
3674
|
+
if (t31.isIdentifier(exp)) {
|
|
3545
3675
|
return exp.name;
|
|
3546
3676
|
}
|
|
3547
|
-
if (
|
|
3677
|
+
if (t31.isMemberExpression(exp) || t31.isOptionalMemberExpression(exp)) {
|
|
3548
3678
|
const objectKey = getDependencyKey(exp.object);
|
|
3549
3679
|
const opt = exp.optional ? "?" : "";
|
|
3550
|
-
if (!exp.computed &&
|
|
3680
|
+
if (!exp.computed && t31.isIdentifier(exp.property)) {
|
|
3551
3681
|
return `${objectKey}${opt}.${exp.property.name}`;
|
|
3552
3682
|
}
|
|
3553
|
-
if (
|
|
3683
|
+
if (t31.isStringLiteral(exp.property) || t31.isNumericLiteral(exp.property)) {
|
|
3554
3684
|
return `${objectKey}${opt}[${JSON.stringify(exp.property.value)}]`;
|
|
3555
3685
|
}
|
|
3556
3686
|
return `${objectKey}${opt}[*]`;
|
|
3557
3687
|
}
|
|
3558
3688
|
return exp.type;
|
|
3559
3689
|
}
|
|
3560
|
-
function isNestedMemberObject(
|
|
3561
|
-
const parent =
|
|
3690
|
+
function isNestedMemberObject(path8) {
|
|
3691
|
+
const parent = path8.parentPath;
|
|
3562
3692
|
if (!parent) return false;
|
|
3563
3693
|
if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
|
|
3564
|
-
return parent.node.object ===
|
|
3694
|
+
return parent.node.object === path8.node;
|
|
3565
3695
|
}
|
|
3566
3696
|
return false;
|
|
3567
3697
|
}
|
|
3568
3698
|
function isReactiveBinding(node) {
|
|
3569
3699
|
if (!node) return false;
|
|
3570
|
-
return !!_optionalChain([getScriptNodeMeta, 'call',
|
|
3700
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _94 => _94(node), 'optionalAccess', _95 => _95.is_reactive]);
|
|
3571
3701
|
}
|
|
3572
3702
|
function markAsAnalyzed(node, flag = true) {
|
|
3573
3703
|
const analyzed = getIsAnalyzed(node);
|
|
@@ -3575,21 +3705,21 @@ function markAsAnalyzed(node, flag = true) {
|
|
|
3575
3705
|
setScriptNodeMeta(node, { is_deps_analyzed: flag });
|
|
3576
3706
|
}
|
|
3577
3707
|
function getIsAnalyzed(node) {
|
|
3578
|
-
return _optionalChain([getScriptNodeMeta, 'call',
|
|
3708
|
+
return _optionalChain([getScriptNodeMeta, 'call', _96 => _96(node), 'optionalAccess', _97 => _97.is_deps_analyzed]);
|
|
3579
3709
|
}
|
|
3580
3710
|
|
|
3581
3711
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
3582
3712
|
function resolveAnalysisOnlyAdapter(ctx) {
|
|
3583
3713
|
return {
|
|
3584
|
-
"CallExpression|Identifier"(
|
|
3585
|
-
const node =
|
|
3714
|
+
"CallExpression|Identifier"(path8) {
|
|
3715
|
+
const node = path8.node;
|
|
3586
3716
|
const apiName = getApiName(node);
|
|
3587
3717
|
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
3588
3718
|
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
3589
3719
|
return;
|
|
3590
3720
|
}
|
|
3591
|
-
if (
|
|
3592
|
-
resolveCallNode(
|
|
3721
|
+
if (t32.isCallExpression(node)) {
|
|
3722
|
+
resolveCallNode(path8, adapter, ctx);
|
|
3593
3723
|
} else {
|
|
3594
3724
|
replaceIdName(node, adapter.target);
|
|
3595
3725
|
}
|
|
@@ -3598,24 +3728,24 @@ function resolveAnalysisOnlyAdapter(ctx) {
|
|
|
3598
3728
|
};
|
|
3599
3729
|
}
|
|
3600
3730
|
function getApiName(node) {
|
|
3601
|
-
const isCallNode =
|
|
3731
|
+
const isCallNode = t32.isCallExpression(node);
|
|
3602
3732
|
let apiName = "";
|
|
3603
|
-
if (
|
|
3733
|
+
if (t32.isIdentifier(node)) {
|
|
3604
3734
|
apiName = node.name;
|
|
3605
|
-
} else if (isCallNode &&
|
|
3735
|
+
} else if (isCallNode && t32.isIdentifier(node.callee)) {
|
|
3606
3736
|
apiName = node.callee.name;
|
|
3607
3737
|
}
|
|
3608
3738
|
return apiName;
|
|
3609
3739
|
}
|
|
3610
|
-
function resolveCallNode(
|
|
3611
|
-
const { node } =
|
|
3740
|
+
function resolveCallNode(path8, adapter, ctx) {
|
|
3741
|
+
const { node } = path8;
|
|
3612
3742
|
const { arguments: args } = node;
|
|
3613
3743
|
if (!args.length) return;
|
|
3614
3744
|
const fn = args[0];
|
|
3615
|
-
if (!
|
|
3745
|
+
if (!t32.isArrowFunctionExpression(fn) && !t32.isFunctionExpression(fn)) {
|
|
3616
3746
|
return;
|
|
3617
3747
|
}
|
|
3618
|
-
const fnPath =
|
|
3748
|
+
const fnPath = path8.get("arguments")[0];
|
|
3619
3749
|
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
3620
3750
|
args.push(deps);
|
|
3621
3751
|
replaceCallName(node, adapter.target);
|
|
@@ -3625,41 +3755,41 @@ function resolveCallNode(path7, adapter, ctx) {
|
|
|
3625
3755
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
|
|
3626
3756
|
function resolveArrowFnDeps(ctx, ast) {
|
|
3627
3757
|
return {
|
|
3628
|
-
ArrowFunctionExpression(
|
|
3629
|
-
const { node, parentPath } =
|
|
3630
|
-
if (isSkip(
|
|
3758
|
+
ArrowFunctionExpression(path8) {
|
|
3759
|
+
const { node, parentPath } = path8;
|
|
3760
|
+
if (isSkip(path8) || !atComponentOrHookRoot(parentPath, ast.program)) {
|
|
3631
3761
|
return;
|
|
3632
3762
|
}
|
|
3633
|
-
const deps = analyzeDeps(node, ctx,
|
|
3763
|
+
const deps = analyzeDeps(node, ctx, path8);
|
|
3634
3764
|
if (!deps.elements.length) return;
|
|
3635
3765
|
const newNode = createUseCallback(node, deps);
|
|
3636
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3766
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
3637
3767
|
markAsAnalyzed(newNode.arguments[0]);
|
|
3638
3768
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
3639
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
3640
|
-
|
|
3769
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _98 => _98.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
3770
|
+
path8.replaceWith(newNode);
|
|
3641
3771
|
}
|
|
3642
3772
|
};
|
|
3643
3773
|
}
|
|
3644
3774
|
function resolveUnanalyzedArrow(ctx) {
|
|
3645
3775
|
return {
|
|
3646
|
-
ArrowFunctionExpression(
|
|
3647
|
-
const { node } =
|
|
3776
|
+
ArrowFunctionExpression(path8) {
|
|
3777
|
+
const { node } = path8;
|
|
3648
3778
|
const analyzed = getIsAnalyzed(node);
|
|
3649
3779
|
if (typeof analyzed === "undefined" || analyzed) return;
|
|
3650
3780
|
const newNode = createUseCallback(node);
|
|
3651
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3652
|
-
if (_optionalChain([declaratorPath, 'optionalAccess',
|
|
3781
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
3782
|
+
if (_optionalChain([declaratorPath, 'optionalAccess', _99 => _99.node])) {
|
|
3653
3783
|
setScriptNodeMeta(declaratorPath.node, { is_reactive: true, reactive_type: "indirect" });
|
|
3654
3784
|
}
|
|
3655
3785
|
markAsAnalyzed(newNode.arguments[0]);
|
|
3656
|
-
|
|
3786
|
+
path8.replaceWith(newNode);
|
|
3657
3787
|
}
|
|
3658
3788
|
};
|
|
3659
3789
|
}
|
|
3660
|
-
function isSkip(
|
|
3661
|
-
const { parentPath } =
|
|
3662
|
-
const isVariableDecl = () => getVariableDeclaratorPath(
|
|
3790
|
+
function isSkip(path8) {
|
|
3791
|
+
const { parentPath } = path8;
|
|
3792
|
+
const isVariableDecl = () => getVariableDeclaratorPath(path8) !== null;
|
|
3663
3793
|
const isReturnFunc = () => !isVariableDecl() && parentPath.isReturnStatement();
|
|
3664
3794
|
const isCallback = () => {
|
|
3665
3795
|
if (!parentPath) {
|
|
@@ -3668,12 +3798,12 @@ function isSkip(path7) {
|
|
|
3668
3798
|
if (parentPath.isCallExpression()) {
|
|
3669
3799
|
const callExpressionPath = parentPath;
|
|
3670
3800
|
const args = callExpressionPath.node.arguments;
|
|
3671
|
-
return args.some((arg) => arg ===
|
|
3801
|
+
return args.some((arg) => arg === path8.node);
|
|
3672
3802
|
}
|
|
3673
3803
|
if (parentPath.isArrayExpression()) {
|
|
3674
3804
|
const arrayExpressionPath = parentPath;
|
|
3675
3805
|
const elements = arrayExpressionPath.node.elements;
|
|
3676
|
-
return elements.some((element) => element ===
|
|
3806
|
+
return elements.some((element) => element === path8.node);
|
|
3677
3807
|
}
|
|
3678
3808
|
return false;
|
|
3679
3809
|
};
|
|
@@ -3697,13 +3827,13 @@ function isSkip(path7) {
|
|
|
3697
3827
|
|
|
3698
3828
|
function resolveElementRef(ctx) {
|
|
3699
3829
|
return {
|
|
3700
|
-
CallExpression(
|
|
3830
|
+
CallExpression(path8) {
|
|
3701
3831
|
const {
|
|
3702
3832
|
inputType,
|
|
3703
3833
|
templateData: { refBindings }
|
|
3704
3834
|
} = ctx;
|
|
3705
3835
|
if (inputType !== "sfc") return;
|
|
3706
|
-
const { node } =
|
|
3836
|
+
const { node } = path8;
|
|
3707
3837
|
const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
|
|
3708
3838
|
const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
|
|
3709
3839
|
const shouldProcess = isUseTemplateRef || isCompRefBindings;
|
|
@@ -3711,31 +3841,31 @@ function resolveElementRef(ctx) {
|
|
|
3711
3841
|
return;
|
|
3712
3842
|
}
|
|
3713
3843
|
if (isCompRefBindings) {
|
|
3714
|
-
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3715
|
-
if (!
|
|
3844
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _100 => _100(path8), 'optionalAccess', _101 => _101.node]);
|
|
3845
|
+
if (!t33.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _102 => _102.id]))) {
|
|
3716
3846
|
return;
|
|
3717
3847
|
}
|
|
3718
3848
|
const varName = varDeclaratorPath.id.name;
|
|
3719
3849
|
const compRef = refBindings.componentRefs[varName];
|
|
3720
3850
|
if (!compRef) return;
|
|
3721
3851
|
}
|
|
3722
|
-
node.arguments[0] =
|
|
3723
|
-
resolveTypeParameters(ctx,
|
|
3852
|
+
node.arguments[0] = t33.identifier("null");
|
|
3853
|
+
resolveTypeParameters(ctx, path8);
|
|
3724
3854
|
replaceCallName(node, REACT_API_MAP.useRef);
|
|
3725
3855
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
3726
3856
|
},
|
|
3727
|
-
MemberExpression(
|
|
3728
|
-
resolveRefValueToCurrent(
|
|
3857
|
+
MemberExpression(path8) {
|
|
3858
|
+
resolveRefValueToCurrent(path8);
|
|
3729
3859
|
}
|
|
3730
3860
|
};
|
|
3731
3861
|
}
|
|
3732
|
-
function resolveTypeParameters(ctx,
|
|
3862
|
+
function resolveTypeParameters(ctx, path8) {
|
|
3733
3863
|
const {
|
|
3734
3864
|
templateData: { refBindings },
|
|
3735
3865
|
scriptData
|
|
3736
3866
|
} = ctx;
|
|
3737
|
-
const { node } =
|
|
3738
|
-
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call',
|
|
3867
|
+
const { node } = path8;
|
|
3868
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _103 => _103(path8), 'optionalAccess', _104 => _104.node]);
|
|
3739
3869
|
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
3740
3870
|
return;
|
|
3741
3871
|
}
|
|
@@ -3744,20 +3874,20 @@ function resolveTypeParameters(ctx, path7) {
|
|
|
3744
3874
|
const compBindingMeta = refBindings.componentRefs[idName];
|
|
3745
3875
|
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
3746
3876
|
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
3747
|
-
node.typeParameters =
|
|
3877
|
+
node.typeParameters = t33.tsTypeParameterInstantiation([t33.tsTypeReference(t33.identifier(type))]);
|
|
3748
3878
|
}
|
|
3749
3879
|
}
|
|
3750
|
-
function resolveRefValueToCurrent(
|
|
3751
|
-
const { node } =
|
|
3752
|
-
if (node.computed || !
|
|
3880
|
+
function resolveRefValueToCurrent(path8) {
|
|
3881
|
+
const { node } = path8;
|
|
3882
|
+
if (node.computed || !t33.isIdentifier(node.property) || node.property.name !== "value") {
|
|
3753
3883
|
return;
|
|
3754
3884
|
}
|
|
3755
|
-
const rootPath = findRootVariablePath(
|
|
3756
|
-
if (!_optionalChain([rootPath, 'optionalAccess',
|
|
3885
|
+
const rootPath = findRootVariablePath(path8);
|
|
3886
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _105 => _105.node]) || !t33.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
3757
3887
|
return;
|
|
3758
3888
|
}
|
|
3759
3889
|
const rootId = findRootIdentifier(node);
|
|
3760
|
-
if (!
|
|
3890
|
+
if (!t33.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _106 => _106.name])) {
|
|
3761
3891
|
return;
|
|
3762
3892
|
}
|
|
3763
3893
|
node.property.name = "current";
|
|
@@ -3768,21 +3898,21 @@ function resolveRefValueToCurrent(path7) {
|
|
|
3768
3898
|
function resolveExprMemo(ctx, ast) {
|
|
3769
3899
|
const isScriptFile = ctx.inputType !== "sfc";
|
|
3770
3900
|
return {
|
|
3771
|
-
VariableDeclarator(
|
|
3772
|
-
const { node } =
|
|
3901
|
+
VariableDeclarator(path8) {
|
|
3902
|
+
const { node } = path8;
|
|
3773
3903
|
const { init } = node;
|
|
3774
3904
|
if (!init) return;
|
|
3775
3905
|
const shouldMemo = () => {
|
|
3776
|
-
if (!atComponentOrHookRoot(
|
|
3906
|
+
if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
|
|
3777
3907
|
return false;
|
|
3778
3908
|
}
|
|
3779
|
-
if (
|
|
3909
|
+
if (t34.isCallExpression(init) && t34.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
3780
3910
|
return false;
|
|
3781
3911
|
}
|
|
3782
3912
|
return true;
|
|
3783
3913
|
};
|
|
3784
3914
|
if (!shouldMemo()) return;
|
|
3785
|
-
const initPath =
|
|
3915
|
+
const initPath = path8.get("init");
|
|
3786
3916
|
if (!initPath.isExpression()) return;
|
|
3787
3917
|
const deps = analyzeDeps(initPath.node, ctx, initPath);
|
|
3788
3918
|
if (!deps.elements.length) return;
|
|
@@ -3798,9 +3928,9 @@ function resolveExprMemo(ctx, ast) {
|
|
|
3798
3928
|
function resolveLintRules(ctx, ast) {
|
|
3799
3929
|
const inScriptFile = ctx.inputType !== "sfc";
|
|
3800
3930
|
return {
|
|
3801
|
-
CallExpression(
|
|
3802
|
-
const { node, parentPath } =
|
|
3803
|
-
if (!
|
|
3931
|
+
CallExpression(path8) {
|
|
3932
|
+
const { node, parentPath } = path8;
|
|
3933
|
+
if (!t35.isIdentifier(node.callee)) return;
|
|
3804
3934
|
const { name: callName } = node.callee;
|
|
3805
3935
|
const addLog = (t41) => {
|
|
3806
3936
|
logger.error(t41, {
|
|
@@ -3818,7 +3948,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
3818
3948
|
);
|
|
3819
3949
|
return;
|
|
3820
3950
|
}
|
|
3821
|
-
if (!atComponentOrHookRoot(
|
|
3951
|
+
if (!atComponentOrHookRoot(path8, ast.program)) {
|
|
3822
3952
|
addLog(
|
|
3823
3953
|
`The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
|
|
3824
3954
|
);
|
|
@@ -3834,7 +3964,7 @@ function resolveLintRules(ctx, ast) {
|
|
|
3834
3964
|
};
|
|
3835
3965
|
const lintHooks = () => {
|
|
3836
3966
|
if (!callName.startsWith("use")) return;
|
|
3837
|
-
if (!atComponentOrHookRoot(
|
|
3967
|
+
if (!atComponentOrHookRoot(path8, ast.program, inScriptFile)) {
|
|
3838
3968
|
addLog(
|
|
3839
3969
|
`The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
|
|
3840
3970
|
);
|
|
@@ -3850,18 +3980,20 @@ function resolveLintRules(ctx, ast) {
|
|
|
3850
3980
|
|
|
3851
3981
|
|
|
3852
3982
|
function resolveProvide(ctx) {
|
|
3853
|
-
if (ctx.inputType
|
|
3983
|
+
if (ctx.inputType === "style") return {};
|
|
3854
3984
|
return {
|
|
3855
|
-
CallExpression(
|
|
3856
|
-
const { node } =
|
|
3857
|
-
|
|
3985
|
+
CallExpression(path8) {
|
|
3986
|
+
const { node } = path8;
|
|
3987
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _107 => _107.runtime, 'access', _108 => _108[VUE_API_MAP.provide], 'optionalAccess', _109 => _109.target]);
|
|
3988
|
+
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
3989
|
+
if (!isProvideCall) return;
|
|
3858
3990
|
const { provide } = ctx.scriptData;
|
|
3859
3991
|
const [key, value] = node.arguments;
|
|
3860
3992
|
const target = findOrCreateCtxProvider(provide);
|
|
3861
3993
|
const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
3862
3994
|
assignProviderValue(target, key, value);
|
|
3863
3995
|
recordImport(ctx, adapter.package, adapter.target);
|
|
3864
|
-
|
|
3996
|
+
path8.parentPath.remove();
|
|
3865
3997
|
}
|
|
3866
3998
|
};
|
|
3867
3999
|
}
|
|
@@ -3870,7 +4002,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
3870
4002
|
return root;
|
|
3871
4003
|
}
|
|
3872
4004
|
let cur = root.provide;
|
|
3873
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
4005
|
+
while (_optionalChain([cur, 'optionalAccess', _110 => _110.isOccupied])) {
|
|
3874
4006
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
3875
4007
|
}
|
|
3876
4008
|
return cur || (root.provide = {});
|
|
@@ -3878,18 +4010,18 @@ function findOrCreateCtxProvider(root) {
|
|
|
3878
4010
|
function assignProviderValue(target, key, value) {
|
|
3879
4011
|
const getRawExp = (exp) => {
|
|
3880
4012
|
if (!exp) return "''";
|
|
3881
|
-
if (
|
|
3882
|
-
return
|
|
4013
|
+
if (t36.isStringLiteral(exp)) {
|
|
4014
|
+
return JSON.stringify(exp.value);
|
|
3883
4015
|
}
|
|
3884
|
-
if (
|
|
4016
|
+
if (t36.isNumericLiteral(exp)) {
|
|
3885
4017
|
return exp.value.toString();
|
|
3886
4018
|
}
|
|
3887
|
-
if (
|
|
4019
|
+
if (t36.isIdentifier(exp)) {
|
|
3888
4020
|
return exp.name;
|
|
3889
4021
|
}
|
|
3890
4022
|
try {
|
|
3891
4023
|
return _generator.generate.call(void 0, exp).code;
|
|
3892
|
-
} catch (
|
|
4024
|
+
} catch (e6) {
|
|
3893
4025
|
return "null";
|
|
3894
4026
|
}
|
|
3895
4027
|
};
|
|
@@ -3903,13 +4035,13 @@ function assignProviderValue(target, key, value) {
|
|
|
3903
4035
|
|
|
3904
4036
|
function resolveRenameAdapter(ctx) {
|
|
3905
4037
|
return {
|
|
3906
|
-
"CallExpression|Identifier"(
|
|
3907
|
-
const node =
|
|
3908
|
-
const isCallNode =
|
|
4038
|
+
"CallExpression|Identifier"(path8) {
|
|
4039
|
+
const node = path8.node;
|
|
4040
|
+
const isCallNode = t37.isCallExpression(node);
|
|
3909
4041
|
let apiName = "";
|
|
3910
|
-
if (
|
|
4042
|
+
if (t37.isIdentifier(node)) {
|
|
3911
4043
|
apiName = node.name;
|
|
3912
|
-
} else if (isCallNode &&
|
|
4044
|
+
} else if (isCallNode && t37.isIdentifier(node.callee)) {
|
|
3913
4045
|
apiName = node.callee.name;
|
|
3914
4046
|
}
|
|
3915
4047
|
const runtimeAdapter = ADAPTER_RULES.runtime[apiName];
|
|
@@ -3920,8 +4052,8 @@ function resolveRenameAdapter(ctx) {
|
|
|
3920
4052
|
}
|
|
3921
4053
|
if (adapter.isTrackable) {
|
|
3922
4054
|
const reactiveType = getReactiveType(apiName);
|
|
3923
|
-
const declaratorPath = getVariableDeclaratorPath(
|
|
3924
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
4055
|
+
const declaratorPath = getVariableDeclaratorPath(path8);
|
|
4056
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _111 => _111.node]), {
|
|
3925
4057
|
is_reactive: true,
|
|
3926
4058
|
reactive_type: reactiveType
|
|
3927
4059
|
});
|
|
@@ -3956,11 +4088,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
3956
4088
|
process: {
|
|
3957
4089
|
applyBabel: [
|
|
3958
4090
|
resolveElementRef,
|
|
4091
|
+
// provide 需要在 rename 之前收集并移除原始调用,避免被重命名后失配
|
|
4092
|
+
resolveProvide,
|
|
3959
4093
|
resolveRenameAdapter,
|
|
3960
4094
|
resolveArrowFnDeps,
|
|
3961
4095
|
resolveUnanalyzedArrow,
|
|
3962
4096
|
resolveAnalysisOnlyAdapter,
|
|
3963
|
-
resolveProvide,
|
|
3964
4097
|
resolveExprMemo,
|
|
3965
4098
|
resolveLintRules
|
|
3966
4099
|
],
|
|
@@ -3974,12 +4107,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
3974
4107
|
}
|
|
3975
4108
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
3976
4109
|
const runExcludeThenApply = (cfg) => {
|
|
3977
|
-
_optionalChain([cfg, 'access',
|
|
3978
|
-
_optionalChain([cfg, 'access',
|
|
4110
|
+
_optionalChain([cfg, 'access', _112 => _112.excludeBabel, 'optionalAccess', _113 => _113.forEach, 'call', _114 => _114((fn) => fn(ctx, ast))]);
|
|
4111
|
+
_optionalChain([cfg, 'access', _115 => _115.applyBabel, 'optionalAccess', _116 => _116.forEach, 'call', _117 => _117((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
3979
4112
|
};
|
|
3980
4113
|
const runApplyThenExclude = (cfg) => {
|
|
3981
|
-
_optionalChain([cfg, 'access',
|
|
3982
|
-
_optionalChain([cfg, 'access',
|
|
4114
|
+
_optionalChain([cfg, 'access', _118 => _118.applyBabel, 'optionalAccess', _119 => _119.forEach, 'call', _120 => _120((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4115
|
+
_optionalChain([cfg, 'access', _121 => _121.excludeBabel, 'optionalAccess', _122 => _122.forEach, 'call', _123 => _123((fn) => fn(ctx, ast))]);
|
|
3983
4116
|
};
|
|
3984
4117
|
runExcludeThenApply(options.preprocess);
|
|
3985
4118
|
runExcludeThenApply(options.process);
|
|
@@ -4074,25 +4207,25 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
4074
4207
|
let node;
|
|
4075
4208
|
try {
|
|
4076
4209
|
node = _parser.parseExpression.call(void 0, code);
|
|
4077
|
-
} catch (
|
|
4210
|
+
} catch (e7) {
|
|
4078
4211
|
return false;
|
|
4079
4212
|
}
|
|
4080
|
-
if (
|
|
4213
|
+
if (t38.isLiteral(node)) {
|
|
4081
4214
|
return true;
|
|
4082
4215
|
}
|
|
4083
|
-
if (!excludeVar &&
|
|
4216
|
+
if (!excludeVar && t38.isIdentifier(node)) {
|
|
4084
4217
|
return true;
|
|
4085
4218
|
}
|
|
4086
|
-
if (
|
|
4087
|
-
return isSimpleExpression(node.object) &&
|
|
4219
|
+
if (t38.isMemberExpression(node)) {
|
|
4220
|
+
return isSimpleExpression(node.object) && t38.isIdentifier(node.property);
|
|
4088
4221
|
}
|
|
4089
|
-
if (
|
|
4222
|
+
if (t38.isObjectExpression(node) || t38.isArrayExpression(node)) {
|
|
4090
4223
|
return false;
|
|
4091
4224
|
}
|
|
4092
|
-
if (
|
|
4225
|
+
if (t38.isCallExpression(node) || t38.isAssignmentExpression(node)) {
|
|
4093
4226
|
return false;
|
|
4094
4227
|
}
|
|
4095
|
-
if (
|
|
4228
|
+
if (t38.isBinaryExpression(node) || t38.isUnaryExpression(node)) {
|
|
4096
4229
|
return true;
|
|
4097
4230
|
}
|
|
4098
4231
|
return false;
|
|
@@ -4100,77 +4233,20 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
4100
4233
|
function isIdentifier20(code) {
|
|
4101
4234
|
try {
|
|
4102
4235
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4103
|
-
return
|
|
4104
|
-
} catch (
|
|
4236
|
+
return t38.isIdentifier(node);
|
|
4237
|
+
} catch (e8) {
|
|
4105
4238
|
return false;
|
|
4106
4239
|
}
|
|
4107
4240
|
}
|
|
4108
4241
|
function isStringLiteral12(code) {
|
|
4109
4242
|
try {
|
|
4110
4243
|
const node = _parser.parseExpression.call(void 0, code);
|
|
4111
|
-
return
|
|
4112
|
-
} catch (
|
|
4244
|
+
return t38.isStringLiteral(node) || t38.isTemplateLiteral(node);
|
|
4245
|
+
} catch (e9) {
|
|
4113
4246
|
return false;
|
|
4114
4247
|
}
|
|
4115
4248
|
}
|
|
4116
4249
|
|
|
4117
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/special-expressions.ts
|
|
4121
|
-
function resolveSpecialExpressions(input, ctx) {
|
|
4122
|
-
input = resolveEmitsCalls(input, ctx);
|
|
4123
|
-
input = resolveRefVariable(input, ctx);
|
|
4124
|
-
return input;
|
|
4125
|
-
}
|
|
4126
|
-
function resolveEmitsCalls(input, ctx) {
|
|
4127
|
-
const result = matchEmitCalls(input, ctx);
|
|
4128
|
-
if (!result) return input;
|
|
4129
|
-
const [, , eventName, args] = result;
|
|
4130
|
-
const callee = eventName.split(/[:\-]/).map((part) => capitalize(camelCase(part))).join("");
|
|
4131
|
-
const event = args ? `on${callee}(${args})` : `on${callee}()`;
|
|
4132
|
-
return `${ctx.propField}?.${event}`;
|
|
4133
|
-
}
|
|
4134
|
-
function matchEmitCalls(input, ctx) {
|
|
4135
|
-
const { reactiveBindings } = ctx.templateData;
|
|
4136
|
-
const macroBinding = Object.values(reactiveBindings).find((b) => b.source === "defineEmits");
|
|
4137
|
-
if (!macroBinding) return null;
|
|
4138
|
-
const escapedName = macroBinding.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4139
|
-
const regex = new RegExp(
|
|
4140
|
-
`${escapedName}\\s*\\(\\s*(['"\`])([^\\1]*?)\\1\\s*(?:,\\s*(.*?))?\\s*\\)$`,
|
|
4141
|
-
// 可选的第二个参数
|
|
4142
|
-
"s"
|
|
4143
|
-
// s 标志让 . 匹配换行符
|
|
4144
|
-
);
|
|
4145
|
-
return input.trim().match(regex);
|
|
4146
|
-
}
|
|
4147
|
-
function resolveRefVariable(input, ctx) {
|
|
4148
|
-
const { reactiveBindings } = ctx.templateData;
|
|
4149
|
-
const addValueProperty = (input2, varName) => {
|
|
4150
|
-
const escapedVarName = varName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4151
|
-
const regex = new RegExp(`(?<![a-zA-Z0-9_])${escapedVarName}(?![a-zA-Z0-9_])(?!\\.value)`, "g");
|
|
4152
|
-
return input2.replace(regex, `${varName}.value`);
|
|
4153
|
-
};
|
|
4154
|
-
for (const name in reactiveBindings) {
|
|
4155
|
-
const binding = reactiveBindings[name];
|
|
4156
|
-
if (_optionalChain([binding, 'optionalAccess', _120 => _120.reactiveType]) !== "ref") continue;
|
|
4157
|
-
input = addValueProperty(input, name);
|
|
4158
|
-
}
|
|
4159
|
-
return input;
|
|
4160
|
-
}
|
|
4161
|
-
|
|
4162
|
-
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
4163
|
-
function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
4164
|
-
if (toStrLiteral) return t38.stringLiteral(input);
|
|
4165
|
-
const { filename, scriptData } = ctx;
|
|
4166
|
-
const newContent = resolveSpecialExpressions(input, ctx);
|
|
4167
|
-
try {
|
|
4168
|
-
return stringToExpr(newContent, scriptData.lang, filename);
|
|
4169
|
-
} catch (e8) {
|
|
4170
|
-
return t38.identifier(newContent);
|
|
4171
|
-
}
|
|
4172
|
-
}
|
|
4173
|
-
|
|
4174
4250
|
// src/core/transform/sfc/template/shared/style-utils.ts
|
|
4175
4251
|
function parseStyleString(styleStr) {
|
|
4176
4252
|
if (isSimpleStyle(styleStr) || strCodeTypes.isIdentifier(styleStr)) {
|
|
@@ -4272,12 +4348,12 @@ function wrapSingleQuotes(content, condition) {
|
|
|
4272
4348
|
return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
|
|
4273
4349
|
}
|
|
4274
4350
|
function checkPropIsDynamicKey(ctx, node) {
|
|
4275
|
-
const isKeyStatic = _optionalChain([node, 'access',
|
|
4351
|
+
const isKeyStatic = _optionalChain([node, 'access', _124 => _124.arg, 'optionalAccess', _125 => _125.isStatic]);
|
|
4276
4352
|
const { source, filename } = ctx;
|
|
4277
4353
|
if (node.rawName === "v-bind" && !node.name) {
|
|
4278
4354
|
logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
|
|
4279
4355
|
source,
|
|
4280
|
-
loc: _optionalChain([node, 'access',
|
|
4356
|
+
loc: _optionalChain([node, 'access', _126 => _126.arg, 'optionalAccess', _127 => _127.loc]),
|
|
4281
4357
|
file: filename
|
|
4282
4358
|
});
|
|
4283
4359
|
return;
|
|
@@ -4285,7 +4361,7 @@ function checkPropIsDynamicKey(ctx, node) {
|
|
|
4285
4361
|
if (isKeyStatic === false) {
|
|
4286
4362
|
logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
|
|
4287
4363
|
source,
|
|
4288
|
-
loc: _optionalChain([node, 'access',
|
|
4364
|
+
loc: _optionalChain([node, 'access', _128 => _128.arg, 'optionalAccess', _129 => _129.loc]),
|
|
4289
4365
|
file: filename
|
|
4290
4366
|
});
|
|
4291
4367
|
}
|
|
@@ -4330,19 +4406,19 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
4330
4406
|
}
|
|
4331
4407
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
4332
4408
|
const dirCls = ADAPTER_RULES.runtime.dirCls;
|
|
4333
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
4409
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _130 => _130.join, 'call', _131 => _131(",")]) || wrapSingleQuotes(valueContent);
|
|
4334
4410
|
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
4335
4411
|
applyRuntimeExpression(expression, true, name);
|
|
4336
4412
|
return;
|
|
4337
4413
|
}
|
|
4338
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
4414
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _132 => _132.some, 'call', _133 => _133((item) => !isSimpleStyle(item))]))) {
|
|
4339
4415
|
const dirStyle = ADAPTER_RULES.runtime.dirStyle;
|
|
4340
|
-
const arg = _optionalChain([mergedItems, 'optionalAccess',
|
|
4416
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _134 => _134.join, 'call', _135 => _135(",")]) || valueContent;
|
|
4341
4417
|
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
4342
4418
|
applyRuntimeExpression(expression, true, name);
|
|
4343
4419
|
return;
|
|
4344
4420
|
}
|
|
4345
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
4421
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _136 => _136.modifiers, 'optionalAccess', _137 => _137.length])) {
|
|
4346
4422
|
const dirOn = ADAPTER_RULES.runtime.dirOn;
|
|
4347
4423
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
4348
4424
|
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
@@ -4397,7 +4473,7 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
4397
4473
|
continue;
|
|
4398
4474
|
}
|
|
4399
4475
|
const nodeIR = child;
|
|
4400
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
4476
|
+
if (_optionalChain([parentIR, 'optionalAccess', _138 => _138.isBuiltIn])) {
|
|
4401
4477
|
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
4402
4478
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
4403
4479
|
}
|
|
@@ -4438,7 +4514,7 @@ function walkElementNodes(node, onElement) {
|
|
|
4438
4514
|
}
|
|
4439
4515
|
function resolveDefaultStyleModuleName(node) {
|
|
4440
4516
|
const { exp } = node;
|
|
4441
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
4517
|
+
if (_optionalChain([exp, 'optionalAccess', _139 => _139.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4442
4518
|
return;
|
|
4443
4519
|
}
|
|
4444
4520
|
if (exp.content.includes("$style")) {
|
|
@@ -4451,6 +4527,8 @@ function resolveDefaultStyleModuleName(node) {
|
|
|
4451
4527
|
|
|
4452
4528
|
|
|
4453
4529
|
|
|
4530
|
+
|
|
4531
|
+
|
|
4454
4532
|
function resolveStyleScopeAttribute(node, _ir, ctx) {
|
|
4455
4533
|
if (!ctx.styleData.scopeId) {
|
|
4456
4534
|
return;
|
|
@@ -4470,11 +4548,11 @@ function walkElementNodes2(node, onElement) {
|
|
|
4470
4548
|
}
|
|
4471
4549
|
function injectStyleScopeAttribute(node, ctx) {
|
|
4472
4550
|
const { scopeId } = ctx.styleData;
|
|
4473
|
-
if (!scopeId || isComponentElement(node)) {
|
|
4551
|
+
if (!scopeId || isComponentElement(node) || _compilercore.isSlotOutlet.call(void 0, node) || _compilercore.isTemplateNode.call(void 0, node)) {
|
|
4474
4552
|
return;
|
|
4475
4553
|
}
|
|
4476
4554
|
const hasDynamicIs = node.props.some((prop) => {
|
|
4477
|
-
if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access',
|
|
4555
|
+
if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access', _140 => _140.arg, 'optionalAccess', _141 => _141.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4478
4556
|
return false;
|
|
4479
4557
|
}
|
|
4480
4558
|
return prop.arg.content === "is";
|
|
@@ -4540,7 +4618,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
4540
4618
|
const oldStyle = oldAttr.value.content;
|
|
4541
4619
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
4542
4620
|
let merged = oldAttr.value.merge;
|
|
4543
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
4621
|
+
if (!_optionalChain([merged, 'optionalAccess', _142 => _142.length])) {
|
|
4544
4622
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
4545
4623
|
} else {
|
|
4546
4624
|
merged.push(newStyle);
|
|
@@ -4570,7 +4648,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
4570
4648
|
const { source, filename } = ctx;
|
|
4571
4649
|
let value = "";
|
|
4572
4650
|
let loc;
|
|
4573
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
4651
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _143 => _143.exp, 'optionalAccess', _144 => _144.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4574
4652
|
value = node.exp.content;
|
|
4575
4653
|
loc = node.exp.loc;
|
|
4576
4654
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -4624,11 +4702,11 @@ function resolveRefProp(node, ctx, nodeIR) {
|
|
|
4624
4702
|
} = ctx;
|
|
4625
4703
|
let propIR;
|
|
4626
4704
|
if (node.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
4627
|
-
const tag = _optionalChain([node, 'access',
|
|
4705
|
+
const tag = _optionalChain([node, 'access', _145 => _145.value, 'optionalAccess', _146 => _146.content]);
|
|
4628
4706
|
if (!tag) return;
|
|
4629
4707
|
collectComponentRef(tag, ctx);
|
|
4630
4708
|
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
4631
|
-
const refVar = _optionalChain([domRefBinding, 'optionalAccess',
|
|
4709
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _147 => _147.name]) || _optionalChain([refBindings, 'access', _148 => _148.componentRefs, 'access', _149 => _149[tag], 'optionalAccess', _150 => _150.name]);
|
|
4632
4710
|
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
4633
4711
|
} else {
|
|
4634
4712
|
const exp = node.exp;
|
|
@@ -4663,8 +4741,8 @@ function collectComponentRef(tag, ctx) {
|
|
|
4663
4741
|
function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
4664
4742
|
const arg = node.arg;
|
|
4665
4743
|
const exp = node.exp;
|
|
4666
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4667
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4744
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _151 => _151.content]), () => ( ""));
|
|
4745
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _152 => _152.content]), () => ( "true"));
|
|
4668
4746
|
warnUnsupportedVueDollarVar(ctx, node);
|
|
4669
4747
|
if (name === "is") {
|
|
4670
4748
|
resolveDynamicIsProp(node, ir, ctx, nodeIR);
|
|
@@ -4675,7 +4753,7 @@ function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
|
4675
4753
|
return;
|
|
4676
4754
|
}
|
|
4677
4755
|
const dynamicPropIR = createPropsIR(node.rawName, name, content);
|
|
4678
|
-
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4756
|
+
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _153 => _153.isStatic]), () => ( true));
|
|
4679
4757
|
checkPropIsDynamicKey(ctx, node);
|
|
4680
4758
|
resolvePropertyIR(dynamicPropIR, ir, ctx, nodeIR, true);
|
|
4681
4759
|
}
|
|
@@ -4703,7 +4781,7 @@ function resolvePropertyIR(node, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
4703
4781
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
4704
4782
|
function resolveAttributeProp(node, ir, ctx, nodeIR) {
|
|
4705
4783
|
const name = node.name;
|
|
4706
|
-
const content = _nullishCoalesce(_optionalChain([node, 'access',
|
|
4784
|
+
const content = _nullishCoalesce(_optionalChain([node, 'access', _154 => _154.value, 'optionalAccess', _155 => _155.content]), () => ( "true"));
|
|
4707
4785
|
if (name === "is") {
|
|
4708
4786
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
4709
4787
|
return;
|
|
@@ -4727,10 +4805,10 @@ function resolveRouterLinkVSlotProp(node, nodeIR, ctx) {
|
|
|
4727
4805
|
type: 2 /* SLOT */,
|
|
4728
4806
|
name: "customRender",
|
|
4729
4807
|
rawName: _nullishCoalesce(node.rawName, () => ( "v-slot")),
|
|
4730
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4808
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _156 => _156.isStatic]), () => ( true)),
|
|
4731
4809
|
isScoped: true,
|
|
4732
4810
|
callback: {
|
|
4733
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4811
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _157 => _157.content, 'optionalAccess', _158 => _158.trim, 'call', _159 => _159()]), () => ( "")),
|
|
4734
4812
|
exp: []
|
|
4735
4813
|
}
|
|
4736
4814
|
};
|
|
@@ -4746,10 +4824,10 @@ function resolveVFor(node, _ir, _ctx, nodeIR) {
|
|
|
4746
4824
|
};
|
|
4747
4825
|
}
|
|
4748
4826
|
function resolveForResult(forParseResult) {
|
|
4749
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
4750
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
4751
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
4752
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
4827
|
+
const source = _optionalChain([forParseResult, 'access', _160 => _160.source, 'optionalAccess', _161 => _161.content]);
|
|
4828
|
+
const value = _optionalChain([forParseResult, 'access', _162 => _162.value, 'optionalAccess', _163 => _163.content]);
|
|
4829
|
+
const index = _optionalChain([forParseResult, 'access', _164 => _164.index, 'optionalAccess', _165 => _165.content]);
|
|
4830
|
+
const key = _optionalChain([forParseResult, 'access', _166 => _166.key, 'optionalAccess', _167 => _167.content]);
|
|
4753
4831
|
return {
|
|
4754
4832
|
source,
|
|
4755
4833
|
value,
|
|
@@ -4769,7 +4847,7 @@ function resolveVHtml(node, ir, ctx, nodeIR) {
|
|
|
4769
4847
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
4770
4848
|
function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
4771
4849
|
const name = node.name === "else-if" ? "elseIf" : node.name;
|
|
4772
|
-
const value = _nullishCoalesce(_optionalChain([node, 'access',
|
|
4850
|
+
const value = _nullishCoalesce(_optionalChain([node, 'access', _168 => _168.exp, 'optionalAccess', _169 => _169.content]), () => ( "true"));
|
|
4773
4851
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
4774
4852
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
4775
4853
|
let hasError = false;
|
|
@@ -4808,7 +4886,7 @@ function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
4808
4886
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
4809
4887
|
function resolveVMemo(node, _ir, ctx, nodeIR) {
|
|
4810
4888
|
const exp = node.exp;
|
|
4811
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
4889
|
+
let value = _optionalChain([exp, 'optionalAccess', _170 => _170.content]);
|
|
4812
4890
|
if (value !== void 0) {
|
|
4813
4891
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
4814
4892
|
const { source, filename } = ctx;
|
|
@@ -4848,15 +4926,14 @@ function resolveVModel(node, _ir, ctx, elementNode, nodeIR) {
|
|
|
4848
4926
|
const getterName = exp.content;
|
|
4849
4927
|
const isComponent = elementNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
4850
4928
|
const inputType = resolveHtmlInput(elementNode, isComponent);
|
|
4851
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4929
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _171 => _171.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
4852
4930
|
let valuePropIR;
|
|
4853
4931
|
let eventPropIR;
|
|
4854
4932
|
if (isComponent) {
|
|
4855
4933
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
4856
|
-
const
|
|
4857
|
-
const
|
|
4858
|
-
const
|
|
4859
|
-
const isTS = _optionalChain([ctx, 'access', _169 => _169.scriptData, 'optionalAccess', _170 => _170.lang, 'optionalAccess', _171 => _171.startsWith, 'call', _172 => _172("ts")]);
|
|
4934
|
+
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
4935
|
+
const eventVueName = `update:${propName}`;
|
|
4936
|
+
const isTS = _optionalChain([ctx, 'access', _172 => _172.scriptData, 'optionalAccess', _173 => _173.lang, 'optionalAccess', _174 => _174.startsWith, 'call', _175 => _175("ts")]);
|
|
4860
4937
|
const valueArg = isTS ? "value: any" : "value";
|
|
4861
4938
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
4862
4939
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -4894,7 +4971,7 @@ function getRadioValue(elementNode) {
|
|
|
4894
4971
|
const valueAttr = elementNode.props.find(
|
|
4895
4972
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
4896
4973
|
);
|
|
4897
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
4974
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _176 => _176.value, 'optionalAccess', _177 => _177.content])) return '""';
|
|
4898
4975
|
const content = valueAttr.value.content;
|
|
4899
4976
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
4900
4977
|
}
|
|
@@ -4904,7 +4981,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
4904
4981
|
const typeProp = node.props.find(
|
|
4905
4982
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
4906
4983
|
);
|
|
4907
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
4984
|
+
return _optionalChain([typeProp, 'optionalAccess', _178 => _178.value, 'optionalAccess', _179 => _179.content, 'optionalAccess', _180 => _180.toLowerCase, 'call', _181 => _181()]);
|
|
4908
4985
|
}
|
|
4909
4986
|
function applyValueModifiers(valueExp, modifiers) {
|
|
4910
4987
|
let result = valueExp;
|
|
@@ -4916,12 +4993,6 @@ function applyValueModifiers(valueExp, modifiers) {
|
|
|
4916
4993
|
}
|
|
4917
4994
|
return result;
|
|
4918
4995
|
}
|
|
4919
|
-
function getRootIdName(expr) {
|
|
4920
|
-
if (typeof expr !== "string") return;
|
|
4921
|
-
const pattern = /^([a-zA-Z_$][a-zA-Z0-9_$]*)(?:[\.\?\.\[\(].*)?$/;
|
|
4922
|
-
const match = pattern.exec(expr.trim());
|
|
4923
|
-
return _optionalChain([match, 'optionalAccess', _179 => _179[1]]);
|
|
4924
|
-
}
|
|
4925
4996
|
|
|
4926
4997
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
|
|
4927
4998
|
|
|
@@ -5109,7 +5180,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
5109
5180
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
5110
5181
|
const content = !isScoped ? [] : void 0;
|
|
5111
5182
|
const callback = isScoped ? {
|
|
5112
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
5183
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _182 => _182.content, 'optionalAccess', _183 => _183.trim, 'call', _184 => _184()]), () => ( "")),
|
|
5113
5184
|
exp: []
|
|
5114
5185
|
} : void 0;
|
|
5115
5186
|
checkPropIsDynamicKey(ctx, node);
|
|
@@ -5117,7 +5188,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
5117
5188
|
type: 2 /* SLOT */,
|
|
5118
5189
|
name,
|
|
5119
5190
|
rawName: _nullishCoalesce(node.rawName, () => ( "default")),
|
|
5120
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5191
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _185 => _185.isStatic]), () => ( true)),
|
|
5121
5192
|
isScoped,
|
|
5122
5193
|
content,
|
|
5123
5194
|
callback
|
|
@@ -5151,7 +5222,7 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
5151
5222
|
if (routerAdapter) {
|
|
5152
5223
|
if (!ctx.route) ctx.route = true;
|
|
5153
5224
|
nodeIR.isRoute = true;
|
|
5154
|
-
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess',
|
|
5225
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _186 => _186.package]), routerAdapter.target);
|
|
5155
5226
|
}
|
|
5156
5227
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
5157
5228
|
return nodeIR;
|
|
@@ -5287,7 +5358,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
5287
5358
|
for (const prop of node.props) {
|
|
5288
5359
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5289
5360
|
const attr = prop.name;
|
|
5290
|
-
const value = _optionalChain([prop, 'access',
|
|
5361
|
+
const value = _optionalChain([prop, 'access', _187 => _187.value, 'optionalAccess', _188 => _188.content, 'access', _189 => _189.trim, 'call', _190 => _190()]);
|
|
5291
5362
|
if (attr === "name" && value) {
|
|
5292
5363
|
result.name = camelCase(value);
|
|
5293
5364
|
} else {
|
|
@@ -5377,19 +5448,19 @@ function resolveTemplate2(root, ctx) {
|
|
|
5377
5448
|
// src/core/transform/sfc/index.ts
|
|
5378
5449
|
function transform(ast, ctx, options) {
|
|
5379
5450
|
const { template, script, style } = ast;
|
|
5380
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
5381
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
5451
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _191 => _191.ast]), ctx);
|
|
5452
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _192 => _192.ast]), ctx);
|
|
5382
5453
|
const result = {
|
|
5383
5454
|
template: templateIR,
|
|
5384
5455
|
script: scriptIR,
|
|
5385
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
5456
|
+
style: _optionalChain([style, 'optionalAccess', _193 => _193.source, 'optionalAccess', _194 => _194.content])
|
|
5386
5457
|
};
|
|
5387
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
5458
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _195 => _195.plugins]), result, ctx);
|
|
5388
5459
|
return result;
|
|
5389
5460
|
}
|
|
5390
5461
|
|
|
5391
5462
|
// package.json
|
|
5392
|
-
var version = "1.
|
|
5463
|
+
var version = "1.3.0";
|
|
5393
5464
|
var bin = {
|
|
5394
5465
|
vureact: "./bin/vureact.js"
|
|
5395
5466
|
};
|
|
@@ -5422,7 +5493,7 @@ async function formatWithPrettier(code, lang, opts) {
|
|
|
5422
5493
|
...opts,
|
|
5423
5494
|
parser
|
|
5424
5495
|
});
|
|
5425
|
-
} catch (
|
|
5496
|
+
} catch (e10) {
|
|
5426
5497
|
logger.info("Prettier is unavailable; the built-in simple formatter is used.");
|
|
5427
5498
|
return simpleFormat(code);
|
|
5428
5499
|
}
|
|
@@ -5447,7 +5518,7 @@ var Helper = (_class3 = class {
|
|
|
5447
5518
|
__init6() {this.outDir = "react-app"}
|
|
5448
5519
|
constructor(opts) {;_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);
|
|
5449
5520
|
this.compilerOpts = opts;
|
|
5450
|
-
if (_optionalChain([opts, 'access',
|
|
5521
|
+
if (_optionalChain([opts, 'access', _196 => _196.output, 'optionalAccess', _197 => _197.workspace])) {
|
|
5451
5522
|
this.workspaceDir = opts.output.workspace;
|
|
5452
5523
|
}
|
|
5453
5524
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -5482,7 +5553,7 @@ var Helper = (_class3 = class {
|
|
|
5482
5553
|
}
|
|
5483
5554
|
getOutDirName() {
|
|
5484
5555
|
const { output } = this.compilerOpts;
|
|
5485
|
-
return _optionalChain([output, 'optionalAccess',
|
|
5556
|
+
return _optionalChain([output, 'optionalAccess', _198 => _198.outDir]) || this.outDir;
|
|
5486
5557
|
}
|
|
5487
5558
|
getWorkspaceDir() {
|
|
5488
5559
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -5496,7 +5567,7 @@ var Helper = (_class3 = class {
|
|
|
5496
5567
|
}
|
|
5497
5568
|
getIgnoreAssets() {
|
|
5498
5569
|
const { output } = this.compilerOpts;
|
|
5499
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
5570
|
+
if (_optionalChain([output, 'optionalAccess', _199 => _199.ignoreAssets])) {
|
|
5500
5571
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
5501
5572
|
}
|
|
5502
5573
|
return /* @__PURE__ */ new Set([
|
|
@@ -5577,12 +5648,12 @@ var Helper = (_class3 = class {
|
|
|
5577
5648
|
*/
|
|
5578
5649
|
async formatCode({ code, fileInfo }) {
|
|
5579
5650
|
const { format } = this.compilerOpts;
|
|
5580
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
5581
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
5651
|
+
if (!_optionalChain([format, 'optionalAccess', _200 => _200.enabled])) return code;
|
|
5652
|
+
if (_optionalChain([format, 'optionalAccess', _201 => _201.formatter]) === "builtin") {
|
|
5582
5653
|
return simpleFormat(code);
|
|
5583
5654
|
}
|
|
5584
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
5585
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
5655
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _202 => _202.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _203 => _203.script])));
|
|
5656
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _204 => _204.prettierOptions]));
|
|
5586
5657
|
}
|
|
5587
5658
|
/**
|
|
5588
5659
|
* 通用的缓存校验工具函数
|
|
@@ -5629,7 +5700,7 @@ var Helper = (_class3 = class {
|
|
|
5629
5700
|
target: data[key] || [],
|
|
5630
5701
|
source: data
|
|
5631
5702
|
};
|
|
5632
|
-
} catch (
|
|
5703
|
+
} catch (e11) {
|
|
5633
5704
|
return defaultData;
|
|
5634
5705
|
}
|
|
5635
5706
|
}
|
|
@@ -5701,9 +5772,9 @@ var Helper = (_class3 = class {
|
|
|
5701
5772
|
};
|
|
5702
5773
|
}
|
|
5703
5774
|
async removeOutputFile(filePath, resolveOutputPath) {
|
|
5704
|
-
const
|
|
5705
|
-
if (!_fs2.default.existsSync(
|
|
5706
|
-
await _fs2.default.promises.unlink(
|
|
5775
|
+
const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
|
|
5776
|
+
if (!_fs2.default.existsSync(path8)) return;
|
|
5777
|
+
await _fs2.default.promises.unlink(path8);
|
|
5707
5778
|
}
|
|
5708
5779
|
updateCache(targetFile, newData, cache) {
|
|
5709
5780
|
const index = cache.target.findIndex((c) => c.file === targetFile);
|
|
@@ -5715,7 +5786,7 @@ var Helper = (_class3 = class {
|
|
|
5715
5786
|
}
|
|
5716
5787
|
resolveViteCreateApp() {
|
|
5717
5788
|
const { output } = this.compilerOpts;
|
|
5718
|
-
const config = _optionalChain([output, 'optionalAccess',
|
|
5789
|
+
const config = _optionalChain([output, 'optionalAccess', _205 => _205.bootstrapVite]);
|
|
5719
5790
|
const template = typeof config === "object" ? config.template : "react-ts";
|
|
5720
5791
|
const outDirName = this.getOutDirName();
|
|
5721
5792
|
const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
|
|
@@ -5729,7 +5800,7 @@ var Helper = (_class3 = class {
|
|
|
5729
5800
|
* 获取需要排除编译的文件
|
|
5730
5801
|
*/
|
|
5731
5802
|
getExcludes() {
|
|
5732
|
-
if (!_optionalChain([this, 'access',
|
|
5803
|
+
if (!_optionalChain([this, 'access', _206 => _206.compilerOpts, 'access', _207 => _207.exclude, 'optionalAccess', _208 => _208.length])) {
|
|
5733
5804
|
return PathFilter.withDefaults();
|
|
5734
5805
|
}
|
|
5735
5806
|
return this.compilerOpts.exclude;
|
|
@@ -5768,12 +5839,12 @@ var Helper = (_class3 = class {
|
|
|
5768
5839
|
/**
|
|
5769
5840
|
* 读取 package.json 文件内容,并处理成对象返回
|
|
5770
5841
|
*/
|
|
5771
|
-
async resolvePackageFile(
|
|
5842
|
+
async resolvePackageFile(path8) {
|
|
5772
5843
|
try {
|
|
5773
|
-
if (!_fs2.default.existsSync(
|
|
5844
|
+
if (!_fs2.default.existsSync(path8)) {
|
|
5774
5845
|
return {};
|
|
5775
5846
|
}
|
|
5776
|
-
return JSON.parse(await _fs2.default.promises.readFile(
|
|
5847
|
+
return JSON.parse(await _fs2.default.promises.readFile(path8, "utf-8"));
|
|
5777
5848
|
} catch (error) {
|
|
5778
5849
|
console.error(error);
|
|
5779
5850
|
return {};
|
|
@@ -5810,7 +5881,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
5810
5881
|
ast: void 0
|
|
5811
5882
|
}
|
|
5812
5883
|
};
|
|
5813
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
5884
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _209 => _209.plugins]), result, ctx);
|
|
5814
5885
|
return result;
|
|
5815
5886
|
}
|
|
5816
5887
|
|
|
@@ -5996,16 +6067,16 @@ var BaseCompiler = (_class5 = class extends Helper {
|
|
|
5996
6067
|
});
|
|
5997
6068
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
5998
6069
|
const resolveSFCAndScriptFile = () => {
|
|
5999
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6000
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6070
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _210 => _210.parser]) });
|
|
6071
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _211 => _211.transformer]) });
|
|
6001
6072
|
const gen = generate(ir, ctx.data, {
|
|
6002
6073
|
...genOptions,
|
|
6003
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6074
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _212 => _212.codegen])
|
|
6004
6075
|
});
|
|
6005
6076
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
6006
6077
|
};
|
|
6007
6078
|
const resolveStyleFile = () => {
|
|
6008
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6079
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _213 => _213.parser]) });
|
|
6009
6080
|
return this.resolveStyleResult(result, ctx.data);
|
|
6010
6081
|
};
|
|
6011
6082
|
try {
|
|
@@ -6132,9 +6203,9 @@ var BaseCompiler = (_class5 = class extends Helper {
|
|
|
6132
6203
|
lang
|
|
6133
6204
|
},
|
|
6134
6205
|
css: {
|
|
6135
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
6136
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
6137
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
6206
|
+
file: _optionalChain([styleData, 'optionalAccess', _214 => _214.filePath]),
|
|
6207
|
+
hash: _optionalChain([styleData, 'optionalAccess', _215 => _215.scopeId]),
|
|
6208
|
+
code: _optionalChain([ir, 'optionalAccess', _216 => _216.style])
|
|
6138
6209
|
}
|
|
6139
6210
|
},
|
|
6140
6211
|
...base
|
|
@@ -6208,7 +6279,7 @@ var AssetManager = (_class6 = class {
|
|
|
6208
6279
|
const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
|
|
6209
6280
|
const filename = _path2.default.basename(p).toLowerCase();
|
|
6210
6281
|
const ext = _path2.default.extname(p).toLowerCase();
|
|
6211
|
-
if (!_optionalChain([this, 'access',
|
|
6282
|
+
if (!_optionalChain([this, 'access', _217 => _217.fileCompiler, 'access', _218 => _218.options, 'access', _219 => _219.output, 'optionalAccess', _220 => _220.ignoreAssets])) {
|
|
6212
6283
|
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
6213
6284
|
if (pattern.endsWith(".")) {
|
|
6214
6285
|
return filename.startsWith(pattern);
|
|
@@ -6294,10 +6365,12 @@ var CacheManager = class {
|
|
|
6294
6365
|
const meta = { ...unit };
|
|
6295
6366
|
delete meta.source;
|
|
6296
6367
|
if (key === "sfc" /* SFC */) {
|
|
6297
|
-
|
|
6298
|
-
|
|
6368
|
+
_optionalChainDelete([meta, 'access', _221 => _221.output, 'optionalAccess', _222 => _222.jsx, 'access', _223 => delete _223.code]);
|
|
6369
|
+
_optionalChainDelete([meta, 'access', _224 => _224.output, 'optionalAccess', _225 => _225.css, 'access', _226 => delete _226.code]);
|
|
6299
6370
|
} else if (key === "script" /* SCRIPT */) {
|
|
6300
|
-
|
|
6371
|
+
_optionalChainDelete([meta, 'access', _227 => _227.output, 'optionalAccess', _228 => _228.script, 'access', _229 => delete _229.code]);
|
|
6372
|
+
} else if (key === "style" /* STYLE */) {
|
|
6373
|
+
_optionalChainDelete([meta, 'access', _230 => _230.output, 'optionalAccess', _231 => _231.style, 'access', _232 => delete _232.code]);
|
|
6301
6374
|
}
|
|
6302
6375
|
this.updateCache(unit.file, meta, cache);
|
|
6303
6376
|
await this.fileCompiler.saveCache(cache);
|
|
@@ -6345,10 +6418,10 @@ var CleanupManager = class {
|
|
|
6345
6418
|
const removeFn = async (m) => {
|
|
6346
6419
|
if (key === "sfc" /* SFC */) {
|
|
6347
6420
|
const meta = m;
|
|
6348
|
-
if (!_optionalChain([meta, 'optionalAccess',
|
|
6421
|
+
if (!_optionalChain([meta, 'optionalAccess', _233 => _233.output])) return;
|
|
6349
6422
|
const { jsx, css } = meta.output;
|
|
6350
6423
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
6351
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
6424
|
+
if (_optionalChain([css, 'optionalAccess', _234 => _234.file])) {
|
|
6352
6425
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
6353
6426
|
}
|
|
6354
6427
|
} else if (key === "script" /* SCRIPT */ || key === "copied" /* ASSET */) {
|
|
@@ -6392,7 +6465,7 @@ var CompilationUnitProcessor = class {
|
|
|
6392
6465
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
6393
6466
|
const isStyleFile = key === "style" /* STYLE */;
|
|
6394
6467
|
if (isSFC || isScriptFile) {
|
|
6395
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
6468
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _235 => _235.hasRoute]);
|
|
6396
6469
|
}
|
|
6397
6470
|
const resolveFileInfo = () => {
|
|
6398
6471
|
if (isSFC) {
|
|
@@ -6412,7 +6485,7 @@ var CompilationUnitProcessor = class {
|
|
|
6412
6485
|
const { script } = result.fileInfo;
|
|
6413
6486
|
unit.output = {
|
|
6414
6487
|
script: {
|
|
6415
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
6488
|
+
file: _optionalChain([script, 'optionalAccess', _236 => _236.file]),
|
|
6416
6489
|
code
|
|
6417
6490
|
}
|
|
6418
6491
|
};
|
|
@@ -6458,6 +6531,7 @@ var CompilationUnitProcessor = class {
|
|
|
6458
6531
|
|
|
6459
6532
|
// src/compiler/shared/file-compiler/file-processor.ts
|
|
6460
6533
|
|
|
6534
|
+
|
|
6461
6535
|
var FileProcessor = (_class7 = class {
|
|
6462
6536
|
constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class7.prototype.__init11.call(this);
|
|
6463
6537
|
this.fileCompiler = fileCompiler;
|
|
@@ -6492,7 +6566,7 @@ var FileProcessor = (_class7 = class {
|
|
|
6492
6566
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
6493
6567
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
6494
6568
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
|
|
6495
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
6569
|
+
const record = _optionalChain([cache, 'optionalAccess', _237 => _237.target, 'access', _238 => _238.find, 'call', _239 => _239((c) => c.file === absPath)]);
|
|
6496
6570
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
6497
6571
|
fileMeta,
|
|
6498
6572
|
record,
|
|
@@ -6511,11 +6585,12 @@ var FileProcessor = (_class7 = class {
|
|
|
6511
6585
|
hash: hash || this.fileCompiler.genHash(source)
|
|
6512
6586
|
};
|
|
6513
6587
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
6514
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6588
|
+
if (_optionalChain([processed, 'optionalAccess', _240 => _240.output])) {
|
|
6515
6589
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
6516
6590
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
6517
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6591
|
+
if (_optionalChain([processed, 'optionalAccess', _241 => _241.hasRoute])) {
|
|
6518
6592
|
await this.injectVuReactRouteDep();
|
|
6593
|
+
await this.copyRouteSetupNotes();
|
|
6519
6594
|
}
|
|
6520
6595
|
}
|
|
6521
6596
|
await this.cacheManager.updateCacheIncrementally(processed, key);
|
|
@@ -6526,9 +6601,30 @@ var FileProcessor = (_class7 = class {
|
|
|
6526
6601
|
const pkgPath = this.fileCompiler.getOutputPkgPath();
|
|
6527
6602
|
const pkg = await this.fileCompiler.resolvePackageFile(pkgPath);
|
|
6528
6603
|
const { router } = this.pkgs;
|
|
6604
|
+
if (!pkg["dependencies"]) {
|
|
6605
|
+
pkg["dependencies"] = {};
|
|
6606
|
+
}
|
|
6529
6607
|
pkg["dependencies"][router.name] = router.version;
|
|
6530
6608
|
await _fs2.default.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2), "utf-8");
|
|
6531
6609
|
}
|
|
6610
|
+
/**
|
|
6611
|
+
* 如果使用了路由,则拷贝路由配置说明文档到输出目录根部。
|
|
6612
|
+
*/
|
|
6613
|
+
async copyRouteSetupNotes() {
|
|
6614
|
+
const outputDir = this.fileCompiler.getOuputPath();
|
|
6615
|
+
const packageRoot = _path2.default.resolve(getDirname(import.meta.url), "../");
|
|
6616
|
+
const templateDir = _path2.default.join(packageRoot, "templates");
|
|
6617
|
+
if (!_fs2.default.existsSync(templateDir)) {
|
|
6618
|
+
return;
|
|
6619
|
+
}
|
|
6620
|
+
const files = ["route-setup-notes.md", "route-setup-notes.zh.md"];
|
|
6621
|
+
for (const file of files) {
|
|
6622
|
+
const srcPath = _path2.default.join(templateDir, file);
|
|
6623
|
+
if (!_fs2.default.existsSync(srcPath)) continue;
|
|
6624
|
+
const destPath = _path2.default.join(outputDir, file);
|
|
6625
|
+
await _fs2.default.promises.copyFile(srcPath, destPath);
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6532
6628
|
}, _class7);
|
|
6533
6629
|
|
|
6534
6630
|
// src/compiler/shared/file-compiler/pipeline-manager.ts
|
|
@@ -6704,7 +6800,7 @@ var ViteBootstrapper = (_class9 = class {
|
|
|
6704
6800
|
*/
|
|
6705
6801
|
resolveViteCreateApp() {
|
|
6706
6802
|
const { output } = this.options;
|
|
6707
|
-
const config = _optionalChain([output, 'optionalAccess',
|
|
6803
|
+
const config = _optionalChain([output, 'optionalAccess', _242 => _242.bootstrapVite]);
|
|
6708
6804
|
const template = typeof config === "object" ? config.template : "react-ts";
|
|
6709
6805
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
6710
6806
|
const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
|
|
@@ -6780,27 +6876,55 @@ var FileCompiler = (_class10 = class extends BaseCompiler {
|
|
|
6780
6876
|
}
|
|
6781
6877
|
await this.viteBootstrapper.bootstrapIfNeeded();
|
|
6782
6878
|
try {
|
|
6783
|
-
this.
|
|
6784
|
-
const
|
|
6785
|
-
this.
|
|
6786
|
-
this.
|
|
6787
|
-
|
|
6788
|
-
this.spinner.stop();
|
|
6789
|
-
this.spinner.start("Compiling style files...");
|
|
6790
|
-
const styleCount = await this.pipelineManager.runStylePipeline();
|
|
6791
|
-
this.spinner.stop();
|
|
6792
|
-
this.spinner.start("Copying assets...");
|
|
6793
|
-
const assetCount = await this.assetManager.runAssetPipeline();
|
|
6794
|
-
this.spinner.stop();
|
|
6795
|
-
await _optionalChain([this, 'access', _229 => _229.options, 'access', _230 => _230.onSuccess, 'optionalCall', _231 => _231()]);
|
|
6879
|
+
const sfcCount = await this.runPipelineWithSpinner("sfc" /* SFC */);
|
|
6880
|
+
const scriptCount = await this.runPipelineWithSpinner("script" /* SCRIPT */);
|
|
6881
|
+
const styleCount = await this.runPipelineWithSpinner("style" /* STYLE */);
|
|
6882
|
+
const assetCount = await this.runPipelineWithSpinner("copied" /* ASSET */);
|
|
6883
|
+
await _optionalChain([this, 'access', _243 => _243.options, 'access', _244 => _244.onSuccess, 'optionalCall', _245 => _245()]);
|
|
6796
6884
|
const endTime = calcElapsedTime(startTime);
|
|
6797
6885
|
this.printCoreLogs();
|
|
6798
6886
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|
|
6799
6887
|
} catch (error) {
|
|
6800
|
-
this.spinner.stop();
|
|
6801
6888
|
const endTime = calcElapsedTime(startTime);
|
|
6802
|
-
console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}
|
|
6803
|
-
|
|
6889
|
+
console.error(_kleur2.default.red("\u2716"), `Build failed in ${endTime}`);
|
|
6890
|
+
console.error(error);
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
/**
|
|
6894
|
+
* 运行管线并显示加载动画
|
|
6895
|
+
*
|
|
6896
|
+
* @private
|
|
6897
|
+
* @param text - 加载动画显示的文本
|
|
6898
|
+
* @param pipelineFn - 要执行的管线函数
|
|
6899
|
+
* @returns 返回的处理的文件数
|
|
6900
|
+
*/
|
|
6901
|
+
async runPipelineWithSpinner(name) {
|
|
6902
|
+
const options = {
|
|
6903
|
+
["sfc" /* SFC */]: {
|
|
6904
|
+
text: "Compiling Vue files...",
|
|
6905
|
+
pipeline: () => this.pipelineManager.runSfcPipeline()
|
|
6906
|
+
},
|
|
6907
|
+
["script" /* SCRIPT */]: {
|
|
6908
|
+
text: "Compiling script files...",
|
|
6909
|
+
pipeline: () => this.pipelineManager.runScriptPipeline()
|
|
6910
|
+
},
|
|
6911
|
+
["style" /* STYLE */]: {
|
|
6912
|
+
text: "Compiling style files...",
|
|
6913
|
+
pipeline: () => this.pipelineManager.runStylePipeline()
|
|
6914
|
+
},
|
|
6915
|
+
["copied" /* ASSET */]: {
|
|
6916
|
+
text: "Copying assets...",
|
|
6917
|
+
pipeline: () => this.assetManager.runAssetPipeline()
|
|
6918
|
+
}
|
|
6919
|
+
};
|
|
6920
|
+
const { text, pipeline } = options[name];
|
|
6921
|
+
try {
|
|
6922
|
+
this.spinner.start(text);
|
|
6923
|
+
return await pipeline();
|
|
6924
|
+
} catch (err) {
|
|
6925
|
+
throw err;
|
|
6926
|
+
} finally {
|
|
6927
|
+
this.spinner.stop();
|
|
6804
6928
|
}
|
|
6805
6929
|
}
|
|
6806
6930
|
/**
|
|
@@ -6987,4 +7111,5 @@ var VuReact = class extends FileCompiler {
|
|
|
6987
7111
|
|
|
6988
7112
|
|
|
6989
7113
|
|
|
6990
|
-
|
|
7114
|
+
|
|
7115
|
+
exports.getDirname = getDirname; exports.normalizePath = normalizePath; exports.calcElapsedTime = calcElapsedTime; exports.generateComponent = generateComponent; exports.generateOnlyScript = generateOnlyScript; exports.generate = generate; exports.parseOnlyScript = parseOnlyScript; exports.parseSFC = parseSFC; exports.parse = parse; exports.transform = transform; exports.version = version; exports.bin = bin; exports.CacheKey = CacheKey; exports.Helper = Helper; exports.BaseCompiler = BaseCompiler; exports.FileCompiler = FileCompiler; exports.defineConfig = defineConfig; exports.VuReact = VuReact;
|