@wevu/compiler 6.16.46 → 6.16.47
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 +126 -33
- 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";
|
|
@@ -918,34 +918,6 @@ function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject, enabled) {
|
|
|
918
918
|
return changed;
|
|
919
919
|
}
|
|
920
920
|
//#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
921
|
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/shared.ts
|
|
950
922
|
function createEmptyModuleAnalysis(id, engine) {
|
|
951
923
|
return {
|
|
@@ -1231,6 +1203,7 @@ function createModuleAnalysisWithOxc(id, code) {
|
|
|
1231
1203
|
return {
|
|
1232
1204
|
id,
|
|
1233
1205
|
engine: "oxc",
|
|
1206
|
+
ast,
|
|
1234
1207
|
wevuNamedHookLocals,
|
|
1235
1208
|
wevuNamespaceLocals,
|
|
1236
1209
|
importedBindings,
|
|
@@ -1267,6 +1240,59 @@ function getOrCreateExternalModuleAnalysis(moduleId, code, options) {
|
|
|
1267
1240
|
return analysis;
|
|
1268
1241
|
}
|
|
1269
1242
|
//#endregion
|
|
1243
|
+
//#region src/ast/operations/pageFeatures.ts
|
|
1244
|
+
const CALL_EXPRESSION_TEXT_RE = /\b[a-z_$][\w$]*(?:\s*<[^(){};]+>)?\s*(?:\?\.\s*)?\(/i;
|
|
1245
|
+
const WEVU_PAGE_HOOK_NAMES = Object.keys(WE_VU_PAGE_HOOK_TO_FEATURE);
|
|
1246
|
+
function mayContainWevuPageFeatureHints(code) {
|
|
1247
|
+
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));
|
|
1248
|
+
}
|
|
1249
|
+
function collectWithBabel(code) {
|
|
1250
|
+
return collectWevuPageFeatureFlags(parseJsLike(code));
|
|
1251
|
+
}
|
|
1252
|
+
function collectWithOxc(code) {
|
|
1253
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
1254
|
+
const module = createModuleAnalysisFromCode("<inline>", code, { astEngine: "oxc" });
|
|
1255
|
+
if (module.wevuNamedHookLocals.size === 0 && module.wevuNamespaceLocals.size === 0) return enabled;
|
|
1256
|
+
const visit = (node) => {
|
|
1257
|
+
if (!node) return;
|
|
1258
|
+
if (node.type === "CallExpression") {
|
|
1259
|
+
const callee = node.callee;
|
|
1260
|
+
if (callee?.type === "Identifier") {
|
|
1261
|
+
const matched = module.wevuNamedHookLocals.get(callee.name);
|
|
1262
|
+
if (matched) enabled.add(matched);
|
|
1263
|
+
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1264
|
+
if (module.wevuNamespaceLocals.has(callee.object.name)) {
|
|
1265
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
|
|
1266
|
+
if (matched) enabled.add(matched);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
} else if (node.type === "ChainExpression") {
|
|
1270
|
+
visit(node.expression);
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
for (const value of Object.values(node)) {
|
|
1274
|
+
if (!value) continue;
|
|
1275
|
+
if (Array.isArray(value)) {
|
|
1276
|
+
for (const child of value) if (child && typeof child === "object" && typeof child.type === "string") visit(child);
|
|
1277
|
+
} else if (typeof value === "object" && typeof value.type === "string") visit(value);
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
visit(module.ast);
|
|
1281
|
+
return enabled;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* 从源码中收集 wevu 页面特性。
|
|
1285
|
+
*/
|
|
1286
|
+
function collectWevuPageFeatureFlagsFromCode(code, options) {
|
|
1287
|
+
if (!mayContainWevuPageFeatureHints(code)) return /* @__PURE__ */ new Set();
|
|
1288
|
+
const engine = options?.astEngine ?? "babel";
|
|
1289
|
+
try {
|
|
1290
|
+
return engine === "oxc" ? collectWithOxc(code) : collectWithBabel(code);
|
|
1291
|
+
} catch {
|
|
1292
|
+
return /* @__PURE__ */ new Set();
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
//#endregion
|
|
1270
1296
|
//#region src/plugins/wevu/pageFeatures/optionsObjects.ts
|
|
1271
1297
|
const WEVU_FACTORY_NAMES = new Set([WE_VU_RUNTIME_APIS.defineComponent, WE_VU_RUNTIME_APIS.createWevuComponent]);
|
|
1272
1298
|
const REGEXP_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
@@ -1311,10 +1337,17 @@ function resolveOptionsObjectFromExpression(node) {
|
|
|
1311
1337
|
}
|
|
1312
1338
|
return null;
|
|
1313
1339
|
}
|
|
1340
|
+
function getOxcStaticPropertyName(node) {
|
|
1341
|
+
if (node?.type === "Identifier") return node.name;
|
|
1342
|
+
if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
|
|
1343
|
+
}
|
|
1314
1344
|
function getSetupFunctionFromOptionsObject(options) {
|
|
1315
1345
|
for (const prop of options.properties) if (t.isObjectProperty(prop) && !prop.computed && isStaticObjectKeyMatch$1(prop.key, "setup")) {
|
|
1316
1346
|
if (t.isFunctionExpression(prop.value) || t.isArrowFunctionExpression(prop.value)) return prop.value;
|
|
1317
1347
|
} else if (t.isObjectMethod(prop) && !prop.computed && isStaticObjectKeyMatch$1(prop.key, "setup")) return prop;
|
|
1348
|
+
else if (prop?.type === "Property" && !prop.computed && getOxcStaticPropertyName(prop.key) === "setup") {
|
|
1349
|
+
if (prop.value?.type === "FunctionExpression" || prop.value?.type === "ArrowFunctionExpression") return prop.value;
|
|
1350
|
+
}
|
|
1318
1351
|
return null;
|
|
1319
1352
|
}
|
|
1320
1353
|
function collectTargetOptionsObjectsWithModule(ast, module) {
|
|
@@ -1385,6 +1418,69 @@ function collectTargetOptionsObjectsWithModule(ast, module) {
|
|
|
1385
1418
|
module
|
|
1386
1419
|
};
|
|
1387
1420
|
}
|
|
1421
|
+
function unwrapOxcTypeLikeExpression(node) {
|
|
1422
|
+
if (node?.type === "TSAsExpression" || node?.type === "TSSatisfiesExpression" || node?.type === "TSNonNullExpression" || node?.type === "TSTypeAssertion" || node?.type === "ParenthesizedExpression") return unwrapOxcTypeLikeExpression(node.expression);
|
|
1423
|
+
return node;
|
|
1424
|
+
}
|
|
1425
|
+
function getOxcCallExpression(node) {
|
|
1426
|
+
if (node?.type === "ChainExpression") return getOxcCallExpression(node.expression);
|
|
1427
|
+
if (node?.type === "CallExpression") return node;
|
|
1428
|
+
return null;
|
|
1429
|
+
}
|
|
1430
|
+
function resolveOxcOptionsObjectFromExpression(node, bindings) {
|
|
1431
|
+
const normalized = unwrapOxcTypeLikeExpression(node);
|
|
1432
|
+
if (normalized?.type === "ObjectExpression") return normalized;
|
|
1433
|
+
if (normalized?.type === "Identifier") return bindings.get(normalized.name) ?? null;
|
|
1434
|
+
if (normalized?.type !== "CallExpression") return null;
|
|
1435
|
+
const callee = unwrapOxcTypeLikeExpression(normalized.callee);
|
|
1436
|
+
if (callee?.type !== "MemberExpression" || callee.computed || callee.object?.type !== "Identifier" || callee.object.name !== "Object" || callee.property?.type !== "Identifier" || callee.property.name !== "assign") return null;
|
|
1437
|
+
for (let index = normalized.arguments.length - 1; index >= 0; index -= 1) {
|
|
1438
|
+
const argument = normalized.arguments[index];
|
|
1439
|
+
if (argument?.type === "SpreadElement") continue;
|
|
1440
|
+
const candidate = resolveOxcOptionsObjectFromExpression(argument, bindings);
|
|
1441
|
+
if (candidate) return candidate;
|
|
1442
|
+
}
|
|
1443
|
+
return null;
|
|
1444
|
+
}
|
|
1445
|
+
function isOxcWevuFactoryCall(call, module) {
|
|
1446
|
+
const callee = unwrapOxcTypeLikeExpression(call.callee);
|
|
1447
|
+
if (callee?.type === "Identifier") {
|
|
1448
|
+
const binding = module.importedBindings.get(callee.name);
|
|
1449
|
+
return binding?.kind === "named" && isWevuRuntimeModuleId(binding.source) && WEVU_FACTORY_NAMES.has(binding.importedName);
|
|
1450
|
+
}
|
|
1451
|
+
if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1452
|
+
const binding = module.importedBindings.get(callee.object.name);
|
|
1453
|
+
return binding?.kind === "namespace" && isWevuRuntimeModuleId(binding.source) && WEVU_FACTORY_NAMES.has(callee.property.name);
|
|
1454
|
+
}
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
function collectTargetOptionsObjectsWithOxcModule(ast, module) {
|
|
1458
|
+
const optionsObjects = [];
|
|
1459
|
+
const constObjectBindings = /* @__PURE__ */ new Map();
|
|
1460
|
+
const pendingConstObjectRefs = [];
|
|
1461
|
+
for (const stmt of ast?.body ?? []) {
|
|
1462
|
+
if (stmt?.type === "VariableDeclaration") {
|
|
1463
|
+
for (const decl of stmt.declarations ?? []) if (decl?.id?.type === "Identifier" && decl.init?.type === "ObjectExpression") constObjectBindings.set(decl.id.name, decl.init);
|
|
1464
|
+
continue;
|
|
1465
|
+
}
|
|
1466
|
+
if (stmt?.type !== "ExpressionStatement") continue;
|
|
1467
|
+
const call = getOxcCallExpression(stmt.expression);
|
|
1468
|
+
if (!call || !isOxcWevuFactoryCall(call, module)) continue;
|
|
1469
|
+
const first = call.arguments?.[0];
|
|
1470
|
+
if (!first) continue;
|
|
1471
|
+
const inlineObject = resolveOxcOptionsObjectFromExpression(first, constObjectBindings);
|
|
1472
|
+
if (inlineObject) optionsObjects.push(inlineObject);
|
|
1473
|
+
else if (first.type === "Identifier") pendingConstObjectRefs.push(first.name);
|
|
1474
|
+
}
|
|
1475
|
+
for (const name of pendingConstObjectRefs) {
|
|
1476
|
+
const target = constObjectBindings.get(name);
|
|
1477
|
+
if (target) optionsObjects.push(target);
|
|
1478
|
+
}
|
|
1479
|
+
return {
|
|
1480
|
+
optionsObjects,
|
|
1481
|
+
module
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1388
1484
|
function collectTargetOptionsObjects(ast, moduleId) {
|
|
1389
1485
|
return collectTargetOptionsObjectsWithModule(ast, createModuleAnalysis(moduleId, ast));
|
|
1390
1486
|
}
|
|
@@ -1403,10 +1499,7 @@ function collectTargetOptionsObjectsFromCode(code, moduleId, options) {
|
|
|
1403
1499
|
optionsObjects: [],
|
|
1404
1500
|
module
|
|
1405
1501
|
};
|
|
1406
|
-
return
|
|
1407
|
-
optionsObjects: collectTargetOptionsObjects(parseJsLike(code), moduleId).optionsObjects,
|
|
1408
|
-
module
|
|
1409
|
-
};
|
|
1502
|
+
return collectTargetOptionsObjectsWithOxcModule(module.ast, module);
|
|
1410
1503
|
}
|
|
1411
1504
|
const module = createModuleAnalysisFromCode(moduleId, code, options);
|
|
1412
1505
|
return collectTargetOptionsObjectsWithModule(module.ast, module);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.16.
|
|
4
|
+
"version": "6.16.47",
|
|
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.16.
|
|
55
|
+
"@weapp-vite/ast": "6.16.47",
|
|
56
56
|
"rolldown-require": "2.0.19"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|