提交 cd5c3cdd 编写于 作者: Q qiang

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

上级 9346f034
......@@ -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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册