Conversation
There was a problem hiding this comment.
Pull request overview
Adds a tree-shaking (dead-code elimination) pass to the compiler pipeline, including configuration support and “keep” mechanisms (config rules + bs:keep comment directives), plus extensive automated tests.
Changes:
- Introduce
treeShakingconfig inBsConfigand normalize it during config normalization. - Track
bs:keepcomment locations inBrsFilefor use by the shaker. - Add a new
TreeShakerimplementation and wire it intoBscPlugin’sbeforeProgramTranspile, with a comprehensive test suite.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Normalizes new treeShaking config and injects it into finalized program options. |
| src/BsConfig.ts | Defines public config/types for tree shaking and the normalized internal form. |
| src/files/BrsFile.ts | Captures bs:keep comment line numbers during lexing for tree-shaker hints. |
| src/bscPlugin/BscPlugin.ts | Hooks the tree shaker into the transpile lifecycle via beforeProgramTranspile. |
| src/bscPlugin/treeShaker/TreeShaker.ts | Implements program-wide function/reference analysis and removes unused function statements. |
| src/bscPlugin/treeShaker/TreeShaker.spec.ts | Adds tests covering removal, keep rules, bs:keep, XML interface retention, etc. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an initial tree-shaking (dead-code elimination) feature to the BrighterScript compiler pipeline, including config support and “keep” mechanisms to prevent removal of important entry points and callbacks.
Changes:
- Introduces
treeShakingconfig (with normalization) and wires it into the finalized options. - Tracks
bs:keepcomment directives inBrsFileand uses them in a newTreeShakerpass. - Adds a new tree-shaker plugin pass and a comprehensive test suite for the behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Normalizes treeShaking config into an internal normalized shape. |
| src/BsConfig.ts | Adds public config types for tree shaking and updates finalized config typing. |
| src/files/BrsFile.ts | Records bs:keep comment line numbers for tree-shaker consumption. |
| src/bscPlugin/BscPlugin.ts | Runs the tree shaker during beforeProgramTranspile when enabled. |
| src/bscPlugin/treeShaker/TreeShaker.ts | Implements program-wide analysis and AST rewriting to remove unused functions. |
| src/bscPlugin/treeShaker/TreeShaker.spec.ts | Adds tests validating tree-shaking behavior and keep rules. |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in tree-shaking (dead code elimination) pass to the BrighterScript compiler pipeline, allowing unused function declarations to be removed from transpiled output while supporting explicit keep rules and bs:keep annotations.
Changes:
- Introduces a
TreeShakeranalysis + AST rewrite step, executed duringbeforeProgramTranspilewhen enabled. - Adds
treeShakingconfiguration (types, normalization, and JSON schema) includingkeeprules. - Extends
BrsFilecomment processing to trackbs:keepdirective line locations and adds comprehensive tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Normalizes treeShaking config into a consistent internal form in finalized options. |
| src/files/BrsFile.ts | Tracks bs:keep comment line numbers for use by the tree shaker. |
| src/bscPlugin/treeShaker/TreeShaker.ts | Implements program-wide analysis (defs + refs) and replaces unused functions with empty statements. |
| src/bscPlugin/treeShaker/TreeShaker.spec.ts | Adds tests covering removal, entry points, bs:keep, XML interface hooks, and keep-rule semantics. |
| src/bscPlugin/BscPlugin.ts | Hooks tree shaking into the transpile lifecycle (opt-in via config). |
| src/BsConfig.ts | Adds treeShaking config types and normalizes the finalized config type. |
| bsconfig.schema.json | Documents and validates the new treeShaking configuration shape. |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “tree shaking” (dead-code elimination) feature to BrighterScript to remove unused functions from transpiled output, with configuration-based and comment-based escape hatches.
Changes:
- Introduces
treeShakingconfig (schema + normalization) and wires it into the transpile pipeline viabeforeProgramTranspile. - Implements a new
TreeShakeranalysis + transform pass (includes XML interface /onChangecallback retention andbs:keepcomment directives). - Adds extensive unit tests and end-user documentation for the feature.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Normalizes treeShaking config into an internal normalized form during config normalization. |
| src/files/BrsFile.ts | Captures bs:keep comment line numbers during lex/comment-flag collection for later use by the shaker. |
| src/bscPlugin/treeShaker/TreeShaker.ts | Implements whole-program function collection, reference scanning (AST + XML), and removal of unused functions via AST replacement. |
| src/bscPlugin/treeShaker/TreeShaker.spec.ts | Adds comprehensive tests covering core shaking behavior, bs:keep, XML retention, and keep rules. |
| src/bscPlugin/BscPlugin.ts | Hooks tree shaking into beforeProgramTranspile when enabled. |
| src/BsConfig.ts | Adds treeShaking types and updates FinalizedBsConfig to include normalized tree-shaking config. |
| docs/shaking.md | New documentation page describing configuration, directives, and behavior. |
| docs/readme.md | Links to the new tree shaking documentation and provides a short example. |
| bsconfig.schema.json | Adds JSON schema for treeShaking configuration. |
There was a problem hiding this comment.
Pull request overview
Introduces an opt-in “tree shaking” (dead code elimination) pass to remove unused BrightScript/BrighterScript function declarations during transpilation, with configuration, documentation, and extensive tests.
Changes:
- Add
treeShakingconfiguration (schema + normalized internal form) and wire the tree shaker intobeforeProgramTranspile. - Track
bs:keepdirectives from comment tokens and preserve annotated functions. - Implement the
TreeShakeranalyzer/removal pass (including XML interface/onChange preservation and keep-rule support) with comprehensive specs and new docs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util.ts | Adds normalization for treeShaking config and ensures it stays normalized across merges. |
| src/files/BrsFile.ts | Records bs:keep comment line numbers for use by the tree shaker. |
| src/bscPlugin/treeShaker/TreeShaker.ts | Implements program-wide analysis, keep-rule matching, and function removal. |
| src/bscPlugin/treeShaker/TreeShaker.spec.ts | Adds extensive tests validating shaking behavior and keep mechanisms. |
| src/bscPlugin/BscPlugin.ts | Hooks tree shaking into the transpile pipeline when enabled. |
| src/BsConfig.ts | Defines treeShaking types and updates finalized config typing to normalized form. |
| docs/shaking.md | Adds user-facing documentation for enabling/configuring tree shaking and bs:keep. |
| docs/readme.md | Links to the new tree shaking documentation with a brief usage snippet. |
| bsconfig.schema.json | Adds JSON schema support for treeShaking configuration and keep rules. |
…cript into 183-tree-shaking
No description provided.