Skip to content

Commit be3b7f3

Browse files
committed
Fix crash in prop-types when reassigning props (fixes #345)
1 parent 7800ab1 commit be3b7f3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/rules/prop-types.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,11 @@ module.exports = Components.detect(function(context, components, utils) {
566566
},
567567

568568
VariableDeclarator: function(node) {
569+
var destructuring = node.init && node.id && node.id.type === 'ObjectPattern';
569570
// let {props: {firstname}} = this
570-
var thisDestructuring = node.init && node.init.type === 'ThisExpression' && node.id.type === 'ObjectPattern';
571+
var thisDestructuring = destructuring && node.init.type === 'ThisExpression';
571572
// let {firstname} = props
572-
var statelessDestructuring = node.init && node.init.name === 'props' && utils.getParentStatelessComponent();
573+
var statelessDestructuring = destructuring && node.init.name === 'props' && utils.getParentStatelessComponent();
573574

574575
if (!thisDestructuring && !statelessDestructuring) {
575576
return;

tests/lib/rules/prop-types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,15 @@ ruleTester.run('prop-types', rule, {
953953
ecmaFeatures: {
954954
jsx: true
955955
}
956+
}, {
957+
// Validation is ignored on reassigned props object
958+
code: [
959+
'const statelessComponent = (props) => {',
960+
' let newProps = props;',
961+
' return <span>{newProps.someProp}</span>;',
962+
'}'
963+
].join('\n'),
964+
parser: 'babel-eslint'
956965
}
957966
],
958967

0 commit comments

Comments
 (0)