Skip to content

Commit

Permalink
Fix prop-types crash with Flow spread operator (fixes #1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed May 7, 2017
1 parent 7f53bdb commit dd10133
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,10 @@ module.exports = {
switch (propTypes && propTypes.type) {
case 'ObjectTypeAnnotation':
iterateProperties(propTypes.properties, function(key, value) {
if (!value) {
ignorePropsValidation = true;
return;
}
declaredPropTypes[key] = buildTypeAnnotationDeclarationTypes(value);
});
break;
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,20 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type Person = {',
' ...data,',
' lastname: string',
'};',
'class Hello extends React.Component {',
' props: Person;',
' render () {',
' return <div>Hello {this.props.firstname}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

4 comments on commit dd10133

@ljharb
Copy link
Member

@ljharb ljharb commented on dd10133 May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue had different syntax - with pipes inside the curlies. Is this the same thing?

@yannickcr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code triggered the same crash as the code in the original issue.

But I do not use Flow and I do not know the difference between the two syntaxes 😐

@ljharb
Copy link
Member

@ljharb ljharb commented on dd10133 May 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a test for both syntaxes.

@EugeneZ
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, pipes indicate that the type is "exact" as opposed to loose. They are the same node type to babel, just with an exact flag set.

Please sign in to comment.