Skip to content

Commit

Permalink
feat(mp-baidu): v-bind with scopedSlotsCompiler: legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Mar 15, 2023
1 parent f43c000 commit 9915211
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/uni-mp-baidu/lib/uni.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ module.exports = {
},
children: []
}
Object.keys(props).forEach(name => {
node.attr['var-' + name] = props[name].replace('{{', '').replace('}}', '')
})
if (typeof props === 'string') {
node.attr['s-bind'] = props.replace('{{', '').replace('}}', '')
} else {
Object.keys(props).forEach(name => {
node.attr['var-' + name] = props[name].replace('{{', '').replace('}}', '')
})
}
return node
},
resolveScopedSlots (slotName, {
Expand All @@ -31,4 +35,4 @@ module.exports = {
}
return node
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ describe('mp:compiler-mp-baidu', () => {
'<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>',
'<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>'
)
assertCodegen(
'<span><slot name="header" v-bind="user"></slot></span>',
'<label class="_span"><slot name="header" s-bind="user"></slot></label>'
)
})

it('generate scoped slot with scopedSlotsCompiler: auto', () => {
Expand Down
15 changes: 11 additions & 4 deletions packages/uni-template-compiler/lib/template/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,16 @@ function traverseRenderSlot (callExprNode, state) {
let deleteSlotName = false // 标记是否组件 slot 手动指定了 name="default"
if (state.options.scopedSlotsCompiler !== 'augmented' && callExprNode.arguments.length > 2) { // 作用域插槽
const props = {}
callExprNode.arguments[2].properties.forEach(property => {
props[property.key.value] = genCode(property.value)
})
const arg2 = callExprNode.arguments[2]
const arg3 = callExprNode.arguments[3]
let bindings
if (t.isObjectExpression(arg2)) {
arg2.properties.forEach(property => {
props[property.key.value] = genCode(property.value)
})
} else if (arg3) {
bindings = genCode(arg3)
}
deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1
if (!deleteSlotName) {
if (!isStaticSlotName) {
Expand All @@ -318,7 +325,7 @@ function traverseRenderSlot (callExprNode, state) {
delete props.SLOT_DEFAULT
return genSlotNode(
slotName,
state.options.platform.createScopedSlots(slotName, props, state),
state.options.platform.createScopedSlots(slotName, bindings || props, state),
callExprNode.arguments[1],
state
)
Expand Down

0 comments on commit 9915211

Please sign in to comment.