diff --git a/src/compiler/pre-transform/index.test.ts b/src/compiler/pre-transform/index.test.ts index a33a3fe..bfc370f 100644 --- a/src/compiler/pre-transform/index.test.ts +++ b/src/compiler/pre-transform/index.test.ts @@ -250,4 +250,33 @@ describe(codemodLegacyNodes.name, () => { ] `); }); + + it('moves import declaration of stories target component from instance tag to module tag', async ({ + expect, + }) => { + const code = ` + + + + `; + + const ast = getSvelteAST({ code }); + const transformed = await codemodLegacyNodes({ ast }); + + expect(print(transformed)).toMatchInlineSnapshot(` + "" + `); + }); }); diff --git a/src/compiler/pre-transform/index.ts b/src/compiler/pre-transform/index.ts index 3cec78f..72216a4 100644 --- a/src/compiler/pre-transform/index.ts +++ b/src/compiler/pre-transform/index.ts @@ -80,25 +80,23 @@ export async function codemodLegacyNodes(params: Params): Promise s.local.name === storiesComponentIdentifier?.name ); if (storiesComponentSpecifier) { + // NOTE: We are storing it in the state, so later we will move from instance tag to module tag state.storiesComponentImportDeclaration = declaration; continue; } @@ -301,18 +273,28 @@ export async function codemodLegacyNodes(params: Params): Promise