From 9dbf5080863f77a0cace75f8f6df776de6fdd9a2 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 6 Apr 2022 17:00:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E4=BF=AE=E5=A4=8Dv-if=E4=B8=AD?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=8C=85=E5=90=AB=E6=88=90=E5=91=98=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E5=92=8C=E9=80=BB=E8=BE=91=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=E7=BC=96=E8=AF=91=E5=88=B0=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=88question/142293=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-extra.spec.js | 10 ++++++++++ .../lib/script/traverse/visitor.js | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js index f2385697f..d5b1d2d63 100644 --- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js @@ -797,6 +797,16 @@ describe('mp:compiler-extra', () => { '{{$root.m1}}', 'with(this){var m0=test1(key)&&test2(key);var m1=m0?getValue(key):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}' ) + assertCodegen( + '{{getValue(key)}}', + '{{$root.m0}}', + 'with(this){var g0=test.test(key)&&test2(key);var m0=g0?getValue(key):null;$mp.data=Object.assign({},{$root:{g0:g0,m0:m0}})}' + ) + assertCodegen( + '{{getValue(key)}}', + '{{$root.m0}}', + 'with(this){var g0=show?test.test(key)&&test2(key):null;var m0=show&&g0?getValue(key):null;$mp.data=Object.assign({},{$root:{g0:g0,m0:m0}})}' + ) assertCodegen( '{{getValue(item)}}', '{{item.m0}}', diff --git a/packages/uni-template-compiler/lib/script/traverse/visitor.js b/packages/uni-template-compiler/lib/script/traverse/visitor.js index bec219549..08f3bd4d4 100644 --- a/packages/uni-template-compiler/lib/script/traverse/visitor.js +++ b/packages/uni-template-compiler/lib/script/traverse/visitor.js @@ -251,6 +251,11 @@ module.exports = { t.isMemberExpression(callee) // message.split('').reverse().join('') ) { // Object.assign... + path = path.findParent((path) => path.isLogicalExpression()) || path + path.skip() + if (path.findParent((path) => path.shouldSkip)) { + return + } path.replaceWith(getMemberExpr(path, IDENTIFIER_GLOBAL, path.node, this)) } }, -- GitLab