diff --git a/lib/rules/jsx-no-bind.js b/lib/rules/jsx-no-bind.js index aef6a6aab8..f463f1c992 100644 --- a/lib/rules/jsx-no-bind.js +++ b/lib/rules/jsx-no-bind.js @@ -135,6 +135,9 @@ module.exports = { }, VariableDeclarator(node) { + if (!node.init) { + return; + } const blockAncestors = getBlockStatementAncestors(node); const variableViolationType = getNodeViolationType(node.init); diff --git a/tests/lib/rules/jsx-no-bind.js b/tests/lib/rules/jsx-no-bind.js index ec467f98f7..244acaed56 100644 --- a/tests/lib/rules/jsx-no-bind.js +++ b/tests/lib/rules/jsx-no-bind.js @@ -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
Hello
;', + ' }', + '}' + ].join('\n') } ],