-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Fix variable collisions in storiesof-to-csf (#8106)
CLI: Fix variable collisions in storiesof-to-csf
- Loading branch information
Showing
14 changed files
with
114 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
title: 'Story', | ||
}; | ||
|
||
export const startCase = () => 'foo'; | ||
export const camelCase = () => 'foo'; | ||
|
||
camelCase.story = { | ||
name: 'camelCase', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
lib/codemod/src/transforms/__testfixtures__/storiesof-to-csf/collision.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
export const foo = 1; | ||
storiesOf('bar', module).add('foo', () => <button />); | ||
const bar = 1; | ||
const barStory = 1; | ||
const baz = 1; | ||
const bazStory1 = 1; | ||
|
||
storiesOf('foo', module) | ||
.add('foo', () => <button />) | ||
.add('bar', () => <button />) | ||
.add('bazStory', () => <button />) | ||
.add('baz', () => <button />); |
28 changes: 25 additions & 3 deletions
28
lib/codemod/src/transforms/__testfixtures__/storiesof-to-csf/collision.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
export const foo = 1; | ||
const bar = 1; | ||
const barStory = 1; | ||
const baz = 1; | ||
const bazStory1 = 1; | ||
|
||
export default { | ||
title: 'bar', | ||
title: 'foo', | ||
excludeStories: ['foo'], | ||
}; | ||
|
||
export const story0 = () => <button />; | ||
export const fooStory = () => <button />; | ||
|
||
story0.story = { | ||
fooStory.story = { | ||
name: 'foo', | ||
}; | ||
|
||
export const barStory1 = () => <button />; | ||
|
||
barStory1.story = { | ||
name: 'bar', | ||
}; | ||
|
||
export const bazStory = () => <button />; | ||
|
||
bazStory.story = { | ||
name: 'bazStory', | ||
}; | ||
|
||
export const bazStory2 = () => <button />; | ||
|
||
bazStory2.story = { | ||
name: 'baz', | ||
}; |
1 change: 1 addition & 0 deletions
1
lib/codemod/src/transforms/__testfixtures__/storiesof-to-csf/digit.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
storiesOf('bar', module).add('1', () => <button />); |
5 changes: 5 additions & 0 deletions
5
lib/codemod/src/transforms/__testfixtures__/storiesof-to-csf/digit.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
title: 'bar', | ||
}; | ||
|
||
export const _1 = () => <button />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ export default { | |
}; | ||
|
||
export const baz = () => <button />; | ||
|
||
baz.story = { | ||
name: 'baz', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 10 additions & 17 deletions
27
lib/codemod/src/transforms/__tests__/storiesof-to-csf.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { defineTest } from 'jscodeshift/dist/testUtils'; | ||
|
||
jest.mock('@storybook/node-logger'); | ||
|
||
const testNames = [ | ||
'basic', | ||
'decorators', | ||
'parameters', | ||
'story-parameters', | ||
'module', | ||
'multi', | ||
'default', | ||
'exports', | ||
'collision', | ||
'const', | ||
'story-decorators', | ||
]; | ||
|
||
testNames.forEach(testName => { | ||
defineTest(__dirname, `storiesof-to-csf`, null, `storiesof-to-csf/${testName}`); | ||
}); | ||
fs.readdirSync(path.resolve(__dirname, '../__testfixtures__/storiesof-to-csf')) | ||
.map(filename => filename.match(/^(.*)\.input\.js$/)) | ||
.filter(Boolean) | ||
.map(match => match[1]) | ||
.forEach(testName => { | ||
defineTest(__dirname, `storiesof-to-csf`, null, `storiesof-to-csf/${testName}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters