Skip to content

Commit 84d49dc

Browse files
committed
Fix props validation when using a prop as an object key (fixes #132)
1 parent 8a50a24 commit 84d49dc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/rules/prop-types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ module.exports = function(context) {
338338
return '__COMPUTED_PROP__';
339339
}
340340
return property.name;
341+
case 'MemberExpression':
342+
return void 0;
341343
case 'Literal':
342344
// Accept computed properties that are literal strings
343345
if (typeof property.value === 'string') {

tests/lib/rules/prop-types.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,25 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
493493
classes: true,
494494
jsx: true
495495
}
496+
}, {
497+
code: [
498+
'var TestComp1 = React.createClass({',
499+
' propTypes: {',
500+
' size: React.PropTypes.string',
501+
' },',
502+
' render: function() {',
503+
' var foo = {',
504+
' baz: \'bar\'',
505+
' };',
506+
' var icons = foo[this.props.size].salut;',
507+
' return <div>{icons}</div>;',
508+
' }',
509+
'});'
510+
].join('\n'),
511+
ecmaFeatures: {
512+
classes: true,
513+
jsx: true
514+
}
496515
}
497516
],
498517

0 commit comments

Comments
 (0)