Skip to content

Commit

Permalink
Prevent jsx-no-bind crash
Browse files Browse the repository at this point in the history
The rule would assume a variable is initialized when checking a
VariableDeclarator node.
  • Loading branch information
jomasti committed Nov 18, 2017
1 parent c148893 commit 51ffcd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/jsx-no-bind.js
Expand Up @@ -135,6 +135,9 @@ module.exports = {
},

VariableDeclarator(node) {
if (!node.init) {
return;
}
const blockAncestors = getBlockStatementAncestors(node);
const variableViolationType = getNodeViolationType(node.init);

Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/jsx-no-bind.js
Expand Up @@ -258,6 +258,17 @@ ruleTester.run('jsx-no-bind', rule, {
'};'
].join('\n'),
parser: 'babel-eslint'
},
{
// issue #1543: don't crash on uninitialized variables
code: [
'class Hello extends Component {',
' render() {',
' let click;',
' return <div onClick={onClick}>Hello</div>;',
' }',
'}'
].join('\n')
}
],

Expand Down

0 comments on commit 51ffcd0

Please sign in to comment.