Skip to content

Commit

Permalink
Fix crash in prop-types when reassigning props (fixes #345)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Dec 5, 2015
1 parent 7800ab1 commit be3b7f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,11 @@ module.exports = Components.detect(function(context, components, utils) {
},

VariableDeclarator: function(node) {
var destructuring = node.init && node.id && node.id.type === 'ObjectPattern';
// let {props: {firstname}} = this
var thisDestructuring = node.init && node.init.type === 'ThisExpression' && node.id.type === 'ObjectPattern';
var thisDestructuring = destructuring && node.init.type === 'ThisExpression';
// let {firstname} = props
var statelessDestructuring = node.init && node.init.name === 'props' && utils.getParentStatelessComponent();
var statelessDestructuring = destructuring && node.init.name === 'props' && utils.getParentStatelessComponent();

if (!thisDestructuring && !statelessDestructuring) {
return;
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@ ruleTester.run('prop-types', rule, {
ecmaFeatures: {
jsx: true
}
}, {
// Validation is ignored on reassigned props object
code: [
'const statelessComponent = (props) => {',
' let newProps = props;',
' return <span>{newProps.someProp}</span>;',
'}'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit be3b7f3

Please sign in to comment.