Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/oxc_formatter/examples/sort_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ fn main() -> Result<(), String> {
};

let formatter = Formatter::new(&allocator, options);
let formatted = formatter.format(&ret.program);
if show_ir {
let doc = formatter.doc(&ret.program);
// Do not rely on `Display` of `Document` here, as it shows Prettier IR
println!("[");
for el in doc.iter() {
for el in formatted.document().iter() {
println!(" {el:?},");
}
println!("]");
} else {
let code = formatter.build(&ret.program);
let code = formatted.print().map_err(|e| e.to_string())?.into_code();
println!("{code}");
}

Expand Down
6 changes: 0 additions & 6 deletions crates/oxc_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ impl<'a> Formatter<'a> {
Self { allocator, source_text: "", options }
}

/// Formats the given AST `Program` and returns the IR before printing.
pub fn doc(mut self, program: &'a Program<'a>) -> Document<'a> {
let formatted = self.format(program);
formatted.into_document()
}

/// Formats the given AST `Program` and returns the formatted string.
pub fn build(mut self, program: &Program<'a>) -> String {
let formatted = self.format(program);
Expand Down
Loading