@wevu/compiler 6.16.31 → 6.16.33

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 CHANGED
@@ -31,6 +31,26 @@ declare const WE_VU_PAGE_HOOK_TO_FEATURE: {
31
31
  * wevu 运行时模块 ID。
32
32
  */
33
33
  declare const WE_VU_MODULE_ID: "wevu";
34
+ /**
35
+ * wevu 编译产物内部运行时模块 ID。
36
+ */
37
+ declare const WE_VU_INTERNAL_RUNTIME_MODULE_ID: "wevu/internal-runtime";
38
+ /**
39
+ * wevu 编译产物内部响应式模块 ID。
40
+ */
41
+ declare const WE_VU_INTERNAL_REACTIVITY_MODULE_ID: "wevu/internal-reactivity";
42
+ /**
43
+ * wevu 编译产物内部模板工具模块 ID。
44
+ */
45
+ declare const WE_VU_INTERNAL_TEMPLATE_MODULE_ID: "wevu/internal-template";
46
+ /**
47
+ * wevu 运行时模块 ID 列表。
48
+ */
49
+ declare const WE_VU_RUNTIME_MODULE_IDS: readonly ["wevu", "wevu/internal-runtime"];
50
+ /**
51
+ * 判断模块 ID 是否为 wevu 运行时入口。
52
+ */
53
+ declare function isWevuRuntimeModuleId(moduleId: string): boolean;
34
54
  /**
35
55
  * wevu 运行时 API 名称映射。
36
56
  */
@@ -46,6 +66,18 @@ declare const WE_VU_RUNTIME_APIS: {
46
66
  * wevu 运行时 API 名称类型。
47
67
  */
48
68
  type WevuRuntimeApiName = (typeof WE_VU_RUNTIME_APIS)[keyof typeof WE_VU_RUNTIME_APIS];
69
+ /**
70
+ * wevu 内部响应式 API 名称。
71
+ */
72
+ declare const WE_VU_INTERNAL_REACTIVITY_APIS: readonly ["addMutationRecorder", "batch", "computed", "customRef", "effect", "effectScope", "endBatch", "getCurrentScope", "getDeepWatchStrategy", "getReactiveVersion", "isProxy", "isRaw", "isReactive", "isReadonly", "isRef", "isShallowReactive", "isShallowRef", "markRaw", "nextTick", "onScopeDispose", "prelinkReactiveTree", "reactive", "readonly", "ref", "removeMutationRecorder", "setDeepWatchStrategy", "shallowReactive", "shallowReadonly", "shallowRef", "startBatch", "stop", "toRaw", "toRef", "toRefs", "toValue", "touchReactive", "traverse", "triggerRef", "unref", "watch", "watchEffect", "watchPostEffect", "watchSyncEffect"];
73
+ /**
74
+ * wevu 内部模板工具 API 名称。
75
+ */
76
+ declare const WE_VU_INTERNAL_TEMPLATE_APIS: readonly ["normalizeClass", "normalizeStyle", "resolvePropValue"];
77
+ /**
78
+ * 根据 wevu API 名称解析编译产物内部导入入口。
79
+ */
80
+ declare function resolveWevuInternalImportModuleId(apiName: string): "wevu/internal-runtime" | "wevu/internal-reactivity" | "wevu/internal-template";
49
81
  //#endregion
50
82
  //#region src/types/json.d.ts
51
83
  /**
@@ -934,4 +966,4 @@ interface CollectVueTemplateTagsOptions {
934
966
  */
935
967
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
936
968
  //#endregion
937
- export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ResolvedUsingComponentInfo, type ResolvedUsingComponentPath, type ScopedSlotComponentAsset, type SlotFallbackWrapperComponentAsset, type SlotFallbackWrapperStrategy, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, type WevuDefaults, WevuPageFeatureFlag, WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
969
+ export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ResolvedUsingComponentInfo, type ResolvedUsingComponentPath, type ScopedSlotComponentAsset, type SlotFallbackWrapperComponentAsset, type SlotFallbackWrapperStrategy, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, type WevuDefaults, WevuPageFeatureFlag, WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, isWevuRuntimeModuleId, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
package/dist/index.mjs CHANGED
@@ -142,6 +142,28 @@ const WE_VU_PAGE_HOOK_TO_FEATURE = {
142
142
  */
143
143
  const WE_VU_MODULE_ID = "wevu";
144
144
  /**
145
+ * wevu 编译产物内部运行时模块 ID。
146
+ */
147
+ const WE_VU_INTERNAL_RUNTIME_MODULE_ID = "wevu/internal-runtime";
148
+ /**
149
+ * wevu 编译产物内部响应式模块 ID。
150
+ */
151
+ const WE_VU_INTERNAL_REACTIVITY_MODULE_ID = "wevu/internal-reactivity";
152
+ /**
153
+ * wevu 编译产物内部模板工具模块 ID。
154
+ */
155
+ const WE_VU_INTERNAL_TEMPLATE_MODULE_ID = "wevu/internal-template";
156
+ /**
157
+ * wevu 运行时模块 ID 列表。
158
+ */
159
+ const WE_VU_RUNTIME_MODULE_IDS = [WE_VU_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID];
160
+ /**
161
+ * 判断模块 ID 是否为 wevu 运行时入口。
162
+ */
163
+ function isWevuRuntimeModuleId(moduleId) {
164
+ return WE_VU_RUNTIME_MODULE_IDS.includes(moduleId);
165
+ }
166
+ /**
145
167
  * wevu 运行时 API 名称映射。
146
168
  */
147
169
  const WE_VU_RUNTIME_APIS = {
@@ -152,6 +174,72 @@ const WE_VU_RUNTIME_APIS = {
152
174
  defineComponent: "defineComponent",
153
175
  setWevuDefaults: "setWevuDefaults"
154
176
  };
177
+ /**
178
+ * wevu 内部响应式 API 名称。
179
+ */
180
+ const WE_VU_INTERNAL_REACTIVITY_APIS = [
181
+ "addMutationRecorder",
182
+ "batch",
183
+ "computed",
184
+ "customRef",
185
+ "effect",
186
+ "effectScope",
187
+ "endBatch",
188
+ "getCurrentScope",
189
+ "getDeepWatchStrategy",
190
+ "getReactiveVersion",
191
+ "isProxy",
192
+ "isRaw",
193
+ "isReactive",
194
+ "isReadonly",
195
+ "isRef",
196
+ "isShallowReactive",
197
+ "isShallowRef",
198
+ "markRaw",
199
+ "nextTick",
200
+ "onScopeDispose",
201
+ "prelinkReactiveTree",
202
+ "reactive",
203
+ "readonly",
204
+ "ref",
205
+ "removeMutationRecorder",
206
+ "setDeepWatchStrategy",
207
+ "shallowReactive",
208
+ "shallowReadonly",
209
+ "shallowRef",
210
+ "startBatch",
211
+ "stop",
212
+ "toRaw",
213
+ "toRef",
214
+ "toRefs",
215
+ "toValue",
216
+ "touchReactive",
217
+ "traverse",
218
+ "triggerRef",
219
+ "unref",
220
+ "watch",
221
+ "watchEffect",
222
+ "watchPostEffect",
223
+ "watchSyncEffect"
224
+ ];
225
+ /**
226
+ * wevu 内部模板工具 API 名称。
227
+ */
228
+ const WE_VU_INTERNAL_TEMPLATE_APIS = [
229
+ "normalizeClass",
230
+ "normalizeStyle",
231
+ "resolvePropValue"
232
+ ];
233
+ const WE_VU_INTERNAL_REACTIVITY_API_SET = new Set(WE_VU_INTERNAL_REACTIVITY_APIS);
234
+ const WE_VU_INTERNAL_TEMPLATE_API_SET = new Set(WE_VU_INTERNAL_TEMPLATE_APIS);
235
+ /**
236
+ * 根据 wevu API 名称解析编译产物内部导入入口。
237
+ */
238
+ function resolveWevuInternalImportModuleId(apiName) {
239
+ if (WE_VU_INTERNAL_REACTIVITY_API_SET.has(apiName)) return WE_VU_INTERNAL_REACTIVITY_MODULE_ID;
240
+ if (WE_VU_INTERNAL_TEMPLATE_API_SET.has(apiName)) return WE_VU_INTERNAL_TEMPLATE_MODULE_ID;
241
+ return WE_VU_INTERNAL_RUNTIME_MODULE_ID;
242
+ }
155
243
  //#endregion
156
244
  //#region src/utils/vueTemplateTags.ts
157
245
  const RESERVED_VUE_COMPONENT_TAGS = new Set([
@@ -750,7 +838,7 @@ function collectWevuPageFeatureFlags(ast) {
750
838
  const namedHookLocals = /* @__PURE__ */ new Map();
751
839
  const namespaceLocals = /* @__PURE__ */ new Set();
752
840
  for (const stmt of ast.program.body) {
753
- if (!t.isImportDeclaration(stmt) || stmt.source.value !== "wevu") continue;
841
+ if (!t.isImportDeclaration(stmt) || !isWevuRuntimeModuleId(stmt.source.value)) continue;
754
842
  for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
755
843
  const matched = WE_VU_PAGE_HOOK_TO_FEATURE[specifier.imported.name];
756
844
  if (matched) namedHookLocals.set(specifier.local.name, matched);
@@ -834,11 +922,16 @@ function collectWithBabel(code) {
834
922
  return collectWevuPageFeatureFlags(parseJsLike(code));
835
923
  }
836
924
  function collectWithOxc(code) {
837
- return collectFeatureFlagsFromCode(code, {
838
- astEngine: "oxc",
839
- moduleId: WE_VU_MODULE_ID,
840
- hookToFeature: WE_VU_PAGE_HOOK_TO_FEATURE
841
- });
925
+ const enabled = /* @__PURE__ */ new Set();
926
+ for (const moduleId of WE_VU_RUNTIME_MODULE_IDS) {
927
+ const flags = collectFeatureFlagsFromCode(code, {
928
+ astEngine: "oxc",
929
+ moduleId,
930
+ hookToFeature: WE_VU_PAGE_HOOK_TO_FEATURE
931
+ });
932
+ for (const flag of flags) enabled.add(flag);
933
+ }
934
+ return enabled;
842
935
  }
843
936
  /**
844
937
  * 从源码中收集 wevu 页面特性。
@@ -915,7 +1008,7 @@ function createModuleAnalysis(id, ast) {
915
1008
  const source = stmt.source.value;
916
1009
  for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier)) {
917
1010
  const imported = specifier.imported;
918
- if (source === "wevu" && t.isIdentifier(imported)) {
1011
+ if (isWevuRuntimeModuleId(source) && t.isIdentifier(imported)) {
919
1012
  const matched = WE_VU_PAGE_HOOK_TO_FEATURE[imported.name];
920
1013
  if (matched) wevuNamedHookLocals.set(specifier.local.name, matched);
921
1014
  }
@@ -933,7 +1026,7 @@ function createModuleAnalysis(id, ast) {
933
1026
  kind: "namespace",
934
1027
  source
935
1028
  });
936
- if (source === "wevu") wevuNamespaceLocals.add(specifier.local.name);
1029
+ if (isWevuRuntimeModuleId(source)) wevuNamespaceLocals.add(specifier.local.name);
937
1030
  }
938
1031
  continue;
939
1032
  }
@@ -1053,7 +1146,7 @@ function createModuleAnalysisWithOxc(id, code) {
1053
1146
  for (const specifier of stmt.specifiers ?? []) if (specifier.type === "ImportSpecifier" && specifier.local?.type === "Identifier") {
1054
1147
  const importedName = getImportedSpecifierName(specifier.imported);
1055
1148
  if (!importedName) continue;
1056
- if (source === "wevu") {
1149
+ if (isWevuRuntimeModuleId(source)) {
1057
1150
  const matched = WE_VU_PAGE_HOOK_TO_FEATURE[importedName];
1058
1151
  if (matched) wevuNamedHookLocals.set(specifier.local.name, matched);
1059
1152
  }
@@ -1071,7 +1164,7 @@ function createModuleAnalysisWithOxc(id, code) {
1071
1164
  kind: "namespace",
1072
1165
  source
1073
1166
  });
1074
- if (source === "wevu") wevuNamespaceLocals.add(specifier.local.name);
1167
+ if (isWevuRuntimeModuleId(source)) wevuNamespaceLocals.add(specifier.local.name);
1075
1168
  }
1076
1169
  continue;
1077
1170
  }
@@ -1188,7 +1281,7 @@ function mayContainNamespaceFactoryCall(code, namespaceName) {
1188
1281
  }
1189
1282
  function mayCallWevuFactoryByText(code, module) {
1190
1283
  for (const [localName, binding] of module.importedBindings.entries()) {
1191
- if (binding.source !== "wevu") continue;
1284
+ if (!isWevuRuntimeModuleId(binding.source)) continue;
1192
1285
  if (binding.kind === "named" && WEVU_FACTORY_NAMES.has(binding.importedName)) {
1193
1286
  if (mayContainNamedFactoryCall(code, localName)) return true;
1194
1287
  continue;
@@ -1242,11 +1335,11 @@ function collectTargetOptionsObjectsWithModule(ast, module) {
1242
1335
  if (!first || !t.isExpression(first)) return;
1243
1336
  const binding = t.isIdentifier(node.callee) ? module.importedBindings.get(node.callee.name) : void 0;
1244
1337
  if (t.isIdentifier(node.callee)) {
1245
- if (binding?.kind !== "named" || binding.source !== "wevu") return;
1338
+ if (binding?.kind !== "named" || !isWevuRuntimeModuleId(binding.source)) return;
1246
1339
  if (binding.importedName !== WE_VU_RUNTIME_APIS.defineComponent && binding.importedName !== WE_VU_RUNTIME_APIS.createWevuComponent) return;
1247
1340
  } else if (t.isMemberExpression(node.callee) && !node.callee.computed && t.isIdentifier(node.callee.object) && t.isIdentifier(node.callee.property)) {
1248
1341
  const objectBinding = module.importedBindings.get(node.callee.object.name);
1249
- if (objectBinding?.kind !== "namespace" || objectBinding.source !== "wevu") return;
1342
+ if (objectBinding?.kind !== "namespace" || !isWevuRuntimeModuleId(objectBinding.source)) return;
1250
1343
  if (node.callee.property.name !== WE_VU_RUNTIME_APIS.defineComponent && node.callee.property.name !== WE_VU_RUNTIME_APIS.createWevuComponent) return;
1251
1344
  } else return;
1252
1345
  const inlineObject = resolveOptionsObjectFromExpression(first);
@@ -1266,11 +1359,11 @@ function collectTargetOptionsObjectsWithModule(ast, module) {
1266
1359
  if (!first || !t.isExpression(first)) return;
1267
1360
  if (t.isIdentifier(callee)) {
1268
1361
  const binding = module.importedBindings.get(callee.name);
1269
- if (binding?.kind !== "named" || binding.source !== "wevu") return;
1362
+ if (binding?.kind !== "named" || !isWevuRuntimeModuleId(binding.source)) return;
1270
1363
  if (binding.importedName !== WE_VU_RUNTIME_APIS.defineComponent && binding.importedName !== WE_VU_RUNTIME_APIS.createWevuComponent) return;
1271
1364
  } else if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) {
1272
1365
  const objectBinding = module.importedBindings.get(callee.object.name);
1273
- if (objectBinding?.kind !== "namespace" || objectBinding.source !== "wevu") return;
1366
+ if (objectBinding?.kind !== "namespace" || !isWevuRuntimeModuleId(objectBinding.source)) return;
1274
1367
  if (callee.property.name !== WE_VU_RUNTIME_APIS.defineComponent && callee.property.name !== WE_VU_RUNTIME_APIS.createWevuComponent) return;
1275
1368
  } else return;
1276
1369
  const inlineObject = resolveOptionsObjectFromExpression(first);
@@ -1301,7 +1394,7 @@ function collectTargetOptionsObjectsFromCode(code, moduleId, options) {
1301
1394
  module: createEmptyModuleAnalysis(moduleId, "oxc")
1302
1395
  };
1303
1396
  const module = createModuleAnalysisFromCode(moduleId, code, options);
1304
- if (![...module.importedBindings.values()].some((binding) => binding.source === "wevu" && (binding.kind === "namespace" || binding.kind === "named" && (binding.importedName === WE_VU_RUNTIME_APIS.defineComponent || binding.importedName === WE_VU_RUNTIME_APIS.createWevuComponent)))) return {
1397
+ if (![...module.importedBindings.values()].some((binding) => isWevuRuntimeModuleId(binding.source) && (binding.kind === "namespace" || binding.kind === "named" && (binding.importedName === WE_VU_RUNTIME_APIS.defineComponent || binding.importedName === WE_VU_RUNTIME_APIS.createWevuComponent)))) return {
1305
1398
  optionsObjects: [],
1306
1399
  module
1307
1400
  };
@@ -1891,14 +1984,12 @@ function createCollectVisitors(state) {
1891
1984
  };
1892
1985
  }
1893
1986
  //#endregion
1894
- //#region src/plugins/vue/transform/constants.ts
1895
- const RUNTIME_IMPORT_PATH = WE_VU_MODULE_ID;
1896
- //#endregion
1897
1987
  //#region src/plugins/vue/transform/scriptRuntimeImport.ts
1898
1988
  function ensureRuntimeImport(program, importedName, localName = importedName) {
1899
- let targetImport = program.body.find((node) => t.isImportDeclaration(node) && node.source.value === RUNTIME_IMPORT_PATH);
1989
+ const runtimeImportPath = resolveWevuInternalImportModuleId(importedName);
1990
+ let targetImport = program.body.find((node) => t.isImportDeclaration(node) && node.source.value === runtimeImportPath);
1900
1991
  if (!targetImport) {
1901
- targetImport = t.importDeclaration([t.importSpecifier(t.identifier(localName), t.identifier(importedName))], t.stringLiteral(RUNTIME_IMPORT_PATH));
1992
+ targetImport = t.importDeclaration([t.importSpecifier(t.identifier(localName), t.identifier(importedName))], t.stringLiteral(runtimeImportPath));
1902
1993
  program.body.unshift(targetImport);
1903
1994
  return;
1904
1995
  }
@@ -1910,6 +2001,173 @@ function ensureRuntimeImport(program, importedName, localName = importedName) {
1910
2001
  }
1911
2002
  //#endregion
1912
2003
  //#region src/plugins/vue/transform/transformScript/imports.ts
2004
+ const INTERNAL_RUNTIME_VALUE_EXPORTS = new Set([
2005
+ "addMutationRecorder",
2006
+ "batch",
2007
+ "computed",
2008
+ "createApp",
2009
+ "createWevuComponent",
2010
+ "createWevuScopedSlotComponent",
2011
+ "customRef",
2012
+ "defineAppSetup",
2013
+ "defineComponent",
2014
+ "effect",
2015
+ "effectScope",
2016
+ "endBatch",
2017
+ "getCurrentInstance",
2018
+ "getCurrentPageStackSnapshot",
2019
+ "getCurrentScope",
2020
+ "getCurrentSetupContext",
2021
+ "getDeepWatchStrategy",
2022
+ "getNavigationBarMetrics",
2023
+ "getReactiveVersion",
2024
+ "hasInjectionContext",
2025
+ "inject",
2026
+ "injectGlobal",
2027
+ "isNoSetData",
2028
+ "isProxy",
2029
+ "isRaw",
2030
+ "isReactive",
2031
+ "isReadonly",
2032
+ "isRef",
2033
+ "isShallowReactive",
2034
+ "isShallowRef",
2035
+ "markNoSetData",
2036
+ "markRaw",
2037
+ "mergeModels",
2038
+ "mountRuntimeInstance",
2039
+ "nextTick",
2040
+ "normalizeClass",
2041
+ "normalizeStyle",
2042
+ "onActivated",
2043
+ "onAddToFavorites",
2044
+ "onAttached",
2045
+ "onBeforeMount",
2046
+ "onBeforeUnmount",
2047
+ "onBeforeUpdate",
2048
+ "onDeactivated",
2049
+ "onDetached",
2050
+ "onError",
2051
+ "onErrorCaptured",
2052
+ "onHide",
2053
+ "onLaunch",
2054
+ "onLoad",
2055
+ "onMemoryWarning",
2056
+ "onMounted",
2057
+ "onMoved",
2058
+ "onPageNotFound",
2059
+ "onPageScroll",
2060
+ "onPullDownRefresh",
2061
+ "onReachBottom",
2062
+ "onReady",
2063
+ "onResize",
2064
+ "onRouteDone",
2065
+ "onSaveExitState",
2066
+ "onScopeDispose",
2067
+ "onServerPrefetch",
2068
+ "onShareAppMessage",
2069
+ "onShareTimeline",
2070
+ "onShow",
2071
+ "onTabItemTap",
2072
+ "onThemeChange",
2073
+ "onUnhandledRejection",
2074
+ "onUnload",
2075
+ "onUnmounted",
2076
+ "onUpdated",
2077
+ "prelinkReactiveTree",
2078
+ "provide",
2079
+ "provideGlobal",
2080
+ "reactive",
2081
+ "readonly",
2082
+ "ref",
2083
+ "registerApp",
2084
+ "registerComponent",
2085
+ "removeMutationRecorder",
2086
+ "resetWevuDefaults",
2087
+ "resolveLayoutBridge",
2088
+ "resolveLayoutHost",
2089
+ "resolvePropValue",
2090
+ "resolveRuntimePageLayoutName",
2091
+ "runSetupFunction",
2092
+ "setCurrentInstance",
2093
+ "setCurrentSetupContext",
2094
+ "setDeepWatchStrategy",
2095
+ "setGlobalProvidedValue",
2096
+ "setPageLayout",
2097
+ "setRuntimeSetDataVisibility",
2098
+ "setWevuDefaults",
2099
+ "shallowReactive",
2100
+ "shallowReadonly",
2101
+ "shallowRef",
2102
+ "startBatch",
2103
+ "stop",
2104
+ "syncRuntimePageLayoutState",
2105
+ "syncRuntimePageLayoutStateFromRuntime",
2106
+ "teardownRuntimeInstance",
2107
+ "toRaw",
2108
+ "toRef",
2109
+ "toRefs",
2110
+ "toValue",
2111
+ "touchReactive",
2112
+ "traverse",
2113
+ "triggerRef",
2114
+ "unref",
2115
+ "useAttrs",
2116
+ "useAsyncPullDownRefresh",
2117
+ "useBindModel",
2118
+ "useBoundingClientRect",
2119
+ "useChangeModel",
2120
+ "useDisposables",
2121
+ "useElementIntersectionObserver",
2122
+ "useIntersectionObserver",
2123
+ "useLayoutBridge",
2124
+ "useLayoutHosts",
2125
+ "useModel",
2126
+ "useNativeInstance",
2127
+ "useNativePageRouter",
2128
+ "useNativeRouter",
2129
+ "useNavigationBarMetrics",
2130
+ "usePageLayout",
2131
+ "usePageScrollThrottle",
2132
+ "usePageStack",
2133
+ "useScrollOffset",
2134
+ "useSelectorFields",
2135
+ "useSelectorQuery",
2136
+ "useSlots",
2137
+ "useTemplateRef",
2138
+ "useUpdatePerformanceListener",
2139
+ "version",
2140
+ "waitForLayoutHost",
2141
+ "watch",
2142
+ "watchEffect",
2143
+ "watchPostEffect",
2144
+ "watchSyncEffect"
2145
+ ]);
2146
+ function ensureInternalRuntimeImport(program, importedName, localName = importedName) {
2147
+ const runtimeImportPath = resolveWevuInternalImportModuleId(importedName);
2148
+ let targetImport = program.body.find((node) => t.isImportDeclaration(node) && node.source.value === runtimeImportPath);
2149
+ if (!targetImport) {
2150
+ targetImport = t.importDeclaration([], t.stringLiteral(runtimeImportPath));
2151
+ program.body.unshift(targetImport);
2152
+ }
2153
+ if (!targetImport.specifiers.some((specifier) => t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, { name: importedName }) && t.isIdentifier(specifier.local, { name: localName }))) targetImport.specifiers.push(t.importSpecifier(t.identifier(localName), t.identifier(importedName)));
2154
+ }
2155
+ function splitWevuNamedImportsToInternalRuntime(path, program, state) {
2156
+ if (path.node.source.value !== "wevu" || path.node.importKind === "type") return;
2157
+ const remaining = path.node.specifiers.filter((specifier) => {
2158
+ if (!t.isImportSpecifier(specifier) || specifier.importKind === "type" || !t.isIdentifier(specifier.imported) || !t.isIdentifier(specifier.local)) return true;
2159
+ const importedName = specifier.imported.name;
2160
+ if (!INTERNAL_RUNTIME_VALUE_EXPORTS.has(importedName)) return true;
2161
+ ensureInternalRuntimeImport(program, importedName, specifier.local.name);
2162
+ state.transformed = true;
2163
+ return false;
2164
+ });
2165
+ if (remaining.length === 0) {
2166
+ path.remove();
2167
+ return;
2168
+ }
2169
+ if (remaining.length !== path.node.specifiers.length) path.node.specifiers = remaining;
2170
+ }
1913
2171
  function createImportVisitors(program, state) {
1914
2172
  return { ImportDeclaration(path) {
1915
2173
  if (path.node.source.value === "vue") {
@@ -1966,6 +2224,7 @@ function createImportVisitors(program, state) {
1966
2224
  }
1967
2225
  path.node.specifiers = kept;
1968
2226
  }
2227
+ splitWevuNamedImportsToInternalRuntime(path, program, state);
1969
2228
  } };
1970
2229
  }
1971
2230
  //#endregion
@@ -7172,6 +7431,7 @@ function isWevuComponentTag(node, context) {
7172
7431
  function shouldAugmentPlainSlot(decl, context, ownerNode) {
7173
7432
  if (context.scopedSlotsRequireProps) return false;
7174
7433
  if (context.rewriteScopedSlot && !isWevuComponentTag(ownerNode, context)) return false;
7434
+ if (context.rewriteScopedSlot && !hasDirectComponentSlotChild(decl.children, context)) return false;
7175
7435
  if (context.scopedSlotsCompiler === "augmented") return true;
7176
7436
  if (!decl.implicitDefault) return false;
7177
7437
  if (!isWevuComponentTag(ownerNode, context)) return false;
@@ -8230,6 +8490,9 @@ async function compileConfigPhase(params) {
8230
8490
  if (configObj && Object.keys(configObj).length > 0) result.config = JSON.stringify(configObj, null, 2);
8231
8491
  }
8232
8492
  //#endregion
8493
+ //#region src/plugins/vue/transform/constants.ts
8494
+ const RUNTIME_IMPORT_PATH = WE_VU_INTERNAL_RUNTIME_MODULE_ID;
8495
+ //#endregion
8233
8496
  //#region src/plugins/vue/transform/compileVueFile/finalize.ts
8234
8497
  function finalizeResult(result, options) {
8235
8498
  if (!result.script || result.script.trim() === "") result.script = `import { ${WE_VU_RUNTIME_APIS.createWevuComponent} } from '${RUNTIME_IMPORT_PATH}';\n${WE_VU_RUNTIME_APIS.createWevuComponent}({});\n`;
@@ -8800,8 +9063,28 @@ function typePropsContainReservedName(typeNode, scope, seen = /* @__PURE__ */ ne
8800
9063
  }
8801
9064
  return false;
8802
9065
  }
8803
- function hasDefinePropsReservedName(scriptSetupCode) {
8804
- let hasReservedName = false;
9066
+ function getDefinePropsLocation(node) {
9067
+ const start = node.loc?.start;
9068
+ if (!start) return;
9069
+ return {
9070
+ line: start.line,
9071
+ column: start.column
9072
+ };
9073
+ }
9074
+ function resolveSourceLocation(location, scriptSetupStart) {
9075
+ if (!location) return;
9076
+ if (!scriptSetupStart) return location;
9077
+ return {
9078
+ line: scriptSetupStart.line + location.line - 1,
9079
+ column: location.line === 1 ? scriptSetupStart.column + location.column : location.column
9080
+ };
9081
+ }
9082
+ function createReservedPropsWarning(location, filename) {
9083
+ if (!location || !filename) return RESERVED_PROPS_WARNING;
9084
+ return `${filename}:${location.line}:${location.column + 1} ${RESERVED_PROPS_WARNING}`;
9085
+ }
9086
+ function detectDefinePropsReservedName(scriptSetupCode) {
9087
+ let result;
8805
9088
  try {
8806
9089
  const ast = parseJsLike(scriptSetupCode);
8807
9090
  const typeScope = createTypeScope(ast);
@@ -8809,24 +9092,27 @@ function hasDefinePropsReservedName(scriptSetupCode) {
8809
9092
  const callee = path.node.callee;
8810
9093
  if (!t.isIdentifier(callee, { name: "defineProps" })) return;
8811
9094
  if (runtimePropsContainReservedName(path.node.arguments[0])) {
8812
- hasReservedName = true;
9095
+ result = { location: getDefinePropsLocation(path.node) };
8813
9096
  path.stop();
8814
9097
  return;
8815
9098
  }
8816
9099
  const typeParam = path.node.typeParameters?.params?.[0];
8817
9100
  if (typePropsContainReservedName(typeParam, typeScope)) {
8818
- hasReservedName = true;
9101
+ result = { location: getDefinePropsLocation(path.node) };
8819
9102
  path.stop();
8820
9103
  }
8821
9104
  } });
8822
9105
  } catch {
8823
- return false;
9106
+ return;
8824
9107
  }
8825
- return hasReservedName;
9108
+ return result;
8826
9109
  }
8827
- function warnReservedScriptSetupProps(scriptSetupCode, warn) {
8828
- if (!scriptSetupCode || !hasDefinePropsReservedName(scriptSetupCode)) return;
8829
- warn?.(RESERVED_PROPS_WARNING);
9110
+ function warnReservedScriptSetupProps(scriptSetupCode, warn, context = {}) {
9111
+ if (!scriptSetupCode) return;
9112
+ const result = detectDefinePropsReservedName(scriptSetupCode);
9113
+ if (!result) return;
9114
+ const location = resolveSourceLocation(result.location, context.scriptSetupStart);
9115
+ warn?.(createReservedPropsWarning(location, context.filename));
8830
9116
  }
8831
9117
  //#endregion
8832
9118
  //#region src/plugins/vue/transform/compileVueFile/script.ts
@@ -8929,7 +9215,10 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8929
9215
  id: filename,
8930
9216
  isProd: false
8931
9217
  });
8932
- warnReservedScriptSetupProps(descriptorForCompile.scriptSetup?.content, options?.warn);
9218
+ warnReservedScriptSetupProps(descriptorForCompile.scriptSetup?.content, options?.warn, {
9219
+ filename,
9220
+ scriptSetupStart: descriptorForCompile.scriptSetup?.loc.start
9221
+ });
8933
9222
  propsAliases ??= resolveScriptSetupPropsAliases(scriptCompiled.bindings);
8934
9223
  scriptCode = scriptCompiled.content;
8935
9224
  propsDerivedKeys = resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCode);
@@ -9090,4 +9379,4 @@ async function compileVueFile(source, filename, options) {
9090
9379
  return result;
9091
9380
  }
9092
9381
  //#endregion
9093
- export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
9382
+ export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, isWevuRuntimeModuleId, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.31",
4
+ "version": "6.16.33",
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.35",
53
53
  "@weapp-core/constants": "0.1.12",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.31",
55
+ "@weapp-vite/ast": "6.16.33",
56
56
  "rolldown-require": "2.0.18"
57
57
  },
58
58
  "publishConfig": {