diff --git a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/basic.output.js b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/basic.output.js
index 33fa146ab94..1fd0819fbba 100644
--- a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/basic.output.js
+++ b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/basic.output.js
@@ -5,21 +5,19 @@ import Button from './Button';
import { storiesOf, configure } from '@storybook/react';
import { action } from '@storybook/addon-actions';
-{
- export default {
- title: 'Button',
- };
-
- export const story1 = () => ;
- export const story2 = () => ;
- story2.title = 'second story';
-
- export const story3 = () => (
-
-
-
-
- );
-
- story3.title = 'complex story';
+export default {
+ title: 'Button',
};
+
+export const story1 = () => ;
+export const story2 = () => ;
+story2.title = 'second story';
+
+export const story3 = () => (
+
+
+
+
+ );
+
+story3.title = 'complex story';
diff --git a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/decorators.output.js b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/decorators.output.js
index 962cb336169..3a7e19019ce 100644
--- a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/decorators.output.js
+++ b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/decorators.output.js
@@ -2,13 +2,10 @@
import React from 'react';
import Button from './Button';
-// This isn't a valid story, but it tests the `import { comp } from ...` case
-{
- export default {
- title: 'Some.Button',
- decorators: [withKnobs, storyFn => {storyFn}
],
- };
-
- export const story1 = () => ;
- story1.title = 'with decorator';
+export default {
+ title: 'Some.Button',
+ decorators: [withKnobs, storyFn => {storyFn}
],
};
+
+export const story1 = () => ;
+story1.title = 'with decorator';
diff --git a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/multi.output.js b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/multi.output.js
index e73ba696ff8..ff1fefb3d2b 100644
--- a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/multi.output.js
+++ b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/multi.output.js
@@ -2,23 +2,16 @@
import React from 'react';
import Button from './Button';
-// If we have multiple storiesOf calls, export multiple defaults. It's not valid
-// JS but will still save the user time in converting.
-
-{
- export default {
- title: 'Button1',
- };
-
- export const story1 = () => ;
- export const story2 = () => ;
+export default {
+ title: 'Button1',
};
-{
- export default {
- title: 'Button2',
- };
+export const story1 = () => ;
+export const story2 = () => ;
- export const story1 = () => ;
- export const story2 = () => ;
-};
\ No newline at end of file
+export default {
+ title: 'Button2',
+};
+
+export const story1 = () => ;
+export const story2 = () => ;
diff --git a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/parameters.output.js b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/parameters.output.js
index b83e6ecd2d5..7dcafe93c2e 100644
--- a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/parameters.output.js
+++ b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/parameters.output.js
@@ -4,17 +4,15 @@ import Button from './Button';
import { storiesOf } from '@storybook/react';
-{
- export default {
- title: 'Button',
+export default {
+ title: 'Button',
- parameters: {
- component: Button,
- foo: 1,
- bar: 2,
- },
- };
-
- export const story1 = () => ;
- story1.title = 'with kind parameters';
+ parameters: {
+ component: Button,
+ foo: 1,
+ bar: 2,
+ },
};
+
+export const story1 = () => ;
+story1.title = 'with kind parameters';
diff --git a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/story-parameters.output.js b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/story-parameters.output.js
index 698e15a10a2..555426b67b9 100644
--- a/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/story-parameters.output.js
+++ b/lib/codemod/src/transforms/__testfixtures__/convert-to-module-format/story-parameters.output.js
@@ -4,22 +4,20 @@ import Button from './Button';
import { storiesOf } from '@storybook/react';
-{
- export default {
- title: 'Button',
+export default {
+ title: 'Button',
+};
+
+export const story1 = () => ;
+story1.title = 'with story parameters';
+
+story1.parameters = {
+ header: false,
+ inline: true,
};
- export const story1 = () => ;
- story1.title = 'with story parameters';
+export const foo = () => ;
- story1.parameters = {
- header: false,
- inline: true,
- };
-
- export const foo = () => ;
-
- foo.parameters = {
- bar: 1,
- };
-};
+foo.parameters = {
+ bar: 1,
+ };
diff --git a/lib/codemod/src/transforms/convert-to-module-format.js b/lib/codemod/src/transforms/convert-to-module-format.js
index 05fbbcb0b6a..1b2e09dedab 100644
--- a/lib/codemod/src/transforms/convert-to-module-format.js
+++ b/lib/codemod/src/transforms/convert-to-module-format.js
@@ -140,7 +140,9 @@ export default function transformer(file, api) {
counter += 1;
});
- return j.blockStatement(statements);
+ statements.reverse();
+ statements.forEach(s => path.parent.insertAfter(s));
+ base.remove();
}
// each top-level add expression corresponds to the last "add" of the chain.
@@ -149,9 +151,8 @@ export default function transformer(file, api) {
.find(j.CallExpression)
.filter(add => add.node.callee.property && add.node.callee.property.name === 'add')
.filter(add => add.node.arguments.length >= 2 && add.node.arguments[0].type === 'Literal')
- .filter(add => add.parentPath.node.type === 'ExpressionStatement');
-
- topLevelAddExpressions.replaceWith(convertToModuleExports);
+ .filter(add => add.parentPath.node.type === 'ExpressionStatement')
+ .forEach(convertToModuleExports);
return root.toSource({ quote: 'single', trailingComma: 'true', tabWidth: 2 });
}