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 345c51e990313c0b1d7bdc2e6d867fced8a70161..2b41eef7b6198416bf4c4ab50111399d5cbd30aa 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
@@ -228,6 +228,14 @@ describe('mp:compiler-mp-weixin', () => {
scopedSlotsCompiler: 'augmented'
}
)
+ assertCodegen(
+ '{{item}}{{item}}',
+ '{{$root.m1}}{{$root.m3}}',
+ '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', () => {
diff --git a/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js b/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
index 039a7f6ea289f4583026ecc1555d04d77006a854..eb8af7b83e50c680f4512a7b34641c04359f3e0c 100644
--- a/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
+++ b/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
@@ -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
}