fix(ts/fast-strip): reject unsafe assertion erasure in binary expressions#11828
Conversation
🦋 Changeset detectedLatest 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 |
Binary Sizes
Commit: 0599219 |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
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/satisfieserasure 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.
e7325ed to
cab6c05
Compare
There was a problem hiding this comment.
💡 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".
cab6c05 to
48ac30b
Compare
Description:
BREAKING CHANGE:
Related issue (if exists):