Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #66 #99

Merged
merged 3 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## NEXT
- Fix error on attempted propTypes generation for non-component function (#66)

## 3.1.2
- Fix bug with functions defaulting to react components (#97)

## 3.1.0

- Add support for top-level propTypes assignment of imported types (#88)
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/__snapshots__/test-issue-66.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports[`test issue 66 1`] = `
"\"use strict\";

Object.defineProperty(exports, \"__esModule\", {
value: true
});

exports.default = function (url, options) {
var Html = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultHtml;


return React.createElement(\"div\", null);
};"
`;
25 changes: 25 additions & 0 deletions src/__tests__/test-issue-66.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const babel = require('babel-core');
const content = `

// @flow

export default function(
url: string,
options: PhenomicStaticConfig,
Html: Function = DefaultHtml
): Promise<string> {

return <div/>;
}


`;

it('issue 66', () => {
const res = babel.transform(content, {
babelrc: false,
presets: ['es2015', 'stage-1', 'react'],
plugins: ['syntax-flow', require('../')],
}).code;
expect(res).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const getPropsForTypeAnnotation = typeAnnotation => {
|| typeAnnotation.type === 'AnyTypeAnnotation') {
props = convertNodeToPropTypes(typeAnnotation);
}
else if (typeAnnotation.properties != null || typeAnnotation.type != null) {
$debug('typeAnnotation not of expected type, not generating propTypes: ', typeAnnotation);
}
else {
throw new Error(`Expected prop types, but found none. This is a bug in ${PLUGIN_NAME}`);
}
Expand Down