Skip to content

Commit 54118e1

Browse files
committed
fix(compiler): enhance dynamic slot handling in transTag function to support proper compilation
1 parent 08b3999 commit 54118e1

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

fe/packages/compiler/src/core/view-compiler.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,9 @@ function transTag(opts) {
10161016
// 多 slot 支持,目前在组件定义时的选项中 multipleSlots 未生效
10171017
const multipleSlots = attrs?.slot
10181018
if (attrs?.slot) {
1019+
// 检查是否为动态插槽(slot 属性值被 {{}} 包裹)
1020+
const isDynamicSlot = isWrappedByBraces(multipleSlots)
1021+
10191022
if (isStart) {
10201023
// 如果存在 if/else 属性,则需要转移到 template 中
10211024
const withVIf = []
@@ -1032,12 +1035,24 @@ function transTag(opts) {
10321035
}
10331036
const vIfProps = withVIf.length > 0 ? `${withVIf.join(' ')} ` : ''
10341037
const vOtherProps = withoutVIf.length > 0 ? ` ${withoutVIf.join(' ')}` : ''
1035-
// 动态插槽无法正常编译,添加根节点。
1036-
// Error: Codegen node is missing for element/if/for node. Apply appropriate transforms first.
1037-
tagRes = `<dd-block><template ${vIfProps}${generateSlotDirective(multipleSlots)}><${res}${vOtherProps}>`
1038+
1039+
// 构建共同的 template 内容
1040+
const templateContent = `<template ${vIfProps}${generateSlotDirective(multipleSlots)}><${res}${vOtherProps}>`
1041+
1042+
if (isDynamicSlot) {
1043+
// 动态插槽无法正常编译,添加 dd-block 包装器。
1044+
// Error: Codegen node is missing for element/if/for node. Apply appropriate transforms first.
1045+
tagRes = `<dd-block>${templateContent}`
1046+
} else {
1047+
tagRes = templateContent
1048+
}
10381049
}
10391050
else {
1040-
tagRes = `</${res}></template></dd-block>`
1051+
if (isDynamicSlot) {
1052+
tagRes = `</${res}></template></dd-block>`
1053+
} else {
1054+
tagRes = `</${res}></template>`
1055+
}
10411056
}
10421057
}
10431058
else {

0 commit comments

Comments
 (0)