From b887811c8ae326abe9aea7c74fd6d9f8735f9a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Jel=C3=ADnek?= <131378741+richardjelinek-fastest@users.noreply.github.com> Date: Tue, 22 Jul 2025 15:05:37 +0200 Subject: [PATCH 1/3] fix(svelte): Do not insert preprocess code in script module in Svelte 5 (#17114) Co-authored-by: Lukas Stracke --- packages/svelte/src/preprocessors.ts | 2 +- packages/svelte/test/preprocessors.test.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/svelte/src/preprocessors.ts b/packages/svelte/src/preprocessors.ts index b13b20ec59f6..c7df0e258c0f 100644 --- a/packages/svelte/src/preprocessors.ts +++ b/packages/svelte/src/preprocessors.ts @@ -97,7 +97,7 @@ function shouldInjectFunction( // because the code inside is not executed when the component is instantiated but // when the module is first imported. // see: https://svelte.dev/docs#component-format-script-context-module - if (attributes.context === 'module') { + if (attributes.module || attributes.context === 'module') { return false; } diff --git a/packages/svelte/test/preprocessors.test.ts b/packages/svelte/test/preprocessors.test.ts index 547f58b366ab..207e2d95cce5 100644 --- a/packages/svelte/test/preprocessors.test.ts +++ b/packages/svelte/test/preprocessors.test.ts @@ -170,6 +170,26 @@ describe('componentTrackingPreprocessor', () => { expect(processedComponent.newCode).toEqual(processedComponent.originalCode); }); + + it('doesnt inject the function call to a module context script block with Svelte 5 module attribute', () => { + const preProc = componentTrackingPreprocessor(); + const component = { + originalCode: 'console.log(cmp2)', + filename: 'lib/Cmp2.svelte', + name: 'Cmp2', + }; + + const res: any = preProc.script?.({ + content: component.originalCode, + filename: component.filename, + attributes: { module: true }, + markup: '', + }); + + const processedComponent = { ...component, newCode: res.code, map: res.map }; + + expect(processedComponent.newCode).toEqual(processedComponent.originalCode); + }); }); describe('markup hook', () => { From 9e53e02c9c367123628ebf73d892c2edba452e1a Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 22 Jul 2025 15:39:50 +0200 Subject: [PATCH 2/3] changelog credit --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bc7a377ee5..53ea2ac0304c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott +Work in this release was contributed by @richardjelinek-fastest. Thank you for your contribution! + ## 9.40.0 ### Important Changes From 021a155c6d0c117b7e542f3fb3737479c82dda7b Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 23 Jul 2025 10:32:37 +0200 Subject: [PATCH 3/3] start ci