@wevu/compiler 6.16.40 → 6.16.42

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
@@ -309,6 +309,7 @@ interface ForParseResult {
309
309
  */
310
310
  interface TemplateCompileOptions {
311
311
  platform?: MiniProgramPlatform;
312
+ isPage?: boolean;
312
313
  /**
313
314
  * Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
314
315
  */
@@ -332,6 +333,7 @@ interface TemplateCompileOptions {
332
333
  functionPropNames?: Iterable<FunctionPropNameMatcher>;
333
334
  wevuComponentTags?: Iterable<string>;
334
335
  componentNameMap?: Record<string, string>;
336
+ miniProgramComponentTags?: Iterable<string>;
335
337
  }
336
338
  /**
337
339
  * 作用域插槽编译模式。
@@ -799,6 +801,10 @@ interface TransformScriptOptions {
799
801
  * 以避免小程序属性校验对复杂表达式/代理值产生误报。
800
802
  */
801
803
  relaxStructuredTypeOnlyProps?: boolean;
804
+ /**
805
+ * 当前组件模板包含 scoped slot outlet,需要接收 scoped slot 桥接属性。
806
+ */
807
+ scopedSlotHostProperties?: boolean;
802
808
  }
803
809
  //#endregion
804
810
  //#region src/plugins/vue/transform/transformScript/index.d.ts
package/dist/index.mjs CHANGED
@@ -3194,6 +3194,32 @@ function injectFunctionPropPaths(componentOptionsObject, paths) {
3194
3194
  componentOptionsObject.properties.push(t.objectProperty(t.identifier(WEVU_FUNCTION_PROP_PATHS_KEY), t.arrayExpression(uniquePaths.map((path) => t.stringLiteral(path)))));
3195
3195
  return true;
3196
3196
  }
3197
+ function createScopedSlotHostPropertyDefinition(typeName, value) {
3198
+ return t.objectExpression([t.objectProperty(t.identifier("type"), typeName === "String" ? t.identifier("String") : t.nullLiteral()), t.objectProperty(t.identifier("value"), value === null ? t.nullLiteral() : t.stringLiteral(value))]);
3199
+ }
3200
+ function createScopedSlotHostProperties() {
3201
+ return [
3202
+ t.objectProperty(t.identifier(WEVU_SLOT_NAMES_PROP), createScopedSlotHostPropertyDefinition("null", null)),
3203
+ t.objectProperty(t.identifier(WEVU_SLOT_OWNER_ID_PROP), createScopedSlotHostPropertyDefinition("String", "")),
3204
+ t.objectProperty(t.identifier(WEVU_SLOT_SCOPE_KEY), createScopedSlotHostPropertyDefinition("null", null))
3205
+ ];
3206
+ }
3207
+ function injectScopedSlotHostProperties(componentOptionsObject) {
3208
+ const propertiesProp = getObjectPropertyByKey$1(componentOptionsObject, "properties");
3209
+ if (!propertiesProp) {
3210
+ componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier("properties"), t.objectExpression(createScopedSlotHostProperties())));
3211
+ return true;
3212
+ }
3213
+ if (!t.isObjectExpression(propertiesProp.value)) return false;
3214
+ let changed = false;
3215
+ for (const prop of createScopedSlotHostProperties().reverse()) {
3216
+ const key = t.isIdentifier(prop.key) ? prop.key.name : void 0;
3217
+ if (!key || getObjectPropertyByKey$1(propertiesProp.value, key)) continue;
3218
+ propertiesProp.value.properties.unshift(prop);
3219
+ changed = true;
3220
+ }
3221
+ return changed;
3222
+ }
3197
3223
  function unwrapTypeLikeExpression(node) {
3198
3224
  if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression(node.expression);
3199
3225
  if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression(node.expression);
@@ -3300,6 +3326,7 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
3300
3326
  }) || transformed;
3301
3327
  if (componentOptionsObject) transformed = injectSetupInitialData(componentOptionsObject) || transformed;
3302
3328
  if (componentOptionsObject && options?.relaxStructuredTypeOnlyProps) transformed = relaxStructuredTypeOnlyProps(componentOptionsObject) || transformed;
3329
+ if (componentOptionsObject && options?.scopedSlotHostProperties) transformed = injectScopedSlotHostProperties(componentOptionsObject) || transformed;
3303
3330
  if (componentOptionsObject) {
3304
3331
  transformed = injectPropsAliases(componentOptionsObject, options?.propsAliases) || transformed;
3305
3332
  transformed = injectPropsDerivedKeys(componentOptionsObject, options?.propsDerivedKeys) || transformed;
@@ -6488,6 +6515,30 @@ function isTopLevelObjectLiteral(exp) {
6488
6515
  if (!parsed) return false;
6489
6516
  return unwrapTsExpression(parsed).type === "ObjectExpression";
6490
6517
  }
6518
+ function isStaticLiteralNode(node) {
6519
+ const normalized = unwrapTsExpression(node);
6520
+ if (normalized.type === "StringLiteral" || normalized.type === "NumericLiteral" || normalized.type === "BooleanLiteral" || normalized.type === "NullLiteral") return true;
6521
+ if (normalized.type === "UnaryExpression") return (normalized.operator === "-" || normalized.operator === "+") && normalized.argument.type === "NumericLiteral";
6522
+ if (normalized.type === "ArrayExpression") {
6523
+ for (const element of normalized.elements) if (!element || element.type === "SpreadElement" || !isStaticLiteralNode(element)) return false;
6524
+ return true;
6525
+ }
6526
+ if (normalized.type === "ObjectExpression") {
6527
+ for (const property of normalized.properties) {
6528
+ if (property.type !== "ObjectProperty" || property.computed) return false;
6529
+ const value = property.value;
6530
+ if (!t.isExpression(value) || !isStaticLiteralNode(value)) return false;
6531
+ }
6532
+ return true;
6533
+ }
6534
+ return false;
6535
+ }
6536
+ function isStaticObjectLiteral(exp) {
6537
+ const parsed = parseBabelExpression(exp);
6538
+ if (!parsed) return false;
6539
+ const normalized = unwrapTsExpression(parsed);
6540
+ return normalized.type === "ObjectExpression" && isStaticLiteralNode(normalized);
6541
+ }
6491
6542
  function createBindRuntimeAttr(argValue, rawExpValue, context) {
6492
6543
  const bindingRef = registerRuntimeBindingExpression(rawExpValue, context, { hint: `:${argValue} 绑定` });
6493
6544
  if (!bindingRef) return null;
@@ -6595,7 +6646,7 @@ function transformBindDirective(node, context, forInfo, options) {
6595
6646
  return context.platform.keyAttr(expValue);
6596
6647
  }
6597
6648
  if (isTopLevelObjectLiteral(rawExpValue)) {
6598
- if (context.objectLiteralBindMode === "inline") return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
6649
+ if (context.objectLiteralBindMode === "inline" || isStaticObjectLiteral(rawExpValue)) return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
6599
6650
  return createBindRuntimeAttr(argValue, rawExpValue, context);
6600
6651
  }
6601
6652
  if (shouldFallbackToRuntimeBinding(rawExpValue)) {
@@ -6738,6 +6789,9 @@ function transformModelDirective(node, context, elementNode, options) {
6738
6789
  //#region src/plugins/vue/compiler/template/directives/on.ts
6739
6790
  const SIMPLE_IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
6740
6791
  const isSimpleHandler = (value) => SIMPLE_IDENTIFIER_RE.test(value);
6792
+ function isScriptSetupHandlerBinding(value, context) {
6793
+ return isSimpleHandler(value) && Boolean(context.scriptSetupBindings?.[value]);
6794
+ }
6741
6795
  function shouldUseDetailPayload(options) {
6742
6796
  return options?.isComponent === true;
6743
6797
  }
@@ -6770,7 +6824,7 @@ function transformOnDirective(node, context, options) {
6770
6824
  if (!exp) return null;
6771
6825
  const rawExpValue = exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content.trim() : "";
6772
6826
  const useDetailPayload = shouldUseDetailPayload(options);
6773
- const inlineSource = useDetailPayload && isSimpleHandler(rawExpValue) ? `${rawExpValue}($event)` : rawExpValue;
6827
+ const inlineSource = (useDetailPayload || isScriptSetupHandlerBinding(rawExpValue, context)) && isSimpleHandler(rawExpValue) ? `${rawExpValue}($event)` : rawExpValue;
6774
6828
  const isInlineExpression = inlineSource && !isSimpleHandler(inlineSource);
6775
6829
  const inlineExpression = isInlineExpression ? registerInlineExpression(inlineSource, context) : null;
6776
6830
  const mappedEvent = options?.isComponent === true ? argValue : context.platform.mapEventName(argValue);
@@ -7165,6 +7219,7 @@ function createScopedSlotComponent(context, slotKey, props, children, transformN
7165
7219
  ...context,
7166
7220
  scopedSlotComponents: context.scopedSlotComponents,
7167
7221
  componentGenerics: {},
7222
+ miniProgramComponentTags: context.miniProgramComponentTags,
7168
7223
  scopeStack: [],
7169
7224
  slotPropStack: [],
7170
7225
  rewriteScopedSlot: true,
@@ -7385,7 +7440,7 @@ function transformSlotElement(node, context, transformNode) {
7385
7440
  if (!slotPropsExp && slotPresentExp) slotTag = `${context.platform.wrapIf(slotPresentExp, slotTag, (exp) => renderMustache(exp, context))}${context.platform.wrapElse(fallbackContent)}`;
7386
7441
  else if (!slotPropsExp) slotTag = `<slot${slotAttrString}>${fallbackContent}</slot>`;
7387
7442
  }
7388
- if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default" && context.scopedSlotsCompiler !== "augmented")) return slotTag;
7443
+ if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default" || !context.isPage)) return slotTag;
7389
7444
  const hasScopeBindings = Boolean(slotPropsExp);
7390
7445
  const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
7391
7446
  context.componentGenerics[genericKey] = true;
@@ -7429,14 +7484,45 @@ function hasDirectComponentSlotChild(children, context) {
7429
7484
  function isWevuComponentTag(node, context) {
7430
7485
  return context.wevuComponentTags ? context.wevuComponentTags.has(node.tag) : /^[A-Z]/.test(node.tag);
7431
7486
  }
7432
- function shouldAugmentPlainSlot(decl, context, ownerNode) {
7487
+ function hasDirectWevuComponentSlotChild(children, context) {
7488
+ return children.some((child) => {
7489
+ if (child.type !== NodeTypes.ELEMENT) return false;
7490
+ const element = child;
7491
+ if (element.tag === "template" || isBuiltinTag(resolveTemplateTagName(element.tag, context))) return false;
7492
+ return isWevuComponentTag(element, context);
7493
+ });
7494
+ }
7495
+ function hasMiniProgramComponentSlotDescendant(children, context) {
7496
+ const componentTags = context.miniProgramComponentTags;
7497
+ if (!componentTags?.size) return false;
7498
+ return children.some((child) => {
7499
+ if (child.type !== NodeTypes.ELEMENT) return false;
7500
+ const element = child;
7501
+ if (componentTags.has(element.tag)) return true;
7502
+ return hasMiniProgramComponentSlotDescendant(element.children, context);
7503
+ });
7504
+ }
7505
+ function hasNativeComponentSlotDescendant(children, context) {
7506
+ return children.some((child) => {
7507
+ if (child.type !== NodeTypes.ELEMENT) return false;
7508
+ const element = child;
7509
+ if (!isBuiltinTag(resolveTemplateTagName(element.tag, context)) && element.tag.includes("-") && !isWevuComponentTag(element, context)) return true;
7510
+ return hasNativeComponentSlotDescendant(element.children, context);
7511
+ });
7512
+ }
7513
+ function shouldAugmentPlainSlot(decl, context, ownerNode, hasScopedSlotPropsSibling) {
7433
7514
  if (context.scopedSlotsRequireProps) return false;
7434
7515
  if (context.rewriteScopedSlot && !isWevuComponentTag(ownerNode, context)) return false;
7435
- if (context.rewriteScopedSlot && !hasDirectComponentSlotChild(decl.children, context)) return false;
7436
- if (context.scopedSlotsCompiler === "augmented") return true;
7437
- if (!decl.implicitDefault) return false;
7516
+ if (context.rewriteScopedSlot) {
7517
+ if (context.scopedSlotsCompiler === "augmented" && !decl.implicitDefault) return true;
7518
+ return context.scopedSlotsCompiler === "augmented" ? hasMiniProgramComponentSlotDescendant(decl.children, context) : hasScopedSlotPropsSibling && hasDirectComponentSlotChild(decl.children, context);
7519
+ }
7520
+ if (context.scopedSlotsCompiler === "augmented") {
7521
+ if (!decl.implicitDefault) return true;
7522
+ return hasMiniProgramComponentSlotDescendant(decl.children, context) || !isWevuComponentTag(ownerNode, context) && hasNativeComponentSlotDescendant(decl.children, context);
7523
+ }
7438
7524
  if (!isWevuComponentTag(ownerNode, context)) return false;
7439
- return hasDirectComponentSlotChild(decl.children, context);
7525
+ return hasScopedSlotPropsSibling || hasDirectWevuComponentSlotChild(decl.children, context);
7440
7526
  }
7441
7527
  function resolveTemplateSlotCondition(node, context) {
7442
7528
  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));
@@ -7448,7 +7534,12 @@ function resolveTemplateSlotCondition(node, context) {
7448
7534
  condition: rawExp ? normalizeWxmlExpressionWithContext(rawExp, context) : void 0
7449
7535
  };
7450
7536
  }
7451
- function pushSlotNamesAttr(attrs, slotNames, context) {
7537
+ function resolveInlineStaticSlotName(name) {
7538
+ if (!name.startsWith("'") || !name.endsWith("'")) return null;
7539
+ const normalizedName = name.slice(1, -1);
7540
+ return /^[A-Z_$][\w$]*$/i.test(normalizedName) ? normalizedName : null;
7541
+ }
7542
+ function pushSlotNamesAttr(attrs, slotNames, context, options) {
7452
7543
  if (!slotNames.length) return;
7453
7544
  const seen = /* @__PURE__ */ new Set();
7454
7545
  const entries = /* @__PURE__ */ new Map();
@@ -7469,9 +7560,20 @@ function pushSlotNamesAttr(attrs, slotNames, context) {
7469
7560
  entries.set(item.name, entry);
7470
7561
  }
7471
7562
  const properties = [];
7563
+ const inlineProperties = [];
7564
+ let canInlineStatic = !options?.forInfo;
7472
7565
  for (const [name, entry] of entries) {
7473
7566
  const value = entry.conditions.length ? entry.conditions.map((condition) => `(${condition})`).join("||") : "true";
7567
+ const inlineName = resolveInlineStaticSlotName(name);
7568
+ if (value !== "true" || !inlineName) canInlineStatic = false;
7474
7569
  properties.push(`[${name}]:${value}`);
7570
+ inlineProperties.push(`${inlineName}:${value}`);
7571
+ }
7572
+ if (canInlineStatic) {
7573
+ const inlineSlots = `{${inlineProperties.join(",")}}`;
7574
+ const mustache = context.mustacheInterpolation === "spaced" ? renderMustache(inlineSlots, context) : `{{ ${inlineSlots} }}`;
7575
+ attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${mustache}"`);
7576
+ return;
7475
7577
  }
7476
7578
  const slotNamesRef = registerRuntimeBindingExpression(`{${properties.join(",")}}`, context, { hint: "vue-slots 元数据" });
7477
7579
  if (slotNamesRef) attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${renderMustache(slotNamesRef, context)}"`);
@@ -7620,7 +7722,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
7620
7722
  });
7621
7723
  let children = node.children.map((child) => transformNode(child, context)).join("");
7622
7724
  if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
7623
- if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
7725
+ if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
7624
7726
  const mergedAttrs = [...extraAttrs, ...attrs];
7625
7727
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
7626
7728
  const { tag } = node;
@@ -7628,7 +7730,8 @@ function transformComponentWithSlots(node, context, transformNode, options) {
7628
7730
  }
7629
7731
  const scopedSlotDeclarations = [];
7630
7732
  const plainSlotDeclarations = [];
7631
- for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || shouldAugmentPlainSlot(decl, context, node)) scopedSlotDeclarations.push(decl);
7733
+ const hasScopedSlotProps = slotDeclarations.some((decl) => Object.keys(decl.props).length > 0);
7734
+ for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || shouldAugmentPlainSlot(decl, context, node, hasScopedSlotProps)) scopedSlotDeclarations.push(decl);
7632
7735
  else plainSlotDeclarations.push(decl);
7633
7736
  const slotNames = [];
7634
7737
  const slotGenericAttrs = [];
@@ -7656,7 +7759,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
7656
7759
  ...attrs,
7657
7760
  ...slotGenericAttrs
7658
7761
  ];
7659
- pushSlotNamesAttr(mergedAttrs, slotNames, context);
7762
+ pushSlotNamesAttr(mergedAttrs, slotNames, context, { forInfo: options?.forInfo });
7660
7763
  if (scopedSlotDeclarations.length) {
7661
7764
  const scopePropsExp = buildScopePropsExpression(context);
7662
7765
  if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
@@ -7722,7 +7825,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
7722
7825
  });
7723
7826
  let children = node.children.map((child) => transformNode(child, context)).join("");
7724
7827
  if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
7725
- if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
7828
+ if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
7726
7829
  const mergedAttrs = [...extraAttrs, ...attrs];
7727
7830
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
7728
7831
  const { tag } = node;
@@ -7743,7 +7846,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
7743
7846
  if (shouldExposePlainSlotPresence(node) || isWevuComponentTag(node, context)) pushSlotNamesAttr(mergedAttrs, slotDeclarations.map((decl) => ({
7744
7847
  name: stringifySlotName(decl.name, context),
7745
7848
  condition: decl.condition
7746
- })), context);
7849
+ })), context, { forInfo: options?.forInfo });
7747
7850
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
7748
7851
  const { tag } = node;
7749
7852
  return renderedSlots ? `<${tag}${attrString}>${renderedSlots}</${tag}>` : `<${tag}${attrString} />`;
@@ -8044,6 +8147,11 @@ const HTML_VOID_TAGS = new Set([
8044
8147
  "track",
8045
8148
  "wbr"
8046
8149
  ]);
8150
+ function resolveTemplateIsPage(filename, options) {
8151
+ if (options?.isPage !== true) return false;
8152
+ const normalized = filename.replace(/\\/g, "/");
8153
+ return !/(?:^|\/)(?:components|layouts|custom-tab-bar)\//.test(normalized);
8154
+ }
8047
8155
  function resolveSlotFallbackWrapperComponent(strategy) {
8048
8156
  if (strategy !== "virtual-host") return;
8049
8157
  return {
@@ -8092,6 +8200,7 @@ function compileVueTemplateToWxml(template, filename, options) {
8092
8200
  filename,
8093
8201
  warnings,
8094
8202
  platform: options?.platform ?? getMiniProgramTemplatePlatform(),
8203
+ isPage: resolveTemplateIsPage(filename, options),
8095
8204
  propsAliases: options?.propsAliases,
8096
8205
  propsDerivedKeys: options?.propsDerivedKeys,
8097
8206
  scriptSetupBindings: options?.scriptSetupBindings,
@@ -8127,7 +8236,8 @@ function compileVueTemplateToWxml(template, filename, options) {
8127
8236
  inlineExpressionSeed: 0,
8128
8237
  functionPropPaths: /* @__PURE__ */ new Set(),
8129
8238
  functionPropNames: Array.from(options?.functionPropNames ?? []),
8130
- wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0
8239
+ wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0,
8240
+ miniProgramComponentTags: options?.miniProgramComponentTags ? new Set(options.miniProgramComponentTags) : void 0
8131
8241
  };
8132
8242
  let wxml = ast.children.map((child) => transformNode(child, context)).join("");
8133
8243
  if (context.classStyleWxs) wxml = `${buildClassStyleWxsTag(context.classStyleWxsExtension || "wxs", context.classStyleWxsSrc)}\n${wxml}`;
@@ -8199,6 +8309,32 @@ function extractStaticDefineOptionsName(scriptSetupContent) {
8199
8309
  } });
8200
8310
  return componentName;
8201
8311
  }
8312
+ function extractStaticDefineComponentJsonIsComponent(scriptSetupContent) {
8313
+ let ast;
8314
+ try {
8315
+ ast = parse$3(scriptSetupContent, BABEL_TS_MODULE_PARSER_OPTIONS);
8316
+ } catch {
8317
+ return false;
8318
+ }
8319
+ let isComponent = false;
8320
+ traverse(ast, { CallExpression(path) {
8321
+ if (isComponent) return;
8322
+ const callee = path.node.callee;
8323
+ if (!t.isIdentifier(callee, { name: "defineComponentJson" })) return;
8324
+ const arg = path.node.arguments[0];
8325
+ if (!t.isObjectExpression(arg)) return;
8326
+ for (const property of arg.properties) {
8327
+ if (!t.isObjectProperty(property)) continue;
8328
+ const key = property.key;
8329
+ if ((t.isIdentifier(key) ? key.name === "component" : t.isStringLiteral(key) ? key.value === "component" : false) && t.isBooleanLiteral(property.value) && property.value.value) {
8330
+ isComponent = true;
8331
+ path.stop();
8332
+ return;
8333
+ }
8334
+ }
8335
+ } });
8336
+ return isComponent;
8337
+ }
8202
8338
  async function resolveVueSfcComponentName(resolvedId, warn) {
8203
8339
  if (!resolvedId?.endsWith(".vue")) return;
8204
8340
  try {
@@ -8211,11 +8347,28 @@ async function resolveVueSfcComponentName(resolvedId, warn) {
8211
8347
  return;
8212
8348
  }
8213
8349
  }
8350
+ async function resolveVueSfcIsMiniProgramComponent(resolvedId, warn) {
8351
+ if (!resolvedId?.endsWith(".vue")) return false;
8352
+ try {
8353
+ const { descriptor, errors } = parse(await readFile$1(resolvedId, "utf8"), { filename: resolvedId });
8354
+ if (errors.length > 0 || !descriptor.scriptSetup?.content) return false;
8355
+ return extractStaticDefineComponentJsonIsComponent(descriptor.scriptSetup.content);
8356
+ } catch (error) {
8357
+ const message = error instanceof Error ? error.message : String(error);
8358
+ warn?.(`[Vue 编译] 解析 ${resolvedId} 的 defineComponentJson.component 失败:${message}`);
8359
+ return false;
8360
+ }
8361
+ }
8214
8362
  function registerComponentName(result, tag, componentName) {
8215
8363
  if (!componentName) return;
8216
8364
  result.componentNameMap[tag] = componentName;
8217
8365
  result.componentNameMap[pascalToKebab(tag)] = componentName;
8218
8366
  }
8367
+ function registerMiniProgramComponentTag(result, tag, isComponent) {
8368
+ if (!isComponent) return;
8369
+ result.miniProgramComponentTags.add(tag);
8370
+ result.miniProgramComponentTags.add(pascalToKebab(tag));
8371
+ }
8219
8372
  function collectTemplateComponentNames(template, filename, warn) {
8220
8373
  const warnHandler = resolveWarnHandler(warn);
8221
8374
  const tags = collectVueTemplateTags(template, {
@@ -8287,6 +8440,7 @@ async function collectScriptSetupUsingComponents(options) {
8287
8440
  result.wevuComponentTags.add(pascalToKebab(localName));
8288
8441
  }
8289
8442
  registerComponentName(result, localName, await resolveVueSfcComponentName(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
8443
+ registerMiniProgramComponentTag(result, localName, await resolveVueSfcIsMiniProgramComponent(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
8290
8444
  }
8291
8445
  } catch (error) {
8292
8446
  const message = error instanceof Error ? error.message : String(error);
@@ -8317,7 +8471,12 @@ async function collectAutoImportWevuComponents(options) {
8317
8471
  }
8318
8472
  const componentName = await resolveVueSfcComponentName(resolved.resolvedId, autoImportTags.warn ?? warn);
8319
8473
  registerComponentName(result, tag, componentName);
8320
- if (resolved.name) registerComponentName(result, resolved.name, componentName);
8474
+ const isMiniProgramComponent = await resolveVueSfcIsMiniProgramComponent(resolved.resolvedId, autoImportTags.warn ?? warn);
8475
+ registerMiniProgramComponentTag(result, tag, isMiniProgramComponent);
8476
+ if (resolved.name) {
8477
+ registerComponentName(result, resolved.name, componentName);
8478
+ registerMiniProgramComponentTag(result, resolved.name, isMiniProgramComponent);
8479
+ }
8321
8480
  }
8322
8481
  }
8323
8482
  async function collectComponentSourceInfo(options) {
@@ -8325,6 +8484,7 @@ async function collectComponentSourceInfo(options) {
8325
8484
  autoUsingComponentsMap: {},
8326
8485
  autoComponentMeta: {},
8327
8486
  wevuComponentTags: /* @__PURE__ */ new Set(),
8487
+ miniProgramComponentTags: /* @__PURE__ */ new Set(),
8328
8488
  componentNameMap: {}
8329
8489
  };
8330
8490
  await collectScriptSetupUsingComponents({
@@ -9246,7 +9406,8 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
9246
9406
  functionPropPaths: templateCompiled?.functionPropPaths,
9247
9407
  propsAliases,
9248
9408
  propsDerivedKeys,
9249
- relaxStructuredTypeOnlyProps
9409
+ relaxStructuredTypeOnlyProps,
9410
+ scopedSlotHostProperties: Boolean(templateCompiled?.componentGenerics && Object.keys(templateCompiled.componentGenerics).length > 0)
9250
9411
  });
9251
9412
  return {
9252
9413
  script: transformed.code,
@@ -9339,12 +9500,14 @@ async function compileVueFile(source, filename, options) {
9339
9500
  const propsDerivedKeys = scriptCompiled ? resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCompiled.content) : void 0;
9340
9501
  const baseTemplateOptions = parsed.isAppFile ? {
9341
9502
  ...options?.template,
9503
+ isPage: options?.isPage,
9342
9504
  propsAliases,
9343
9505
  propsDerivedKeys,
9344
9506
  scriptSetupBindings: scriptCompiled?.bindings,
9345
9507
  scopedSlotsRequireProps: true
9346
9508
  } : {
9347
9509
  ...options?.template,
9510
+ isPage: options?.isPage,
9348
9511
  propsAliases,
9349
9512
  propsDerivedKeys,
9350
9513
  scriptSetupBindings: scriptCompiled?.bindings
@@ -9352,11 +9515,13 @@ async function compileVueFile(source, filename, options) {
9352
9515
  const templateOptions = componentSourceInfo.wevuComponentTags.size ? {
9353
9516
  ...baseTemplateOptions,
9354
9517
  wevuComponentTags: componentSourceInfo.wevuComponentTags,
9355
- componentNameMap: componentSourceInfo.componentNameMap
9518
+ componentNameMap: componentSourceInfo.componentNameMap,
9519
+ miniProgramComponentTags: componentSourceInfo.miniProgramComponentTags
9356
9520
  } : {
9357
9521
  ...baseTemplateOptions,
9358
9522
  wevuComponentTags: [],
9359
- componentNameMap: componentSourceInfo.componentNameMap
9523
+ componentNameMap: componentSourceInfo.componentNameMap,
9524
+ miniProgramComponentTags: componentSourceInfo.miniProgramComponentTags
9360
9525
  };
9361
9526
  const templateCompiled = compileTemplatePhase(parsed.descriptor, filename, templateOptions, result);
9362
9527
  const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo, scriptCompiled);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.40",
4
+ "version": "6.16.42",
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.40",
55
+ "@weapp-vite/ast": "6.16.42",
56
56
  "rolldown-require": "2.0.18"
57
57
  },
58
58
  "publishConfig": {