From 23666102ca928cc401d97464c3600bb10c3d0e32 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 17 Jul 2020 15:45:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=9F=9F=E6=8F=92=E6=A7=BD=E5=BD=93=E4=BD=9C=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E6=8F=92=E6=A7=BD=E4=BD=BF=E7=94=A8=EF=BC=88=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=81QQ=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=EF=BC=89=20question/98634?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-weixin/lib/uni.compiler.js | 20 ++++++++++++++----- .../__tests__/compiler-mp-weixin.spec.js | 13 +++++++++--- .../__tests__/compiler.spec.js | 2 ++ .../lib/template/traverse.js | 6 +++--- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/uni-mp-weixin/lib/uni.compiler.js b/packages/uni-mp-weixin/lib/uni.compiler.js index 4a3c0ac4..11d9e52c 100644 --- a/packages/uni-mp-weixin/lib/uni.compiler.js +++ b/packages/uni-mp-weixin/lib/uni.compiler.js @@ -32,11 +32,21 @@ module.exports = { state.componentGenerics[componentName] = true - return { - type: componentName, - attr: props || {}, - children: [] - } + // 返回多个节点,支持作用域插槽当作普通插槽使用 + return [ + { + type: 'slot', + attr: { + name: slotName + }, + children: [] + }, + { + type: componentName, + attr: props || {}, + children: [] + } + ] }, resolveScopedSlots (slotName, { genCode, diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js index 05763b60..aa55c06e 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -72,16 +72,23 @@ describe('mp:compiler-mp-weixin', () => { }) it('generate scoped slot', () => { + assertCodegen( + '', + '', + function (res) { + expect(res.componentGenerics['scoped-slots-default']).toBe(true) + } + ) assertCodegen( // TODO vue-id '{{ user.lastName }}', - '', + '', function (res) { expect(res.componentGenerics['scoped-slots-default']).toBe(true) } ) assertCodegen( '{{ user.lastName }}', - '', + '', function (res) { expect(res.componentGenerics['scoped-slots-header']).toBe(true) } @@ -113,4 +120,4 @@ describe('mp:compiler-mp-weixin', () => { '' ) }) -}) +}) diff --git a/packages/uni-template-compiler/__tests__/compiler.spec.js b/packages/uni-template-compiler/__tests__/compiler.spec.js index cccdc17a..ffe3352f 100644 --- a/packages/uni-template-compiler/__tests__/compiler.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler.spec.js @@ -172,6 +172,8 @@ describe('mp:compiler', () => { it('generate single slot', () => { assertCodegen('', '') + assertCodegen('default', 'default') + assertCodegen('{{hello}}', '{{hello}}') assertCodegen('', '') }) diff --git a/packages/uni-template-compiler/lib/template/traverse.js b/packages/uni-template-compiler/lib/template/traverse.js index fcc98428..3954576e 100644 --- a/packages/uni-template-compiler/lib/template/traverse.js +++ b/packages/uni-template-compiler/lib/template/traverse.js @@ -164,7 +164,7 @@ function traverseCreateElement (callExprNode, state) { node.children = node.children.concat(normalizeChildren(traverseExpr(childNodes, state))) } else { node.children = normalizeChildren(traverseExpr(childNodes, state)) - } + } } return node } @@ -264,7 +264,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) { attr: { [prefix + 'if']: '{{$slots.' + slotName + '}}' }, - children: [slotNode] + children: [].concat(slotNode) }, { type: 'block', attr: { @@ -461,4 +461,4 @@ function traverseCreateTextVNode (callExprNode, state) { function traverseCreateEmptyVNode (callExprNode, state) { return '' -} +} -- GitLab