Skip to content

tree shaking#1643

Open
iObject wants to merge 48 commits intomasterfrom
183-tree-shaking
Open

tree shaking#1643
iObject wants to merge 48 commits intomasterfrom
183-tree-shaking

Conversation

@iObject
Copy link
Collaborator

@iObject iObject commented Mar 18, 2026

No description provided.

@iObject iObject linked an issue Mar 18, 2026 that may be closed by this pull request
@iObject iObject requested a review from Copilot March 18, 2026 13:44
@iObject iObject marked this pull request as draft March 18, 2026 13:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 treeShaking config in BsConfig and normalize it during config normalization.
  • Track bs:keep comment locations in BrsFile for use by the shaker.
  • Add a new TreeShaker implementation and wire it into BscPlugin’s beforeProgramTranspile, 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.

iObject and others added 3 commits March 18, 2026 10:51
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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 treeShaking config (with normalization) and wires it into the finalized options.
  • Tracks bs:keep comment directives in BrsFile and uses them in a new TreeShaker pass.
  • 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TreeShaker analysis + AST rewrite step, executed during beforeProgramTranspile when enabled.
  • Adds treeShaking configuration (types, normalization, and JSON schema) including keep rules.
  • Extends BrsFile comment processing to track bs:keep directive 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 treeShaking config (schema + normalization) and wires it into the transpile pipeline via beforeProgramTranspile.
  • Implements a new TreeShaker analysis + transform pass (includes XML interface / onChange callback retention and bs:keep comment 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.

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 12643fd. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319125722.tgz

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on b6d9d57. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319131045.tgz

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on a9b0de5. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319164640.tgz

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 treeShaking configuration (schema + normalized internal form) and wire the tree shaker into beforeProgramTranspile.
  • Track bs:keep directives from comment tokens and preserve annotated functions.
  • Implement the TreeShaker analyzer/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.

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 94f9c9d. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319212923.tgz

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 8d6d302. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319213214.tgz

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 9267d14. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260319213232.tgz

@iObject iObject marked this pull request as ready for review March 19, 2026 22:16
@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 45a03cf. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260320112118.tgz

@rokucommunity-bot
Copy link
Contributor

Hey there! I just built a new temporary npm package based on 41bcae3. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.70.3-183-tree-shaking.20260320114345.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-package create a temporary npm package on every commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree shaking

3 participants