Skip to content

Commit a46420d

Browse files
committed
Fix crash when propTypes don't have any parent (fixes #182)
1 parent 07f6ba9 commit a46420d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/rules/prop-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ module.exports = function(context) {
466466
// ie: ClassX.propTypes.a.b.c = ...
467467
while (
468468
propTypes &&
469+
propTypes.parent &&
469470
propTypes.parent.type !== 'AssignmentExpression' &&
470471
propTypes.property &&
471472
curDeclaredPropTypes
@@ -480,7 +481,7 @@ module.exports = function(context) {
480481
propTypes = null;
481482
}
482483
}
483-
if (propTypes && propTypes.property) {
484+
if (propTypes && propTypes.parent && propTypes.property) {
484485
curDeclaredPropTypes[propTypes.property.name] =
485486
buildReactDeclarationTypes(propTypes.parent.right);
486487
}

tests/lib/rules/prop-types.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,13 @@ ruleTester.run('prop-types', rule, {
698698
'};'
699699
].join('\n'),
700700
parser: 'babel-eslint'
701+
}, {
702+
code: [
703+
'const SomeComponent = React.createClass({',
704+
' propTypes: SomeOtherComponent.propTypes',
705+
'});'
706+
].join('\n'),
707+
parser: 'babel-eslint'
701708
}
702709
],
703710

0 commit comments

Comments
 (0)