diff --git a/src/compiler/pre-transform/codemods/legacy-story.test.ts b/src/compiler/pre-transform/codemods/legacy-story.test.ts
index 4ec8788..d3ddf47 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,
}) => {
diff --git a/src/compiler/pre-transform/codemods/legacy-story.ts b/src/compiler/pre-transform/codemods/legacy-story.ts
index fcf77d6..523174a 100644
--- a/src/compiler/pre-transform/codemods/legacy-story.ts
+++ b/src/compiler/pre-transform/codemods/legacy-story.ts
@@ -1,5 +1,3 @@
-import { camelCase } from 'es-toolkit/string';
-
import {
createASTArrayExpression,
createASTAttribute,
@@ -11,6 +9,7 @@ import {
} from '$lib/parser/ast.js';
import { InvalidTemplateAttribute } from '$lib/utils/error/legacy-api/index.js';
+import { hashTemplateName } from '#utils/identifier-utils';
import type { State } from '..';
interface Params {
@@ -253,7 +252,7 @@ function templateToChildren(
value: [
createASTExpressionTag({
type: 'Identifier',
- name: camelCase(
+ name: hashTemplateName(
value[0].type === 'Text'
? value[0].data
: ((value[0].expression as ESTreeAST.Literal).value as string)
diff --git a/src/compiler/pre-transform/codemods/template-to-snippet.test.ts b/src/compiler/pre-transform/codemods/template-to-snippet.test.ts
index 4955122..f2ea7dd 100644
--- a/src/compiler/pre-transform/codemods/template-to-snippet.test.ts
+++ b/src/compiler/pre-transform/codemods/template-to-snippet.test.ts
@@ -46,6 +46,27 @@ describe(transformTemplateToSnippet.name, () => {
`);
});
+ it("covers a case with provided prop 'id' and prop `id` not being a valid identifier", async ({
+ expect,
+ }) => {
+ const code = `
+
+
+
+
+
+ `;
+ const component = await parseAndExtractSvelteNode(code, 'Component');
+
+ expect(print(transformTemplateToSnippet({ component }))).toMatchInlineSnapshot(`
+ "{#snippet template_haitqt(args)}
+
+ {/snippet}"
+ `);
+ });
+
it("works with 'let:context' directive", async ({ expect }) => {
const code = `