@wevu/compiler 6.16.19 → 6.16.20

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
@@ -276,6 +276,10 @@ interface ForParseResult {
276
276
  */
277
277
  interface TemplateCompileOptions {
278
278
  platform?: MiniProgramPlatform;
279
+ /**
280
+ * Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
281
+ */
282
+ propsAliases?: Record<string, string>;
279
283
  htmlTagToWxml?: boolean | Record<string, string>;
280
284
  htmlTagToWxmlTagClass?: boolean;
281
285
  scopedSlotsCompiler?: ScopedSlotsCompilerMode;
@@ -705,6 +709,10 @@ interface TransformScriptOptions {
705
709
  * 模板中作为组件 prop 传递的函数候选路径。
706
710
  */
707
711
  functionPropPaths?: string[];
712
+ /**
713
+ * Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
714
+ */
715
+ propsAliases?: Record<string, string>;
708
716
  /**
709
717
  * 对 `<script setup>` 类型声明生成的结构化 props(如 Array/Object)放宽小程序运行时类型约束,
710
718
  * 以避免小程序属性校验对复杂表达式/代理值产生误报。
package/dist/index.mjs CHANGED
@@ -2241,6 +2241,38 @@ function buildConsoleErrorGuard(message, errorId) {
2241
2241
  function buildRuntimeExpressionErrorGuard(binding, errorId) {
2242
2242
  return buildConsoleErrorGuard(`[wevu] 模板运行时表达式执行失败: ${binding.name} = ${binding.exp}`, errorId);
2243
2243
  }
2244
+ function createDataPropsFallbackExpression(fallback) {
2245
+ const propsObject = t.memberExpression(t.thisExpression(), t.identifier(WEVU_PROPS_KEY));
2246
+ const propsAccess = t.memberExpression(propsObject, t.identifier("data"));
2247
+ const hasPropsObject = t.binaryExpression("!=", propsObject, t.nullLiteral());
2248
+ const hasPropsValue = t.logicalExpression("&&", hasPropsObject, t.logicalExpression("||", t.binaryExpression("!==", propsAccess, t.identifier("undefined")), t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Object"), t.identifier("prototype")), t.identifier("hasOwnProperty")), t.identifier("call")), [propsObject, t.stringLiteral("data")])));
2249
+ return t.conditionalExpression(hasPropsValue, propsAccess, fallback);
2250
+ }
2251
+ function createDataRuntimeAccess(helpers) {
2252
+ const unrefHelper = helpers.unref ? t.cloneNode(helpers.unref) : t.identifier("unref");
2253
+ return t.callExpression(unrefHelper, [createDataPropsFallbackExpression(t.memberExpression(t.thisExpression(), t.identifier("data")))]);
2254
+ }
2255
+ function rewriteDataAccessExpression(exp, helpers) {
2256
+ if (t.isIdentifier(exp) && exp.name === "data") return createDataRuntimeAccess(helpers);
2257
+ if (t.isMemberExpression(exp)) return t.memberExpression(rewriteDataAccessExpression(exp.object, helpers), t.cloneNode(exp.property), exp.computed);
2258
+ if (t.isObjectExpression(exp)) return t.objectExpression(exp.properties.map((property) => {
2259
+ if (!t.isObjectProperty(property) || !t.isExpression(property.value)) return t.cloneNode(property, true);
2260
+ return t.objectProperty(t.cloneNode(property.key), rewriteDataAccessExpression(property.value, helpers), property.computed, property.shorthand);
2261
+ }));
2262
+ if (t.isArrayExpression(exp)) return t.arrayExpression(exp.elements.map((element) => {
2263
+ if (!element || t.isSpreadElement(element)) return element ? t.cloneNode(element, true) : null;
2264
+ return rewriteDataAccessExpression(element, helpers);
2265
+ }));
2266
+ if (t.isBinaryExpression(exp)) return t.isPrivateName(exp.left) || t.isPrivateName(exp.right) ? t.cloneNode(exp, true) : t.binaryExpression(exp.operator, rewriteDataAccessExpression(exp.left, helpers), rewriteDataAccessExpression(exp.right, helpers));
2267
+ if (t.isLogicalExpression(exp)) return t.logicalExpression(exp.operator, rewriteDataAccessExpression(exp.left, helpers), rewriteDataAccessExpression(exp.right, helpers));
2268
+ if (t.isConditionalExpression(exp)) return t.conditionalExpression(rewriteDataAccessExpression(exp.test, helpers), rewriteDataAccessExpression(exp.consequent, helpers), rewriteDataAccessExpression(exp.alternate, helpers));
2269
+ if (t.isUnaryExpression(exp)) return t.unaryExpression(exp.operator, rewriteDataAccessExpression(exp.argument, helpers), exp.prefix);
2270
+ if (t.isCallExpression(exp)) return t.callExpression(rewriteDataAccessExpression(exp.callee, helpers), exp.arguments.map((arg) => {
2271
+ if (t.isSpreadElement(arg)) return t.cloneNode(arg, true);
2272
+ return rewriteDataAccessExpression(arg, helpers);
2273
+ }));
2274
+ return t.cloneNode(exp, true);
2275
+ }
2244
2276
  function buildNormalizedExpression(binding, helpers) {
2245
2277
  const errorId = t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER);
2246
2278
  if (binding.type === "bind") {
@@ -2249,7 +2281,7 @@ function buildNormalizedExpression(binding, helpers) {
2249
2281
  }
2250
2282
  const normalizeHelper = binding.type === "class" ? helpers.normalizeClass : helpers.normalizeStyle;
2251
2283
  const errorFallback = binding.errorFallback ?? "";
2252
- const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.stringLiteral("");
2284
+ const exp = binding.expAst ? rewriteDataAccessExpression(binding.expAst, helpers) : t.stringLiteral("");
2253
2285
  const normalizedCall = t.callExpression(t.cloneNode(normalizeHelper), [exp]);
2254
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)])), []);
2255
2287
  }
@@ -2318,11 +2350,37 @@ function buildComputedFunctionBody(binding, helpers) {
2318
2350
  }
2319
2351
  //#endregion
2320
2352
  //#region src/plugins/vue/transform/classStyleComputed.ts
2321
- function buildClassStyleComputedEntries(bindings, helpers) {
2353
+ function createMemberAccess$2(target, prop) {
2354
+ if (t.isValidIdentifier(prop)) return t.memberExpression(target, t.identifier(prop));
2355
+ return t.memberExpression(target, t.stringLiteral(prop), true);
2356
+ }
2357
+ function applyPropsAliasesToExpression(expression, propsAliases) {
2358
+ if (!propsAliases || !Object.keys(propsAliases).length) return expression;
2359
+ const ast = t.file(t.program([t.expressionStatement(expression)]));
2360
+ traverse(ast, { Identifier(path) {
2361
+ if (!path.isReferencedIdentifier()) return;
2362
+ const propName = propsAliases[path.node.name];
2363
+ if (!propName || path.scope.hasBinding(path.node.name)) return;
2364
+ const replacement = createMemberAccess$2(t.identifier("props"), propName);
2365
+ const parent = path.parentPath;
2366
+ if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
2367
+ parent.node.shorthand = false;
2368
+ parent.node.value = replacement;
2369
+ return;
2370
+ }
2371
+ path.replaceWith(replacement);
2372
+ } });
2373
+ const statement = ast.program.body[0];
2374
+ return t.isExpressionStatement(statement) ? statement.expression : expression;
2375
+ }
2376
+ function buildClassStyleComputedEntries(bindings, helpers, propsAliases) {
2322
2377
  const entries = [];
2323
2378
  for (const binding of bindings) {
2324
2379
  const key = createStaticObjectKey(binding.name);
2325
- const body = buildComputedFunctionBody(binding, helpers);
2380
+ const body = buildComputedFunctionBody({
2381
+ ...binding,
2382
+ expAst: binding.expAst ? applyPropsAliasesToExpression(t.cloneNode(binding.expAst, true), propsAliases) : binding.expAst
2383
+ }, helpers);
2326
2384
  const fn = t.functionExpression(null, [], body);
2327
2385
  entries.push(t.objectProperty(key, fn));
2328
2386
  }
@@ -2347,14 +2405,14 @@ function buildClassStyleComputedCode(bindings, helpers) {
2347
2405
  }
2348
2406
  //#endregion
2349
2407
  //#region src/plugins/vue/transform/transformScript/rewrite/classStyle.ts
2350
- function injectClassStyleComputed(optionsObject, bindings, warn) {
2408
+ function injectClassStyleComputed(optionsObject, bindings, propsAliases, warn) {
2351
2409
  if (!bindings.length) return false;
2352
2410
  const warnHandler = resolveWarnHandler(warn);
2353
2411
  const entries = buildClassStyleComputedEntries(bindings, {
2354
2412
  normalizeClass: t.identifier("__wevuNormalizeClass"),
2355
2413
  normalizeStyle: t.identifier("__wevuNormalizeStyle"),
2356
2414
  unref: t.identifier("__wevuUnref")
2357
- });
2415
+ }, propsAliases);
2358
2416
  if (!entries.length) return false;
2359
2417
  const computedProp = getObjectPropertyByKey$1(optionsObject, "computed");
2360
2418
  if (!computedProp) {
@@ -2939,7 +2997,7 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
2939
2997
  const classStyleBindings = options?.classStyleBindings ?? [];
2940
2998
  if (classStyleBindings.length) if (componentOptionsObject) {
2941
2999
  ensureClassStyleRuntimeImports(ast.program);
2942
- transformed = injectClassStyleComputed(componentOptionsObject, classStyleBindings, warn) || transformed;
3000
+ transformed = injectClassStyleComputed(componentOptionsObject, classStyleBindings, options?.propsAliases, warn) || transformed;
2943
3001
  } else warn("无法自动注入 class/style 计算属性:组件选项不是对象字面量。");
2944
3002
  const templateRefs = options?.templateRefs ?? [];
2945
3003
  if (templateRefs.length) if (componentOptionsObject) transformed = injectTemplateRefs(componentOptionsObject, templateRefs, warn) || transformed;
@@ -5355,7 +5413,8 @@ function rewriteScopedSlotExpression(exp, context) {
5355
5413
  function rewriteForAliasExpression(exp, context) {
5356
5414
  const normalized = normalizeWxmlExpression(exp);
5357
5415
  const forAliases = collectForAliasMapping$2(context);
5358
- if (!Object.keys(forAliases).length) return normalized;
5416
+ const propsAliases = context.propsAliases ?? {};
5417
+ if (!Object.keys(forAliases).length && !Object.keys(propsAliases).length) return normalized;
5359
5418
  const parsed = parseBabelExpressionFile(normalized);
5360
5419
  if (!parsed) return normalized;
5361
5420
  const { ast } = parsed;
@@ -5363,10 +5422,13 @@ function rewriteForAliasExpression(exp, context) {
5363
5422
  if (!path.isReferencedIdentifier()) return;
5364
5423
  const name = path.node.name;
5365
5424
  if (path.scope.hasBinding(name)) return;
5366
- if (!hasOwn(forAliases, name)) return;
5367
- const aliasExp = parseBabelExpression(forAliases[name]);
5368
- if (!aliasExp) return;
5369
- replaceIdentifierWithExpression(path, t.cloneNode(aliasExp, true));
5425
+ if (hasOwn(forAliases, name)) {
5426
+ const aliasExp = parseBabelExpression(forAliases[name]);
5427
+ if (aliasExp) replaceIdentifierWithExpression(path, t.cloneNode(aliasExp, true));
5428
+ return;
5429
+ }
5430
+ const propName = propsAliases[name];
5431
+ if (propName && t.isValidIdentifier(propName)) replaceIdentifierWithExpression(path, t.identifier(propName));
5370
5432
  } });
5371
5433
  const stmt = ast.program.body[0];
5372
5434
  const updatedExpression = stmt && "expression" in stmt ? stmt.expression : null;
@@ -5714,11 +5776,19 @@ function createUnrefCall(exp) {
5714
5776
  function createHasOwnPropertyCall(target, key) {
5715
5777
  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)]);
5716
5778
  }
5779
+ function createPropsKeyAccessFallback(name, fallback) {
5780
+ const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5781
+ const propsAccess = createMemberAccess(propsObject, name);
5782
+ const hasPropsObject = t.binaryExpression("!=", propsObject, t.nullLiteral());
5783
+ const hasPropsValue = t.logicalExpression("&&", hasPropsObject, t.logicalExpression("||", t.binaryExpression("!==", propsAccess, t.identifier("undefined")), createHasOwnPropertyCall(propsObject, name)));
5784
+ return t.conditionalExpression(hasPropsValue, propsAccess, fallback);
5785
+ }
5717
5786
  function createIdentifierAccessWithPropsFallback(name) {
5718
5787
  if (name === "props") {
5719
5788
  const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5720
5789
  return t.conditionalExpression(t.binaryExpression("!=", propsObject, t.nullLiteral()), propsObject, createThisMemberAccess("props"));
5721
5790
  }
5791
+ if (name === "data") return createPropsKeyAccessFallback(name, createThisMemberAccess(name));
5722
5792
  const thisAccess = createThisMemberAccess(name);
5723
5793
  const propsAccess = createMemberAccess(createThisMemberAccess(WEVU_PROPS_KEY), name);
5724
5794
  const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
@@ -5734,6 +5804,17 @@ function createIdentifierAccessWithPropsFallback(name) {
5734
5804
  const shouldUsePropsAccess = t.logicalExpression("&&", hasUsablePropsValue, t.unaryExpression("!", hasThisMember));
5735
5805
  return t.conditionalExpression(shouldUseStateAccess, thisAccess, t.conditionalExpression(shouldUsePropsAccess, propsAccess, thisAccess));
5736
5806
  }
5807
+ 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);
5817
+ }
5737
5818
  function collectForAliasMapping(context) {
5738
5819
  const mapping = {};
5739
5820
  for (const forInfo of context.forStack) {
@@ -5782,7 +5863,10 @@ function normalizeJsExpressionWithContext(exp, context, options) {
5782
5863
  replacement = createUnrefCall(prop ? createMemberAccess(base, prop) : base);
5783
5864
  } else if (name === WEVU_SLOT_OWNER_KEY || name === WEVU_SLOT_PROPS_DATA_KEY || name === WEVU_SLOT_PROPS_KEY || name === WEVU_SLOT_SCOPE_KEY) replacement = createUnrefCall(createThisMemberAccess(name));
5784
5865
  else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_PROXY_KEY), name));
5785
- else replacement = createUnrefCall(createIdentifierAccessWithPropsFallback(name));
5866
+ else {
5867
+ const propsAlias = context.propsAliases?.[name];
5868
+ replacement = createUnrefCall(propsAlias ? createAliasedPropsAccess(name, propsAlias) : createIdentifierAccessWithPropsFallback(name));
5869
+ }
5786
5870
  const parent = path.parentPath;
5787
5871
  if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
5788
5872
  parent.node.shorthand = false;
@@ -6644,6 +6728,7 @@ function buildSlotDeclaration(name, propsExp, children, context, options) {
6644
6728
  props: propsExp ? parseSlotPropsExpression(propsExp, context) : {},
6645
6729
  children,
6646
6730
  implicitDefault: options?.implicitDefault,
6731
+ conditionKind: options?.conditionKind,
6647
6732
  condition: options?.condition
6648
6733
  };
6649
6734
  }
@@ -6737,6 +6822,9 @@ function isRenderableFallbackChild(child) {
6737
6822
  function renderSlotFallback(decl, context, transformNode) {
6738
6823
  const slotAttr = renderSlotNameAttribute(decl.name, context, "slot");
6739
6824
  const wrapCondition = (content) => {
6825
+ if (decl.conditionKind === "else") return context.platform.wrapElse(content);
6826
+ if (decl.conditionKind === "else-if" && decl.condition) return context.platform.wrapElseIf(decl.condition, content, (exp) => renderMustache(exp, context));
6827
+ if (decl.conditionKind === "if" && decl.condition) return context.platform.wrapIf(decl.condition, content, (exp) => renderMustache(exp, context));
6740
6828
  return decl.condition ? context.platform.wrapIf(decl.condition, content, (exp) => renderMustache(exp, context)) : content;
6741
6829
  };
6742
6830
  if (!slotAttr) {
@@ -6844,9 +6932,14 @@ function shouldAugmentPlainSlot(decl, context, ownerNode) {
6844
6932
  return hasDirectComponentSlotChild(decl.children, context);
6845
6933
  }
6846
6934
  function resolveTemplateSlotCondition(node, context) {
6847
- const ifDirective = node.props.find((prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "if" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION);
6848
- const rawExp = ifDirective?.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? ifDirective.exp.content : "";
6849
- return rawExp ? normalizeWxmlExpressionWithContext(rawExp, context) : void 0;
6935
+ const directive = node.props.find((prop) => prop.type === NodeTypes.DIRECTIVE && (prop.name === "if" || prop.name === "else-if" || prop.name === "else") && (prop.name === "else" || prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION));
6936
+ if (!directive) return {};
6937
+ if (directive.name === "else") return { conditionKind: "else" };
6938
+ const rawExp = directive.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? directive.exp.content : "";
6939
+ return {
6940
+ conditionKind: directive.name === "else-if" ? "else-if" : "if",
6941
+ condition: rawExp ? normalizeWxmlExpressionWithContext(rawExp, context) : void 0
6942
+ };
6850
6943
  }
6851
6944
  function pushSlotNamesAttr(attrs, slotNames, context) {
6852
6945
  if (!slotNames.length) return;
@@ -6905,7 +6998,9 @@ function transformComponentWithSlots(node, context, transformNode, options) {
6905
6998
  if (child.type === NodeTypes.ELEMENT && child.tag === "template") {
6906
6999
  const templateSlot = findSlotDirective(child);
6907
7000
  if (templateSlot) {
6908
- const declaration = buildSlotDeclaration(resolveSlotNameFromDirective(templateSlot), templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) });
7001
+ const slotName = resolveSlotNameFromDirective(templateSlot);
7002
+ const templateSlotCondition = resolveTemplateSlotCondition(child, context);
7003
+ const declaration = buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, templateSlotCondition);
6909
7004
  slotDeclarations.push(declaration);
6910
7005
  renderItems.push({
6911
7006
  type: "declaration",
@@ -7000,7 +7095,9 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
7000
7095
  if (child.type === NodeTypes.ELEMENT && child.tag === "template") {
7001
7096
  const templateSlot = findSlotDirective(child);
7002
7097
  if (templateSlot) {
7003
- const declaration = buildSlotDeclaration(resolveSlotNameFromDirective(templateSlot), templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) });
7098
+ const slotName = resolveSlotNameFromDirective(templateSlot);
7099
+ const templateSlotCondition = resolveTemplateSlotCondition(child, context);
7100
+ const declaration = buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, templateSlotCondition);
7004
7101
  slotDeclarations.push(declaration);
7005
7102
  renderItems.push({
7006
7103
  type: "declaration",
@@ -7370,6 +7467,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7370
7467
  filename,
7371
7468
  warnings,
7372
7469
  platform: options?.platform ?? getMiniProgramTemplatePlatform(),
7470
+ propsAliases: options?.propsAliases,
7373
7471
  htmlTagToWxmlMap,
7374
7472
  htmlTagToWxmlTagClass: options?.htmlTagToWxmlTagClass ?? true,
7375
7473
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
@@ -8228,17 +8326,26 @@ function composeSourceMaps(transformedMap, originalMap) {
8228
8326
  //#endregion
8229
8327
  //#region src/plugins/vue/transform/compileVueFile/script.ts
8230
8328
  const TYPE_ONLY_DEFINE_PROPS_RE = /\bdefineProps\s*</;
8231
- async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo) {
8329
+ function resolveScriptSetupPropsAliases(bindings) {
8330
+ const aliases = bindings?.__propsAliases;
8331
+ if (!aliases || typeof aliases !== "object") return;
8332
+ const resolved = {};
8333
+ for (const [alias, propName] of Object.entries(aliases)) if (typeof propName === "string" && propName.length > 0) resolved[alias] = propName;
8334
+ return Object.keys(resolved).length ? resolved : void 0;
8335
+ }
8336
+ async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo, precompiledScript) {
8232
8337
  const autoUsingComponentsMap = { ...componentSourceInfo?.autoUsingComponentsMap ?? {} };
8233
8338
  const autoComponentMeta = { ...componentSourceInfo?.autoComponentMeta ?? {} };
8234
8339
  const relaxStructuredTypeOnlyProps = Boolean(descriptor.scriptSetup?.content && TYPE_ONLY_DEFINE_PROPS_RE.test(descriptor.scriptSetup.content));
8235
8340
  let scriptCode;
8236
8341
  let scriptMap = null;
8342
+ let propsAliases = options?.template?.propsAliases;
8237
8343
  if (descriptor.script || descriptor.scriptSetup) {
8238
- const scriptCompiled = compileScript(descriptorForCompile, {
8344
+ const scriptCompiled = precompiledScript ?? compileScript(descriptorForCompile, {
8239
8345
  id: filename,
8240
8346
  isProd: false
8241
8347
  });
8348
+ propsAliases ??= resolveScriptSetupPropsAliases(scriptCompiled.bindings);
8242
8349
  scriptCode = scriptCompiled.content;
8243
8350
  scriptMap = scriptCompiled.map && typeof scriptCompiled.map === "object" ? scriptCompiled.map : null;
8244
8351
  if (scriptCode.includes("defineAppJson") || scriptCode.includes("definePageJson") || scriptCode.includes("defineComponentJson")) scriptCode = stripJsonMacroCallsFromCode(scriptCode, filename);
@@ -8259,6 +8366,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8259
8366
  layoutHosts: templateCompiled?.layoutHosts,
8260
8367
  inlineExpressions: templateCompiled?.inlineExpressions,
8261
8368
  functionPropPaths: templateCompiled?.functionPropPaths,
8369
+ propsAliases,
8262
8370
  relaxStructuredTypeOnlyProps
8263
8371
  });
8264
8372
  return {
@@ -8343,10 +8451,19 @@ async function compileVueFile(source, filename, options) {
8343
8451
  autoUsingComponents,
8344
8452
  autoImportTags
8345
8453
  });
8454
+ const scriptCompiled = parsed.descriptor.script || parsed.descriptor.scriptSetup ? compileScript(parsed.descriptorForCompile, {
8455
+ id: filename,
8456
+ isProd: false
8457
+ }) : void 0;
8458
+ const propsAliases = scriptCompiled ? resolveScriptSetupPropsAliases(scriptCompiled.bindings) : void 0;
8346
8459
  const baseTemplateOptions = parsed.isAppFile ? {
8347
8460
  ...options?.template,
8461
+ propsAliases,
8348
8462
  scopedSlotsRequireProps: true
8349
- } : options?.template;
8463
+ } : {
8464
+ ...options?.template,
8465
+ propsAliases
8466
+ };
8350
8467
  const templateOptions = componentSourceInfo.wevuComponentTags.size ? {
8351
8468
  ...baseTemplateOptions,
8352
8469
  wevuComponentTags: componentSourceInfo.wevuComponentTags
@@ -8355,7 +8472,7 @@ async function compileVueFile(source, filename, options) {
8355
8472
  wevuComponentTags: []
8356
8473
  };
8357
8474
  const templateCompiled = compileTemplatePhase(parsed.descriptor, filename, templateOptions, result);
8358
- const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo);
8475
+ const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo, scriptCompiled);
8359
8476
  result.script = scriptPhase.script;
8360
8477
  result.scriptMap = scriptPhase.scriptMap;
8361
8478
  compileStylePhase(parsed.descriptor, filename, result);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.19",
4
+ "version": "6.16.20",
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.34",
53
53
  "@weapp-core/constants": "0.1.8",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.19",
55
+ "@weapp-vite/ast": "6.16.20",
56
56
  "rolldown-require": "2.0.17"
57
57
  },
58
58
  "publishConfig": {