diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3aee2..441b793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/__tests__/__snapshots__/test-issue-66.js.snap b/src/__tests__/__snapshots__/test-issue-66.js.snap new file mode 100644 index 0000000..6b05c7e --- /dev/null +++ b/src/__tests__/__snapshots__/test-issue-66.js.snap @@ -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); +};" +`; diff --git a/src/__tests__/test-issue-66.js b/src/__tests__/test-issue-66.js new file mode 100644 index 0000000..9d2e384 --- /dev/null +++ b/src/__tests__/test-issue-66.js @@ -0,0 +1,25 @@ +const babel = require('babel-core'); +const content = ` + +// @flow + +export default function( + url: string, + options: PhenomicStaticConfig, + Html: Function = DefaultHtml +): Promise { + + return
; +} + + +`; + +it('issue 66', () => { + const res = babel.transform(content, { + babelrc: false, + presets: ['es2015', 'stage-1', 'react'], + plugins: ['syntax-flow', require('../')], + }).code; + expect(res).toMatchSnapshot(); +}); diff --git a/src/index.js b/src/index.js index 5dae5a0..cf84bc5 100644 --- a/src/index.js +++ b/src/index.js @@ -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}`); }