Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/svelte/src/preprocessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions packages/svelte/test/preprocessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ describe('componentTrackingPreprocessor', () => {
});
});

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', () => {
it("adds a <script> tag to components that don't have one", () => {
const preProc = componentTrackingPreprocessor();
Expand Down
Loading