Skip to content

Commit 728df92

Browse files
committed
Fix crash in ES5 components detection (fixes #286)
1 parent 7b625f0 commit 728df92

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/util/Components.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function componentRule(rule, context) {
110110
* @returns {Boolean} True if the node is a React ES5 component, false if not
111111
*/
112112
isES5Component: function(node) {
113-
return sourceCode.getText(node.parent.callee) === 'React.createClass';
113+
return node.parent && sourceCode.getText(node.parent.callee) === 'React.createClass';
114114
},
115115

116116
/**

tests/lib/rules/prop-types.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,20 @@ ruleTester.run('prop-types', rule, {
14711471
errors: [
14721472
{message: '\'text\' is missing in props validation'}
14731473
]
1474+
}, {
1475+
code: [
1476+
'for (var key in foo) {',
1477+
' var Hello = React.createClass({',
1478+
' render: function() {',
1479+
' return <div>Hello {this.props.name}</div>;',
1480+
' }',
1481+
' });',
1482+
'}'
1483+
].join('\n'),
1484+
parser: 'babel-eslint',
1485+
errors: [
1486+
{message: '\'name\' is missing in props validation'}
1487+
]
14741488
}
14751489
]
14761490
});

0 commit comments

Comments
 (0)