refactor(formatter,oxfmt): Remove EmbeddedIR and use FormatElement directly#19800
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
Merging this PR will not alter performance
Comparing Footnotes
|
0fa957f to
2b3ca30
Compare
EmbeddedIR and use FormatElement directly
fe072d0 to
4a395e0
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the embedded language formatting system by removing the intermediate EmbeddedIR type and using FormatElement<'a> directly. This is a follow-up to PR #19670, which introduced GraphQL-in-JS formatting support.
Changes:
- Removed the
EmbeddedIRenum and its conversion logic fromoxc_formatter - Modified
EmbeddedDocFormatterCallbackto directly returnVec<FormatElement<'a>>instead ofVec<EmbeddedIR> - Updated the callback to receive
&Allocatorand&UniqueGroupIdBuilderparameters for arena allocation and group ID management - Made
UniqueGroupIdBuilderpublic to support external group ID creation - Moved
escape_template_charactersfunction fromembed/mod.rstofrom_prettier_doc.rs - Updated GraphQL formatting to work directly with
FormatElement<'a> - Removed unit tests from
from_prettier_doc.rs
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
crates/oxc_formatter/src/external_formatter.rs |
Updated EmbeddedDocFormatterCallback signature to accept allocator/group_id_builder and return FormatElement<'a> directly; removed EmbeddedIR enum definition |
crates/oxc_formatter/src/lib.rs |
Exported additional types (Align, Condition, Group, GroupMode, Tag, TextWidth, UniqueGroupIdBuilder) needed by external callbacks |
crates/oxc_formatter/src/formatter/state.rs |
Added group_id_builder() accessor method |
crates/oxc_formatter/src/formatter/mod.rs |
Exported UniqueGroupIdBuilder publicly |
crates/oxc_formatter/src/formatter/group_id.rs |
Changed UniqueGroupIdBuilder visibility from pub(super) to pub |
crates/oxc_formatter/src/formatter/formatter.rs |
Added group_id_builder() accessor method |
crates/oxc_formatter/src/formatter/format_element/tag.rs |
Added #[must_use] attributes to builder methods; added Align::new() constructor |
crates/oxc_formatter/src/print/template/embed/mod.rs |
Removed write_embedded_ir() function and escape_template_characters() function (moved to from_prettier_doc.rs) |
crates/oxc_formatter/src/print/template/embed/graphql.rs |
Updated to work directly with Vec<FormatElement<'a>> instead of Vec<EmbeddedIR>; uses allocator for text allocation |
apps/oxfmt/src/prettier_compat/from_prettier_doc.rs |
Rewrote to convert Doc JSON directly to FormatElement<'a> instead of EmbeddedIR; added escape_template_characters() from embed/mod.rs; removed all unit tests |
apps/oxfmt/src/core/external_formatter.rs |
Updated callback invocation to pass allocator and group_id_builder parameters |
89e4fdd to
94ac8e2
Compare
|
Thanks as always! 🫶 I've also made it compatible with Copilot reviews, so will merge it. |
Merge activity
|
…` directly (#19800) Follow up on #19670 (comment) It seems it was achievable without requiring such major changes. Thank you for your suggestion! 🙏🏻
94ac8e2 to
805ee60
Compare

Follow up on #19670 (comment)
It seems it was achievable without requiring such major changes.
Thank you for your suggestion! 🙏🏻