diff --git a/crates/oxc_prettier/examples/prettier.rs b/crates/oxc_prettier/examples/prettier.rs index 038819de2d6c32..45ff38236c56b9 100644 --- a/crates/oxc_prettier/examples/prettier.rs +++ b/crates/oxc_prettier/examples/prettier.rs @@ -27,7 +27,6 @@ fn main() -> std::io::Result<()> { .parse(); let output = Prettier::new( &allocator, - &source_text, PrettierOptions { semi, trailing_comma: TrailingComma::All, ..PrettierOptions::default() }, ) .build(&ret.program); diff --git a/crates/oxc_prettier/src/lib.rs b/crates/oxc_prettier/src/lib.rs index 5475ecee1b36f5..74d093c221c2ed 100644 --- a/crates/oxc_prettier/src/lib.rs +++ b/crates/oxc_prettier/src/lib.rs @@ -71,10 +71,10 @@ impl<'a> DocBuilder<'a> for Prettier<'a> { impl<'a> Prettier<'a> { #[allow(clippy::needless_pass_by_value)] - pub fn new(allocator: &'a Allocator, source_text: &'a str, options: PrettierOptions) -> Self { + pub fn new(allocator: &'a Allocator, options: PrettierOptions) -> Self { Self { allocator, - source_text, + source_text: "", options, stack: vec![], group_id_builder: GroupIdBuilder::default(), @@ -83,8 +83,9 @@ impl<'a> Prettier<'a> { } pub fn build(&mut self, program: &Program<'a>) -> String { + self.source_text = program.source_text; let doc = program.format(self); - Printer::new(doc, self.source_text, self.options, self.allocator).build() + Printer::new(doc, program.source_text, self.options, self.allocator).build() } pub fn doc(mut self, program: &Program<'a>) -> Doc<'a> { diff --git a/crates/oxc_wasm/src/lib.rs b/crates/oxc_wasm/src/lib.rs index 4f533bb99b32de..abea67d29ccfb5 100644 --- a/crates/oxc_wasm/src/lib.rs +++ b/crates/oxc_wasm/src/lib.rs @@ -316,7 +316,7 @@ impl Oxc { .with_options(ParseOptions { preserve_parens: false, ..ParseOptions::default() }) .parse(); - let mut prettier = Prettier::new(&allocator, source_text, PrettierOptions::default()); + let mut prettier = Prettier::new(&allocator, PrettierOptions::default()); if run_options.prettier_format.unwrap_or_default() { self.prettier_formatted_text = prettier.build(&ret.program); @@ -326,8 +326,7 @@ impl Oxc { let prettier_doc = prettier.doc(&ret.program).to_string(); self.prettier_ir_text = { let ret = Parser::new(&allocator, &prettier_doc, SourceType::default()).parse(); - Prettier::new(&allocator, &prettier_doc, PrettierOptions::default()) - .build(&ret.program) + Prettier::new(&allocator, PrettierOptions::default()).build(&ret.program) }; } } diff --git a/tasks/benchmark/benches/prettier.rs b/tasks/benchmark/benches/prettier.rs index 73037a8c09485f..0c0961b36f1eab 100644 --- a/tasks/benchmark/benches/prettier.rs +++ b/tasks/benchmark/benches/prettier.rs @@ -17,8 +17,8 @@ fn bench_prettier(criterion: &mut Criterion) { let allocator1 = Allocator::default(); let allocator2 = Allocator::default(); let ret = Parser::new(&allocator1, source_text, source_type).parse(); - let _ = Prettier::new(&allocator2, source_text, PrettierOptions::default()) - .build(&ret.program); + let _ = + Prettier::new(&allocator2, PrettierOptions::default()).build(&ret.program); }); }, ); diff --git a/tasks/coverage/src/tools/prettier.rs b/tasks/coverage/src/tools/prettier.rs index 9cfadbf1123b3e..36f7ad2f20404b 100644 --- a/tasks/coverage/src/tools/prettier.rs +++ b/tasks/coverage/src/tools/prettier.rs @@ -23,12 +23,12 @@ fn get_result(source_text: &str, source_type: SourceType) -> TestResult { let parse_options = ParseOptions { preserve_parens: false, ..ParseOptions::default() }; let ParserReturn { program, .. } = Parser::new(&allocator, source_text, source_type).with_options(parse_options).parse(); - let source_text1 = Prettier::new(&allocator, source_text, options).build(&program); + let source_text1 = Prettier::new(&allocator, options).build(&program); let allocator = Allocator::default(); let ParserReturn { program, .. } = Parser::new(&allocator, &source_text1, source_type).with_options(parse_options).parse(); - let source_text2 = Prettier::new(&allocator, &source_text1, options).build(&program); + let source_text2 = Prettier::new(&allocator, options).build(&program); if source_text1 == source_text2 { TestResult::Passed diff --git a/tasks/prettier_conformance/src/lib.rs b/tasks/prettier_conformance/src/lib.rs index 31d4153c050573..d7f37b06a3c40a 100644 --- a/tasks/prettier_conformance/src/lib.rs +++ b/tasks/prettier_conformance/src/lib.rs @@ -389,7 +389,7 @@ impl TestRunner { let ret = Parser::new(&allocator, source_text, source_type) .with_options(ParseOptions { preserve_parens: false, ..ParseOptions::default() }) .parse(); - Prettier::new(&allocator, source_text, prettier_options).build(&ret.program) + Prettier::new(&allocator, prettier_options).build(&ret.program) } }