diff --git a/examples/official-storybook/stories/core/interleaved-exports.stories.js b/examples/official-storybook/stories/core/interleaved-exports.stories.js
new file mode 100644
index 000000000000..b585bfa6b3d2
--- /dev/null
+++ b/examples/official-storybook/stories/core/interleaved-exports.stories.js
@@ -0,0 +1,16 @@
+/* eslint-disable import/first,import/no-duplicates */
+import React from 'react';
+import { action } from '@storybook/addon-actions';
+
+export default {
+ title: 'Core/Interleaved exports',
+ parameters: { chromatic: { disable: true } },
+};
+
+import { Welcome } from '@storybook/react/demo';
+
+export const First = () => ;
+
+import { Button } from '@storybook/react/demo';
+
+export const Second = () => ;
diff --git a/lib/source-loader/src/server/__snapshots__/build.test.js.snap b/lib/source-loader/src/server/__snapshots__/build.test.js.snap
deleted file mode 100644
index 1e30b863dd27..000000000000
--- a/lib/source-loader/src/server/__snapshots__/build.test.js.snap
+++ /dev/null
@@ -1,50 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`insertAfterImports addon-notes 1`] = `
-"import React from 'react';
-
-import BaseButton from '../components/BaseButton';
-import markdownNotes from './notes/notes.md';
-INSERT
-
-
-
-const markdownString = '...';"
-`;
-
-exports[`insertAfterImports imports 1`] = `
-"import './foo';
-import './bar';
-INSERT
-
-
-whatever;"
-`;
-
-exports[`insertAfterImports multi-line imports 1`] = `
-"import 'foo';
-import {
- bar
-} from 'baz';
-INSERT
-
-
-whatever;"
-`;
-
-exports[`insertAfterImports no imports 1`] = `
-"
-INSERT
-
-foo bar;
-baz;"
-`;
-
-exports[`insertAfterImports single-line imports 1`] = `
-"import 'foo';
-import { bar } from 'baz';
-INSERT
-
-
-whatever;"
-`;
diff --git a/lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js b/lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js
index f80ae30b22fd..29b77043235e 100644
--- a/lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js
+++ b/lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js
@@ -257,22 +257,6 @@ export function findDependencies(ast) {
return { dependencies, storiesOfIdentifiers };
}
-export function endOfImports(ast) {
- let end = 0;
-
- estraverse.traverse(ast, {
- fallback: 'iteration',
- enter: node => {
- patchNode(node);
-
- if (node.type === 'ImportDeclaration') {
- end = Math.max(node.end, end);
- }
- },
- });
- return end;
-}
-
export function popParametersObjectFromDefaultExport(source, ast) {
let splicedSource = source;
let parametersSliceOfCode = '';
diff --git a/lib/source-loader/src/server/build.js b/lib/source-loader/src/server/build.js
index eb9fb4a86340..cd7cf7158599 100644
--- a/lib/source-loader/src/server/build.js
+++ b/lib/source-loader/src/server/build.js
@@ -1,26 +1,5 @@
-import { getOptions } from 'loader-utils';
import { readStory } from './dependencies-lookup/readAsObject';
import { getRidOfUselessFilePrefixes } from './dependencies-lookup/getRidOfUselessFilePrefixes';
-import getParser from './abstract-syntax-tree/parsers';
-import { endOfImports } from './abstract-syntax-tree/traverse-helpers';
-
-export function insertAfterImports(classLoader, insert, source) {
- const options = getOptions(classLoader) || {};
- let ast;
- try {
- ast = getParser(options.parser || classLoader.extension || 'javascript').parse(source);
- } catch (e) {
- // if not working, then we will fallback to not adding anything
- // perhaps the code was not written in javascript
- return source;
- }
- if (!ast) return `${insert}${source}`;
- const endOfImportsIndex = endOfImports(ast);
- const result = `${source.substring(0, endOfImportsIndex)}\n${insert}\n${source.substring(
- endOfImportsIndex
- )}`;
- return result;
-}
export function transform(inputSource) {
return readStory(this, inputSource)
@@ -38,6 +17,7 @@ export function transform(inputSource) {
}) => {
const preamble = `
/* eslint-disable */
+// @ts-nocheck
// @ts-ignore
var withSourceLoader = require('@storybook/source-loader/preview').withSource;
// @ts-ignore
@@ -57,8 +37,7 @@ var __LOCAL_DEPENDENCIES__ = ${JSON.stringify(localDependencies)};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = ${JSON.stringify(idsToFrameworks)};
`;
- return insertAfterImports(this, preamble, source);
- // return `${preamble}${source}`;
+ return `${preamble}\n${source}`;
}
);
}
diff --git a/lib/source-loader/src/server/build.test.js b/lib/source-loader/src/server/build.test.js
deleted file mode 100644
index 7b4a15fb73a4..000000000000
--- a/lib/source-loader/src/server/build.test.js
+++ /dev/null
@@ -1,54 +0,0 @@
-import { insertAfterImports } from './build';
-
-const insert = 'INSERT\n';
-
-describe('insertAfterImports', () => {
- it('no imports', () => {
- const noImports = `
-foo bar;
-baz;
- `.trim();
- expect(insertAfterImports({}, insert, noImports)).toMatchSnapshot();
- });
-
- it('imports', () => {
- const hasImports = `
-import './foo';
-import './bar';
-whatever;
- `.trim();
- expect(insertAfterImports({}, insert, hasImports)).toMatchSnapshot();
- });
-
- it('single-line imports', () => {
- const hasImports = `
-import 'foo';
-import { bar } from 'baz';
-whatever;
- `.trim();
- expect(insertAfterImports({}, insert, hasImports)).toMatchSnapshot();
- });
-
- it('multi-line imports', () => {
- const hasImports = `
-import 'foo';
-import {
- bar
-} from 'baz';
-whatever;
- `.trim();
- expect(insertAfterImports({}, insert, hasImports)).toMatchSnapshot();
- });
-
- it('addon-notes', () => {
- const notesStory = `
- import React from 'react';
-
-import BaseButton from '../components/BaseButton';
-import markdownNotes from './notes/notes.md';
-
-const markdownString = '...';
- `.trim();
- expect(insertAfterImports({}, insert, notesStory)).toMatchSnapshot();
- });
-});