@wevu/compiler 6.16.20 → 6.16.22

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
@@ -280,6 +280,7 @@ interface TemplateCompileOptions {
280
280
  * Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
281
281
  */
282
282
  propsAliases?: Record<string, string>;
283
+ propsDerivedKeys?: string[];
283
284
  htmlTagToWxml?: boolean | Record<string, string>;
284
285
  htmlTagToWxmlTagClass?: boolean;
285
286
  scopedSlotsCompiler?: ScopedSlotsCompilerMode;
@@ -713,6 +714,10 @@ interface TransformScriptOptions {
713
714
  * Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
714
715
  */
715
716
  propsAliases?: Record<string, string>;
717
+ /**
718
+ * Vue `<script setup>` 中直接来自 props 的绑定名,用于运行时区分 props-derived binding 与普通 setup state。
719
+ */
720
+ propsDerivedKeys?: string[];
716
721
  /**
717
722
  * 对 `<script setup>` 类型声明生成的结构化 props(如 Array/Object)放宽小程序运行时类型约束,
718
723
  * 以避免小程序属性校验对复杂表达式/代理值产生误报。
package/dist/index.mjs CHANGED
@@ -13,7 +13,7 @@ import os from "node:os";
13
13
  import process from "node:process";
14
14
  import { collectFeatureFlagsFromCode, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
15
15
  import { LRUCache } from "lru-cache";
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_KEY, 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 } from "@weapp-core/constants";
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_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 } from "@weapp-core/constants";
17
17
  import { compileScript, parse } from "vue/compiler-sfc";
18
18
  import { fileURLToPath } from "node:url";
19
19
  import { parse as parse$1 } from "@vue/compiler-dom";
@@ -2241,6 +2241,12 @@ function buildConsoleErrorGuard(message, errorId) {
2241
2241
  function buildRuntimeExpressionErrorGuard(binding, errorId) {
2242
2242
  return buildConsoleErrorGuard(`[wevu] 模板运行时表达式执行失败: ${binding.name} = ${binding.exp}`, errorId);
2243
2243
  }
2244
+ function shouldReportRuntimeExpressionError(binding) {
2245
+ return binding.type === "bind";
2246
+ }
2247
+ function shouldReportForSourceError(info) {
2248
+ return !(info.listExp?.trim() ?? "").startsWith(`${WEVU_SLOT_PROPS_DATA_KEY}.`);
2249
+ }
2244
2250
  function createDataPropsFallbackExpression(fallback) {
2245
2251
  const propsObject = t.memberExpression(t.thisExpression(), t.identifier(WEVU_PROPS_KEY));
2246
2252
  const propsAccess = t.memberExpression(propsObject, t.identifier("data"));
@@ -2283,7 +2289,7 @@ function buildNormalizedExpression(binding, helpers) {
2283
2289
  const errorFallback = binding.errorFallback ?? "";
2284
2290
  const exp = binding.expAst ? rewriteDataAccessExpression(binding.expAst, helpers) : t.stringLiteral("");
2285
2291
  const normalizedCall = t.callExpression(t.cloneNode(normalizeHelper), [exp]);
2286
- return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.cloneNode(errorId), t.blockStatement([buildRuntimeExpressionErrorGuard(binding, errorId), t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
2292
+ return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.cloneNode(errorId), t.blockStatement([...shouldReportRuntimeExpressionError(binding) ? [buildRuntimeExpressionErrorGuard(binding, errorId)] : [], t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
2287
2293
  }
2288
2294
  function buildArrayMapExpression(binding, forStack, level, listId, helpers) {
2289
2295
  const itemParam = createValidIdentifier(forStack[level].item, `__wv_item_${level}`);
@@ -2331,7 +2337,7 @@ function buildForExpression(binding, forStack, level, helpers) {
2331
2337
  const unrefHelper = helpers.unref ? t.cloneNode(helpers.unref) : t.identifier("unref");
2332
2338
  const listUnrefExp = t.callExpression(unrefHelper, [listExp]);
2333
2339
  const listDecl = t.variableDeclaration("let", [t.variableDeclarator(listId, t.arrayExpression([]))]);
2334
- const listSafeAssign = t.tryStatement(t.blockStatement([t.expressionStatement(t.assignmentExpression("=", listId, listUnrefExp))]), t.catchClause(t.identifier(`__wv_err_${level}`), t.blockStatement([buildConsoleErrorGuard(`[wevu] 模板 v-for 数据源表达式执行失败: ${info.listExp}`, t.identifier(`__wv_err_${level}`)), t.expressionStatement(t.assignmentExpression("=", listId, t.arrayExpression([])))])), null);
2340
+ const listSafeAssign = t.tryStatement(t.blockStatement([t.expressionStatement(t.assignmentExpression("=", listId, listUnrefExp))]), t.catchClause(t.identifier(`__wv_err_${level}`), t.blockStatement([...shouldReportForSourceError(info) ? [buildConsoleErrorGuard(`[wevu] 模板 v-for 数据源表达式执行失败: ${info.listExp}`, t.identifier(`__wv_err_${level}`))] : [], t.expressionStatement(t.assignmentExpression("=", listId, t.arrayExpression([])))])), null);
2335
2341
  const arrayCheck = t.callExpression(t.memberExpression(t.identifier("Array"), t.identifier("isArray")), [listId]);
2336
2342
  const arrayMap = buildArrayMapExpression(binding, forStack, level, listId, helpers);
2337
2343
  const objectCheck = t.logicalExpression("&&", t.binaryExpression("!=", listId, t.nullLiteral()), t.binaryExpression("===", t.unaryExpression("typeof", listId), t.stringLiteral("object")));
@@ -2361,7 +2367,7 @@ function applyPropsAliasesToExpression(expression, propsAliases) {
2361
2367
  if (!path.isReferencedIdentifier()) return;
2362
2368
  const propName = propsAliases[path.node.name];
2363
2369
  if (!propName || path.scope.hasBinding(path.node.name)) return;
2364
- const replacement = createMemberAccess$2(t.identifier("props"), propName);
2370
+ const replacement = createMemberAccess$2(t.memberExpression(t.thisExpression(), t.identifier("__wevuProps")), propName);
2365
2371
  const parent = path.parentPath;
2366
2372
  if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
2367
2373
  parent.node.shorthand = false;
@@ -2411,7 +2417,8 @@ function injectClassStyleComputed(optionsObject, bindings, propsAliases, warn) {
2411
2417
  const entries = buildClassStyleComputedEntries(bindings, {
2412
2418
  normalizeClass: t.identifier("__wevuNormalizeClass"),
2413
2419
  normalizeStyle: t.identifier("__wevuNormalizeStyle"),
2414
- unref: t.identifier("__wevuUnref")
2420
+ unref: t.identifier("__wevuUnref"),
2421
+ resolvePropValue: t.identifier("__wevuResolvePropValue")
2415
2422
  }, propsAliases);
2416
2423
  if (!entries.length) return false;
2417
2424
  const computedProp = getObjectPropertyByKey$1(optionsObject, "computed");
@@ -2434,6 +2441,7 @@ function ensureClassStyleRuntimeImports(program) {
2434
2441
  ensureRuntimeImport(program, "normalizeClass", "__wevuNormalizeClass");
2435
2442
  ensureRuntimeImport(program, "normalizeStyle", "__wevuNormalizeStyle");
2436
2443
  ensureRuntimeImport(program, "unref", "__wevuUnref");
2444
+ ensureRuntimeImport(program, "resolvePropValue", "__wevuResolvePropValue");
2437
2445
  }
2438
2446
  //#endregion
2439
2447
  //#region src/plugins/vue/transform/transformScript/rewrite/defaults.ts
@@ -2733,6 +2741,24 @@ function injectLayoutHosts(optionsObject, bindings, warn) {
2733
2741
  return false;
2734
2742
  }
2735
2743
  //#endregion
2744
+ //#region src/plugins/vue/transform/transformScript/rewrite/propsAliases.ts
2745
+ function injectPropsAliases(optionsObject, propsAliases) {
2746
+ const entries = Object.entries(propsAliases ?? {}).filter(([alias, propName]) => alias && propName).map(([alias, propName]) => {
2747
+ return t.objectProperty(createStaticObjectKey$1(alias), t.stringLiteral(propName));
2748
+ });
2749
+ if (!entries.length) return false;
2750
+ if (getObjectPropertyByKey$1(optionsObject, WEVU_PROPS_ALIASES_KEY)) return false;
2751
+ optionsObject.properties.push(t.objectProperty(createStaticObjectKey$1(WEVU_PROPS_ALIASES_KEY), t.objectExpression(entries)));
2752
+ return true;
2753
+ }
2754
+ function injectPropsDerivedKeys(optionsObject, propsDerivedKeys) {
2755
+ const keys = [...new Set(propsDerivedKeys ?? [])].filter(Boolean);
2756
+ if (!keys.length) return false;
2757
+ if (getObjectPropertyByKey$1(optionsObject, WEVU_PROPS_DERIVED_KEYS_KEY)) return false;
2758
+ optionsObject.properties.push(t.objectProperty(createStaticObjectKey$1(WEVU_PROPS_DERIVED_KEYS_KEY), t.arrayExpression(keys.map((key) => t.stringLiteral(key)))));
2759
+ return true;
2760
+ }
2761
+ //#endregion
2736
2762
  //#region src/plugins/vue/transform/transformScript/rewrite/setupInitialData.ts
2737
2763
  function unwrapExpression(node) {
2738
2764
  if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node) || t.isParenthesizedExpression(node)) return unwrapExpression(node.expression);
@@ -2994,6 +3020,10 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
2994
3020
  }) || transformed;
2995
3021
  if (componentOptionsObject) transformed = injectSetupInitialData(componentOptionsObject) || transformed;
2996
3022
  if (componentOptionsObject && options?.relaxStructuredTypeOnlyProps) transformed = relaxStructuredTypeOnlyProps(componentOptionsObject) || transformed;
3023
+ if (componentOptionsObject) {
3024
+ transformed = injectPropsAliases(componentOptionsObject, options?.propsAliases) || transformed;
3025
+ transformed = injectPropsDerivedKeys(componentOptionsObject, options?.propsDerivedKeys) || transformed;
3026
+ }
2997
3027
  const classStyleBindings = options?.classStyleBindings ?? [];
2998
3028
  if (classStyleBindings.length) if (componentOptionsObject) {
2999
3029
  ensureClassStyleRuntimeImports(ast.program);
@@ -5413,8 +5443,7 @@ function rewriteScopedSlotExpression(exp, context) {
5413
5443
  function rewriteForAliasExpression(exp, context) {
5414
5444
  const normalized = normalizeWxmlExpression(exp);
5415
5445
  const forAliases = collectForAliasMapping$2(context);
5416
- const propsAliases = context.propsAliases ?? {};
5417
- if (!Object.keys(forAliases).length && !Object.keys(propsAliases).length) return normalized;
5446
+ if (!Object.keys(forAliases).length) return normalized;
5418
5447
  const parsed = parseBabelExpressionFile(normalized);
5419
5448
  if (!parsed) return normalized;
5420
5449
  const { ast } = parsed;
@@ -5425,10 +5454,7 @@ function rewriteForAliasExpression(exp, context) {
5425
5454
  if (hasOwn(forAliases, name)) {
5426
5455
  const aliasExp = parseBabelExpression(forAliases[name]);
5427
5456
  if (aliasExp) replaceIdentifierWithExpression(path, t.cloneNode(aliasExp, true));
5428
- return;
5429
5457
  }
5430
- const propName = propsAliases[name];
5431
- if (propName && t.isValidIdentifier(propName)) replaceIdentifierWithExpression(path, t.identifier(propName));
5432
5458
  } });
5433
5459
  const stmt = ast.program.body[0];
5434
5460
  const updatedExpression = stmt && "expression" in stmt ? stmt.expression : null;
@@ -5745,6 +5771,7 @@ const JS_RUNTIME_GLOBALS = new Set([
5745
5771
  "arguments",
5746
5772
  "globalThis",
5747
5773
  "__wevuUnref",
5774
+ "__wevuResolvePropValue",
5748
5775
  "getApp",
5749
5776
  "getCurrentPages",
5750
5777
  ...getMiniProgramRuntimeGlobalKeys()
@@ -5776,6 +5803,15 @@ function createUnrefCall(exp) {
5776
5803
  function createHasOwnPropertyCall(target, key) {
5777
5804
  return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Object"), t.identifier("prototype")), t.identifier("hasOwnProperty")), t.identifier("call")), [target, t.stringLiteral(key)]);
5778
5805
  }
5806
+ function createResolvePropValueCall(name, fallback, preferProps = false) {
5807
+ const args = [
5808
+ t.thisExpression(),
5809
+ t.stringLiteral(name),
5810
+ fallback
5811
+ ];
5812
+ if (preferProps) args.push(t.booleanLiteral(true));
5813
+ return t.callExpression(t.identifier("__wevuResolvePropValue"), args);
5814
+ }
5779
5815
  function createPropsKeyAccessFallback(name, fallback) {
5780
5816
  const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5781
5817
  const propsAccess = createMemberAccess(propsObject, name);
@@ -5783,7 +5819,14 @@ function createPropsKeyAccessFallback(name, fallback) {
5783
5819
  const hasPropsValue = t.logicalExpression("&&", hasPropsObject, t.logicalExpression("||", t.binaryExpression("!==", propsAccess, t.identifier("undefined")), createHasOwnPropertyCall(propsObject, name)));
5784
5820
  return t.conditionalExpression(hasPropsValue, propsAccess, fallback);
5785
5821
  }
5786
- function createIdentifierAccessWithPropsFallback(name) {
5822
+ function createIdentifierAccessWithPropsFallback(name, context, useRuntimePropHelper = false) {
5823
+ if (useRuntimePropHelper) {
5824
+ if (name === "props") {
5825
+ const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5826
+ return t.conditionalExpression(t.binaryExpression("!=", propsObject, t.nullLiteral()), propsObject, createThisMemberAccess("props"));
5827
+ }
5828
+ return createResolvePropValueCall(name, createThisMemberAccess(name));
5829
+ }
5787
5830
  if (name === "props") {
5788
5831
  const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5789
5832
  return t.conditionalExpression(t.binaryExpression("!=", propsObject, t.nullLiteral()), propsObject, createThisMemberAccess("props"));
@@ -5800,20 +5843,13 @@ function createIdentifierAccessWithPropsFallback(name) {
5800
5843
  const hasStateObject = t.binaryExpression("!=", stateObject, t.nullLiteral());
5801
5844
  const hasStateKey = createHasOwnPropertyCall(stateObject, name);
5802
5845
  const hasThisMember = t.binaryExpression("in", t.stringLiteral(name), t.thisExpression());
5803
- const shouldUseStateAccess = t.logicalExpression("&&", hasStateObject, hasStateKey);
5804
- const shouldUsePropsAccess = t.logicalExpression("&&", hasUsablePropsValue, t.unaryExpression("!", hasThisMember));
5846
+ const isPropsDerivedKey = Boolean(context.propsDerivedKeys?.includes(name));
5847
+ const shouldUseStateAccess = isPropsDerivedKey ? t.booleanLiteral(false) : t.logicalExpression("&&", hasStateObject, hasStateKey);
5848
+ const shouldUsePropsAccess = t.logicalExpression("&&", hasUsablePropsValue, isPropsDerivedKey ? t.booleanLiteral(true) : t.unaryExpression("!", hasThisMember));
5805
5849
  return t.conditionalExpression(shouldUseStateAccess, thisAccess, t.conditionalExpression(shouldUsePropsAccess, propsAccess, thisAccess));
5806
5850
  }
5807
5851
  function createAliasedPropsAccess(name, propName) {
5808
- const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5809
- const propsAccess = createMemberAccess(propsObject, propName);
5810
- const hasPropsObject = t.binaryExpression("!=", propsObject, t.nullLiteral());
5811
- const hasDefinedPropsValue = t.binaryExpression("!==", propsAccess, t.identifier("undefined"));
5812
- const hasPropsKey = createHasOwnPropertyCall(propsObject, propName);
5813
- const hasUsablePropsValue = t.logicalExpression("&&", hasPropsObject, t.logicalExpression("||", hasDefinedPropsValue, hasPropsKey));
5814
- const thisAccess = createThisMemberAccess(name);
5815
- const hasThisMember = t.binaryExpression("in", t.stringLiteral(name), t.thisExpression());
5816
- return t.conditionalExpression(t.logicalExpression("&&", hasUsablePropsValue, t.unaryExpression("!", hasThisMember)), propsAccess, thisAccess);
5852
+ return createResolvePropValueCall(propName, createThisMemberAccess(name), true);
5817
5853
  }
5818
5854
  function collectForAliasMapping(context) {
5819
5855
  const mapping = {};
@@ -5865,15 +5901,17 @@ function normalizeJsExpressionWithContext(exp, context, options) {
5865
5901
  else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_PROXY_KEY), name));
5866
5902
  else {
5867
5903
  const propsAlias = context.propsAliases?.[name];
5868
- replacement = createUnrefCall(propsAlias ? createAliasedPropsAccess(name, propsAlias) : createIdentifierAccessWithPropsFallback(name));
5904
+ replacement = createUnrefCall(propsAlias ? createAliasedPropsAccess(name, propsAlias) : createIdentifierAccessWithPropsFallback(name, context, options?.runtimePropAccess === "helper"));
5869
5905
  }
5870
5906
  const parent = path.parentPath;
5871
5907
  if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
5872
5908
  parent.node.shorthand = false;
5873
5909
  parent.node.value = replacement;
5910
+ path.skip();
5874
5911
  return;
5875
5912
  }
5876
5913
  path.replaceWith(replacement);
5914
+ path.skip();
5877
5915
  } });
5878
5916
  const stmt = ast.program.body[0];
5879
5917
  return (stmt && "expression" in stmt ? stmt.expression : null) || null;
@@ -5909,7 +5947,10 @@ function shouldFallbackToRuntimeBinding(exp) {
5909
5947
  * 将复杂表达式注册为 JS 运行时计算绑定,返回可用于模板 mustache 的绑定引用。
5910
5948
  */
5911
5949
  function registerRuntimeBindingExpression(exp, context, options) {
5912
- const expAst = normalizeJsExpressionWithContext(exp, context, options);
5950
+ const expAst = normalizeJsExpressionWithContext(exp, context, {
5951
+ ...options,
5952
+ runtimePropAccess: "helper"
5953
+ });
5913
5954
  if (!expAst) return null;
5914
5955
  const binding = {
5915
5956
  name: `__wv_bind_${context.classStyleBindings.filter((item) => item.type === "bind").length}`,
@@ -6020,7 +6061,10 @@ function renderClassAttribute(staticClass, dynamicClassExp, context) {
6020
6061
  }
6021
6062
  const jsParts = [];
6022
6063
  if (staticValue) jsParts.push(t.stringLiteral(staticValue));
6023
- const dynamicAst = normalizeJsExpressionWithContext(dynamicClassExp, context, { hint: "class 绑定" });
6064
+ const dynamicAst = normalizeJsExpressionWithContext(dynamicClassExp, context, {
6065
+ hint: "class 绑定",
6066
+ runtimePropAccess: "helper"
6067
+ });
6024
6068
  if (dynamicAst) jsParts.push(dynamicAst);
6025
6069
  const expAst = mergeJsExpressionParts(jsParts);
6026
6070
  const binding = createClassStyleBinding(context, "class", generateExpressionCode(expAst), expAst, staticValue ?? "");
@@ -6049,11 +6093,17 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
6049
6093
  const jsParts = [];
6050
6094
  if (staticValue) jsParts.push(t.stringLiteral(staticValue));
6051
6095
  if (dynamicStyleExp) {
6052
- const dynamicAst = normalizeJsExpressionWithContext(dynamicStyleExp, context, { hint: "style 绑定" });
6096
+ const dynamicAst = normalizeJsExpressionWithContext(dynamicStyleExp, context, {
6097
+ hint: "style 绑定",
6098
+ runtimePropAccess: "helper"
6099
+ });
6053
6100
  if (dynamicAst) jsParts.push(dynamicAst);
6054
6101
  }
6055
6102
  if (vShowExp) {
6056
- const showAst = normalizeJsExpressionWithContext(vShowExp, context, { hint: "v-show" });
6103
+ const showAst = normalizeJsExpressionWithContext(vShowExp, context, {
6104
+ hint: "v-show",
6105
+ runtimePropAccess: "helper"
6106
+ });
6057
6107
  if (showAst) jsParts.push(t.conditionalExpression(showAst, t.stringLiteral(""), t.stringLiteral("display: none")));
6058
6108
  }
6059
6109
  const expAst = mergeJsExpressionParts(jsParts);
@@ -7468,6 +7518,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7468
7518
  warnings,
7469
7519
  platform: options?.platform ?? getMiniProgramTemplatePlatform(),
7470
7520
  propsAliases: options?.propsAliases,
7521
+ propsDerivedKeys: options?.propsDerivedKeys,
7471
7522
  htmlTagToWxmlMap,
7472
7523
  htmlTagToWxmlTagClass: options?.htmlTagToWxmlTagClass ?? true,
7473
7524
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
@@ -8333,6 +8384,68 @@ function resolveScriptSetupPropsAliases(bindings) {
8333
8384
  for (const [alias, propName] of Object.entries(aliases)) if (typeof propName === "string" && propName.length > 0) resolved[alias] = propName;
8334
8385
  return Object.keys(resolved).length ? resolved : void 0;
8335
8386
  }
8387
+ function resolveScriptSetupPropsDerivedKeys(bindings) {
8388
+ const keys = /* @__PURE__ */ new Set();
8389
+ for (const [key, bindingType] of Object.entries(bindings ?? {})) {
8390
+ if (key.startsWith("__") || bindingType !== "props" && bindingType !== "props-aliased") continue;
8391
+ keys.add(key);
8392
+ }
8393
+ return keys.size ? [...keys] : void 0;
8394
+ }
8395
+ function collectScriptSetupReturnInfo(scriptCode) {
8396
+ const keys = /* @__PURE__ */ new Set();
8397
+ const propsObjectAliases = new Set(["__props"]);
8398
+ const destructuredPropsKeys = /* @__PURE__ */ new Set();
8399
+ try {
8400
+ traverse(parseJsLike(scriptCode), {
8401
+ VariableDeclarator(path) {
8402
+ const init = path.node.init;
8403
+ if (t.isIdentifier(path.node.id) && t.isIdentifier(init) && propsObjectAliases.has(init.name)) {
8404
+ propsObjectAliases.add(path.node.id.name);
8405
+ return;
8406
+ }
8407
+ if (!t.isObjectPattern(path.node.id) || !t.isIdentifier(init) || !propsObjectAliases.has(init.name)) return;
8408
+ for (const property of path.node.id.properties) {
8409
+ if (!t.isObjectProperty(property)) continue;
8410
+ if (t.isIdentifier(property.value)) destructuredPropsKeys.add(property.value.name);
8411
+ else if (t.isAssignmentPattern(property.value) && t.isIdentifier(property.value.left)) destructuredPropsKeys.add(property.value.left.name);
8412
+ }
8413
+ },
8414
+ ObjectProperty(path) {
8415
+ const objectPath = path.parentPath;
8416
+ if (!objectPath.isObjectExpression() || !objectPath.parentPath.isVariableDeclarator() || !t.isIdentifier(objectPath.parentPath.node.id, { name: "__returned__" })) return;
8417
+ const prop = path.node;
8418
+ if (prop.computed) return;
8419
+ if (t.isIdentifier(prop.key)) keys.add(prop.key.name);
8420
+ else if (t.isStringLiteral(prop.key)) keys.add(prop.key.value);
8421
+ }
8422
+ });
8423
+ } catch {
8424
+ return {
8425
+ returnedKeys: keys,
8426
+ destructuredPropsKeys
8427
+ };
8428
+ }
8429
+ return {
8430
+ returnedKeys: keys,
8431
+ destructuredPropsKeys
8432
+ };
8433
+ }
8434
+ function resolveEffectivePropsDerivedKeys(bindings, scriptCode) {
8435
+ const directKeys = resolveScriptSetupPropsDerivedKeys(bindings) ?? [];
8436
+ const { returnedKeys, destructuredPropsKeys } = collectScriptSetupReturnInfo(scriptCode);
8437
+ const aliases = resolveScriptSetupPropsAliases(bindings) ?? {};
8438
+ const propsKeys = new Set(Object.entries(bindings ?? {}).filter(([key, bindingType]) => key && !key.startsWith("__") && bindingType === "props").map(([key]) => key));
8439
+ const keys = /* @__PURE__ */ new Set();
8440
+ for (const key of directKeys) keys.add(key);
8441
+ for (const key of destructuredPropsKeys) keys.add(key);
8442
+ for (const [alias, propName] of Object.entries(aliases)) {
8443
+ if (!returnedKeys.has(alias)) keys.add(alias);
8444
+ if (propsKeys.has(propName) && !returnedKeys.has(propName)) keys.add(propName);
8445
+ }
8446
+ for (const key of propsKeys) if (!returnedKeys.has(key)) keys.add(key);
8447
+ return keys.size ? [...keys] : void 0;
8448
+ }
8336
8449
  async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo, precompiledScript) {
8337
8450
  const autoUsingComponentsMap = { ...componentSourceInfo?.autoUsingComponentsMap ?? {} };
8338
8451
  const autoComponentMeta = { ...componentSourceInfo?.autoComponentMeta ?? {} };
@@ -8340,6 +8453,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8340
8453
  let scriptCode;
8341
8454
  let scriptMap = null;
8342
8455
  let propsAliases = options?.template?.propsAliases;
8456
+ let propsDerivedKeys;
8343
8457
  if (descriptor.script || descriptor.scriptSetup) {
8344
8458
  const scriptCompiled = precompiledScript ?? compileScript(descriptorForCompile, {
8345
8459
  id: filename,
@@ -8347,6 +8461,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8347
8461
  });
8348
8462
  propsAliases ??= resolveScriptSetupPropsAliases(scriptCompiled.bindings);
8349
8463
  scriptCode = scriptCompiled.content;
8464
+ propsDerivedKeys = resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCode);
8350
8465
  scriptMap = scriptCompiled.map && typeof scriptCompiled.map === "object" ? scriptCompiled.map : null;
8351
8466
  if (scriptCode.includes("defineAppJson") || scriptCode.includes("definePageJson") || scriptCode.includes("defineComponentJson")) scriptCode = stripJsonMacroCallsFromCode(scriptCode, filename);
8352
8467
  if (!isAppFile && !scriptCode.includes("export default")) scriptCode += "\nexport default {}";
@@ -8367,6 +8482,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8367
8482
  inlineExpressions: templateCompiled?.inlineExpressions,
8368
8483
  functionPropPaths: templateCompiled?.functionPropPaths,
8369
8484
  propsAliases,
8485
+ propsDerivedKeys,
8370
8486
  relaxStructuredTypeOnlyProps
8371
8487
  });
8372
8488
  return {
@@ -8456,13 +8572,16 @@ async function compileVueFile(source, filename, options) {
8456
8572
  isProd: false
8457
8573
  }) : void 0;
8458
8574
  const propsAliases = scriptCompiled ? resolveScriptSetupPropsAliases(scriptCompiled.bindings) : void 0;
8575
+ const propsDerivedKeys = scriptCompiled ? resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCompiled.content) : void 0;
8459
8576
  const baseTemplateOptions = parsed.isAppFile ? {
8460
8577
  ...options?.template,
8461
8578
  propsAliases,
8579
+ propsDerivedKeys,
8462
8580
  scopedSlotsRequireProps: true
8463
8581
  } : {
8464
8582
  ...options?.template,
8465
- propsAliases
8583
+ propsAliases,
8584
+ propsDerivedKeys
8466
8585
  };
8467
8586
  const templateOptions = componentSourceInfo.wevuComponentTags.size ? {
8468
8587
  ...baseTemplateOptions,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.20",
4
+ "version": "6.16.22",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -50,9 +50,9 @@
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
52
  "vue": "^3.5.34",
53
- "@weapp-core/constants": "0.1.8",
53
+ "@weapp-core/constants": "0.1.9",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.20",
55
+ "@weapp-vite/ast": "6.16.22",
56
56
  "rolldown-require": "2.0.17"
57
57
  },
58
58
  "publishConfig": {