Skip to content

Commit

Permalink
fix flow nested object type spread
Browse files Browse the repository at this point in the history
  • Loading branch information
rosskevin authored and ljharb committed Jun 13, 2017
1 parent 5b2f4e3 commit 7e5863e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/rules/prop-types.js
Expand Up @@ -480,13 +480,23 @@ module.exports = {
}
return true;
case 'ObjectTypeAnnotation':
let containsObjectTypeSpread = false;
var shapeTypeDefinition = {
type: 'shape',
children: {}
};
iterateProperties(annotation.properties, function(childKey, childValue) {
shapeTypeDefinition.children[childKey] = buildTypeAnnotationDeclarationTypes(childValue);
if (!childKey && !childValue) {
containsObjectTypeSpread = true;
} else {
shapeTypeDefinition.children[childKey] = buildTypeAnnotationDeclarationTypes(childValue);
}
});

// nested object type spread means we need to ignore/accept everything in this object
if (containsObjectTypeSpread) {
return true;
}
return shapeTypeDefinition;
case 'UnionTypeAnnotation':
var unionTypeDefinition = {
Expand Down
61 changes: 61 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -1414,6 +1414,67 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type Person = {',
' ...$Exact<data>,',
' lastname: string',
'};',
'class Hello extends React.Component {',
' props: Person;',
' render () {',
' return <div>Hello {this.props.firstname}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'import type {Data} from \'./Data\'',
'type Person = {',
' ...Data,',
' lastname: string',
'};',
'class Hello extends React.Component {',
' props: Person;',
' render () {',
' return <div>Hello {this.props.bar}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'import type {Data} from \'some-libdef-like-flow-typed-provides\'',
'type Person = {',
' ...Data,',
' lastname: string',
'};',
'class Hello extends React.Component {',
' props: Person;',
' render () {',
' return <div>Hello {this.props.bar}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'import type {BasePerson} from \'./types\'',
'type Props = {',
' person: {',
' ...$Exact<BasePerson>,',
' lastname: string',
' }',
'};',
'class Hello extends React.Component {',
' props: Props;',
' render () {',
' return <div>Hello {this.props.person.firstname}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type Person = {',
Expand Down

0 comments on commit 7e5863e

Please sign in to comment.