提交 1af0b60b 编写于 作者: Q qiang

fix(mp): 修复相同作用域插槽嵌套时在新版作用域编译模式编译错误的问题

上级 5b79464c
......@@ -228,6 +228,14 @@ describe('mp:compiler-mp-weixin', () => {
scopedSlotsCompiler: 'augmented'
}
)
assertCodegen(
'<my-component><template v-slot="{item}">{{item}}<my-component><template v-slot="{item}">{{item}}<template></my-component><template></my-component>',
'<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}<my-component vue-id="{{(\'551070e6-2\')+\',\'+(\'551070e6-1\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m2}}">{{$root.m3}}</block></block></my-component></block></block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?$getScopedSlotsParams("551070e6-1","default","item"):null;var m2=$hasScopedSlotsParams("551070e6-2");var m3=m2?$getScopedSlotsParams("551070e6-2","default","item"):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1,m2:m2,m3:m3}})}',
{
scopedSlotsCompiler: 'augmented'
}
)
})
it('generate scoped slot', () => {
......
......@@ -26,11 +26,12 @@ function needSlotMode (path, ids) {
function replaceId (path, ids) {
let replaced
const fnPath = path.parentPath
path.traverse({
noScope: true,
noScope: false,
Identifier (path) {
const name = path.node.name
if (name in ids && path.key !== 'key' && (path.key !== 'property' || path.parent.computed)) {
if (name in ids && path.key !== 'key' && (path.key !== 'property' || path.parent.computed) && path.scope.path === fnPath) {
path.replaceWith(ids[name])
replaced = true
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册