@wevu/compiler 6.16.11 → 6.16.13

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.
Files changed (2) hide show
  1. package/dist/index.mjs +85 -23
  2. package/package.json +3 -3
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_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_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_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";
@@ -5623,7 +5623,7 @@ function normalizeJsExpressionWithContext(exp, context, options) {
5623
5623
  const base = createThisMemberAccess(WEVU_SLOT_PROPS_DATA_KEY);
5624
5624
  replacement = createUnrefCall(prop ? createMemberAccess(base, prop) : base);
5625
5625
  } 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));
5626
- else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_KEY), name));
5626
+ else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_PROXY_KEY), name));
5627
5627
  else replacement = createUnrefCall(createIdentifierAccessWithPropsFallback(name));
5628
5628
  const parent = path.parentPath;
5629
5629
  if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
@@ -6324,12 +6324,13 @@ function parseSlotPropsExpression(exp, context) {
6324
6324
  function collectSlotBindingExpression(node, context) {
6325
6325
  let bindObjectExp = null;
6326
6326
  const namedBindings = [];
6327
+ const hasForDirective = node.props.some((prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "for");
6327
6328
  for (const prop of node.props) {
6328
6329
  if (prop.type === NodeTypes.ATTRIBUTE && prop.name === "name") continue;
6329
6330
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
6330
6331
  if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
6331
6332
  const rawExpValue = getBindDirectiveExpression(prop);
6332
- if (prop.arg.content === "name") continue;
6333
+ if (prop.arg.content === "name" || hasForDirective && prop.arg.content === "key") continue;
6333
6334
  if (rawExpValue) namedBindings.push({
6334
6335
  key: prop.arg.content,
6335
6336
  value: normalizeWxmlExpressionWithContext(rawExpValue, context)
@@ -6552,13 +6553,13 @@ function transformSlotElement(node, context, transformNode) {
6552
6553
  if (!slotPropsExp && slotPresentExp) slotTag = `${context.platform.wrapIf(slotPresentExp, slotTag, (exp) => renderMustache(exp, context))}${context.platform.wrapElse(fallbackContent)}`;
6553
6554
  else if (!slotPropsExp) slotTag = `<slot${slotAttrString}>${fallbackContent}</slot>`;
6554
6555
  }
6555
- if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default")) return slotTag;
6556
+ if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default" && context.scopedSlotsCompiler !== "augmented")) return slotTag;
6556
6557
  const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
6557
6558
  context.componentGenerics[genericKey] = true;
6558
6559
  slotPropsExp = slotPropsExp ?? "[]";
6559
6560
  const scopedAttrs = [
6560
6561
  `${context.platform.directives.ifAttr}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`,
6561
- `${WEVU_SLOT_OWNER_ATTR}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`,
6562
+ `${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`,
6562
6563
  `${WEVU_SLOT_PROPS_ATTR}="${renderMustache(slotPropsExp, context)}"`
6563
6564
  ];
6564
6565
  if (context.slotMultipleInstance) scopedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(WEVU_SLOT_SCOPE_KEY, context)}"`);
@@ -6569,15 +6570,23 @@ function transformSlotElement(node, context, transformNode) {
6569
6570
  }
6570
6571
  function transformSlotElementPlain(node, context, transformNode) {
6571
6572
  const slotNameInfo = resolveSlotNameFromSlotElement(node);
6572
- if (node.props.some((prop) => {
6573
+ const hasScopeBindings = node.props.some((prop) => {
6573
6574
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") return prop.arg?.type !== NodeTypes.SIMPLE_EXPRESSION || prop.arg.content !== "name";
6574
6575
  return false;
6575
- })) context.warnings.push("已禁用作用域插槽参数,插槽绑定将被忽略。");
6576
+ });
6577
+ if (hasScopeBindings) context.warnings.push("已禁用作用域插槽参数,插槽绑定将被忽略。");
6576
6578
  const fallbackContent = node.children.map((child) => transformNode(child, context)).join("");
6577
6579
  const slotAttrs = [];
6578
6580
  const nameAttr = renderSlotNameAttribute(slotNameInfo, context, "name");
6579
6581
  if (nameAttr) slotAttrs.push(nameAttr);
6580
6582
  const slotAttrString = slotAttrs.length ? ` ${slotAttrs.join(" ")}` : "";
6583
+ if (!hasScopeBindings && fallbackContent) {
6584
+ const slotPresentExp = createSlotPresenceExpression(slotNameInfo);
6585
+ if (slotPresentExp) {
6586
+ const slotTag = `<slot${slotAttrString} />`;
6587
+ return `${context.platform.wrapIf(slotPresentExp, slotTag, (exp) => renderMustache(exp, context))}${context.platform.wrapElse(fallbackContent)}`;
6588
+ }
6589
+ }
6581
6590
  return fallbackContent ? `<slot${slotAttrString}>${fallbackContent}</slot>` : `<slot${slotAttrString} />`;
6582
6591
  }
6583
6592
  //#endregion
@@ -6605,11 +6614,12 @@ function hasDirectComponentSlotChild(children, context) {
6605
6614
  function isWevuComponentTag(node, context) {
6606
6615
  return context.wevuComponentTags ? context.wevuComponentTags.has(node.tag) : /^[A-Z]/.test(node.tag);
6607
6616
  }
6608
- function shouldAugmentPlainDefaultSlot(decl, context, ownerNode) {
6609
- if (context.scopedSlotsRequireProps || !decl.implicitDefault) return false;
6610
- if (context.scopedSlotsCompiler !== "augmented" && !isWevuComponentTag(ownerNode, context)) return false;
6617
+ function shouldAugmentPlainSlot(decl, context, ownerNode) {
6618
+ if (context.scopedSlotsRequireProps) return false;
6611
6619
  if (context.rewriteScopedSlot && !isWevuComponentTag(ownerNode, context)) return false;
6612
6620
  if (context.scopedSlotsCompiler === "augmented") return true;
6621
+ if (!decl.implicitDefault) return false;
6622
+ if (!isWevuComponentTag(ownerNode, context)) return false;
6613
6623
  return hasDirectComponentSlotChild(decl.children, context);
6614
6624
  }
6615
6625
  function resolveTemplateSlotCondition(node, context) {
@@ -6648,6 +6658,14 @@ function pushSlotNamesAttr(attrs, slotNames, context) {
6648
6658
  function shouldExposePlainSlotPresence(node) {
6649
6659
  return node.tag === "component";
6650
6660
  }
6661
+ function renderPlainSlotContentInSourceOrder(renderItems, plainSlotDeclarations, implicitDefaultDeclaration, context, transformNode) {
6662
+ const plainSlots = new Set(plainSlotDeclarations);
6663
+ const shouldRenderImplicitDefault = implicitDefaultDeclaration ? plainSlots.has(implicitDefaultDeclaration) : false;
6664
+ return renderItems.map((item) => {
6665
+ if (item.type === "declaration") return plainSlots.has(item.declaration) ? renderSlotFallback(item.declaration, context, transformNode) : "";
6666
+ return shouldRenderImplicitDefault ? transformNode(item.child, context) : "";
6667
+ }).join("");
6668
+ }
6651
6669
  function shouldTransformAsComponentWithSlots(node, context, resolvedTag = resolveTemplateTagName(node.tag, context)) {
6652
6670
  const slotDirective = findSlotDirective(node);
6653
6671
  const templateSlotChildren = node.children.filter((child) => child.type === NodeTypes.ELEMENT && child.tag === "template" && findSlotDirective(child));
@@ -6661,25 +6679,41 @@ function transformComponentWithSlots(node, context, transformNode, options) {
6661
6679
  const slotDeclarations = [];
6662
6680
  const slotDirective = findSlotDirective(node);
6663
6681
  const nonTemplateChildren = [];
6682
+ const renderItems = [];
6664
6683
  for (const child of node.children) {
6665
6684
  if (child.type === NodeTypes.ELEMENT && child.tag === "template") {
6666
6685
  const templateSlot = findSlotDirective(child);
6667
6686
  if (templateSlot) {
6668
- const slotName = resolveSlotNameFromDirective(templateSlot);
6669
- slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) }));
6687
+ const declaration = buildSlotDeclaration(resolveSlotNameFromDirective(templateSlot), templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) });
6688
+ slotDeclarations.push(declaration);
6689
+ renderItems.push({
6690
+ type: "declaration",
6691
+ declaration
6692
+ });
6670
6693
  continue;
6671
6694
  }
6672
6695
  }
6673
6696
  nonTemplateChildren.push(child);
6697
+ if (isRenderableSlotChild(child)) renderItems.push({
6698
+ type: "default-child",
6699
+ child
6700
+ });
6674
6701
  }
6675
6702
  const defaultSlotChildren = nonTemplateChildren.filter(isRenderableSlotChild);
6703
+ let implicitDefaultDeclaration;
6676
6704
  if (slotDirective) {
6677
6705
  if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
6678
6706
  slotDeclarations.length = 0;
6679
6707
  slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context));
6680
6708
  } else if (slotDeclarations.length && defaultSlotChildren.length) if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
6681
- else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true }));
6682
- else if (!slotDeclarations.length && defaultSlotChildren.length && !context.scopedSlotsRequireProps && !hasLegacySlotAttribute(defaultSlotChildren)) slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true }));
6709
+ else {
6710
+ implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true });
6711
+ slotDeclarations.push(implicitDefaultDeclaration);
6712
+ }
6713
+ else if (!slotDeclarations.length && defaultSlotChildren.length && !context.scopedSlotsRequireProps && !hasLegacySlotAttribute(defaultSlotChildren)) {
6714
+ implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true });
6715
+ slotDeclarations.push(implicitDefaultDeclaration);
6716
+ }
6683
6717
  if (!slotDeclarations.length) {
6684
6718
  const { attrs, vTextExp } = collectElementAttributes(node, context, {
6685
6719
  skipSlotDirective: true,
@@ -6696,7 +6730,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
6696
6730
  }
6697
6731
  const scopedSlotDeclarations = [];
6698
6732
  const plainSlotDeclarations = [];
6699
- for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || shouldAugmentPlainDefaultSlot(decl, context, node)) scopedSlotDeclarations.push(decl);
6733
+ for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || shouldAugmentPlainSlot(decl, context, node)) scopedSlotDeclarations.push(decl);
6700
6734
  else plainSlotDeclarations.push(decl);
6701
6735
  const slotNames = [];
6702
6736
  const slotGenericAttrs = [];
@@ -6727,11 +6761,12 @@ function transformComponentWithSlots(node, context, transformNode, options) {
6727
6761
  if (scopedSlotDeclarations.length) {
6728
6762
  const scopePropsExp = buildScopePropsExpression(context);
6729
6763
  if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
6730
- mergedAttrs.push(`${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(`${WEVU_SLOT_OWNER_ID_KEY} || ''`, context)}"`);
6764
+ const ownerIdExp = context.rewriteScopedSlot ? `${WEVU_SLOT_OWNER_ID_PROP} || ${WEVU_SLOT_OWNER_ID_KEY} || ''` : `${WEVU_SLOT_OWNER_ID_KEY} || ''`;
6765
+ mergedAttrs.push(`${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(ownerIdExp, context)}"`);
6731
6766
  }
6732
6767
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
6733
6768
  const { tag } = node;
6734
- const plainSlotContent = plainSlotDeclarations.map((decl) => renderSlotFallback(decl, context, transformNode)).join("");
6769
+ const plainSlotContent = slotDirective ? plainSlotDeclarations.map((decl) => renderSlotFallback(decl, context, transformNode)).join("") : renderPlainSlotContentInSourceOrder(renderItems, plainSlotDeclarations, implicitDefaultDeclaration, context, transformNode);
6735
6770
  return plainSlotContent ? `<${tag}${attrString}>${plainSlotContent}</${tag}>` : `<${tag}${attrString} />`;
6736
6771
  }
6737
6772
  function transformComponentWithSlotsFallback(node, context, transformNode, options) {
@@ -6739,24 +6774,37 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
6739
6774
  const slotDeclarations = [];
6740
6775
  const slotDirective = findSlotDirective(node);
6741
6776
  const nonTemplateChildren = [];
6777
+ const renderItems = [];
6742
6778
  for (const child of node.children) {
6743
6779
  if (child.type === NodeTypes.ELEMENT && child.tag === "template") {
6744
6780
  const templateSlot = findSlotDirective(child);
6745
6781
  if (templateSlot) {
6746
- const slotName = resolveSlotNameFromDirective(templateSlot);
6747
- slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) }));
6782
+ const declaration = buildSlotDeclaration(resolveSlotNameFromDirective(templateSlot), templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) });
6783
+ slotDeclarations.push(declaration);
6784
+ renderItems.push({
6785
+ type: "declaration",
6786
+ declaration
6787
+ });
6748
6788
  continue;
6749
6789
  }
6750
6790
  }
6751
6791
  nonTemplateChildren.push(child);
6792
+ if (isRenderableSlotChild(child)) renderItems.push({
6793
+ type: "default-child",
6794
+ child
6795
+ });
6752
6796
  }
6753
6797
  const defaultSlotChildren = nonTemplateChildren.filter(isRenderableSlotChild);
6798
+ let implicitDefaultDeclaration;
6754
6799
  if (slotDirective) {
6755
6800
  if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
6756
6801
  slotDeclarations.length = 0;
6757
6802
  slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context));
6758
6803
  } else if (slotDeclarations.length && defaultSlotChildren.length) if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
6759
- else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context));
6804
+ else {
6805
+ implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context);
6806
+ slotDeclarations.push(implicitDefaultDeclaration);
6807
+ }
6760
6808
  if (!slotDeclarations.length) {
6761
6809
  const { attrs, vTextExp } = collectElementAttributes(node, context, {
6762
6810
  skipSlotDirective: true,
@@ -6772,7 +6820,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
6772
6820
  return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
6773
6821
  }
6774
6822
  if (slotDeclarations.some((decl) => Object.keys(decl.props).length)) context.warnings.push("已禁用作用域插槽参数,插槽绑定将被忽略。");
6775
- const renderedSlots = slotDeclarations.map((decl) => renderSlotFallback(decl, context, transformNode)).join("");
6823
+ const renderedSlots = slotDirective ? slotDeclarations.map((decl) => renderSlotFallback(decl, context, transformNode)).join("") : renderPlainSlotContentInSourceOrder(renderItems, slotDeclarations, implicitDefaultDeclaration, context, transformNode);
6776
6824
  const { attrs } = collectElementAttributes(node, context, {
6777
6825
  skipSlotDirective: true,
6778
6826
  forInfo: options?.forInfo,
@@ -6841,6 +6889,9 @@ function transformNormalElement(node, context, transformNode) {
6841
6889
  //#region src/plugins/vue/compiler/template/elements/tag-structural.ts
6842
6890
  const REGEX_SPECIAL_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
6843
6891
  function resolveConditionExpression$1(rawExpValue, context, hint) {
6892
+ return (context.rewriteScopedSlot || shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
6893
+ }
6894
+ function resolveListExpression(rawExpValue, context, hint) {
6844
6895
  return (shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
6845
6896
  }
6846
6897
  function transformIfElement(node, context, transformNode) {
@@ -6884,7 +6935,7 @@ function transformForElement(node, context, transformNode) {
6884
6935
  }
6885
6936
  }
6886
6937
  if (context.classStyleRuntime === "js" && !forInfo.index) forInfo.index = `__wv_index_${context.forIndexSeed++}`;
6887
- const listExp = forInfo.listExp ? resolveConditionExpression$1(forInfo.listExp, context, "v-for 列表") : void 0;
6938
+ const listExp = forInfo.listExp ? resolveListExpression(forInfo.listExp, context, "v-for 列表") : void 0;
6888
6939
  const listExpAst = forInfo.listExp ? normalizeJsExpressionWithContext(forInfo.listExp, context, { hint: "v-for 列表" }) : void 0;
6889
6940
  const scopedForInfo = listExp ? {
6890
6941
  ...forInfo,
@@ -6907,6 +6958,16 @@ function transformForElement(node, context, transformNode) {
6907
6958
  props: otherProps
6908
6959
  };
6909
6960
  const extraAttrs = listExp ? context.platform.forAttrs(listExp, renderTemplateMustache, forInfo.item, forInfo.index) : [];
6961
+ if (elementWithoutFor.tag === "slot") {
6962
+ const content = transformSlotElement({
6963
+ ...elementWithoutFor,
6964
+ props: elementWithoutFor.props.filter((prop) => {
6965
+ return !(prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "key");
6966
+ })
6967
+ }, context, transformNode);
6968
+ const attrString = extraAttrs.length ? ` ${extraAttrs.join(" ")}` : "";
6969
+ return attrString ? `<block${attrString}>${content}</block>` : content;
6970
+ }
6910
6971
  const resolvedTag = resolveTemplateTagName(elementWithoutFor.tag, context);
6911
6972
  if (shouldTransformAsComponentWithSlots(elementWithoutFor, context, resolvedTag)) return transformComponentWithSlots(elementWithoutFor, context, transformNode, {
6912
6973
  extraAttrs,
@@ -6930,7 +6991,7 @@ function transformForElement(node, context, transformNode) {
6930
6991
  const TEMPLATE_OPEN_RE = /<template/g;
6931
6992
  const TEMPLATE_CLOSE_RE = /<\/template>/g;
6932
6993
  function resolveConditionExpression(rawExpValue, context, hint) {
6933
- return (shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
6994
+ return (context.rewriteScopedSlot || shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
6934
6995
  }
6935
6996
  function transformTransitionElement(node, context, transformNode) {
6936
6997
  context.warnings.push("<transition> 组件:过渡效果需要动画库或运行时支持,仅渲染子节点。");
@@ -7004,6 +7065,7 @@ function transformElement(node, context, transformNode) {
7004
7065
  if (tag === "slot") {
7005
7066
  const { type } = isStructuralDirective(node);
7006
7067
  if (type === "if") return transformIfElement(node, context, transformNode);
7068
+ if (type === "for") return transformForElement(node, context, transformNode);
7007
7069
  return transformSlotElement(node, context, transformNode);
7008
7070
  }
7009
7071
  if (tag === "component") return transformComponentElement(node, context, transformNode);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.11",
4
+ "version": "6.16.13",
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.6",
53
+ "@weapp-core/constants": "^0.1.7",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.11",
55
+ "@weapp-vite/ast": "6.16.13",
56
56
  "rolldown-require": "2.0.15"
57
57
  },
58
58
  "publishConfig": {