Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/modern-colts-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: treeshake `$inspect.trace` code if unused in modules
7 changes: 5 additions & 2 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ export function analyze_module(ast, options) {
}
}

const analysis = { runes: true, tracing: false };

walk(
/** @type {Node} */ (ast),
{
scope,
scopes,
// @ts-expect-error TODO
analysis: { runes: true }
analysis
},
visitors
);
Expand All @@ -259,7 +261,8 @@ export function analyze_module(ast, options) {
name: options.filename,
accessors: false,
runes: true,
immutable: true
immutable: true,
tracing: analysis.tracing
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,15 @@ export function client_module(analysis, options) {
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, visitors)
);

const body = [b.import_all('$', 'svelte/internal/client')];

if (analysis.tracing) {
body.push(b.imports([], 'svelte/internal/flags/tracing'));
}

return {
type: 'Program',
sourceType: 'module',
body: [b.import_all('$', 'svelte/internal/client'), ...module.body]
body: [...body, ...module.body]
};
}
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/phases/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Analysis {
name: string; // TODO should this be filename? it's used in `compileModule` as well as `compile`
runes: boolean;
immutable: boolean;
tracing: boolean;

// TODO figure out if we can move this to ComponentAnalysis
accessors: boolean;
Expand Down
Loading