Skip to content

Commit 6829c5c

Browse files
authored
Merge pull request #1560 from jomasti/issue-1559
Fix crash in no-access-state-in-setstate
2 parents f06db3d + 9cbd67e commit 6829c5c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/rules/no-access-state-in-setstate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = {
9595
node: node
9696
});
9797
break;
98-
} else if (current.type === 'FunctionExpression') {
98+
} else if (current.type === 'FunctionExpression' && current.parent.key) {
9999
methods.push({
100100
methodName: current.parent.key.name,
101101
node: node

tests/lib/rules/no-access-state-in-setstate.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ ruleTester.run('no-access-state-in-setstate', rule, {
4646
'});'
4747
].join('\n'),
4848
parserOptions: parserOptions
49+
}, {
50+
// issue 1559: don't crash
51+
code: `
52+
var SearchForm = createReactClass({
53+
render: function () {
54+
return (
55+
<div>
56+
{(function () {
57+
if (this.state.prompt) {
58+
return <div>{this.state.prompt}</div>
59+
}
60+
}).call(this)}
61+
</div>
62+
);
63+
}
64+
});
65+
`,
66+
parserOptions: parserOptions
4967
}],
5068

5169
invalid: [{

0 commit comments

Comments
 (0)