@wevu/compiler 6.9.0 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +33 -4
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1128,6 +1128,29 @@ function getOrCreateExternalModuleAnalysis(moduleId, code, options) {
1128
1128
  }
1129
1129
  //#endregion
1130
1130
  //#region src/plugins/wevu/pageFeatures/optionsObjects.ts
1131
+ const WEVU_FACTORY_NAMES = new Set([WE_VU_RUNTIME_APIS.defineComponent, WE_VU_RUNTIME_APIS.createWevuComponent]);
1132
+ const REGEXP_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
1133
+ function escapeRegExp(value) {
1134
+ return value.replace(REGEXP_META_CHARS_RE, "\\$&");
1135
+ }
1136
+ function mayContainNamedFactoryCall(code, localName) {
1137
+ return new RegExp(`\\b${escapeRegExp(localName)}\\b(?:\\s*<[^(){};]+>)?\\s*(?:\\?\\.)?\\s*\\(`, "m").test(code);
1138
+ }
1139
+ function mayContainNamespaceFactoryCall(code, namespaceName) {
1140
+ const factoryAlternation = Array.from(WEVU_FACTORY_NAMES, (name) => escapeRegExp(name)).join("|");
1141
+ return new RegExp(`\\b${escapeRegExp(namespaceName)}\\b\\s*\\.\\s*(?:${factoryAlternation})\\b(?:\\s*<[^(){};]+>)?\\s*(?:\\?\\.)?\\s*\\(`, "m").test(code);
1142
+ }
1143
+ function mayCallWevuFactoryByText(code, module) {
1144
+ for (const [localName, binding] of module.importedBindings.entries()) {
1145
+ if (binding.source !== "wevu") continue;
1146
+ if (binding.kind === "named" && WEVU_FACTORY_NAMES.has(binding.importedName)) {
1147
+ if (mayContainNamedFactoryCall(code, localName)) return true;
1148
+ continue;
1149
+ }
1150
+ if (binding.kind === "namespace" && mayContainNamespaceFactoryCall(code, localName)) return true;
1151
+ }
1152
+ return false;
1153
+ }
1131
1154
  function unwrapTypeLikeExpression$2(node) {
1132
1155
  if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression$2(node.expression);
1133
1156
  if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression$2(node.expression);
@@ -1154,8 +1177,7 @@ function getSetupFunctionFromOptionsObject(options) {
1154
1177
  } else if (t.isObjectMethod(prop) && !prop.computed && isStaticObjectKeyMatch$1(prop.key, "setup")) return prop;
1155
1178
  return null;
1156
1179
  }
1157
- function collectTargetOptionsObjects(ast, moduleId) {
1158
- const module = createModuleAnalysis(moduleId, ast);
1180
+ function collectTargetOptionsObjectsWithModule(ast, module) {
1159
1181
  const optionsObjects = [];
1160
1182
  const constObjectBindings = /* @__PURE__ */ new Map();
1161
1183
  const pendingConstObjectRefs = [];
@@ -1223,6 +1245,9 @@ function collectTargetOptionsObjects(ast, moduleId) {
1223
1245
  module
1224
1246
  };
1225
1247
  }
1248
+ function collectTargetOptionsObjects(ast, moduleId) {
1249
+ return collectTargetOptionsObjectsWithModule(ast, createModuleAnalysis(moduleId, ast));
1250
+ }
1226
1251
  function collectTargetOptionsObjectsFromCode(code, moduleId, options) {
1227
1252
  if (options?.astEngine === "oxc") {
1228
1253
  if (!(code.includes("wevu") && (code.includes(WE_VU_RUNTIME_APIS.defineComponent) || code.includes(WE_VU_RUNTIME_APIS.createWevuComponent)))) return {
@@ -1234,13 +1259,17 @@ function collectTargetOptionsObjectsFromCode(code, moduleId, options) {
1234
1259
  optionsObjects: [],
1235
1260
  module
1236
1261
  };
1262
+ if (!mayCallWevuFactoryByText(code, module)) return {
1263
+ optionsObjects: [],
1264
+ module
1265
+ };
1237
1266
  return {
1238
1267
  optionsObjects: collectTargetOptionsObjects(parseJsLike(code), moduleId).optionsObjects,
1239
1268
  module
1240
1269
  };
1241
1270
  }
1242
- const ast = createModuleAnalysisFromCode(moduleId, code, options).ast;
1243
- return collectTargetOptionsObjects(ast, moduleId);
1271
+ const module = createModuleAnalysisFromCode(moduleId, code, options);
1272
+ return collectTargetOptionsObjectsWithModule(module.ast, module);
1244
1273
  }
1245
1274
  //#endregion
1246
1275
  //#region src/plugins/wevu/pageFeatures/reachability/calls.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.9.0",
4
+ "version": "6.10.0",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  "pathe": "^2.0.3",
51
51
  "vue": "^3.5.30",
52
52
  "@weapp-core/shared": "3.0.2",
53
- "@weapp-vite/ast": "6.9.0",
53
+ "@weapp-vite/ast": "6.10.0",
54
54
  "rolldown-require": "2.0.8"
55
55
  },
56
56
  "publishConfig": {