Latest Results
fix(formatter): preserve parens around `intrinsic` in type alias annotation (#21410)
## Summary
Fixes #20205 β `type t = (intrinsic);` was losing its parentheses during formatting, changing the AST on re-parse or producing unparseable TypeScript.
## Why this happens
The parser treats a leading `intrinsic` identifier in a type alias annotation as `TSIntrinsicKeyword`:
- `type t = intrinsic;` β `TSIntrinsicKeyword`
- `type t = (intrinsic);` β `TSParenthesizedType(TSTypeReference(IdentifierReference))`
`oxc_formatter` runs the parser with `preserve_parens: false`, which drops the `TSParenthesizedType` wrapper. Without re-emitting the parens:
| Input | Naive output | Re-parses as |
|-------|-------------|--------------|
| `type t = (intrinsic);` | `type t = intrinsic;` | `TSIntrinsicKeyword` (different AST) |
| `type t = (intrinsic) \| string;` | `type t = intrinsic \| string;` | **Syntax error** β oxc and TypeScript both reject it |
| `type t = (intrinsic) & string;` | `type t = intrinsic & string;` | **Syntax error** |
Prettier has the same bug and emits the broken outputs; we intentionally diverge to produce correct, round-trippable TypeScript.
## Fix
In `FormatWrite<TSTypeReference>::write`, detect when the reference is a bare `intrinsic` identifier AND is the leftmost descendant of a `TSTypeAliasDeclaration` (directly, or through leftmost members of union/intersection types). When so, wrap the output in parens. Any other `intrinsic` position (right arm of union, array element, object property, type arguments, etc.) is unambiguous and is left alone.
Fast-pathed on the name check so non-`intrinsic` references pay only a hash-prefixed string compare.
## Test plan
- [x] New fixture `crates/oxc_formatter/tests/fixtures/ts/parenthesis/intrinsic.ts` covers direct, leftmost-union, leftmost-intersection, right-arm, tuple, object property, and type-argument positions
- [x] Output round-trips through `oxc_parser`
- [x] `cargo test -p oxc_formatter` β 269/269 passing
- [x] `cargo run -p oxc_prettier_conformance` β js 746/753, ts 591/601 (no delta) Latest Branches
0%
0%
fazba:fix/minifier-rewrite-arguments-copy-loop 0%
04-15-fix_formatter_follow_up_on_21410 Β© 2026 CodSpeed Technology