Skip to content

Comments

feat(formatter): Export doc() API to inspect IR in example#14068

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-24-feat_formatter_export_doc_api_to_inspect_ir_in_example
Sep 24, 2025
Merged

feat(formatter): Export doc() API to inspect IR in example#14068
graphite-app[bot] merged 1 commit intomainfrom
09-24-feat_formatter_export_doc_api_to_inspect_ir_in_example

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Sep 24, 2025

❯ cargo run -p oxc_formatter --example formatter t.ts --ir
    Finished `dev` profile [unoptimized] target(s) in 0.05s
     Running `target/debug/examples/formatter t.ts --ir`
[
  StaticText("import"),
  Space,
  StaticText("{"),
  Space,
  DynamicText("useState"),
  Space,
  StaticText("}"),
  Space,
  StaticText("from"),
  Space,
  LocatedTokenText("\"react\""),
  StaticText(";"),
  Line(Empty),
  StaticText("export"),
  Space,
  StaticText("function"),
  Space,
  DynamicText("useData"),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  Tag(EndGroup),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  StaticText("("),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  Tag(EndGroup),
  StaticText(")"),
  Tag(EndGroup),
  Space,
  Space,
  StaticText("{"),
  Tag(StartIndent),
  Line(Hard),

...

  StaticText("}"),
  Line(Hard),
]

@github-actions github-actions bot added the A-formatter Area - Formatter label Sep 24, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-enhancement Category - New feature or request label Sep 24, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 24, 2025

CodSpeed Instrumentation Performance Report

Merging #14068 will not alter performance

Comparing 09-24-feat_formatter_export_doc_api_to_inspect_ir_in_example (10a41ab) with main (1b3f437)

Summary

✅ 37 untouched

@leaysgur leaysgur marked this pull request as ready for review September 24, 2025 05:18
Copilot AI review requested due to automatic review settings September 24, 2025 05:18
@leaysgur leaysgur requested a review from Dunqing as a code owner September 24, 2025 05:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new doc() API to the Formatter that returns the intermediate representation (IR) before printing, allowing inspection of the formatting document structure. This enables debugging and understanding of how the formatter processes code internally.

  • Introduces doc() method that returns the formatting IR as a Document
  • Refactors build() method to use shared internal format() function
  • Adds --ir flag to formatter example to display the IR structure

Reviewed Changes

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

File Description
crates/oxc_formatter/src/lib.rs Adds doc() API and refactors build() to share formatting logic
crates/oxc_formatter/examples/formatter.rs Adds --ir flag support to display IR structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

It looks good for now. I will refactor it when the TypeScript support is complete.

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
Copy link
Member

Dunqing commented Sep 24, 2025

Merge activity

```sh
❯ cargo run -p oxc_formatter --example formatter t.ts --ir
    Finished `dev` profile [unoptimized] target(s) in 0.05s
     Running `target/debug/examples/formatter t.ts --ir`
[
  StaticText("import"),
  Space,
  StaticText("{"),
  Space,
  DynamicText("useState"),
  Space,
  StaticText("}"),
  Space,
  StaticText("from"),
  Space,
  LocatedTokenText("\"react\""),
  StaticText(";"),
  Line(Empty),
  StaticText("export"),
  Space,
  StaticText("function"),
  Space,
  DynamicText("useData"),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  Tag(EndGroup),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  StaticText("("),
  Tag(StartGroup(Group { id: None, mode: Cell { value: Flat } })),
  Tag(EndGroup),
  StaticText(")"),
  Tag(EndGroup),
  Space,
  Space,
  StaticText("{"),
  Tag(StartIndent),
  Line(Hard),

...

  StaticText("}"),
  Line(Hard),
]
```
@graphite-app graphite-app bot force-pushed the 09-24-feat_formatter_export_doc_api_to_inspect_ir_in_example branch from fe97cc6 to 10a41ab Compare September 24, 2025 06:22
@graphite-app graphite-app bot merged commit 10a41ab into main Sep 24, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 09-24-feat_formatter_export_doc_api_to_inspect_ir_in_example branch September 24, 2025 06:27
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
@Boshen Boshen mentioned this pull request Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants