@wevu/compiler 6.16.46 → 6.17.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/dist/index.d.mts +12 -3
- package/dist/index.mjs +170 -56
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MpPlatform } from "@weapp-core/shared";
|
|
2
2
|
import * as t from "@weapp-vite/ast/babelTypes";
|
|
3
3
|
import { Expression } from "@weapp-vite/ast/babelTypes";
|
|
4
|
-
import { AstEngineName, AstEngineName as AstEngineName$1 } from "@weapp-vite/ast";
|
|
5
4
|
import { LRUCache } from "lru-cache";
|
|
5
|
+
import { AstEngineName, AstEngineName as AstEngineName$1 } from "@weapp-vite/ast";
|
|
6
6
|
import { SFCBlock, SFCDescriptor, SFCParseResult, SFCStyleBlock } from "vue/compiler-sfc";
|
|
7
7
|
//#region src/auto-import-components/builtin.d.ts
|
|
8
8
|
/**
|
|
@@ -865,10 +865,14 @@ type ImportBinding = {
|
|
|
865
865
|
kind: 'namespace';
|
|
866
866
|
source: string;
|
|
867
867
|
};
|
|
868
|
+
type ModuleAst = t.File | {
|
|
869
|
+
type: string;
|
|
870
|
+
[key: string]: any;
|
|
871
|
+
};
|
|
868
872
|
interface ModuleAnalysis {
|
|
869
873
|
id: string;
|
|
870
874
|
engine: AstEngineName$1;
|
|
871
|
-
ast?:
|
|
875
|
+
ast?: ModuleAst;
|
|
872
876
|
wevuNamedHookLocals: Map<string, WevuPageFeatureFlag>;
|
|
873
877
|
wevuNamespaceLocals: Set<string>;
|
|
874
878
|
importedBindings: Map<string, ImportBinding>;
|
|
@@ -877,10 +881,15 @@ interface ModuleAnalysis {
|
|
|
877
881
|
}
|
|
878
882
|
//#endregion
|
|
879
883
|
//#region src/plugins/wevu/pageFeatures/optionsObjects.d.ts
|
|
884
|
+
type OptionsObject = t.ObjectExpression | {
|
|
885
|
+
type: 'ObjectExpression';
|
|
886
|
+
properties: any[];
|
|
887
|
+
[key: string]: any;
|
|
888
|
+
};
|
|
880
889
|
declare function collectTargetOptionsObjectsFromCode(code: string, moduleId: string, options?: {
|
|
881
890
|
astEngine?: AstEngineName$1;
|
|
882
891
|
}): {
|
|
883
|
-
optionsObjects:
|
|
892
|
+
optionsObjects: OptionsObject[];
|
|
884
893
|
module: ModuleAnalysis;
|
|
885
894
|
};
|
|
886
895
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -11,8 +11,8 @@ import { BABEL_TS_MODULE_PARSER_OPTIONS, generate, parse as parse$3, parseJsLike
|
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import process from "node:process";
|
|
14
|
-
import { collectFeatureFlagsFromCode, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
|
|
15
14
|
import { LRUCache } from "lru-cache";
|
|
15
|
+
import { collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
|
|
16
16
|
import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_FUNCTION_PROP_PATHS_KEY, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_ALIASES_KEY, WEVU_PROPS_DERIVED_KEYS_KEY, WEVU_PROPS_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_OWNER_PROXY_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY, WEVU_TEMPLATE_REF_CLASS_PREFIX } from "@weapp-core/constants";
|
|
17
17
|
import { compileScript, parse } from "vue/compiler-sfc";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
@@ -490,6 +490,10 @@ function rewriteJsLikeImportsForTempDir(source, fromDir, tempDir) {
|
|
|
490
490
|
const sourceNode = p.node?.source;
|
|
491
491
|
if (sourceNode && t.isStringLiteral(sourceNode)) rewriteLiteral(sourceNode, sourceNode.value);
|
|
492
492
|
},
|
|
493
|
+
ImportExpression(p) {
|
|
494
|
+
const sourceNode = p.node?.source;
|
|
495
|
+
if (sourceNode && t.isStringLiteral(sourceNode)) rewriteLiteral(sourceNode, sourceNode.value);
|
|
496
|
+
},
|
|
493
497
|
CallExpression(p) {
|
|
494
498
|
const callee = p.node?.callee;
|
|
495
499
|
if (!callee) return;
|
|
@@ -918,34 +922,6 @@ function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject, enabled) {
|
|
|
918
922
|
return changed;
|
|
919
923
|
}
|
|
920
924
|
//#endregion
|
|
921
|
-
//#region src/ast/operations/pageFeatures.ts
|
|
922
|
-
function collectWithBabel(code) {
|
|
923
|
-
return collectWevuPageFeatureFlags(parseJsLike(code));
|
|
924
|
-
}
|
|
925
|
-
function collectWithOxc(code) {
|
|
926
|
-
const enabled = /* @__PURE__ */ new Set();
|
|
927
|
-
for (const moduleId of WE_VU_RUNTIME_MODULE_IDS) {
|
|
928
|
-
const flags = collectFeatureFlagsFromCode(code, {
|
|
929
|
-
astEngine: "oxc",
|
|
930
|
-
moduleId,
|
|
931
|
-
hookToFeature: WE_VU_PAGE_HOOK_TO_FEATURE
|
|
932
|
-
});
|
|
933
|
-
for (const flag of flags) enabled.add(flag);
|
|
934
|
-
}
|
|
935
|
-
return enabled;
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* 从源码中收集 wevu 页面特性。
|
|
939
|
-
*/
|
|
940
|
-
function collectWevuPageFeatureFlagsFromCode(code, options) {
|
|
941
|
-
const engine = options?.astEngine ?? "babel";
|
|
942
|
-
try {
|
|
943
|
-
return engine === "oxc" ? collectWithOxc(code) : collectWithBabel(code);
|
|
944
|
-
} catch {
|
|
945
|
-
return /* @__PURE__ */ new Set();
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
//#endregion
|
|
949
925
|
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/shared.ts
|
|
950
926
|
function createEmptyModuleAnalysis(id, engine) {
|
|
951
927
|
return {
|
|
@@ -1231,6 +1207,7 @@ function createModuleAnalysisWithOxc(id, code) {
|
|
|
1231
1207
|
return {
|
|
1232
1208
|
id,
|
|
1233
1209
|
engine: "oxc",
|
|
1210
|
+
ast,
|
|
1234
1211
|
wevuNamedHookLocals,
|
|
1235
1212
|
wevuNamespaceLocals,
|
|
1236
1213
|
importedBindings,
|
|
@@ -1267,6 +1244,59 @@ function getOrCreateExternalModuleAnalysis(moduleId, code, options) {
|
|
|
1267
1244
|
return analysis;
|
|
1268
1245
|
}
|
|
1269
1246
|
//#endregion
|
|
1247
|
+
//#region src/ast/operations/pageFeatures.ts
|
|
1248
|
+
const CALL_EXPRESSION_TEXT_RE = /\b[a-z_$][\w$]*(?:\s*<[^(){};]+>)?\s*(?:\?\.\s*)?\(/i;
|
|
1249
|
+
const WEVU_PAGE_HOOK_NAMES = Object.keys(WE_VU_PAGE_HOOK_TO_FEATURE);
|
|
1250
|
+
function mayContainWevuPageFeatureHints(code) {
|
|
1251
|
+
return WE_VU_RUNTIME_MODULE_IDS.some((moduleId) => code.includes(moduleId)) && CALL_EXPRESSION_TEXT_RE.test(code) && WEVU_PAGE_HOOK_NAMES.some((hookName) => code.includes(hookName));
|
|
1252
|
+
}
|
|
1253
|
+
function collectWithBabel(code) {
|
|
1254
|
+
return collectWevuPageFeatureFlags(parseJsLike(code));
|
|
1255
|
+
}
|
|
1256
|
+
function collectWithOxc(code) {
|
|
1257
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
1258
|
+
const module = createModuleAnalysisFromCode("<inline>", code, { astEngine: "oxc" });
|
|
1259
|
+
if (module.wevuNamedHookLocals.size === 0 && module.wevuNamespaceLocals.size === 0) return enabled;
|
|
1260
|
+
const visit = (node) => {
|
|
1261
|
+
if (!node) return;
|
|
1262
|
+
if (node.type === "CallExpression") {
|
|
1263
|
+
const callee = node.callee;
|
|
1264
|
+
if (callee?.type === "Identifier") {
|
|
1265
|
+
const matched = module.wevuNamedHookLocals.get(callee.name);
|
|
1266
|
+
if (matched) enabled.add(matched);
|
|
1267
|
+
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1268
|
+
if (module.wevuNamespaceLocals.has(callee.object.name)) {
|
|
1269
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
|
|
1270
|
+
if (matched) enabled.add(matched);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
} else if (node.type === "ChainExpression") {
|
|
1274
|
+
visit(node.expression);
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
for (const value of Object.values(node)) {
|
|
1278
|
+
if (!value) continue;
|
|
1279
|
+
if (Array.isArray(value)) {
|
|
1280
|
+
for (const child of value) if (child && typeof child === "object" && typeof child.type === "string") visit(child);
|
|
1281
|
+
} else if (typeof value === "object" && typeof value.type === "string") visit(value);
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
visit(module.ast);
|
|
1285
|
+
return enabled;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* 从源码中收集 wevu 页面特性。
|
|
1289
|
+
*/
|
|
1290
|
+
function collectWevuPageFeatureFlagsFromCode(code, options) {
|
|
1291
|
+
if (!mayContainWevuPageFeatureHints(code)) return /* @__PURE__ */ new Set();
|
|
1292
|
+
const engine = options?.astEngine ?? "babel";
|
|
1293
|
+
try {
|
|
1294
|
+
return engine === "oxc" ? collectWithOxc(code) : collectWithBabel(code);
|
|
1295
|
+
} catch {
|
|
1296
|
+
return /* @__PURE__ */ new Set();
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
//#endregion
|
|
1270
1300
|
//#region src/plugins/wevu/pageFeatures/optionsObjects.ts
|
|
1271
1301
|
const WEVU_FACTORY_NAMES = new Set([WE_VU_RUNTIME_APIS.defineComponent, WE_VU_RUNTIME_APIS.createWevuComponent]);
|
|
1272
1302
|
const REGEXP_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
@@ -1311,10 +1341,17 @@ function resolveOptionsObjectFromExpression(node) {
|
|
|
1311
1341
|
}
|
|
1312
1342
|
return null;
|
|
1313
1343
|
}
|
|
1344
|
+
function getOxcStaticPropertyName(node) {
|
|
1345
|
+
if (node?.type === "Identifier") return node.name;
|
|
1346
|
+
if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
|
|
1347
|
+
}
|
|
1314
1348
|
function getSetupFunctionFromOptionsObject(options) {
|
|
1315
1349
|
for (const prop of options.properties) if (t.isObjectProperty(prop) && !prop.computed && isStaticObjectKeyMatch$1(prop.key, "setup")) {
|
|
1316
1350
|
if (t.isFunctionExpression(prop.value) || t.isArrowFunctionExpression(prop.value)) return prop.value;
|
|
1317
1351
|
} else if (t.isObjectMethod(prop) && !prop.computed && isStaticObjectKeyMatch$1(prop.key, "setup")) return prop;
|
|
1352
|
+
else if (prop?.type === "Property" && !prop.computed && getOxcStaticPropertyName(prop.key) === "setup") {
|
|
1353
|
+
if (prop.value?.type === "FunctionExpression" || prop.value?.type === "ArrowFunctionExpression") return prop.value;
|
|
1354
|
+
}
|
|
1318
1355
|
return null;
|
|
1319
1356
|
}
|
|
1320
1357
|
function collectTargetOptionsObjectsWithModule(ast, module) {
|
|
@@ -1385,6 +1422,69 @@ function collectTargetOptionsObjectsWithModule(ast, module) {
|
|
|
1385
1422
|
module
|
|
1386
1423
|
};
|
|
1387
1424
|
}
|
|
1425
|
+
function unwrapOxcTypeLikeExpression(node) {
|
|
1426
|
+
if (node?.type === "TSAsExpression" || node?.type === "TSSatisfiesExpression" || node?.type === "TSNonNullExpression" || node?.type === "TSTypeAssertion" || node?.type === "ParenthesizedExpression") return unwrapOxcTypeLikeExpression(node.expression);
|
|
1427
|
+
return node;
|
|
1428
|
+
}
|
|
1429
|
+
function getOxcCallExpression(node) {
|
|
1430
|
+
if (node?.type === "ChainExpression") return getOxcCallExpression(node.expression);
|
|
1431
|
+
if (node?.type === "CallExpression") return node;
|
|
1432
|
+
return null;
|
|
1433
|
+
}
|
|
1434
|
+
function resolveOxcOptionsObjectFromExpression(node, bindings) {
|
|
1435
|
+
const normalized = unwrapOxcTypeLikeExpression(node);
|
|
1436
|
+
if (normalized?.type === "ObjectExpression") return normalized;
|
|
1437
|
+
if (normalized?.type === "Identifier") return bindings.get(normalized.name) ?? null;
|
|
1438
|
+
if (normalized?.type !== "CallExpression") return null;
|
|
1439
|
+
const callee = unwrapOxcTypeLikeExpression(normalized.callee);
|
|
1440
|
+
if (callee?.type !== "MemberExpression" || callee.computed || callee.object?.type !== "Identifier" || callee.object.name !== "Object" || callee.property?.type !== "Identifier" || callee.property.name !== "assign") return null;
|
|
1441
|
+
for (let index = normalized.arguments.length - 1; index >= 0; index -= 1) {
|
|
1442
|
+
const argument = normalized.arguments[index];
|
|
1443
|
+
if (argument?.type === "SpreadElement") continue;
|
|
1444
|
+
const candidate = resolveOxcOptionsObjectFromExpression(argument, bindings);
|
|
1445
|
+
if (candidate) return candidate;
|
|
1446
|
+
}
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
function isOxcWevuFactoryCall(call, module) {
|
|
1450
|
+
const callee = unwrapOxcTypeLikeExpression(call.callee);
|
|
1451
|
+
if (callee?.type === "Identifier") {
|
|
1452
|
+
const binding = module.importedBindings.get(callee.name);
|
|
1453
|
+
return binding?.kind === "named" && isWevuRuntimeModuleId(binding.source) && WEVU_FACTORY_NAMES.has(binding.importedName);
|
|
1454
|
+
}
|
|
1455
|
+
if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1456
|
+
const binding = module.importedBindings.get(callee.object.name);
|
|
1457
|
+
return binding?.kind === "namespace" && isWevuRuntimeModuleId(binding.source) && WEVU_FACTORY_NAMES.has(callee.property.name);
|
|
1458
|
+
}
|
|
1459
|
+
return false;
|
|
1460
|
+
}
|
|
1461
|
+
function collectTargetOptionsObjectsWithOxcModule(ast, module) {
|
|
1462
|
+
const optionsObjects = [];
|
|
1463
|
+
const constObjectBindings = /* @__PURE__ */ new Map();
|
|
1464
|
+
const pendingConstObjectRefs = [];
|
|
1465
|
+
for (const stmt of ast?.body ?? []) {
|
|
1466
|
+
if (stmt?.type === "VariableDeclaration") {
|
|
1467
|
+
for (const decl of stmt.declarations ?? []) if (decl?.id?.type === "Identifier" && decl.init?.type === "ObjectExpression") constObjectBindings.set(decl.id.name, decl.init);
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
if (stmt?.type !== "ExpressionStatement") continue;
|
|
1471
|
+
const call = getOxcCallExpression(stmt.expression);
|
|
1472
|
+
if (!call || !isOxcWevuFactoryCall(call, module)) continue;
|
|
1473
|
+
const first = call.arguments?.[0];
|
|
1474
|
+
if (!first) continue;
|
|
1475
|
+
const inlineObject = resolveOxcOptionsObjectFromExpression(first, constObjectBindings);
|
|
1476
|
+
if (inlineObject) optionsObjects.push(inlineObject);
|
|
1477
|
+
else if (first.type === "Identifier") pendingConstObjectRefs.push(first.name);
|
|
1478
|
+
}
|
|
1479
|
+
for (const name of pendingConstObjectRefs) {
|
|
1480
|
+
const target = constObjectBindings.get(name);
|
|
1481
|
+
if (target) optionsObjects.push(target);
|
|
1482
|
+
}
|
|
1483
|
+
return {
|
|
1484
|
+
optionsObjects,
|
|
1485
|
+
module
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1388
1488
|
function collectTargetOptionsObjects(ast, moduleId) {
|
|
1389
1489
|
return collectTargetOptionsObjectsWithModule(ast, createModuleAnalysis(moduleId, ast));
|
|
1390
1490
|
}
|
|
@@ -1403,10 +1503,7 @@ function collectTargetOptionsObjectsFromCode(code, moduleId, options) {
|
|
|
1403
1503
|
optionsObjects: [],
|
|
1404
1504
|
module
|
|
1405
1505
|
};
|
|
1406
|
-
return
|
|
1407
|
-
optionsObjects: collectTargetOptionsObjects(parseJsLike(code), moduleId).optionsObjects,
|
|
1408
|
-
module
|
|
1409
|
-
};
|
|
1506
|
+
return collectTargetOptionsObjectsWithOxcModule(module.ast, module);
|
|
1410
1507
|
}
|
|
1411
1508
|
const module = createModuleAnalysisFromCode(moduleId, code, options);
|
|
1412
1509
|
return collectTargetOptionsObjectsWithModule(module.ast, module);
|
|
@@ -1424,6 +1521,11 @@ function getCallCalleeName(callee) {
|
|
|
1424
1521
|
object: callee.object.name,
|
|
1425
1522
|
property: callee.property.name
|
|
1426
1523
|
};
|
|
1524
|
+
if (t.isOptionalMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
|
|
1525
|
+
type: "member",
|
|
1526
|
+
object: callee.object.name,
|
|
1527
|
+
property: callee.property.name
|
|
1528
|
+
};
|
|
1427
1529
|
return null;
|
|
1428
1530
|
}
|
|
1429
1531
|
function collectCalledBindingsFromFunctionBody(fn, engine = "babel") {
|
|
@@ -1469,6 +1571,23 @@ function collectCalledBindingsFromFunctionBody(fn, engine = "babel") {
|
|
|
1469
1571
|
}
|
|
1470
1572
|
//#endregion
|
|
1471
1573
|
//#region src/plugins/wevu/pageFeatures/reachability/hooks.ts
|
|
1574
|
+
function getMemberHookName(callee) {
|
|
1575
|
+
if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
|
|
1576
|
+
object: callee.object.name,
|
|
1577
|
+
hook: callee.property.name
|
|
1578
|
+
};
|
|
1579
|
+
if (t.isOptionalMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
|
|
1580
|
+
object: callee.object.name,
|
|
1581
|
+
hook: callee.property.name
|
|
1582
|
+
};
|
|
1583
|
+
return null;
|
|
1584
|
+
}
|
|
1585
|
+
function addNamespaceHookFeature(module, callee, enabled) {
|
|
1586
|
+
const memberHook = getMemberHookName(callee);
|
|
1587
|
+
if (!memberHook || !module.wevuNamespaceLocals.has(memberHook.object)) return;
|
|
1588
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[memberHook.hook];
|
|
1589
|
+
if (matched) enabled.add(matched);
|
|
1590
|
+
}
|
|
1472
1591
|
function collectWevuHookCallsInFunctionBody(module, fn) {
|
|
1473
1592
|
const enabled = /* @__PURE__ */ new Set();
|
|
1474
1593
|
if (module.engine === "oxc") {
|
|
@@ -1507,11 +1626,7 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
|
|
|
1507
1626
|
if (matched) enabled.add(matched);
|
|
1508
1627
|
return;
|
|
1509
1628
|
}
|
|
1510
|
-
|
|
1511
|
-
if (!module.wevuNamespaceLocals.has(callee.object.name)) return;
|
|
1512
|
-
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
|
|
1513
|
-
if (matched) enabled.add(matched);
|
|
1514
|
-
}
|
|
1629
|
+
addNamespaceHookFeature(module, callee, enabled);
|
|
1515
1630
|
} else if (t.isOptionalCallExpression(node)) {
|
|
1516
1631
|
const callee = node.callee;
|
|
1517
1632
|
if (t.isIdentifier(callee)) {
|
|
@@ -1519,11 +1634,7 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
|
|
|
1519
1634
|
if (matched) enabled.add(matched);
|
|
1520
1635
|
return;
|
|
1521
1636
|
}
|
|
1522
|
-
|
|
1523
|
-
if (!module.wevuNamespaceLocals.has(callee.object.name)) return;
|
|
1524
|
-
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
|
|
1525
|
-
if (matched) enabled.add(matched);
|
|
1526
|
-
}
|
|
1637
|
+
addNamespaceHookFeature(module, callee, enabled);
|
|
1527
1638
|
}
|
|
1528
1639
|
});
|
|
1529
1640
|
return enabled;
|
|
@@ -2382,6 +2493,18 @@ function stripOptionalFromPattern(pattern) {
|
|
|
2382
2493
|
}
|
|
2383
2494
|
//#endregion
|
|
2384
2495
|
//#region src/plugins/vue/transform/transformScript/macros/stripTypes.ts
|
|
2496
|
+
function stripTypeArguments(node) {
|
|
2497
|
+
let stripped = false;
|
|
2498
|
+
if (node.typeParameters) {
|
|
2499
|
+
node.typeParameters = null;
|
|
2500
|
+
stripped = true;
|
|
2501
|
+
}
|
|
2502
|
+
if (node.typeArguments) {
|
|
2503
|
+
node.typeArguments = null;
|
|
2504
|
+
stripped = true;
|
|
2505
|
+
}
|
|
2506
|
+
return stripped;
|
|
2507
|
+
}
|
|
2385
2508
|
function createStripTypesVisitors(state) {
|
|
2386
2509
|
return {
|
|
2387
2510
|
ExportNamedDeclaration(path) {
|
|
@@ -2413,16 +2536,10 @@ function createStripTypesVisitors(state) {
|
|
|
2413
2536
|
return;
|
|
2414
2537
|
}
|
|
2415
2538
|
}
|
|
2416
|
-
if (path.node
|
|
2417
|
-
path.node.typeParameters = null;
|
|
2418
|
-
state.transformed = true;
|
|
2419
|
-
}
|
|
2539
|
+
if (stripTypeArguments(path.node)) state.transformed = true;
|
|
2420
2540
|
},
|
|
2421
2541
|
NewExpression(path) {
|
|
2422
|
-
if (path.node
|
|
2423
|
-
path.node.typeParameters = null;
|
|
2424
|
-
state.transformed = true;
|
|
2425
|
-
}
|
|
2542
|
+
if (stripTypeArguments(path.node)) state.transformed = true;
|
|
2426
2543
|
},
|
|
2427
2544
|
ObjectProperty(path) {
|
|
2428
2545
|
if (t.isIdentifier(path.node.key, { name: "__name" }) || t.isStringLiteral(path.node.key, { value: "__name" })) {
|
|
@@ -2479,10 +2596,7 @@ function createStripTypesVisitors(state) {
|
|
|
2479
2596
|
path.node.returnType = null;
|
|
2480
2597
|
state.transformed = true;
|
|
2481
2598
|
}
|
|
2482
|
-
if (path.node
|
|
2483
|
-
path.node.typeParameters = null;
|
|
2484
|
-
state.transformed = true;
|
|
2485
|
-
}
|
|
2599
|
+
if (stripTypeArguments(path.node)) state.transformed = true;
|
|
2486
2600
|
for (const param of path.node.params) if (stripOptionalFromPattern(param)) state.transformed = true;
|
|
2487
2601
|
},
|
|
2488
2602
|
ClassMethod(path) {
|
|
@@ -9309,7 +9423,7 @@ function detectDefinePropsReservedName(scriptSetupCode) {
|
|
|
9309
9423
|
path.stop();
|
|
9310
9424
|
return;
|
|
9311
9425
|
}
|
|
9312
|
-
const typeParam = path.node.typeParameters?.params?.[0];
|
|
9426
|
+
const typeParam = (path.node.typeParameters ?? path.node.typeArguments)?.params?.[0];
|
|
9313
9427
|
if (typePropsContainReservedName(typeParam, typeScope)) {
|
|
9314
9428
|
result = { location: getDefinePropsLocation(path.node) };
|
|
9315
9429
|
path.stop();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.17.0",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue": "^3.5.38",
|
|
53
53
|
"@weapp-core/constants": "0.1.12",
|
|
54
54
|
"@weapp-core/shared": "3.0.4",
|
|
55
|
-
"@weapp-vite/ast": "6.
|
|
55
|
+
"@weapp-vite/ast": "6.17.0",
|
|
56
56
|
"rolldown-require": "2.0.19"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|