Skip to content

Commit

Permalink
Merge pull request #1560 from jomasti/issue-1559
Browse files Browse the repository at this point in the history
Fix crash in no-access-state-in-setstate
  • Loading branch information
yannickcr committed Nov 21, 2017
2 parents f06db3d + 9cbd67e commit 6829c5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = {
node: node
});
break;
} else if (current.type === 'FunctionExpression') {
} else if (current.type === 'FunctionExpression' && current.parent.key) {
methods.push({
methodName: current.parent.key.name,
node: node
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ ruleTester.run('no-access-state-in-setstate', rule, {
'});'
].join('\n'),
parserOptions: parserOptions
}, {
// issue 1559: don't crash
code: `
var SearchForm = createReactClass({
render: function () {
return (
<div>
{(function () {
if (this.state.prompt) {
return <div>{this.state.prompt}</div>
}
}).call(this)}
</div>
);
}
});
`,
parserOptions: parserOptions
}],

invalid: [{
Expand Down

0 comments on commit 6829c5c

Please sign in to comment.