diff --git a/packages/svelte2tsx/test/helpers.ts b/packages/svelte2tsx/test/helpers.ts index b3ca7151c..c392d5631 100644 --- a/packages/svelte2tsx/test/helpers.ts +++ b/packages/svelte2tsx/test/helpers.ts @@ -225,6 +225,8 @@ const enum TestError { const isSvelte5Plus = Number(VERSION[0]) >= 5; +console.log('IS SVELTE 5 +', isSvelte5Plus); + export function test_samples(dir: string, transform: TransformSampleFn, js: 'js' | 'ts') { for (const sample of each_sample(dir)) { if (sample.name.endsWith('.v5') && !isSvelte5Plus) continue; @@ -320,12 +322,16 @@ export function test_samples(dir: string, transform: TransformSampleFn, js: 'js' try { assert.strictEqual(actual, expected, TestError.WrongExpected); } catch (e) { + // html2jsx tests don't have the default export + const expectDefaultExportPosition = expected.lastIndexOf( + '\n\nexport default class' + ); + if (expectDefaultExportPosition === -1) { + throw e; + } // retry with the last part (the returned default export) stripped because it's always differing between old and new, // and if that fails then we're going to rethrow the original error - const expectedModified = expected.substring( - 0, - expected.lastIndexOf('\n\nexport default class') - ); + const expectedModified = expected.substring(0, expectDefaultExportPosition); const actualModified = actual.substring(0, actual.lastIndexOf('\nconst ')); try { assert.strictEqual( diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/expectedv2.js index 3f235b718..36a68ba18 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/expectedv2.js +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/expectedv2.js @@ -24,6 +24,8 @@ item as string; var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[string | number, (str: string)=>void]>/*Ωignore_endΩ*/ = (bar : string | number, baz : (str: string)=>void) => {async () => { };return __sveltets_2_any(0)}; + var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[{baz: string}]>/*Ωignore_endΩ*/ = (bar: {baz: string}) => {async () => { };return __sveltets_2_any(0)}; + ;__sveltets_2_ensureSnippet(foo(bar as string)); { svelteHTML.createElement("button", { "onclick":(e: Event) => {e as any},}); } diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/input.svelte index 08e917628..d2e086c0c 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/input.svelte +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/input.svelte @@ -38,6 +38,10 @@ snippet {/snippet} +{#snippet foo3(bar: {baz: string})} + snippet +{/snippet} + {@render foo(bar as string)}