From 770c9adef0f2158d9097bfd392e182af11d3e4e3 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Thu, 31 Oct 2024 16:57:40 +0100 Subject: [PATCH] fix: properly transform invalid identifiers --- .../codemods/legacy-story.test.ts | 26 +++++++++++-- .../pre-transform/codemods/legacy-story.ts | 5 +-- .../codemods/template-to-snippet.test.ts | 39 ++++++++++++------- .../codemods/template-to-snippet.ts | 3 +- src/utils/identifier-utils.ts | 20 ++++++++++ 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/compiler/pre-transform/codemods/legacy-story.test.ts b/src/compiler/pre-transform/codemods/legacy-story.test.ts index cb140d8..517865c 100644 --- a/src/compiler/pre-transform/codemods/legacy-story.test.ts +++ b/src/compiler/pre-transform/codemods/legacy-story.test.ts @@ -188,6 +188,28 @@ describe(transformLegacyStory.name, () => { ).toMatchInlineSnapshot(`""`); }); + it("transforms 'template' prop to 'children' and text expression becomes expression tag with identifier to snippet (case with invalid identifier)", async ({ + expect, + }) => { + const code = ` + + + + `; + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect( + print( + transformLegacyStory({ + component, + state: { componentIdentifierName: {} }, + }) + ) + ).toMatchInlineSnapshot(`""`); + }); + it("when directive 'let:args' is used then it wraps Story fragment with 'children' snippet block", async ({ expect, }) => { @@ -280,9 +302,7 @@ describe(transformLegacyStory.name, () => { `); }); - it("leaves existing Story parameters untouched", async ({ - expect, - }) => { + it('leaves existing Story parameters untouched', async ({ expect }) => { const code = ` + + + `; + const component = await parseAndExtractSvelteNode(code, 'Component'); + + expect(print(transformTemplateToSnippet({ component }))).toMatchInlineSnapshot(` + "{#snippet template_haitqt(args)} +