提交 cd5c3cdd 编写于 作者: Q qiang

fix: 修复小程序端for循环中复杂表达式报错的问题 question/102443

上级 9346f034
...@@ -4,15 +4,6 @@ function isMatch (name, forItem, forIndex) { ...@@ -4,15 +4,6 @@ function isMatch (name, forItem, forIndex) {
return name === forItem || name === 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) { function findScoped (path, state) {
if (!path) { if (!path) {
return state return state
...@@ -23,30 +14,17 @@ function findScoped (path, state) { ...@@ -23,30 +14,17 @@ function findScoped (path, state) {
forIndex forIndex
} = scoped } = scoped
let match = false let match = false
if (path.isIdentifier() || path.isMemberExpression()) { path.traverse({
match = isMatch(getIdentifierName(path.node), forItem, forIndex) noScope: true,
} else { Identifier (path) {
path.traverse({ if (!match && path.key !== 'key' && (path.key !== 'property' || path.parent.computed)) {
noScope: true, match = isMatch(path.node.name, forItem, forIndex)
Identifier (path) { if (match) {
if (!match) { path.stop()
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()
} }
} }
}) }
} })
return match return match
}) })
if (!scoped && state.scoped.length > 1) { if (!scoped && state.scoped.length > 1) {
...@@ -75,4 +53,4 @@ module.exports = function getMemberExpr (path, name, init, state, variableDeclar ...@@ -75,4 +53,4 @@ module.exports = function getMemberExpr (path, name, init, state, variableDeclar
const contextIdentifier = t.identifier(scoped.context) const contextIdentifier = t.identifier(scoped.context)
contextIdentifier.$mpProcessed = true contextIdentifier.$mpProcessed = true
return t.memberExpression(contextIdentifier, identifier) return t.memberExpression(contextIdentifier, identifier)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册