From cd5c3cddca2c12cb895f522479e39e56d99b0e3e Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 28 Jul 2020 17:10:23 +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=AFfor=E5=BE=AA=E7=8E=AF=E4=B8=AD=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20question/102443?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/script/traverse/member-expr.js | 42 +++++-------------- 1 file changed, 10 insertions(+), 32 deletions(-) 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 e6cd4b36..9678461d 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) -} +} -- GitLab