提交 593e6e8d 编写于 作者: Q qiang

fix(mp): dynamic slot name with scopedSlotsCompiler: legacy

上级 b695a0c3
......@@ -105,6 +105,17 @@ describe('mp:compiler-mp-alipay', () => {
)
})
it('generate scoped slot with dynamic slot name', () => {
assertCodegen(
'<view><slot :name="test" :user="user"></slot></view>',
'<view><slot name="{{test}}" user="{{user}}"></slot></view>'
)
assertCodegen(
'<foo><template v-slot:[test]="{user}"><view>{{user}}</view></template></foo>',
'<foo vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[test]}}"><view slot="{{test}}" slot-scope="__SCOPED__"><view>{{__SCOPED__.user}}</view></view></foo>'
)
})
it('generate scoped slot with scopedSlotsCompiler: auto', () => {
assertCodegen(
'<my-component><template v-slot="{item}">{{item}}<template></my-component>',
......
......@@ -81,6 +81,17 @@ describe('mp:compiler-mp-baidu', () => {
)
})
it('generate scoped slot with dynamic slot name', () => {
assertCodegen(
'<view><slot :name="test" :user="user"></slot></view>',
'<view><slot name="{{test}}" var-user="user"></slot></view>'
)
assertCodegen(
'<foo><template v-slot:[test]="{user}"><view>{{user}}</view></template></foo>',
'<foo vue-id="551070e6-1" vue-slots="{{[test]}}"><view slot="{{test}}"><view>{{user}}</view></view></foo>'
)
})
it('generate scoped slot with scopedSlotsCompiler: auto', () => {
assertCodegen(
'<my-component><template v-slot="{item}">{{item}}<template></my-component>',
......
......@@ -124,9 +124,9 @@ module.exports = function getResolveScopedSlots (parent, state) {
updateIds(vueId, slotNode, params.node.name)
}
const fnBody = fn.get('value.body')
// 暂不处理旧版编译模式对于动态 slotName 的处理,含有动态 slotName 的情况下,scopedSlotsCompiler 指定使用增强编译模式
// 非原生支持作用域插槽的平台在含有动态 slotName 的情况下,scopedSlotsCompiler 指定使用增强编译模式
const isStaticSlotName = t.isStringLiteral(slotNode)
if (state.options.scopedSlotsCompiler === 'augmented' || needAugmentedSlotMode(fnBody, ids, state) || !isStaticSlotName) {
if (state.options.scopedSlotsCompiler === 'augmented' || needAugmentedSlotMode(fnBody, ids, state) || (!['mp-baidu', 'mp-alipay'].includes(state.options.platform.name) && !isStaticSlotName)) {
if (replaceId(fnBody, ids)) {
const test = t.callExpression(t.identifier('$hasSSP'), [vueId])
// scopedSlotsCompiler auto
......
......@@ -318,7 +318,8 @@ function traverseRenderSlot (callExprNode, state) {
}
deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1
if (!deleteSlotName) {
if (!isStaticSlotName) {
// TODO 非原生支持作用域插槽的平台在未启用增强的模式下也允许使用动态插槽名
if (!isStaticSlotName && !['mp-baidu', 'mp-alipay'].includes(state.options.platform.name)) {
state.errors.add(uniI18n.__('templateCompiler.notSupportDynamicSlotName', { 0: 'v-slot' }))
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册