@wevu/compiler 6.16.14 → 6.16.16

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
@@ -257,6 +257,7 @@ interface TemplateCompileResult {
257
257
  templateRefs?: TemplateRefBinding[];
258
258
  layoutHosts?: LayoutHostBinding[];
259
259
  inlineExpressions?: InlineExpressionAsset[];
260
+ functionPropPaths?: string[];
260
261
  }
261
262
  /**
262
263
  * v-for 解析结果。
@@ -283,6 +284,7 @@ interface TemplateCompileOptions {
283
284
  classStyleRuntime?: ClassStyleRuntime | 'auto';
284
285
  objectLiteralBindMode?: ObjectLiteralBindMode;
285
286
  mustacheInterpolation?: MustacheInterpolationMode;
287
+ formatWxml?: boolean;
286
288
  wxsExtension?: string;
287
289
  classStyleWxsSrc?: string;
288
290
  wevuComponentTags?: Iterable<string>;
@@ -689,6 +691,10 @@ interface TransformScriptOptions {
689
691
  * 内联表达式元数据(用于事件处理)
690
692
  */
691
693
  inlineExpressions?: InlineExpressionAsset[];
694
+ /**
695
+ * 模板中作为组件 prop 传递的函数候选路径。
696
+ */
697
+ functionPropPaths?: string[];
692
698
  /**
693
699
  * 对 `<script setup>` 类型声明生成的结构化 props(如 Array/Object)放宽小程序运行时类型约束,
694
700
  * 以避免小程序属性校验对复杂表达式/代理值产生误报。
@@ -859,4 +865,4 @@ interface CollectVueTemplateTagsOptions {
859
865
  */
860
866
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
861
867
  //#endregion
862
- 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 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, type WevuPageFeatureFlag, type 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 };
868
+ 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 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 };
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_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_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";
@@ -2812,6 +2812,13 @@ function hasStaticProperty(target, keyName) {
2812
2812
  }
2813
2813
  return false;
2814
2814
  }
2815
+ function injectFunctionPropPaths(componentOptionsObject, paths) {
2816
+ const uniquePaths = [...new Set(paths)].filter(Boolean);
2817
+ if (!uniquePaths.length) return false;
2818
+ if (hasStaticProperty(componentOptionsObject, WEVU_FUNCTION_PROP_PATHS_KEY)) return false;
2819
+ componentOptionsObject.properties.push(t.objectProperty(t.identifier(WEVU_FUNCTION_PROP_PATHS_KEY), t.arrayExpression(uniquePaths.map((path) => t.stringLiteral(path)))));
2820
+ return true;
2821
+ }
2815
2822
  function unwrapTypeLikeExpression(node) {
2816
2823
  if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression(node.expression);
2817
2824
  if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression(node.expression);
@@ -2935,6 +2942,9 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
2935
2942
  if (!injected) warn("无法自动注入内联表达式元数据:methods 不是对象字面量。");
2936
2943
  transformed = injected || transformed;
2937
2944
  } else warn("无法自动注入内联表达式元数据:组件选项不是对象字面量。");
2945
+ const functionPropPaths = options?.functionPropPaths ?? [];
2946
+ if (functionPropPaths.length) if (componentOptionsObject) transformed = injectFunctionPropPaths(componentOptionsObject, functionPropPaths) || transformed;
2947
+ else warn("无法自动注入函数 prop 元数据:组件选项不是对象字面量。");
2938
2948
  if (componentExpr) {
2939
2949
  if (options?.isApp) transformed = injectWevuDefaultsForApp({
2940
2950
  astProgram: ast.program,
@@ -3277,6 +3287,114 @@ function stripRenderOptionFromScript(source, filename, warn) {
3277
3287
  return generate(ast).code;
3278
3288
  }
3279
3289
  //#endregion
3290
+ //#region src/plugins/vue/compiler/template/format.ts
3291
+ const TOKEN_RE = /<[^>]+>/g;
3292
+ function tokenizeWxml(source) {
3293
+ const tokens = [];
3294
+ let index = 0;
3295
+ for (const match of source.matchAll(TOKEN_RE)) {
3296
+ const start = match.index ?? 0;
3297
+ if (start > index) tokens.push({
3298
+ type: "text",
3299
+ value: source.slice(index, start)
3300
+ });
3301
+ tokens.push({
3302
+ type: "tag",
3303
+ value: match[0]
3304
+ });
3305
+ index = start + match[0].length;
3306
+ }
3307
+ if (index < source.length) tokens.push({
3308
+ type: "text",
3309
+ value: source.slice(index)
3310
+ });
3311
+ return tokens.filter((token) => token.value.length > 0);
3312
+ }
3313
+ function isClosingTag(value) {
3314
+ return /^<\//.test(value);
3315
+ }
3316
+ function isSelfClosingTag(value) {
3317
+ return /\/>$/.test(value) || /^<(?:import|include|wxs|sjs)\b/i.test(value);
3318
+ }
3319
+ function isOpeningTag(value) {
3320
+ return /^<[^/!][\s\S]*>$/.test(value) && !isSelfClosingTag(value);
3321
+ }
3322
+ function isWhitespaceText(token) {
3323
+ return token.type === "text" && token.value.trim().length === 0;
3324
+ }
3325
+ function shouldKeepInline(tokens, openIndex, closeIndex) {
3326
+ const inner = tokens.slice(openIndex + 1, closeIndex);
3327
+ return inner.some((token) => token.type === "text" && token.value.trim().length > 0) && inner.every((token) => token.type !== "tag" || isSelfClosingTag(token.value));
3328
+ }
3329
+ function findMatchingClosingTag(tokens, openIndex) {
3330
+ const openTag = tokens[openIndex]?.value;
3331
+ const match = /^<([^\s>/]+)/.exec(openTag ?? "");
3332
+ if (!match) return -1;
3333
+ const tagName = match[1];
3334
+ let depth = 0;
3335
+ for (let index = openIndex; index < tokens.length; index++) {
3336
+ const token = tokens[index];
3337
+ if (token?.type !== "tag") continue;
3338
+ if (new RegExp(`^<${tagName}(?:\\s|>|/)`).test(token.value) && !isSelfClosingTag(token.value)) {
3339
+ depth += 1;
3340
+ continue;
3341
+ }
3342
+ if (new RegExp(`^</${tagName}>`).test(token.value)) {
3343
+ depth -= 1;
3344
+ if (depth === 0) return index;
3345
+ }
3346
+ }
3347
+ return -1;
3348
+ }
3349
+ function appendLine(lines, level, value, indent) {
3350
+ lines.push(`${indent.repeat(Math.max(level, 0))}${value}`);
3351
+ }
3352
+ /**
3353
+ * 轻量格式化 WXML,只调整标签层级缩进,不重排文本内容。
3354
+ */
3355
+ function formatWxml(source, options = {}) {
3356
+ const tokens = tokenizeWxml(source).filter((token) => !isWhitespaceText(token));
3357
+ const indent = options.indent ?? " ";
3358
+ const lines = [];
3359
+ let level = 0;
3360
+ let index = 0;
3361
+ while (index < tokens.length) {
3362
+ const token = tokens[index];
3363
+ if (!token) {
3364
+ index += 1;
3365
+ continue;
3366
+ }
3367
+ if (token.type === "text") {
3368
+ const value = token.value.trim();
3369
+ if (value) appendLine(lines, level, value, indent);
3370
+ index += 1;
3371
+ continue;
3372
+ }
3373
+ if (isClosingTag(token.value)) {
3374
+ level -= 1;
3375
+ appendLine(lines, level, token.value, indent);
3376
+ index += 1;
3377
+ continue;
3378
+ }
3379
+ if (isOpeningTag(token.value)) {
3380
+ const closeIndex = findMatchingClosingTag(tokens, index);
3381
+ if (closeIndex > index && shouldKeepInline(tokens, index, closeIndex)) {
3382
+ const inline = tokens.slice(index, closeIndex + 1).map((item) => item.value).join("");
3383
+ appendLine(lines, level, inline, indent);
3384
+ index = closeIndex + 1;
3385
+ continue;
3386
+ }
3387
+ appendLine(lines, level, token.value, indent);
3388
+ level += 1;
3389
+ index += 1;
3390
+ continue;
3391
+ }
3392
+ appendLine(lines, level, token.value, indent);
3393
+ index += 1;
3394
+ }
3395
+ return `${lines.join("\n")}\n`;
3396
+ }
3397
+ //#endregion
3280
3398
  //#region src/plugins/vue/compiler/template/platform.ts
3281
3399
  /**
3282
3400
  * 创建结构指令属性名。
@@ -3898,6 +4016,7 @@ function createJsxCompileContext(options) {
3898
4016
  return {
3899
4017
  platform: options?.template?.platform ?? getMiniProgramTemplatePlatform(),
3900
4018
  mustacheInterpolation: options?.template?.mustacheInterpolation ?? "compact",
4019
+ formatWxml: options?.template?.formatWxml ?? false,
3901
4020
  warnings: [],
3902
4021
  inlineExpressions: [],
3903
4022
  inlineExpressionSeed: 0,
@@ -3912,8 +4031,10 @@ function compileJsxTemplateAndCollectComponents(source, filename, options) {
3912
4031
  const context = createJsxCompileContext(options);
3913
4032
  const { renderExpression, autoComponentContext } = analyzeJsxAst(ast, context);
3914
4033
  let template;
3915
- if (renderExpression) template = compileRenderableExpression(renderExpression, context);
3916
- else context.warnings = context.warnings.map((message) => message === "未识别到默认导出组件。" ? `未在 ${filename} 中识别到默认导出组件。` : message);
4034
+ if (renderExpression) {
4035
+ template = compileRenderableExpression(renderExpression, context);
4036
+ if (context.formatWxml) template = formatWxml(template);
4037
+ } else context.warnings = context.warnings.map((message) => message === "未识别到默认导出组件。" ? `未在 ${filename} 中识别到默认导出组件。` : message);
3917
4038
  return {
3918
4039
  template,
3919
4040
  warnings: context.warnings,
@@ -5851,12 +5972,60 @@ const SIMPLE_IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
5851
5972
  const SIMPLE_MEMBER_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
5852
5973
  const isSimpleIdentifier = (value) => SIMPLE_IDENTIFIER_RE$1.test(value);
5853
5974
  const isSimpleMemberPath = (value) => SIMPLE_MEMBER_PATH_RE.test(value);
5854
- function transformBindDirective(node, context, forInfo) {
5975
+ const COMPONENT_NON_PROP_BINDINGS = new Set([
5976
+ "class",
5977
+ "style",
5978
+ "id",
5979
+ "key",
5980
+ "ref",
5981
+ "is",
5982
+ "slot",
5983
+ "layout-host"
5984
+ ]);
5985
+ function collectFunctionPropPath(rawExpValue) {
5986
+ const parsed = parseBabelExpression(rawExpValue);
5987
+ if (!parsed) return null;
5988
+ const normalized = unwrapTsExpression(parsed);
5989
+ if (normalized.type === "Identifier") return normalized.name;
5990
+ if (normalized.type !== "MemberExpression" || normalized.computed) return null;
5991
+ const parts = [];
5992
+ let current = normalized;
5993
+ while (current.type === "MemberExpression" && !current.computed) {
5994
+ if (current.property.type !== "Identifier") return null;
5995
+ parts.unshift(current.property.name);
5996
+ current = unwrapTsExpression(current.object);
5997
+ }
5998
+ if (current.type !== "Identifier") return null;
5999
+ parts.unshift(current.name);
6000
+ return parts.join(".");
6001
+ }
6002
+ function isComputedMemberExpression(rawExpValue) {
6003
+ const parsed = parseBabelExpression(rawExpValue);
6004
+ if (!parsed) return false;
6005
+ const normalized = unwrapTsExpression(parsed);
6006
+ return normalized.type === "MemberExpression" && normalized.computed;
6007
+ }
6008
+ function transformBindDirective(node, context, forInfo, options) {
5855
6009
  const { arg } = node;
5856
6010
  if (!arg) return null;
5857
6011
  const argValue = arg.type === NodeTypes.SIMPLE_EXPRESSION ? arg.content : "";
5858
6012
  const rawExpValue = getBindDirectiveExpression(node);
5859
6013
  if (!rawExpValue) return null;
6014
+ if (options?.isComponent && !COMPONENT_NON_PROP_BINDINGS.has(argValue)) {
6015
+ const path = collectFunctionPropPath(rawExpValue);
6016
+ if (path) if (path.includes(".")) {
6017
+ const bindingRef = registerRuntimeBindingExpression(rawExpValue, context, { hint: `:${argValue} 函数 prop 绑定` });
6018
+ if (bindingRef) {
6019
+ const bindingName = bindingRef.split("[")[0] || bindingRef;
6020
+ context.functionPropPaths.add(bindingName);
6021
+ return `${argValue}="${renderMustache(bindingRef, context)}"`;
6022
+ }
6023
+ } else context.functionPropPaths.add(path);
6024
+ else if (isComputedMemberExpression(rawExpValue)) {
6025
+ const runtimeAttr = createBindRuntimeAttr(argValue, rawExpValue, context);
6026
+ if (runtimeAttr) return runtimeAttr;
6027
+ }
6028
+ }
5860
6029
  if (argValue === "key") {
5861
6030
  const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
5862
6031
  const trimmed = expValue.trim();
@@ -6118,7 +6287,7 @@ function transformShowDirective(node, context) {
6118
6287
  //#region src/plugins/vue/compiler/template/directives/index.ts
6119
6288
  function transformDirective(node, context, elementNode, forInfo, options) {
6120
6289
  const { name, exp, arg } = node;
6121
- if (name === "bind") return transformBindDirective(node, context, forInfo);
6290
+ if (name === "bind") return transformBindDirective(node, context, forInfo, options);
6122
6291
  if (name === "on") return transformOnDirective(node, context, options);
6123
6292
  if (name === "model") return transformModelDirective(node, context, elementNode, options);
6124
6293
  if (name === "show") return transformShowDirective(node, context);
@@ -6453,7 +6622,8 @@ function createScopedSlotComponent(context, slotKey, props, children, transformN
6453
6622
  forStack: [],
6454
6623
  forIndexSeed: 0,
6455
6624
  inlineExpressions: [],
6456
- inlineExpressionSeed: 0
6625
+ inlineExpressionSeed: 0,
6626
+ functionPropPaths: /* @__PURE__ */ new Set()
6457
6627
  };
6458
6628
  let template = withSlotProps(scopedContext, {
6459
6629
  ...collectScopePropMapping(context),
@@ -7163,6 +7333,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7163
7333
  classStyleRuntime: resolvedRuntime === "wxs" ? "wxs" : "js",
7164
7334
  objectLiteralBindMode: options?.objectLiteralBindMode ?? "runtime",
7165
7335
  mustacheInterpolation: options?.mustacheInterpolation ?? "compact",
7336
+ formatWxml: options?.formatWxml ?? false,
7166
7337
  classStyleBindings: [],
7167
7338
  classStyleWxs: false,
7168
7339
  classStyleWxsExtension: wxsExtension,
@@ -7175,10 +7346,12 @@ function compileVueTemplateToWxml(template, filename, options) {
7175
7346
  layoutHostIndexSeed: 0,
7176
7347
  inlineExpressions: [],
7177
7348
  inlineExpressionSeed: 0,
7349
+ functionPropPaths: /* @__PURE__ */ new Set(),
7178
7350
  wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0
7179
7351
  };
7180
7352
  let wxml = ast.children.map((child) => transformNode(child, context)).join("");
7181
7353
  if (context.classStyleWxs) wxml = `${buildClassStyleWxsTag(context.classStyleWxsExtension || "wxs", context.classStyleWxsSrc)}\n${wxml}`;
7354
+ if (context.formatWxml) wxml = formatWxml(wxml);
7182
7355
  const result = {
7183
7356
  code: wxml,
7184
7357
  warnings
@@ -7193,6 +7366,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7193
7366
  if (context.templateRefs.length) result.templateRefs = context.templateRefs;
7194
7367
  if (context.layoutHosts.length) result.layoutHosts = context.layoutHosts;
7195
7368
  if (context.inlineExpressions.length) result.inlineExpressions = context.inlineExpressions;
7369
+ if (context.functionPropPaths.size) result.functionPropPaths = [...context.functionPropPaths];
7196
7370
  return result;
7197
7371
  } catch (error) {
7198
7372
  warnings.push(`模板编译失败:${error}`);
@@ -8031,6 +8205,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8031
8205
  templateRefs: templateCompiled?.templateRefs,
8032
8206
  layoutHosts: templateCompiled?.layoutHosts,
8033
8207
  inlineExpressions: templateCompiled?.inlineExpressions,
8208
+ functionPropPaths: templateCompiled?.functionPropPaths,
8034
8209
  relaxStructuredTypeOnlyProps
8035
8210
  });
8036
8211
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.14",
4
+ "version": "6.16.16",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -45,15 +45,15 @@
45
45
  "@vue/compiler-core": "^3.5.34",
46
46
  "@vue/compiler-dom": "^3.5.34",
47
47
  "comment-json": "^5.0.0",
48
- "lru-cache": "^11.3.6",
48
+ "lru-cache": "^11.4.0",
49
49
  "magic-string": "^0.30.21",
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
52
  "vue": "^3.5.34",
53
53
  "@weapp-core/constants": "^0.1.7",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.14",
56
- "rolldown-require": "2.0.15"
55
+ "@weapp-vite/ast": "6.16.16",
56
+ "rolldown-require": "2.0.16"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public",