Skip to content

feat: module mangling & tree shaking - #1

Merged
AlphaKR93 merged 2 commits into
devfrom
claude/mangle-treeshake
Sep 21, 2026
Merged

AlphaKR93 merged 2 commits into
devfrom
claude/mangle-treeshake

Conversation

@AlphaKR93

Copy link
Copy Markdown
Member

Summary

  • Add project-wide module-level mangling (locals/nonlocals) and tree-shaking of unreachable/unused code.
  • Resolve FFI library binaries so they're carried through project-wide processing correctly.

Test plan

  • Run project-mode minify over a multi-module tree with FFI resources and confirm output is syntactically valid and importable.
  • Verify mangled names don't collide across linked modules.

@AlphaKR93
AlphaKR93 changed the base branch from main to dev July 24, 2026 06:14
@AlphaKR93
AlphaKR93 marked this pull request as draft July 24, 2026 16:42
Comment thread src/terser/project.py Outdated
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/mangler/_modules.py
Comment thread src/terser/_pipeline/tree_shake.py
@AlphaKR93
AlphaKR93 added this pull request to stack #8 September 21, 2026 03:14
@AlphaKR93
AlphaKR93 force-pushed the claude/mangle-treeshake branch from 210de85 to bcea787 Compare September 21, 2026 03:48
@AlphaKR93
AlphaKR93 marked this pull request as ready for review September 21, 2026 03:49
AlphaKR93 pushed a commit that referenced this pull request Sep 21, 2026
- Represent FFI binaries as a proper FfiModuleSpec occupying their
  namespace slot in PathProvider's module tree, instead of tracking
  them separately and re-deriving their dotted path via ad hoc
  root/prefix matching. Fixes ABI-tagged filenames (e.g.
  foo.cpython-314-x86_64-linux-gnu.so) being mis-split on suffix.
  FFI specs are explicitly excluded before parsing, since there's no
  source for the AST.
- Inline the single-use `_insert_after` helper into
  `_rename_import_alias`, reversing the loop condition to continue/
  return early.
- Rename module-private helpers in mangler/_modules.py and
  tree_shake.py to the double-underscore convention used elsewhere
  for names not used outside their module.
- Move `module_output_path` out of the mangler package into
  project.py, its only caller.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N9opxiKpdU1g69c2rVJnqk
AlphaKR93 pushed a commit that referenced this pull request Sep 21, 2026
- Represent FFI binaries as a proper FfiModuleSpec occupying their
  namespace slot in PathProvider's module tree, instead of tracking
  them separately and re-deriving their dotted path via ad hoc
  root/prefix matching. Fixes ABI-tagged filenames (e.g.
  foo.cpython-314-x86_64-linux-gnu.so) being mis-split on suffix.
  FFI specs are explicitly excluded before parsing, since there's no
  source for the AST.
- Inline the single-use `_insert_after` helper into
  `_rename_import_alias`, reversing the loop condition to continue/
  return early.
- Rename module-private helpers in mangler/_modules.py and
  tree_shake.py to the double-underscore convention used elsewhere
  for names not used outside their module.
- Move `module_output_path` out of the mangler package into
  project.py, its only caller.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N9opxiKpdU1g69c2rVJnqk
@AlphaKR93
AlphaKR93 force-pushed the claude/mangle-treeshake branch from bcea787 to c041f1d Compare September 21, 2026 03:57
AlphaKR93 pushed a commit that referenced this pull request Sep 21, 2026
- Represent FFI binaries as a proper FfiModuleSpec occupying their
  namespace slot in PathProvider's module tree, instead of tracking
  them separately and re-deriving their dotted path via ad hoc
  root/prefix matching. Fixes ABI-tagged filenames (e.g.
  foo.cpython-314-x86_64-linux-gnu.so) being mis-split on suffix.
  FFI specs are explicitly excluded before parsing, since there's no
  source for the AST.
- Inline the single-use `_insert_after` helper into
  `_rename_import_alias`, reversing the loop condition to continue/
  return early.
- Rename module-private helpers in mangler/_modules.py and
  tree_shake.py to the double-underscore convention used elsewhere
  for names not used outside their module.
- Move `module_output_path` out of the mangler package into
  project.py, its only caller.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N9opxiKpdU1g69c2rVJnqk
@AlphaKR93
AlphaKR93 merged commit a6ce542 into dev Sep 21, 2026
@AlphaKR93
AlphaKR93 deleted the claude/mangle-treeshake branch September 21, 2026 03:58
AlphaKR93 added a commit that referenced this pull request Sep 21, 2026
- Represent FFI binaries as a proper FfiModuleSpec occupying their
  namespace slot in PathProvider's module tree, instead of tracking
  them separately and re-deriving their dotted path via ad hoc
  root/prefix matching. Fixes ABI-tagged filenames (e.g.
  foo.cpython-314-x86_64-linux-gnu.so) being mis-split on suffix.
  FFI specs are explicitly excluded before parsing, since there's no
  source for the AST.
- Inline the single-use `_insert_after` helper into
  `_rename_import_alias`, reversing the loop condition to continue/
  return early.
- Rename module-private helpers in mangler/_modules.py and
  tree_shake.py to the double-underscore convention used elsewhere
  for names not used outside their module.
- Move `module_output_path` out of the mangler package into
  project.py, its only caller.


Claude-Session: https://claude.ai/code/session_01N9opxiKpdU1g69c2rVJnqk

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants