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 e6cd4b36d3d6a8064ef57dc27244a8a62a67b4a3..9678461d8e57cef35bc66c65e7ce2949dda44300 100644 --- a/packages/uni-template-compiler/lib/script/traverse/member-expr.js +++ b/packages/uni-template-compiler/lib/script/traverse/member-expr.js @@ -4,15 +4,6 @@ function isMatch (name, forItem, forIndex) { return name === forItem || name === forIndex } -function getIdentifierName (element) { - if (t.isMemberExpression(element)) { - return getIdentifierName(element.object) - } else if (t.isCallExpression(element)) { - return getIdentifierName(element.callee) - } - return element.name && element.name.split('.')[0] -} - function findScoped (path, state) { if (!path) { return state @@ -23,30 +14,17 @@ function findScoped (path, state) { forIndex } = scoped let match = false - if (path.isIdentifier() || path.isMemberExpression()) { - match = isMatch(getIdentifierName(path.node), forItem, forIndex) - } else { - path.traverse({ - noScope: true, - Identifier (path) { - if (!match) { - match = isMatch(path.node.name, forItem, forIndex) - if (match) { - path.stop() - } - } - }, - MemberExpression (path) { - if (!match) { - match = isMatch(getIdentifierName(path.node), forItem, forIndex) - if (match) { - path.stop() - } - path.skip() + path.traverse({ + noScope: true, + Identifier (path) { + if (!match && path.key !== 'key' && (path.key !== 'property' || path.parent.computed)) { + match = isMatch(path.node.name, forItem, forIndex) + if (match) { + path.stop() } } - }) - } + } + }) return match }) if (!scoped && state.scoped.length > 1) { @@ -75,4 +53,4 @@ module.exports = function getMemberExpr (path, name, init, state, variableDeclar const contextIdentifier = t.identifier(scoped.context) contextIdentifier.$mpProcessed = true return t.memberExpression(contextIdentifier, identifier) -} +}