From cfc7beb82f63157e791470f73cfb1a5efd4e3c8b Mon Sep 17 00:00:00 2001 From: Mateusz Kadlubowski Date: Sat, 7 Sep 2024 14:37:02 +0800 Subject: [PATCH] handle id-less templates and stories --- .../codemods/legacy-story.test.ts | 138 +++++++++++++----- .../pre-transform/codemods/legacy-story.ts | 28 +++- .../codemods/template-to-snippet.test.ts | 49 +++++-- .../codemods/template-to-snippet.ts | 12 +- src/compiler/pre-transform/index.test.ts | 78 +++++++--- src/compiler/pre-transform/index.ts | 28 ++-- 6 files changed, 242 insertions(+), 91 deletions(-) diff --git a/src/compiler/pre-transform/codemods/legacy-story.test.ts b/src/compiler/pre-transform/codemods/legacy-story.test.ts index 002514c..4dc08e1 100644 --- a/src/compiler/pre-transform/codemods/legacy-story.test.ts +++ b/src/compiler/pre-transform/codemods/legacy-story.test.ts @@ -15,11 +15,16 @@ describe(transformLegacyStory.name, () => { `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( - `""` - ); + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot(`""`); }); it("moving 'autodocs' prop doesn't break with existing 'tags' prop", async ({ expect }) => { @@ -30,11 +35,16 @@ describe(transformLegacyStory.name, () => { `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( - `""` - ); + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot(`""`); }); it("'source' prop when is a shorthand gets removed", async ({ expect }) => { @@ -45,11 +55,16 @@ describe(transformLegacyStory.name, () => { `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( - `""` - ); + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot(`""`); }); it("'source' prop when is a text expression gets moved to 'parameters' prop", async ({ @@ -62,9 +77,16 @@ describe(transformLegacyStory.name, () => { `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot( ` "'" } } @@ -85,9 +107,16 @@ describe(transformLegacyStory.name, () => { {'Hi'} `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot( ` " { }} /> `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot( ` " { `; - const node = await parseAndExtractSvelteNode(code, 'Component'); - - expect(print(transformLegacyStory({ node }))).toMatchInlineSnapshot( - `""` - ); + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {}, templateComponents: [] }, + }) + ) + ).toMatchInlineSnapshot(`""`); }); it("when directive 'let:args' is used then it wraps Story fragment with 'children' snippet block", async ({ @@ -159,9 +200,16 @@ describe(transformLegacyStory.name, () => {