Skip to content

Commit 5bc4033

Browse files
authored
fix: treeshake $inspect.trace code if unused in modules (#14774)
1 parent 69d198e commit 5bc4033

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Diff for: .changeset/modern-colts-drive.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: treeshake `$inspect.trace` code if unused in modules

Diff for: packages/svelte/src/compiler/phases/2-analyze/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,15 @@ export function analyze_module(ast, options) {
243243
}
244244
}
245245

246+
const analysis = { runes: true, tracing: false };
247+
246248
walk(
247249
/** @type {Node} */ (ast),
248250
{
249251
scope,
250252
scopes,
251253
// @ts-expect-error TODO
252-
analysis: { runes: true }
254+
analysis
253255
},
254256
visitors
255257
);
@@ -259,7 +261,8 @@ export function analyze_module(ast, options) {
259261
name: options.filename,
260262
accessors: false,
261263
runes: true,
262-
immutable: true
264+
immutable: true,
265+
tracing: analysis.tracing
263266
};
264267
}
265268

Diff for: packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,15 @@ export function client_module(analysis, options) {
671671
walk(/** @type {AST.SvelteNode} */ (analysis.module.ast), state, visitors)
672672
);
673673

674+
const body = [b.import_all('$', 'svelte/internal/client')];
675+
676+
if (analysis.tracing) {
677+
body.push(b.imports([], 'svelte/internal/flags/tracing'));
678+
}
679+
674680
return {
675681
type: 'Program',
676682
sourceType: 'module',
677-
body: [b.import_all('$', 'svelte/internal/client'), ...module.body]
683+
body: [...body, ...module.body]
678684
};
679685
}

Diff for: packages/svelte/src/compiler/phases/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface Analysis {
2727
name: string; // TODO should this be filename? it's used in `compileModule` as well as `compile`
2828
runes: boolean;
2929
immutable: boolean;
30+
tracing: boolean;
3031

3132
// TODO figure out if we can move this to ComponentAnalysis
3233
accessors: boolean;

0 commit comments

Comments
 (0)