From db4532eb12261838c51942937014637fbe94366c Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 7 Aug 2020 12:54:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=AB=AF=20v-for=20=E4=B8=AD=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E9=83=A8=E5=88=86=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=BD=AC=E6=8D=A2=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20question/103466?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-extra.spec.js | 5 +++++ .../lib/script/traverse/member-expr.js | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js index b720fe778..a5880d491 100644 --- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js @@ -692,5 +692,10 @@ describe('mp:compiler-extra', () => { '{{item.m0}}', 'with(this){var l0=__map(list,function(item,index){var $orig=__get_orig(item);var m0=item?getValue(item):null;return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}' ) + assertCodegen( + '{{getValue(item)}}', + '{{item.m0}}', + 'with(this){var l0=__map(list,function(item,index){var $orig=__get_orig(item);var m0=item.length?getValue(item):null;return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}' + ) }) }) diff --git a/packages/uni-template-compiler/lib/script/traverse/member-expr.js b/packages/uni-template-compiler/lib/script/traverse/member-expr.js index 06e16d73a..c8a42dd7f 100644 --- a/packages/uni-template-compiler/lib/script/traverse/member-expr.js +++ b/packages/uni-template-compiler/lib/script/traverse/member-expr.js @@ -45,12 +45,12 @@ function findTest (path, state) { let test = t.arrayExpression([t.clone(path.container.test)]) traverse(test, { noScope: true, - MemberExpression (path) { + MemberExpression (path_) { const names = state.scoped.map(scoped => scoped.forItem) - const node = path.node + const node = path_.node const objectName = node.object.name - if (objectName === VAR_ROOT || names.includes(objectName)) { - path.replaceWith(node.property) + if (objectName === VAR_ROOT || (names.includes(objectName) && path.scope.hasOwnBinding(node.property.name))) { + path_.replaceWith(node.property) } } }) -- GitLab