Skip to content

fix(es/minifier): avoid preserved name collisions - #12172

Open
labor0-bot[bot] wants to merge 9 commits into
mainfrom
fix-12155-preserved-mangle-collision
Open

fix(es/minifier): avoid preserved name collisions#12172
labor0-bot[bot] wants to merge 9 commits into
mainfrom
fix-12155-preserved-mangle-collision

Conversation

@labor0-bot

@labor0-bot labor0-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description:

Prevent mangled identifiers from colliding with preserved bindings visible from the scope where a generated name is emitted. Preserved names are now recorded in the shared renamer's reverse map so descendant scopes reject capturing candidates while unrelated scopes can still reuse them.

The minifier's name preserver also treats lexical for, for-in, and for-of bindings as scoped below the top level, while retaining top-level handling for var loop bindings.

Adds a general scope-renamer regression test and an SWC-owned execution fixture covering compression plus mangling. The reported input now reads the outer binding and prints undefined without a TDZ ReferenceError.

Validation:

  • cargo test -p swc_ecma_minifier
  • ./scripts/test.sh
  • ./scripts/exec.sh
  • cargo fmt --all
  • cargo clippy -p swc_ecma_transforms_base -p swc_ecma_minifier --all-targets -- -D warnings

The runner blocked git submodule update --init --recursive because submodules require separately bound credentials. Consequently, workspace-wide Clippy reached the test targets but could not expand the absent swc_html_parser html5lib fixtures.

Related issue (if exists):

Closes #12155

@labor0-bot
labor0-bot Bot requested a review from a team as a code owner September 1, 2026 06:27
@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5d1cbd8

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@labor0-bot

labor0-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Continue working with Labor0

Submit a formal review from Files changed, or leave an inline review comment; neither requires an @mention. To request work from Conversation, include @labor0-bot plus a meaningful instruction in the comment.

Reviews from collaborators with Write, Maintain, or Admin access are handled automatically. Ask a question for an explanation, or request a code change and Labor0 will evaluate it and update this pull request when appropriate.

Successful change requests update the branch without a routine completion reply. Labor0 replies to questions and non-actionable feedback and resolves each processed inline review thread unless clarification is required. Conversation comments have no review thread to resolve. Automated review boilerplate paired with selected inline feedback does not receive a separate reply. Related feedback may be handled together, so wait for any necessary replies, new commits, and required checks before merging.

Learn more


Labor0 task status

  • Status: Waiting for review or merge
  • Current work: None
  • Last updated: 2026-09-01 09:10 UTC

Open the Labor0 task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e39e63eef4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs Outdated
@codspeed-hq

codspeed-hq Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 200 untouched benchmarks
⏩ 61 skipped benchmarks1


Comparing fix-12155-preserved-mangle-collision (5d1cbd8) with main (c0b6f12)

Open in CodSpeed

Footnotes

  1. 61 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54bb14860c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs Outdated
Comment thread crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9fb2943431

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs Outdated
Comment thread crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs
Comment thread crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4de37c71f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs Outdated
@labor0-bot
labor0-bot Bot requested a review from a team as a code owner September 1, 2026 08:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8291763d32

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread .changeset/restrict-loop-function-preservation.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

mangle reassigns the shadowing-avoidance rename that compress introduced

1 participant