Skip to content

Commit

Permalink
Fix props validation when using a prop as an object key (fixes #132)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 28, 2015
1 parent 8a50a24 commit 84d49dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ module.exports = function(context) {
return '__COMPUTED_PROP__';
}
return property.name;
case 'MemberExpression':
return void 0;
case 'Literal':
// Accept computed properties that are literal strings
if (typeof property.value === 'string') {
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,25 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
classes: true,
jsx: true
}
}, {
code: [
'var TestComp1 = React.createClass({',
' propTypes: {',
' size: React.PropTypes.string',
' },',
' render: function() {',
' var foo = {',
' baz: \'bar\'',
' };',
' var icons = foo[this.props.size].salut;',
' return <div>{icons}</div>;',
' }',
'});'
].join('\n'),
ecmaFeatures: {
classes: true,
jsx: true
}
}
],

Expand Down

0 comments on commit 84d49dc

Please sign in to comment.