Skip to content

fix(ts/fast-strip): reject unsafe assertion erasure in binary expressions#11828

Merged
kdy1 merged 3 commits into
swc-project:mainfrom
magic-akari:fix/type-strip-assertions
May 20, 2026
Merged

fix(ts/fast-strip): reject unsafe assertion erasure in binary expressions#11828
kdy1 merged 3 commits into
swc-project:mainfrom
magic-akari:fix/type-strip-assertions

Conversation

@magic-akari

Copy link
Copy Markdown
Member

Description:

BREAKING CHANGE:

Related issue (if exists):

@changeset-bot

changeset-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1415b9c

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

@github-actions

Copy link
Copy Markdown
Contributor

Binary Sizes

File Size
swc.linux-x64-gnu.node 27M (27787720 bytes)

Commit: 0599219

@codspeed-hq

codspeed-hq Bot commented Apr 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 219 untouched benchmarks
⏩ 31 skipped benchmarks1


Comparing magic-akari:fix/type-strip-assertions (1415b9c) with main (3bc1c2b)

Open in CodSpeed

Footnotes

  1. 31 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.

@magic-akari magic-akari marked this pull request as ready for review April 27, 2026 18:30
@magic-akari magic-akari requested a review from a team as a code owner April 27, 2026 18:30
Copilot AI review requested due to automatic review settings April 27, 2026 18:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds safety checks to swc_ts_fast_strip to avoid producing incorrect JavaScript when stripping TypeScript-only operators (as / satisfies) inside binary-expression chains where erasure would change parse grouping.

Changes:

  • Track the current binary-expression “path” during AST visitation and reject unsafe as / satisfies erasure when it would change binary grouping.
  • Add new non-error fixtures covering “safe” precedence/associativity scenarios for assertion erasure.
  • Add new error fixtures asserting diagnostics for known-unsafe precedence/associativity cases.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/swc_ts_fast_strip/src/lib.rs Adds binary-path tracking and grouping-safety detection; emits diagnostics for unsafe as/satisfies stripping.
crates/swc_ts_fast_strip/tests/fixture/type-assertions/precedence-non-errors.ts New fixture enumerating “safe to erase” cases across operators and precedence tiers.
crates/swc_ts_fast_strip/tests/fixture/type-assertions/precedence-non-errors.js Expected StripOnly output for the new “safe cases” fixture.
crates/swc_ts_fast_strip/tests/fixture/type-assertions/precedence-non-errors.transform.js Expected Transform-mode output for the new “safe cases” fixture.
crates/swc_ts_fast_strip/tests/errors/assertion-precedence-as.ts New StripOnly error fixture for unsafe precedence change with as.
crates/swc_ts_fast_strip/tests/errors/assertion-precedence-as.swc-stderr Expected diagnostic output for the unsafe precedence as case.
crates/swc_ts_fast_strip/tests/errors/assertion-precedence-satisfies.ts New StripOnly error fixture for unsafe precedence change with satisfies.
crates/swc_ts_fast_strip/tests/errors/assertion-precedence-satisfies.swc-stderr Expected diagnostic output for the unsafe precedence satisfies case.
crates/swc_ts_fast_strip/tests/errors/assertion-associativity-as.ts New StripOnly error fixture for unsafe associativity change with as and **.
crates/swc_ts_fast_strip/tests/errors/assertion-associativity-as.swc-stderr Expected diagnostic output for the unsafe associativity as case.
crates/swc_ts_fast_strip/tests/errors/assertion-associativity-satisfies.ts New StripOnly error fixture for unsafe associativity change with satisfies and **.
crates/swc_ts_fast_strip/tests/errors/assertion-associativity-satisfies.swc-stderr Expected diagnostic output for the unsafe associativity satisfies case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/swc_ts_fast_strip/src/lib.rs Outdated
Comment thread crates/swc_ts_fast_strip/src/lib.rs
Comment thread crates/swc_ts_fast_strip/src/lib.rs
@magic-akari magic-akari marked this pull request as draft April 28, 2026 04:47
@magic-akari magic-akari force-pushed the fix/type-strip-assertions branch from e7325ed to cab6c05 Compare May 19, 2026 13:43
@magic-akari magic-akari marked this pull request as ready for review May 19, 2026 13:45

@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: cab6c05811

ℹ️ 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 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 address that feedback".

Comment thread crates/swc_ts_fast_strip/src/lib.rs Outdated
@magic-akari magic-akari marked this pull request as draft May 19, 2026 14:25
@magic-akari magic-akari force-pushed the fix/type-strip-assertions branch from cab6c05 to 48ac30b Compare May 19, 2026 15:18
@magic-akari magic-akari marked this pull request as ready for review May 19, 2026 15:47
@magic-akari magic-akari requested a review from a team as a code owner May 19, 2026 15:47
@magic-akari magic-akari requested a review from kdy1 May 19, 2026 16:04

@kdy1 kdy1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@kdy1 kdy1 enabled auto-merge (squash) May 20, 2026 04:19
@kdy1 kdy1 disabled auto-merge May 20, 2026 04:36
@kdy1 kdy1 merged commit aa5b539 into swc-project:main May 20, 2026
112 checks passed
@github-actions github-actions Bot added this to the Planned milestone May 20, 2026
@kdy1 kdy1 modified the milestones: Planned, v1.15.40 Jun 10, 2026
@magic-akari magic-akari deleted the fix/type-strip-assertions branch June 14, 2026 03:59
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.

3 participants