提交 fce0dc32 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊 提交者: 折腾笔记

feat(uni-mp-compiler): 对具名插槽 name 包含短横线的边缘情况进行处理

上级 6a675dcf
......@@ -65,6 +65,16 @@ describe('compiler: transform slot', () => {
}`
)
})
test('names slots with fallback content 带横线', () => {
assert(
`<button><slot name="text-name">Submit</slot></button>`,
`<button><block wx:if="{{$slots['text-name']}}"><slot name="text-name"></slot></block><block wx:else>Submit</block></button>`,
`(_ctx, _cache) => {
return {}
}`
)
})
test('names slots with fallback content', () => {
assert(
`<button><slot name="text">Submit</slot></button>`,
......
......@@ -187,7 +187,11 @@ function genSlot(node: SlotOutletNode, context: TemplateCodegenContext) {
}
}
}
genVIf(`$slots.${name}`, context)
if (name.includes('-')) {
genVIf(`$slots['${name}']`, context)
} else {
genVIf(`$slots.${name}`, context)
}
push(`>`)
genElement(node, context)
push(`</block>`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册