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

Source-loader: Bypass if file has no exports #9505

Merged
merged 1 commit into from Jan 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

what's the concept of prefix? can you make a short comment above this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Its not specific to prefix, just to signify the source loader is not parsing this file. Also prevents an rte since prefix was being used without a check below

Copy link
Member Author

Choose a reason for hiding this comment

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

added comment

? `
/* 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