diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
index b38ae059e431936a2c34b4187b05c6729692e50f..7b6b75a1926454ee13061d44a8ba3e1be38bc999 100644
--- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
@@ -697,6 +697,11 @@ describe('mp:compiler-extra', () => {
'{{$root.m1}}',
'with(this){var m0=getValue(key);var m1=m0?getValue(key):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}'
)
+ assertCodegen(
+ '{{getValue(key)}}',
+ '{{$root.m2}}',
+ 'with(this){var m0=test1(key);var m1=test2(key);var m2=m0&&m1?getValue(key):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1,m2:m2}})}'
+ )
assertCodegen(
'{{getValue(item)}}',
'{{item.m0}}',
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 f5d32f1a1bb350e8023e77e1cc973684b71fe825..fe9100ffe3f7fe77e3d9c1a32c6f63aa69e9047a 100644
--- a/packages/uni-template-compiler/lib/script/traverse/member-expr.js
+++ b/packages/uni-template-compiler/lib/script/traverse/member-expr.js
@@ -71,18 +71,14 @@ function findTest (path, state) {
const property = node.property
const propertyName = property.name
if (objectName === VAR_ROOT || (names.includes(objectName) && (propertyName === IDENTIFIER_METHOD || propertyName === IDENTIFIER_FILTER || propertyName === IDENTIFIER_GLOBAL))) {
- let property
- traverse(testOrig, {
- noScope: true,
- Identifier (identifierPath) {
- const node = identifierPath.node
- if (node.name === propertyName) {
- property = node
- identifierPath.stop()
- }
- }
- })
- memberExpressionPath.replaceWith(property)
+ const array = []
+ let tempPath = memberExpressionPath
+ while (tempPath.parentPath) {
+ const key = tempPath.key
+ array.unshift(typeof key === 'number' ? `[${key}]` : `.${key}`)
+ tempPath = tempPath.parentPath
+ }
+ memberExpressionPath.replaceWith(path.parentPath.get('test' + array.join('')).node.property)
}
}
})