diff --git a/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts b/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts index 0c3856a6b..e4e72b497 100644 --- a/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts @@ -483,60 +483,66 @@ describe('SveltePlugin#getDiagnostics', () => { const { plugin, document } = setupFromFile('diagnostics-module.svelte'); const diagnostics = await plugin.getDiagnostics(document); - assert.deepStrictEqual(diagnostics, [ - { - range: { start: { line: 1, character: 4 }, end: { line: 1, character: 26 } }, - message: isSvelte5Plus - ? 'Reactive declarations only exist at the top level of the instance script' - : '$: has no effect in a module script', - severity: 2, - source: 'svelte', - code: isSvelte5Plus - ? 'reactive_declaration_invalid_placement' - : 'module-script-reactive-declaration' - } - ]); + assert.deepStrictEqual( + diagnostics.filter((d) => d.code !== 'script_context_deprecated'), + [ + { + range: { start: { line: 1, character: 4 }, end: { line: 1, character: 26 } }, + message: isSvelte5Plus + ? 'Reactive declarations only exist at the top level of the instance script' + : '$: has no effect in a module script', + severity: 2, + source: 'svelte', + code: isSvelte5Plus + ? 'reactive_declaration_invalid_placement' + : 'module-script-reactive-declaration' + } + ] + ); }); it('should correctly determine diagnostic position for script when theres also context="module"', async () => { const { plugin, document } = setupFromFile('diagnostics-module-and-instance.svelte'); const diagnostics = await plugin.getDiagnostics(document); - assert.deepStrictEqual(diagnostics, [ - { - code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', - message: - "Component has unused export property 'unused1'. If it is for external reference only, please consider using `export const unused1`", - range: { - start: { - line: 5, - character: 13 + assert.deepStrictEqual( + diagnostics.filter((d) => d.code !== 'script_context_deprecated'), + [ + { + code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', + message: + "Component has unused export property 'unused1'. If it is for external reference only, please consider using `export const unused1`", + range: { + start: { + line: 5, + character: 13 + }, + end: { + line: 5, + character: isSvelte5Plus ? 20 : 27 + } }, - end: { - line: 5, - character: isSvelte5Plus ? 20 : 27 - } + severity: 2, + source: 'svelte' }, - severity: 2, - source: 'svelte' - }, - { - code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', - message: - "Component has unused export property 'unused2'. If it is for external reference only, please consider using `export const unused2`", - range: { - start: { - line: 6, - character: 13 + { + code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', + message: + "Component has unused export property 'unused2'. If it is for external reference only, please consider using `export const unused2`", + range: { + start: { + line: 6, + character: 13 + }, + end: { + line: 6, + character: isSvelte5Plus ? 20 : 27 + } }, - end: { - line: 6, - character: isSvelte5Plus ? 20 : 27 - } - }, - severity: 2, - source: 'svelte' - } - ]); + severity: 2, + source: 'svelte' + } + ] + ); }); }); diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/Scripts.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/Scripts.ts index 853a72fd1..560e00de0 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/Scripts.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/Scripts.ts @@ -35,7 +35,11 @@ export class Scripts { if ( tag.attributes && tag.attributes.find( - (a) => a.name == 'context' && a.value.length == 1 && a.value[0].raw == 'module' + (a) => + (a.name == 'context' && + a.value.length == 1 && + a.value[0].raw == 'module') || + a.name === 'module' ) ) { moduleScriptTag = tag; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/expectedv2.ts new file mode 100644 index 000000000..6406a56c2 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/expectedv2.ts @@ -0,0 +1,15 @@ +/// +; + export function preload() {} + let b = 5; +;;function render() { + + let world = "name" +; +async () => { + + { svelteHTML.createElement("h1", {}); world; }}; +return { props: {world: world}, slots: {}, events: {} }} + +export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(['world'], __sveltets_2_with_any_event(render()))) { +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/input.svelte new file mode 100644 index 000000000..9465aa0d6 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/module-script-and-script3.v5/input.svelte @@ -0,0 +1,8 @@ + + +

hello {world}