From 51ffcd0b7abe2364db5f8d257ae260b8107bbecc Mon Sep 17 00:00:00 2001 From: Joshua Stiefer Date: Sat, 18 Nov 2017 11:29:34 -0700 Subject: [PATCH] Prevent jsx-no-bind crash The rule would assume a variable is initialized when checking a VariableDeclarator node. --- lib/rules/jsx-no-bind.js | 3 +++ tests/lib/rules/jsx-no-bind.js | 11 +++++++++++ 2 files changed, 14 insertions(+) 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') } ],