Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f5b045a
Base tree shaking implementation
iObject Mar 18, 2026
022dd84
bsconfig control
iObject Mar 18, 2026
f04302e
Change from annotation to comments
iObject Mar 18, 2026
0ab9294
spec update
iObject Mar 18, 2026
adf11e7
Potential fix for pull request finding
iObject Mar 18, 2026
b6aed2e
Potential fix for pull request finding
iObject Mar 18, 2026
5d18b91
correct tests
iObject Mar 18, 2026
208d9d6
remove only
iObject Mar 18, 2026
e690a39
bsconfig.schema.json update
iObject Mar 18, 2026
0d70977
readme updates
iObject Mar 18, 2026
b001258
spec rename
iObject Mar 18, 2026
e226ecd
documentation fix
iObject Mar 18, 2026
c58c812
runscreensaver
iObject Mar 18, 2026
7ee5624
optimizations
iObject Mar 18, 2026
19f13f8
Potential fix for pull request finding
iObject Mar 18, 2026
6b6a080
Merge branch 'master' into 183-tree-shaking
iObject Mar 18, 2026
def4082
Potential fix for pull request finding
iObject Mar 18, 2026
e5d83aa
resolve issues
iObject Mar 18, 2026
421d77b
fix shorthand conflict
iObject Mar 18, 2026
1f32d43
Potential fix for pull request finding
iObject Mar 18, 2026
4879eb7
Potential fix for pull request finding
iObject Mar 18, 2026
18f7fd5
Potential fix for pull request finding
iObject Mar 18, 2026
cf64d4c
fix bug
iObject Mar 19, 2026
de7dece
Windows src path normalization
iObject Mar 19, 2026
0569d01
Tree shaking now lives in Program.beforeProgramTranspile
iObject Mar 19, 2026
5ca9b74
remove space
iObject Mar 19, 2026
4296778
Potential fix for pull request finding
iObject Mar 19, 2026
ff2d8df
Move TreeShaker
iObject Mar 19, 2026
949f67b
Merge branch '183-tree-shaking' of github.com:rokucommunity/brighters…
iObject Mar 19, 2026
edd9cea
Updated comment
iObject Mar 19, 2026
301a919
Potential fix for pull request finding
iObject Mar 19, 2026
12643fd
logging
iObject Mar 19, 2026
b6d9d57
fix(tree-shaker): retain .brs library functions called via namespace …
iObject Mar 19, 2026
bbc8752
move logging to single output
iObject Mar 19, 2026
83e0f6b
tests for excludes brs
iObject Mar 19, 2026
b6f036a
Move treeShaker back into BscPlugin.ts
iObject Mar 19, 2026
7672891
remove whitespace
iObject Mar 19, 2026
5986f59
readme update
iObject Mar 19, 2026
c4d231d
omit fully protected files from transpiler
iObject Mar 19, 2026
a9b0de5
Fix issue
iObject Mar 19, 2026
e3717f1
pattern fix
iObject Mar 19, 2026
94f9c9d
treeShaking normalization tests
iObject Mar 19, 2026
8d6d302
changes map for any compiled rule that ends up with no criteria
iObject Mar 19, 2026
9267d14
Merge branch 'master' into 183-tree-shaking
iObject Mar 19, 2026
84a4da2
readme update
iObject Mar 19, 2026
ac3d832
customizations support
iObject Mar 20, 2026
45a03cf
Merge branch '183-tree-shaking' of github.com:rokucommunity/brighters…
iObject Mar 20, 2026
41bcae3
test for function passed by reference as an argument to another function
iObject Mar 20, 2026
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
60 changes: 60 additions & 0 deletions bsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,66 @@
"description": "Allow brighterscript features (classes, interfaces, etc...) to be included in BrightScript (`.brs`) files, and force those files to be transpiled.",
"type": "boolean",
"default": false
},
"treeShaking": {
"description": "Configuration for tree shaking (dead code elimination). Disabled by default; set `enabled: true` to opt in.",
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"description": "Enable tree shaking. Defaults to false.",
"type": "boolean",
"default": false
},
"keep": {
"description": "List of keep rules. Functions matching any rule are always retained along with their full dependency closure. A plain string is shorthand for `{ functions: [string] }`.",
Comment thread
iObject marked this conversation as resolved.
"type": "array",
"items": {
"oneOf": [
{
"type": "string",
"description": "Exact BrightScript function name to always keep."
},
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"description": "Keep rule object. All specified fields must match (AND semantics). Rules are combined with OR semantics.",
"properties": {
"src": {
"description": "Glob pattern(s) matched against the source file path.",
"oneOf": [
{ "type": "string" },
{ "type": "array", "items": { "type": "string" } }
]
},
"dest": {
"description": "Glob pattern(s) matched against the package-relative destination path.",
"oneOf": [
{ "type": "string" },
{ "type": "array", "items": { "type": "string" } }
]
},
"functions": {
"description": "Exact BrightScript function name(s) to keep.",
"oneOf": [
{ "type": "string" },
{ "type": "array", "items": { "type": "string" } }
]
},
"matches": {
"description": "Glob/wildcard pattern(s) matched against the BrightScript function name.",
"oneOf": [
{ "type": "string" },
{ "type": "array", "items": { "type": "string" } }
]
}
}
}
]
}
}
}
}
}
}
56 changes: 54 additions & 2 deletions src/BsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,57 @@ export interface BsConfig {
* scripts inside `source` that depend on bslib.brs. Defaults to `source`.
*/
bslibDestinationDir?: string;

/**
* Configuration for tree shaking (dead code elimination).
*/
treeShaking?: TreeShakingConfig;
Comment thread
iObject marked this conversation as resolved.
}

/**
* A single keep-rule entry in `treeShaking.keep`.
*
* A plain string is shorthand for `{ functions: [string] }`.
* An object entry must contain at least one of `src`, `dest`, `functions`, or `matches`.
* All fields present on one rule are combined with AND semantics.
* Rules across the list are combined with OR semantics.
*/
export type TreeShakingKeepEntry = string | TreeShakingKeepRule;

export interface TreeShakingKeepRule {
/** Glob pattern(s) matched against the declaration's source file path. */
src?: string | string[];
/** Glob pattern(s) matched against the declaration's package-relative destination path. */
dest?: string | string[];
/** Exact function name(s) to keep (BrightScript/transpiled names). */
functions?: string | string[];
/** Glob/wildcard pattern(s) matched against the function name (BrightScript/transpiled names). */
matches?: string | string[];
}

export interface TreeShakingConfig {
/**
* Enable or disable tree shaking. Defaults to `false` (opt-in).
*/
enabled?: boolean;
/**
* Declarations matching any rule in this list are always retained,
* along with their full dependency closure.
Comment thread
iObject marked this conversation as resolved.
Outdated
*/
keep?: TreeShakingKeepEntry[];
}

/** Normalized internal form produced by `normalizeConfig`. */
export interface NormalizedKeepRule {
src?: string[];
dest?: string[];
functions?: string[];
matches?: string[];
}

export interface NormalizedTreeShakingConfig {
enabled: boolean;
keep: NormalizedKeepRule[];
}

type OptionalBsConfigFields =
Expand All @@ -231,5 +282,6 @@ type OptionalBsConfigFields =
| 'stagingDir';

export type FinalizedBsConfig =
Omit<Required<BsConfig>, OptionalBsConfigFields>
& Pick<BsConfig, OptionalBsConfigFields>;
Omit<Required<BsConfig>, OptionalBsConfigFields | 'treeShaking'>
& Pick<BsConfig, OptionalBsConfigFields>
& { treeShaking: NormalizedTreeShakingConfig };
16 changes: 15 additions & 1 deletion src/bscPlugin/BscPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isBrsFile, isXmlFile } from '../astUtils/reflection';
import type { AstEditor } from '../astUtils/AstEditor';
import type { BeforeFileTranspileEvent, Plugin, OnFileValidateEvent, OnGetCodeActionsEvent, ProvideHoverEvent, OnGetSemanticTokensEvent, OnScopeValidateEvent, ProvideCompletionsEvent, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent } from '../interfaces';
import type { Program } from '../Program';
import type { Program, TranspileObj } from '../Program';
import { CodeActionsProcessor } from './codeActions/CodeActionsProcessor';
import { CompletionsProcessor } from './completions/CompletionsProcessor';
import { DefinitionProvider } from './definition/DefinitionProvider';
Expand All @@ -14,6 +15,7 @@ import { ProgramValidator } from './validation/ProgramValidator';
import { ScopeValidator } from './validation/ScopeValidator';
import { XmlFileValidator } from './validation/XmlFileValidator';
import { WorkspaceSymbolProcessor } from './symbols/WorkspaceSymbolProcessor';
import { TreeShaker } from './treeShaker/TreeShaker';

export class BscPlugin implements Plugin {
public name = 'BscPlugin';
Expand Down Expand Up @@ -60,6 +62,18 @@ export class BscPlugin implements Plugin {
}
}

private treeShaker = new TreeShaker();

public beforeProgramTranspile(program: Program, entries: TranspileObj[], editor: AstEditor) {
if (!program.options.treeShaking.enabled) {
return;
}
this.treeShaker.analyze(program, program.options.treeShaking.keep);
for (const entry of entries) {
this.treeShaker.shake(entry.file, editor);
}
Comment thread
iObject marked this conversation as resolved.
Outdated
}

private scopeValidator = new ScopeValidator();

public onScopeValidate(event: OnScopeValidateEvent) {
Expand Down
Loading
Loading