Skip to content

Commit

Permalink
[Fix] display-name: avoid crash on for..of
Browse files Browse the repository at this point in the history
Fixes #2137.
  • Loading branch information
ljharb committed Jan 17, 2019
1 parent 433cc3f commit e635964
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/util/Components.js
Expand Up @@ -567,7 +567,12 @@ function componentRule(rule, context) {
}
if (refId.type === 'MemberExpression') {
componentNode = refId.parent.right;
} else if (refId.parent && refId.parent.type === 'VariableDeclarator' && refId.parent.init.type !== 'Identifier') {
} else if (
refId.parent
&& refId.parent.type === 'VariableDeclarator'
&& refId.parent.init
&& refId.parent.init.type !== 'Identifier'
) {
componentNode = refId.parent.init;
}
break;
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -452,6 +452,17 @@ ruleTester.run('display-name', rule, {
export default React.memo(Component)
`
}, {
code: `
function F() {
let items = [];
let testData = [{a: "test1", displayName: "test2"}, {a: "test1", displayName: "test2"}];
for (let item of testData) {
items.push({a: item.a, b: item.displayName});
}
return <div>{items}</div>;
}
`
}],

invalid: [{
Expand Down

0 comments on commit e635964

Please sign in to comment.