Skip to content

Commit 8dffb2d

Browse files
authored
Merge pull request #310 from storybookjs/fix/export-stories-specifiers
fix: Prevent exported runtime stories from colliding with story names
2 parents b5c9e39 + 8b588ac commit 8dffb2d

36 files changed

+572
-4576
lines changed

.storybook/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const config: StorybookConfig = {
2424
legacyTemplate: true,
2525
},
2626
},
27-
'@storybook/addon-essentials',
2827
'@chromatic-com/storybook',
29-
'@storybook/experimental-addon-test',
28+
'@storybook/addon-docs',
29+
'@storybook/addon-vitest',
3030
],
3131
};
3232

examples/Button.stories.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<script module lang="ts">
2-
import { defineMeta, type StoryContext } from '@storybook/addon-svelte-csf';
3-
import { fn } from '@storybook/test';
2+
import { defineMeta } from '@storybook/addon-svelte-csf';
3+
import { fn } from 'storybook/test';
44
55
import Button from './components/Button.svelte';
6-
import type { ComponentProps } from 'svelte';
76
87
const onclickFn = fn().mockName('onclick');
98

examples/README.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, Markdown } from '@storybook/blocks';
1+
import { Meta, Markdown } from '@storybook/addon-docs/blocks';
22
import README from '../README.md?raw';
33

44
<Meta title="README" />

examples/StoryImporter.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, Canvas } from '@storybook/blocks';
1+
import { Meta, Canvas } from '@storybook/addon-docs/blocks';
22
import * as ExportNameStories from './ExportName.stories.svelte';
33

44
<Meta title="Examples/ExportName" name="MDX Docs" />

examples/Templating.stories.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script module lang="ts">
22
import { defineMeta } from '@storybook/addon-svelte-csf';
3-
import { expect, within } from '@storybook/test';
3+
import { expect, within } from 'storybook/test';
44
55
/**
66
* Demonstration on the **different ways of setting a template** for `<Story />` components within one stories file.

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,15 @@
6363
},
6464
"devDependencies": {
6565
"@auto-it/released": "^11.1.6",
66-
"@chromatic-com/storybook": "^4.0.0-0",
66+
"@chromatic-com/storybook": "^4.0.0-next.6",
6767
"@eslint/compat": "^1.2.8",
6868
"@eslint/js": "^9.25.0",
69-
"@storybook/addon-actions": "^9.0.0-0",
70-
"@storybook/addon-essentials": "^9.0.0-0",
71-
"@storybook/experimental-addon-test": "^9.0.0-0",
72-
"@storybook/svelte": "^9.0.0-0",
73-
"@storybook/svelte-vite": "^9.0.0-0",
74-
"@storybook/test": "^9.0.0-0",
69+
"@storybook/addon-vitest": "^9.0.0-rc.3",
70+
"@storybook/addon-docs": "^9.0.0-rc.3",
71+
"@storybook/svelte": "^9.0.0-rc.3",
72+
"@storybook/svelte-vite": "^9.0.0-rc.3",
7573
"@sveltejs/package": "^2.3.7",
76-
"@sveltejs/vite-plugin-svelte": "4.0.0",
74+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
7775
"@tsconfig/svelte": "^5.0.4",
7876
"@types/estree": "^1.0.6",
7977
"@types/node": "^20.14.9",
@@ -92,7 +90,7 @@
9290
"prettier-plugin-svelte": "^3.2.5",
9391
"rimraf": "^5.0.7",
9492
"rollup": "^4.25.0",
95-
"storybook": "^9.0.0-0",
93+
"storybook": "^9.0.0-rc.3",
9694
"svelte": "^5.28.2",
9795
"svelte-check": "^4.1.7",
9896
"tslib": "^2.6.3",
@@ -102,7 +100,6 @@
102100
"typescript-svelte-plugin": "^0.3.42",
103101
"vite": "^6.3.5",
104102
"vite-plugin-inspect": "^0.8.7",
105-
"vite-plugin-virtual": "^0.3.0",
106103
"vitest": "^3.1.3"
107104
},
108105
"peerDependencies": {

pnpm-lock.yaml

Lines changed: 247 additions & 4260 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/post-transform/appendix/create-export-order.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { print } from 'esrap';
22
import { describe, it } from 'vitest';
33

4-
import { createExportOrderVariable } from './create-export-order.js';
4+
import { createExportOrderVariableDeclaration } from './create-export-order.js';
55

6-
describe(createExportOrderVariable.name, () => {
6+
describe(createExportOrderVariableDeclaration.name, () => {
77
it('correctly creates a variable with named exports order', ({ expect }) => {
88
const stringified = print(
9-
createExportOrderVariable({
10-
storyIdentifiers: [
9+
createExportOrderVariableDeclaration({
10+
storiesIdentifiers: [
1111
{ exportName: 'Default', name: 'Default' },
1212
{ exportName: 'SomeComponent', name: 'Some Component' },
1313
{ exportName: 'ThisNameIsWeird', name: 'This-Name-Is-Weird' },

src/compiler/post-transform/appendix/create-export-order.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
import type { getStoriesIdentifiers } from '$lib/parser/analyse/story/attributes/identifiers.js';
2-
import type { ESTreeAST } from '$lib/parser/ast.js';
2+
import {
3+
type ESTreeAST,
4+
createASTArrayExpression,
5+
createASTExportSpecifier,
6+
} from '$lib/parser/ast.js';
37

4-
interface Params {
5-
storyIdentifiers: ReturnType<typeof getStoriesIdentifiers>;
8+
interface ExportOrderVariableDeclarationParams {
9+
storiesIdentifiers: ReturnType<typeof getStoriesIdentifiers>;
610
filename?: string;
711
}
812

9-
export function createExportOrderVariable(params: Params): ESTreeAST.ExportNamedDeclaration {
10-
const { storyIdentifiers } = params;
13+
export function createExportOrderVariableDeclaration(
14+
params: ExportOrderVariableDeclarationParams
15+
): ESTreeAST.ExportNamedDeclaration {
16+
const { storiesIdentifiers: storyIdentifiers } = params;
1117

12-
const exported = {
13-
type: 'Identifier',
14-
name: '__namedExportsOrder',
15-
} as const;
18+
const specifier = createASTExportSpecifier({ local: '__namedExportsOrder' });
1619

1720
return {
1821
type: 'ExportNamedDeclaration',
19-
specifiers: [
20-
{
21-
type: 'ExportSpecifier',
22-
local: exported,
23-
exported,
24-
},
25-
],
22+
specifiers: [specifier],
2623
declaration: {
2724
type: 'VariableDeclaration',
2825
kind: 'const',
2926
declarations: [
3027
{
3128
type: 'VariableDeclarator',
32-
id: exported,
33-
init: {
34-
type: 'ArrayExpression',
35-
elements: storyIdentifiers.map(({ exportName }) => ({
29+
id: specifier.local as ESTreeAST.Identifier,
30+
init: createASTArrayExpression(
31+
storyIdentifiers.map(({ exportName }) => ({
3632
type: 'Literal',
3733
value: exportName,
38-
})),
39-
},
34+
}))
35+
),
4036
},
4137
],
4238
},
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { print } from 'esrap';
2+
import { describe, it } from 'vitest';
3+
4+
import { createNamedExportStories } from './create-named-export-stories.js';
5+
6+
describe(createNamedExportStories, () => {
7+
it('works', ({ expect }) => {
8+
const namedExportDeclaration = createNamedExportStories({
9+
storiesIdentifiers: [
10+
{
11+
exportName: 'Default',
12+
name: undefined,
13+
},
14+
{
15+
exportName: 'Primary',
16+
name: 'Primary',
17+
},
18+
{
19+
exportName: 'Secondary',
20+
name: 'Secondary',
21+
},
22+
{
23+
exportName: 'Disabled',
24+
name: 'Disabled',
25+
},
26+
],
27+
});
28+
29+
expect(print(namedExportDeclaration).code).toMatchInlineSnapshot(`
30+
"export {
31+
$__Default as Default,
32+
$__Primary as Primary,
33+
$__Secondary as Secondary,
34+
$__Disabled as Disabled
35+
};"
36+
`);
37+
});
38+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { STORYBOOK_INTERNAL_PREFIX } from '$lib/constants.js';
2+
import type { getStoriesIdentifiers } from '$lib/parser/analyse/story/attributes/identifiers.js';
3+
import { createASTIdentifier, type ESTreeAST } from '$lib/parser/ast.js';
4+
5+
interface NamedExportStoriesParams {
6+
storiesIdentifiers: ReturnType<typeof getStoriesIdentifiers>;
7+
}
8+
9+
export function createNamedExportStories(
10+
params: NamedExportStoriesParams
11+
): ESTreeAST.ExportNamedDeclaration {
12+
return {
13+
type: 'ExportNamedDeclaration',
14+
specifiers: params.storiesIdentifiers.map(createExportSpecifier),
15+
declaration: null,
16+
};
17+
}
18+
19+
function createExportSpecifier(
20+
storyIdentifier: ReturnType<typeof getStoriesIdentifiers>[number]
21+
): ESTreeAST.ExportSpecifier {
22+
return {
23+
type: 'ExportSpecifier',
24+
local: createASTIdentifier(`${STORYBOOK_INTERNAL_PREFIX}${storyIdentifier.exportName}`),
25+
exported: createASTIdentifier(storyIdentifier.exportName),
26+
};
27+
}

src/compiler/post-transform/appendix/create-named-export-story.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)