Skip to content

Commit

Permalink
Source-loader: Bypass if file has no exports (#9505)
Browse files Browse the repository at this point in the history
Source-loader: Bypass if file has no exports
  • Loading branch information
shilman committed Jan 17, 2020
2 parents 3a4f187 + 018b6d2 commit 3e52df6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
@@ -0,0 +1,8 @@
export default {
title: 'Core/Re-export source loader',
};

const Story1 = () => 'story1';
const Story2 = () => 'story2';

export { Story1, Story2 };
17 changes: 14 additions & 3 deletions lib/source-loader/src/server/build.js
Expand Up @@ -3,7 +3,16 @@ import { getRidOfUselessFilePrefixes } from './dependencies-lookup/getRidOfUsele

export function transform(inputSource) {
return readStory(this, inputSource)
.then(getRidOfUselessFilePrefixes)
.then(sourceObject => {
// if source-loader had trouble parsing the story exports, return the original story
// example is
// const myStory = () => xxx
// export { myStory }
if (!sourceObject.source || sourceObject.source.length === 0) {
return { source: inputSource };
}
return getRidOfUselessFilePrefixes(sourceObject);
})
.then(
({
prefix,
Expand All @@ -15,7 +24,8 @@ export function transform(inputSource) {
localDependencies,
idsToFrameworks,
}) => {
const preamble = `
const preamble = prefix
? `
/* eslint-disable */
// @ts-nocheck
// @ts-ignore
Expand All @@ -36,7 +46,8 @@ var __MODULE_DEPENDENCIES__ = ${JSON.stringify(dependencies)};
var __LOCAL_DEPENDENCIES__ = ${JSON.stringify(localDependencies)};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = ${JSON.stringify(idsToFrameworks)};
`;
`
: '';
return `${preamble}\n${source}`;
}
);
Expand Down

1 comment on commit 3e52df6

@vercel
Copy link

@vercel vercel bot commented on 3e52df6 Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.