Skip to content

Commit

Permalink
Merge pull request #224 from storybookjs/fix-legacy-story-parameters
Browse files Browse the repository at this point in the history
fix: `parameters` attribute from legacy `<Story>` being removed
  • Loading branch information
JReinhold authored Oct 29, 2024
2 parents aaa2def + 6c887e6 commit e9c7cd2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/compiler/pre-transform/codemods/legacy-story.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,59 @@ describe(transformLegacyStory.name, () => {
</Story>"
`);
});

it("leaves existing Story parameters untouched", async ({
expect,
}) => {
const code = `
<script context="module">
import { Story } from "@storybook/addon-svelte-csf";
</script>
<Story
name="Default"
parameters={{
sveltekit_experimental: {
stores: {
page: {
data: {
test: 'passed',
},
},
navigating: {
route: {
id: '/storybook',
},
},
updated: true,
},
},
}}
>
<h1>{"Test"}</h1>
</Story>
`;
const component = await parseAndExtractSvelteNode<SvelteAST.Component>(code, 'Component');

expect(
print(
transformLegacyStory({
component,
state: { componentIdentifierName: {} },
})
)
).toMatchInlineSnapshot(`
"<Story name="Default" parameters={{
sveltekit_experimental: {
stores: {
page: { data: { test: 'passed' } },
navigating: { route: { id: '/storybook' } },
updated: true
}
}
}}>
<h1>{"Test"}</h1>
</Story>"
`);
});
});
4 changes: 4 additions & 0 deletions src/compiler/pre-transform/codemods/legacy-story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export function transformLegacyStory(params: Params): SvelteAST.Component {
});
}

if (parameters) {
newAttributes.push(parameters);
}

if (tags) {
newAttributes.push(tags);
}
Expand Down

0 comments on commit e9c7cd2

Please sign in to comment.