Skip to content

Commit 8682320

Browse files
committed
Fix crash in prop-types when encountering an empty variable declaration (fixes #130)
1 parent 3e280a6 commit 8682320

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/rules/prop-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ module.exports = function(context) {
533533
},
534534

535535
VariableDeclarator: function(node) {
536-
if (node.init.type !== 'ThisExpression' || node.id.type !== 'ObjectPattern') {
536+
if (!node.init || node.init.type !== 'ThisExpression' || node.id.type !== 'ObjectPattern') {
537537
return;
538538
}
539539
markPropTypesAsUsed(node);

tests/lib/rules/prop-types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,10 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
894894
code: [
895895
'class Hello extends React.Component {',
896896
' render() {',
897+
' var text;',
898+
' text = \'Hello \';',
897899
' let {props: {firstname}} = this;',
898-
' return <div>Hello {firstname}</div>;',
900+
' return <div>{text} {firstname}</div>;',
899901
' }',
900902
'}'
901903
].join('\n'),

0 commit comments

Comments
 (0)