Skip to content

refactor(formatter): port is_complex_type_arguments from Prettier#19399

Merged
graphite-app[bot] merged 1 commit intomainfrom
refactor/formatter-is-complex-type-arguments
Feb 16, 2026
Merged

refactor(formatter): port is_complex_type_arguments from Prettier#19399
graphite-app[bot] merged 1 commit intomainfrom
refactor/formatter-is-complex-type-arguments

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Feb 15, 2026

Summary

  • Replaces the heuristic approximation in is_complex_type_arguments with the actual Prettier approach: willBreak(print(typeArgs)) via Formatter::will_break(type_arguments, span)
  • Adds Formatter::will_break(content, span) — a method that speculatively formats content and checks if it would break, with proper comment handling:
    1. Snapshots the comment state
    2. Skips comments before span.start (so only comments within the content are processed)
    3. Formats content and checks will_break()
    4. Restores the comment state
  • Adds CommentStateSnapshot and snapshot/restore methods to Comments
  • Adds Comments::skip_comments_before(pos) to skip comments outside the span of interest

This ensures that speculative formatting only processes comments within the formatted content's span, preventing comment state corruption.

Test plan

  • cargo clippy -p oxc_formatter — no warnings
  • cargo run -p oxc_prettier_conformance — no regression (js 746/753, ts 591/601)

🤖 Generated with Claude Code

@github-actions github-actions bot added A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Feb 15, 2026
@Dunqing Dunqing requested a review from leaysgur February 15, 2026 14:56
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 15, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing refactor/formatter-is-complex-type-arguments (46803f8) with main (c2b1870)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on main (706be70) during the generation of this report, so c2b1870 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Dunqing Dunqing force-pushed the refactor/formatter-is-complex-type-arguments branch 4 times, most recently from e7c46a1 to 46803f8 Compare February 15, 2026 15:09
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

So we've returned #17353 in the end. 👀

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Feb 16, 2026
Copy link
Member

leaysgur commented Feb 16, 2026

Merge activity

…19399)

I've found many differences caused by this in a private codebase. To fix this, we have to fully match this logic from Prettier, anyway.

## Summary

- Replaces the heuristic approximation in `is_complex_type_arguments` with the actual Prettier approach: `willBreak(print(typeArgs))` via `f.intern(type_arguments).will_break()`
- The previous code used custom `is_complex_type_reference` / `is_complex_ts_type` / `has_comment_in_span` heuristics to approximate the check
- Comment cursor advancement from `f.intern()` is not a concern here because the caller already guards with `has_comment_in_span(call_expressions[0].span)`

## Test plan

- [x] `cargo clippy -p oxc_formatter` — no warnings
- [x] `cargo run -p oxc_prettier_conformance` — no regression (js 746/753, ts 591/601)
- [x] `cargo run -p oxc_prettier_conformance -- --filter assignment` — all pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the refactor/formatter-is-complex-type-arguments branch from 46803f8 to 5f705e7 Compare February 16, 2026 00:49
@graphite-app graphite-app bot merged commit 5f705e7 into main Feb 16, 2026
21 checks passed
@graphite-app graphite-app bot deleted the refactor/formatter-is-complex-type-arguments branch February 16, 2026 00:55
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 16, 2026
leaysgur added a commit that referenced this pull request Feb 16, 2026
graphite-app bot pushed a commit that referenced this pull request Feb 16, 2026
> https://github.com/oxc-project/monitor-oxc/actions/runs/22057084633/job/63727963672

Formatter DCR detected this:

```ts
export const globalRegistry: $ZodRegistry<GlobalMeta> = /*@__PURE__*/ registry<GlobalMeta>();
```

becomes

```ts
export const globalRegistry: $ZodRegistry<GlobalMeta> = registry<GlobalMeta>();
```

(`BlockComment` removed)

So, I'll revert it for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants