Skip to content

Commit 2d11982

Browse files
committed
Fix prop-types crash (fixes #389)
1 parent 1f5a340 commit 2d11982

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/rules/prop-types.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ module.exports = Components.detect(function(context, components, utils) {
272272
}
273273

274274
if (
275+
value &&
275276
value.type === 'MemberExpression' &&
276277
value.property &&
277278
value.property.name &&
@@ -282,6 +283,7 @@ module.exports = Components.detect(function(context, components, utils) {
282283

283284
// Verify React.PropTypes that are functions
284285
if (
286+
value &&
285287
value.type === 'CallExpression' &&
286288
value.callee &&
287289
value.callee.property &&
@@ -597,6 +599,10 @@ module.exports = Components.detect(function(context, components, utils) {
597599
break;
598600
case 'ObjectExpression':
599601
iterateProperties(propTypes.properties, function(key, value) {
602+
if (!value) {
603+
ignorePropsValidation = true;
604+
return;
605+
}
600606
declaredPropTypes[key] = buildReactDeclarationTypes(value);
601607
});
602608
break;

tests/lib/rules/prop-types.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,23 @@ ruleTester.run('prop-types', rule, {
10211021
'}'
10221022
].join('\n'),
10231023
parser: 'babel-eslint'
1024+
}, {
1025+
// Ignore component validation if propTypes are composed using spread
1026+
code: [
1027+
'class Hello extends React.Component {',
1028+
' render() {',
1029+
' return <div>Hello {this.props.firstName} {this.props.lastName}</div>;',
1030+
' }',
1031+
'};',
1032+
'const otherPropTypes = {',
1033+
' lastName: React.PropTypes.string',
1034+
'};',
1035+
'Hello.propTypes = {',
1036+
' ...otherPropTypes,',
1037+
' firstName: React.PropTypes.string',
1038+
'};'
1039+
].join('\n'),
1040+
parserOptions: parserOptions
10241041
}
10251042
],
10261043

0 commit comments

Comments
 (0)