Skip to content

Commit

Permalink
Fix crash in no-access-state-in-setstate
Browse files Browse the repository at this point in the history
With an IIFE in the return statement of render that uses `this.state`,
there is no parent with a name. In this rule, the method names are later
checked to see if they are being called elsewhere in the file. Since
there is no intention of this being called anywhere else, the IIFE will
just be skipped being added to the list of methods.
  • Loading branch information
jomasti committed Nov 21, 2017
1 parent f06db3d commit 9cbd67e
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
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
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 9cbd67e

Please sign in to comment.