Skip to content

Commit

Permalink
fix the default export with hoc
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm authored and danielduan committed Oct 24, 2019
1 parent f5339d2 commit 1b4970f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ function injectReactDocgenInfo(path, state, code, t) {
docNode
));

const defaultExportDeclaration = program.get('body').find(t.isExportDefaultDeclaration);
const defaultExportDeclaration = program.get('body').find((node) => {
const isHoC = t.isCallExpression(node.get('declaration').node)
return (
t.isExportDefaultDeclaration(node) &&
(node.get('declaration').node.name === exportName || isHoC)
);
});

if (defaultExportDeclaration) {
defaultExportDeclaration.insertBefore(docgenInfo);
Expand Down
17 changes: 9 additions & 8 deletions test/fixtures/multiple-exports/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ exports.ErrorBox2 = ErrorBox2;
ErrorBox2.propTypes = {
children2: _react["default"].PropTypes.node.isRequired
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
STORYBOOK_REACT_CLASSES["test/fixtures/multiple-exports/actual.js"] = {
name: "ErrorBox",
docgenInfo: ErrorBox.__docgenInfo,
path: "test/fixtures/multiple-exports/actual.js"
};
}

ErrorBox2.__docgenInfo = {
"description": "",
"methods": [],
Expand All @@ -116,14 +125,6 @@ ErrorBox2.__docgenInfo = {
}
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
STORYBOOK_REACT_CLASSES["test/fixtures/multiple-exports/actual.js"] = {
name: "ErrorBox",
docgenInfo: ErrorBox.__docgenInfo,
path: "test/fixtures/multiple-exports/actual.js"
};
}

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
STORYBOOK_REACT_CLASSES["test/fixtures/multiple-exports/actual.js"] = {
name: "ErrorBox2",
Expand Down

0 comments on commit 1b4970f

Please sign in to comment.