Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iterateProperties to support arrow functions #1064

Merged
merged 4 commits into from Mar 14, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/utils/index.js
Expand Up @@ -693,6 +693,8 @@ module.exports = {
yield * this.iterateObjectExpression(item.value, name)
} else if (item.value.type === 'FunctionExpression') {
yield * this.iterateFunctionExpression(item.value, name)
} else if (item.value.type === 'ArrowFunctionExpression') {
yield * this.iterateArrowFunctionExpression(item.value, name)
}
}
},
Expand Down Expand Up @@ -745,6 +747,24 @@ module.exports = {
}
},

/**
* Return generator with all elements inside ArrowFunctionExpression
* @param {ASTNode} node Node to check
* @param {string} groupName Name of parent group
*/
* iterateArrowFunctionExpression (node, groupName) {
assert(node.type === 'ArrowFunctionExpression')
if (node.body.type === 'BlockStatement') {
for (const item of node.body.body) {
if (item.type === 'ReturnStatement' && item.argument && item.argument.type === 'ObjectExpression') {
yield * this.iterateObjectExpression(item.argument, groupName)
}
}
} else if (node.body.type === 'ObjectExpression') {
yield * this.iterateObjectExpression(node.body, groupName)
}
},

/**
* Find all functions which do not always return values
* @param {boolean} treatUndefinedAsUnspecified
Expand Down