Skip to content

Commit

Permalink
fixes error for spread on imported type, resolves #204
Browse files Browse the repository at this point in the history
  • Loading branch information
brigand committed Aug 15, 2018
1 parent dd3a5b4 commit c48e247
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/__snapshots__/imported-spread-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`imported-spread 1`] = `
"'use strict';
var _other_module = require('./other_module');
var React = require('react');"
`;
24 changes: 24 additions & 0 deletions src/__tests__/imported-spread-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const babel = require('babel-core');
const content = `
var React = require('react');
import { type Foo } from './other_module';
type Props = {|
id: string,
...Foo,
|}
`;

it('imported-spread', () => {
const res = babel.transform(content, {
babelrc: false,
presets: ['es2015', 'stage-1', 'react'],
plugins: ['syntax-flow', require('../')],
}).code;

// The type shouldn't show up as we don't support
// spreads from imports
expect(res).not.toMatch(/Foo/);

expect(res).toMatchSnapshot();
});
5 changes: 5 additions & 0 deletions src/convertToPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export default function convertToPropTypes(node, importedTypes, internalTypes) {
}

const spreadShape = convertToPropTypes(subnode, importedTypes, internalTypes);

if (spreadShape.type === 'raw') {
return [];
}

const properties = spreadShape.properties;

// Unless or until the strange default behavior changes in flow (https://github.com/facebook/flow/issues/3214)
Expand Down

0 comments on commit c48e247

Please sign in to comment.