fix: treeshake `$inspect.trace` code if unused in modules (#14774)

pull/14776/head
Dominic Gannaway 9 months ago committed by GitHub
parent 69d198eb44
commit 5bc4033421
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: treeshake `$inspect.trace` code if unused in modules

@ -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
);
@ -259,7 +261,8 @@ export function analyze_module(ast, options) {
name: options.filename,
accessors: false,
runes: true,
immutable: true
immutable: true,
tracing: analysis.tracing
};
}

@ -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]
};
}

@ -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;

Loading…
Cancel
Save