Skip to content

Commit e0bae03

Browse files
authored
Merge pull request #1544 from jomasti/issue-1543
Prevent jsx-no-bind crash
2 parents c148893 + 51ffcd0 commit e0bae03

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/rules/jsx-no-bind.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ module.exports = {
135135
},
136136

137137
VariableDeclarator(node) {
138+
if (!node.init) {
139+
return;
140+
}
138141
const blockAncestors = getBlockStatementAncestors(node);
139142
const variableViolationType = getNodeViolationType(node.init);
140143

tests/lib/rules/jsx-no-bind.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ ruleTester.run('jsx-no-bind', rule, {
258258
'};'
259259
].join('\n'),
260260
parser: 'babel-eslint'
261+
},
262+
{
263+
// issue #1543: don't crash on uninitialized variables
264+
code: [
265+
'class Hello extends Component {',
266+
' render() {',
267+
' let click;',
268+
' return <div onClick={onClick}>Hello</div>;',
269+
' }',
270+
'}'
271+
].join('\n')
261272
}
262273
],
263274

0 commit comments

Comments
 (0)