diff --git a/crates/oxc/README.md b/crates/oxc/README.md index 39a894cbb41cd..a1313f2661808 100644 --- a/crates/oxc/README.md +++ b/crates/oxc/README.md @@ -103,7 +103,7 @@ let SemanticBuilderReturn { .with_check_syntax_error(true) // Enable extra syntax error checking .with_build_jsdoc(true) // Enable JSDoc parsing .with_cfg(true) // Build a Control Flow Graph - .build(&program); // Produce the `Semantic` + .build(program); // Produce the `Semantic` errors.extend(semantic_errors); if errors.is_empty() { diff --git a/crates/oxc/src/compiler.rs b/crates/oxc/src/compiler.rs index 2c8e170d53549..e68d03d2a5c44 100644 --- a/crates/oxc/src/compiler.rs +++ b/crates/oxc/src/compiler.rs @@ -101,11 +101,7 @@ pub trait CompilerInterface { ControlFlow::Continue(()) } - fn after_semantic( - &mut self, - _program: &mut Program<'_>, - _semantic_return: &mut SemanticBuilderReturn, - ) -> ControlFlow<()> { + fn after_semantic(&mut self, _semantic_return: &mut SemanticBuilderReturn) -> ControlFlow<()> { ControlFlow::Continue(()) } @@ -134,21 +130,21 @@ pub trait CompilerInterface { self.handle_errors(parser_return.errors); } - let mut program = parser_return.program; + let program = parser_return.program; /* Isolated Declarations */ if let Some(options) = self.isolated_declaration_options() { - self.isolated_declaration(options, &allocator, &program, source_path); + self.isolated_declaration(options, &allocator, program, source_path); } /* Semantic */ - let mut semantic_return = self.semantic(&program); + let mut semantic_return = self.semantic(program); if !semantic_return.errors.is_empty() { self.handle_errors(semantic_return.errors); return; } - if self.after_semantic(&mut program, &mut semantic_return).is_break() { + if self.after_semantic(&mut semantic_return).is_break() { return; } @@ -159,14 +155,14 @@ pub trait CompilerInterface { if let Some(options) = self.transform_options() { let mut transformer_return = - self.transform(options, &allocator, &mut program, source_path, symbols, scopes); + self.transform(options, &allocator, program, source_path, symbols, scopes); if !transformer_return.errors.is_empty() { self.handle_errors(transformer_return.errors); return; } - if self.after_transform(&mut program, &mut transformer_return).is_break() { + if self.after_transform(program, &mut transformer_return).is_break() { return; } @@ -180,30 +176,23 @@ pub trait CompilerInterface { if inject_options.is_some() || define_options.is_some() { (symbols, scopes) = SemanticBuilder::new() .with_stats(stats) - .build(&program) + .build(program) .semantic .into_symbol_table_and_scope_tree(); } if let Some(options) = inject_options { - let ret = InjectGlobalVariables::new(&allocator, options).build( - symbols, - scopes, - &mut program, - ); + let ret = + InjectGlobalVariables::new(&allocator, options).build(symbols, scopes, program); symbols = ret.symbols; scopes = ret.scopes; } if let Some(options) = define_options { let ret = - ReplaceGlobalDefines::new(&allocator, options).build(symbols, scopes, &mut program); + ReplaceGlobalDefines::new(&allocator, options).build(symbols, scopes, program); Compressor::new(&allocator, CompressOptions::default()) - .dead_code_elimination_with_symbols_and_scopes( - ret.symbols, - ret.scopes, - &mut program, - ); + .dead_code_elimination_with_symbols_and_scopes(ret.symbols, ret.scopes, program); // symbols = ret.symbols; // scopes = ret.scopes; } @@ -211,17 +200,17 @@ pub trait CompilerInterface { /* Compress */ if let Some(options) = self.compress_options() { - self.compress(&allocator, &mut program, options); + self.compress(&allocator, program, options); } /* Mangler */ - let mangler = self.mangle_options().map(|options| self.mangle(&mut program, options)); + let mangler = self.mangle_options().map(|options| self.mangle(program, options)); /* Codegen */ if let Some(options) = self.codegen_options() { - let ret = self.codegen(&program, source_path, mangler, options); + let ret = self.codegen(program, source_path, mangler, options); self.after_codegen(ret); } } @@ -235,7 +224,7 @@ pub trait CompilerInterface { Parser::new(allocator, source_text, source_type).with_options(self.parse_options()).parse() } - fn semantic<'a>(&self, program: &Program<'a>) -> SemanticBuilderReturn<'a> { + fn semantic<'a>(&self, program: &'a Program<'a>) -> SemanticBuilderReturn<'a> { let mut builder = SemanticBuilder::new(); if self.transform_options().is_some() { diff --git a/crates/oxc_codegen/examples/codegen.rs b/crates/oxc_codegen/examples/codegen.rs index e941dfcbe34bd..ccdc5b921d63d 100644 --- a/crates/oxc_codegen/examples/codegen.rs +++ b/crates/oxc_codegen/examples/codegen.rs @@ -70,6 +70,6 @@ fn parse<'a>( fn codegen(ret: &ParserReturn<'_>, minify: bool) -> String { CodeGenerator::new() .with_options(CodegenOptions { minify, ..CodegenOptions::default() }) - .build(&ret.program) + .build(ret.program) .code } diff --git a/crates/oxc_codegen/examples/sourcemap.rs b/crates/oxc_codegen/examples/sourcemap.rs index e3d60072ddbf2..6d42ca446bc8c 100644 --- a/crates/oxc_codegen/examples/sourcemap.rs +++ b/crates/oxc_codegen/examples/sourcemap.rs @@ -32,7 +32,7 @@ fn main() -> std::io::Result<()> { source_map_path: Some(path.to_path_buf()), ..CodegenOptions::default() }) - .build(&ret.program); + .build(ret.program); if let Some(source_map) = map { let result = source_map.to_json_string(); diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index 9c15e0f9fea66..97bac30fe44b3 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -204,7 +204,7 @@ impl<'a> Codegen<'a> { /// /// A source map will be generated if [`CodegenOptions::source_map_path`] is set. #[must_use] - pub fn build(mut self, program: &Program<'a>) -> CodegenReturn { + pub fn build(mut self, program: &'a Program<'a>) -> CodegenReturn { self.quote = if self.options.single_quote { b'\'' } else { b'"' }; self.source_text = program.source_text; self.code.reserve(program.source_text.len()); diff --git a/crates/oxc_codegen/tests/integration/main.rs b/crates/oxc_codegen/tests/integration/main.rs index 8071ead7c5a13..280c98c272aff 100644 --- a/crates/oxc_codegen/tests/integration/main.rs +++ b/crates/oxc_codegen/tests/integration/main.rs @@ -22,7 +22,7 @@ pub fn codegen_options(source_text: &str, options: &CodegenOptions) -> CodegenRe let ret = Parser::new(&allocator, source_text, source_type).parse(); let mut options = options.clone(); options.single_quote = true; - CodeGenerator::new().with_options(options).build(&ret.program) + CodeGenerator::new().with_options(options).build(ret.program) } pub fn snapshot(name: &str, cases: &[&str]) { diff --git a/crates/oxc_codegen/tests/integration/tester.rs b/crates/oxc_codegen/tests/integration/tester.rs index 69f89835feadb..60ef046842fee 100644 --- a/crates/oxc_codegen/tests/integration/tester.rs +++ b/crates/oxc_codegen/tests/integration/tester.rs @@ -28,7 +28,7 @@ pub fn test_options_with_source_type( ) { let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let result = CodeGenerator::new().with_options(options).build(&ret.program).code; + let result = CodeGenerator::new().with_options(options).build(ret.program).code; assert_eq!(result, expected, "\nfor source: {source_text:?}"); } @@ -38,7 +38,7 @@ pub fn test_minify(source_text: &str, expected: &str) { let ret = Parser::new(&allocator, source_text, source_type).parse(); let result = CodeGenerator::new() .with_options(CodegenOptions { minify: true, ..CodegenOptions::default() }) - .build(&ret.program) + .build(ret.program) .code; assert_eq!(result, expected, "\nfor minify source: {source_text}"); } diff --git a/crates/oxc_isolated_declarations/examples/isolated_declarations.rs b/crates/oxc_isolated_declarations/examples/isolated_declarations.rs index ce354f662ae42..9de830cb8a2b3 100644 --- a/crates/oxc_isolated_declarations/examples/isolated_declarations.rs +++ b/crates/oxc_isolated_declarations/examples/isolated_declarations.rs @@ -34,7 +34,7 @@ fn main() { let id_ret = IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions { strip_internal: true }) - .build(&ret.program); + .build(ret.program); let printed = CodeGenerator::new().build(&id_ret.program).code; println!("Dts Emit:\n"); diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index ed76c03d74fa7..0e19a50b4c486 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -78,7 +78,7 @@ impl<'a> IsolatedDeclarations<'a> { /// # Errors /// /// Returns `Vec` if any errors were collected during the transformation. - pub fn build(mut self, program: &Program<'a>) -> IsolatedDeclarationsReturn<'a> { + pub fn build(mut self, program: &'a Program<'a>) -> IsolatedDeclarationsReturn<'a> { self.internal_annotations = self .strip_internal .then(|| Self::build_internal_annotations(program)) diff --git a/crates/oxc_isolated_declarations/tests/deno/mod.rs b/crates/oxc_isolated_declarations/tests/deno/mod.rs index 992fe918620c5..69af7aaf9cf4a 100644 --- a/crates/oxc_isolated_declarations/tests/deno/mod.rs +++ b/crates/oxc_isolated_declarations/tests/deno/mod.rs @@ -17,10 +17,10 @@ mod tests { &allocator, IsolatedDeclarationsOptions { strip_internal: true }, ) - .build(&ret.program); + .build(ret.program); let actual = CodeGenerator::new().build(&ret.program).code; let expected_program = Parser::new(&allocator, expected, source_type).parse().program; - let expected = CodeGenerator::new().build(&expected_program).code; + let expected = CodeGenerator::new().build(expected_program).code; assert_eq!(actual.trim(), expected.trim()); } diff --git a/crates/oxc_isolated_declarations/tests/mod.rs b/crates/oxc_isolated_declarations/tests/mod.rs index 52ff00da3f15e..50256274c6616 100644 --- a/crates/oxc_isolated_declarations/tests/mod.rs +++ b/crates/oxc_isolated_declarations/tests/mod.rs @@ -15,7 +15,7 @@ fn transform(path: &Path, source_text: &str) -> String { let id_ret = IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions { strip_internal: true }) - .build(&parser_ret.program); + .build(parser_ret.program); let code = CodeGenerator::new().build(&id_ret.program).code; let mut snapshot = diff --git a/crates/oxc_language_server/src/linter/isolated_lint_handler.rs b/crates/oxc_language_server/src/linter/isolated_lint_handler.rs index 3c2bb5ad1823d..1a4b644faaef8 100644 --- a/crates/oxc_language_server/src/linter/isolated_lint_handler.rs +++ b/crates/oxc_language_server/src/linter/isolated_lint_handler.rs @@ -131,7 +131,7 @@ impl IsolatedLintHandler { .with_cfg(true) .with_scope_tree_child_ids(true) .with_check_syntax_error(true) - .build(&ret.program); + .build(ret.program); if !semantic_ret.errors.is_empty() { let reports = semantic_ret diff --git a/crates/oxc_linter/examples/linter.rs b/crates/oxc_linter/examples/linter.rs index 571ec40ca3859..5df5dde983872 100644 --- a/crates/oxc_linter/examples/linter.rs +++ b/crates/oxc_linter/examples/linter.rs @@ -29,7 +29,7 @@ fn main() -> std::io::Result<()> { return Ok(()); } - let semantic_ret = SemanticBuilder::new().build(&ret.program); + let semantic_ret = SemanticBuilder::new().build(ret.program); let mut errors: Vec = vec![]; diff --git a/crates/oxc_linter/src/service/runtime.rs b/crates/oxc_linter/src/service/runtime.rs index 62b4060c4f896..ca7cf69a25afd 100644 --- a/crates/oxc_linter/src/service/runtime.rs +++ b/crates/oxc_linter/src/service/runtime.rs @@ -223,7 +223,7 @@ impl Runtime { .with_scope_tree_child_ids(true) .with_build_jsdoc(true) .with_check_syntax_error(check_syntax_errors) - .build(&ret.program); + .build(ret.program); if !semantic_ret.errors.is_empty() { return semantic_ret.errors.into_iter().map(|err| Message::new(err, None)).collect(); diff --git a/crates/oxc_linter/src/utils/jest.rs b/crates/oxc_linter/src/utils/jest.rs index 9ae9b6a6b1e37..30cac1c390b85 100644 --- a/crates/oxc_linter/src/utils/jest.rs +++ b/crates/oxc_linter/src/utils/jest.rs @@ -319,8 +319,7 @@ mod test { let allocator = Allocator::default(); let source_type = SourceType::default(); let parser_ret = Parser::new(&allocator, "", source_type).parse(); - let semantic_ret = - SemanticBuilder::new().with_cfg(true).build(&parser_ret.program).semantic; + let semantic_ret = SemanticBuilder::new().with_cfg(true).build(parser_ret.program).semantic; let semantic_ret = Rc::new(semantic_ret); let build_ctx = |path: &'static str| { diff --git a/crates/oxc_minifier/examples/dce.rs b/crates/oxc_minifier/examples/dce.rs index a555f124cb722..8fd8ff28eb9fb 100644 --- a/crates/oxc_minifier/examples/dce.rs +++ b/crates/oxc_minifier/examples/dce.rs @@ -39,10 +39,10 @@ fn main() -> std::io::Result<()> { fn dce(allocator: &Allocator, source_text: &str, source_type: SourceType, nospace: bool) -> String { let ret = Parser::new(allocator, source_text, source_type).parse(); - let mut program = ret.program; - Compressor::new(allocator, CompressOptions::default()).dead_code_elimination(&mut program); + let program = ret.program; + Compressor::new(allocator, CompressOptions::default()).dead_code_elimination(program); CodeGenerator::new() .with_options(CodegenOptions { minify: nospace, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code } diff --git a/crates/oxc_minifier/examples/mangler.rs b/crates/oxc_minifier/examples/mangler.rs index 70449e81a57dc..137c5969f2b7a 100644 --- a/crates/oxc_minifier/examples/mangler.rs +++ b/crates/oxc_minifier/examples/mangler.rs @@ -40,6 +40,6 @@ fn mangler(source_text: &str, source_type: SourceType, debug: bool) -> String { let ret = Parser::new(&allocator, source_text, source_type).parse(); let mangler = Mangler::new() .with_options(MangleOptions { debug, top_level: source_type.is_module() }) - .build(&ret.program); - CodeGenerator::new().with_mangler(Some(mangler)).build(&ret.program).code + .build(ret.program); + CodeGenerator::new().with_mangler(Some(mangler)).build(ret.program).code } diff --git a/crates/oxc_minifier/examples/minifier.rs b/crates/oxc_minifier/examples/minifier.rs index ab8ad88ebd03f..53719b7a6a56d 100644 --- a/crates/oxc_minifier/examples/minifier.rs +++ b/crates/oxc_minifier/examples/minifier.rs @@ -47,15 +47,15 @@ fn minify( nospace: bool, ) -> String { let ret = Parser::new(allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let options = MinifierOptions { mangle: mangle.then(MangleOptions::default), compress: CompressOptions::default(), }; - let ret = Minifier::new(options).build(allocator, &mut program); + let ret = Minifier::new(options).build(allocator, program); CodeGenerator::new() .with_options(CodegenOptions { minify: nospace, ..CodegenOptions::default() }) .with_mangler(ret.mangler) - .build(&program) + .build(program) .code } diff --git a/crates/oxc_minifier/src/tester.rs b/crates/oxc_minifier/src/tester.rs index 25e438531028a..161e6e32741b8 100644 --- a/crates/oxc_minifier/src/tester.rs +++ b/crates/oxc_minifier/src/tester.rs @@ -38,15 +38,15 @@ fn run<'a, P: CompressorPass<'a>>( remove_whitespace: bool, ) -> String { let source_type = SourceType::mjs(); - let mut program = Parser::new(allocator, source_text, source_type).parse().program; + let program = Parser::new(allocator, source_text, source_type).parse().program; if let Some(pass) = pass { let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); let mut ctx = ReusableTraverseCtx::new(scopes, symbols, allocator); - RemoveSyntax::new(CompressOptions::all_false()).build(&mut program, &mut ctx); - Normalize::new().build(&mut program, &mut ctx); - pass.build(&mut program, &mut ctx); + RemoveSyntax::new(CompressOptions::all_false()).build(program, &mut ctx); + Normalize::new().build(program, &mut ctx); + pass.build(program, &mut ctx); } CodeGenerator::new() @@ -55,6 +55,6 @@ fn run<'a, P: CompressorPass<'a>>( minify: remove_whitespace, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code } diff --git a/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs b/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs index 0422c5736aa0a..ce1a1ad03f44c 100644 --- a/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs +++ b/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs @@ -9,8 +9,8 @@ use oxc_span::SourceType; fn run(source_text: &str, source_type: SourceType) -> String { let allocator = Allocator::default(); - let mut ret = Parser::new(&allocator, source_text, source_type).parse(); - let program = &mut ret.program; + let ret = Parser::new(&allocator, source_text, source_type).parse(); + let program = ret.program; Compressor::new(&allocator, CompressOptions::default()).dead_code_elimination(program); Codegen::new().build(program).code } diff --git a/crates/oxc_minifier/tests/ecmascript/prop_name.rs b/crates/oxc_minifier/tests/ecmascript/prop_name.rs index f08caa1399a98..78d6006c2830e 100644 --- a/crates/oxc_minifier/tests/ecmascript/prop_name.rs +++ b/crates/oxc_minifier/tests/ecmascript/prop_name.rs @@ -35,5 +35,5 @@ fn test_prop_name() { assert!(ret.errors.is_empty()); let mut visitor = TestVisitor; - visitor.visit_program(&ret.program); + visitor.visit_program(ret.program); } diff --git a/crates/oxc_minifier/tests/mangler/mod.rs b/crates/oxc_minifier/tests/mangler/mod.rs index 3d76bed459fca..4395d56ae6b87 100644 --- a/crates/oxc_minifier/tests/mangler/mod.rs +++ b/crates/oxc_minifier/tests/mangler/mod.rs @@ -12,8 +12,8 @@ fn mangle(source_text: &str, top_level: bool) -> String { let ret = Parser::new(&allocator, source_text, source_type).parse(); let program = ret.program; let mangler = - Mangler::new().with_options(MangleOptions { debug: false, top_level }).build(&program); - CodeGenerator::new().with_mangler(Some(mangler)).build(&program).code + Mangler::new().with_options(MangleOptions { debug: false, top_level }).build(program); + CodeGenerator::new().with_mangler(Some(mangler)).build(program).code } #[test] diff --git a/crates/oxc_minifier/tests/mod.rs b/crates/oxc_minifier/tests/mod.rs index 09807d00eb8db..98b8b682d207d 100644 --- a/crates/oxc_minifier/tests/mod.rs +++ b/crates/oxc_minifier/tests/mod.rs @@ -22,12 +22,12 @@ pub(crate) fn run( ) -> String { let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; if let Some(options) = options { - Compressor::new(&allocator, options).build(&mut program); + Compressor::new(&allocator, options).build(program); } CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code } diff --git a/crates/oxc_parser/examples/parser.rs b/crates/oxc_parser/examples/parser.rs index 70a01f6a5a402..aa551f0b5cae8 100644 --- a/crates/oxc_parser/examples/parser.rs +++ b/crates/oxc_parser/examples/parser.rs @@ -34,7 +34,7 @@ fn main() -> Result<(), String> { if show_comments { println!("Comments:"); - for comment in ret.program.comments { + for comment in &ret.program.comments { let s = comment.content_span().source_text(&source_text); println!("{s}"); } diff --git a/crates/oxc_parser/examples/regular_expression.rs b/crates/oxc_parser/examples/regular_expression.rs index 0591615d9fd8e..f26da60f73862 100644 --- a/crates/oxc_parser/examples/regular_expression.rs +++ b/crates/oxc_parser/examples/regular_expression.rs @@ -35,7 +35,7 @@ fn main() { // - RegExpLiteral // - new RegExp() with string or template literal if static RegularExpressionVisitor { source_text: Arc::clone(&source_text) } - .visit_program(&parser_ret.program); + .visit_program(parser_ret.program); } struct RegularExpressionVisitor { diff --git a/crates/oxc_parser/examples/visitor.rs b/crates/oxc_parser/examples/visitor.rs index 3979382ee0ee9..9bdf2edbf2add 100644 --- a/crates/oxc_parser/examples/visitor.rs +++ b/crates/oxc_parser/examples/visitor.rs @@ -32,7 +32,7 @@ fn main() -> std::io::Result<()> { let program = ret.program; let mut ast_pass = CountASTNodes::default(); - ast_pass.visit_program(&program); + ast_pass.visit_program(program); println!("{ast_pass:?}"); Ok(()) diff --git a/crates/oxc_prettier/examples/prettier.rs b/crates/oxc_prettier/examples/prettier.rs index 45ff38236c56b..6c8f245c793a5 100644 --- a/crates/oxc_prettier/examples/prettier.rs +++ b/crates/oxc_prettier/examples/prettier.rs @@ -29,7 +29,7 @@ fn main() -> std::io::Result<()> { &allocator, PrettierOptions { semi, trailing_comma: TrailingComma::All, ..PrettierOptions::default() }, ) - .build(&ret.program); + .build(ret.program); println!("{output}"); Ok(()) diff --git a/crates/oxc_semantic/examples/cfg.rs b/crates/oxc_semantic/examples/cfg.rs index c3e89f2e638b4..5190b7e4be99d 100644 --- a/crates/oxc_semantic/examples/cfg.rs +++ b/crates/oxc_semantic/examples/cfg.rs @@ -56,7 +56,7 @@ fn main() -> std::io::Result<()> { println!("Wrote AST to: {}", &ast_file_name); let semantic = - SemanticBuilder::new().with_check_syntax_error(true).with_cfg(true).build(&program); + SemanticBuilder::new().with_check_syntax_error(true).with_cfg(true).build(program); if !semantic.errors.is_empty() { let error_message: String = semantic diff --git a/crates/oxc_semantic/examples/semantic.rs b/crates/oxc_semantic/examples/semantic.rs index 836a6fe2e2eda..5657b5c03c4b9 100644 --- a/crates/oxc_semantic/examples/semantic.rs +++ b/crates/oxc_semantic/examples/semantic.rs @@ -37,7 +37,7 @@ fn main() -> std::io::Result<()> { let semantic = SemanticBuilder::new() // Enable additional syntax checks not performed by the parser .with_check_syntax_error(true) - .build(&program); + .build(program); if !semantic.errors.is_empty() { let error_message: String = semantic diff --git a/crates/oxc_semantic/src/jsdoc/builder.rs b/crates/oxc_semantic/src/jsdoc/builder.rs index 82be8c41bb8bb..7b9c1f56d972f 100644 --- a/crates/oxc_semantic/src/jsdoc/builder.rs +++ b/crates/oxc_semantic/src/jsdoc/builder.rs @@ -207,7 +207,7 @@ mod test { ) -> Semantic<'a> { let source_type = source_type.unwrap_or_default(); let ret = Parser::new(allocator, source_text, source_type).parse(); - SemanticBuilder::new().with_build_jsdoc(true).build(&ret.program).semantic + SemanticBuilder::new().with_build_jsdoc(true).build(ret.program).semantic } fn get_jsdocs<'a>( diff --git a/crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs b/crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs index ec1976b4070b1..ceabe0b0a2b92 100644 --- a/crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs +++ b/crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs @@ -45,7 +45,7 @@ mod test { fn build_semantic<'a>(allocator: &'a Allocator, source_text: &'a str) -> Semantic<'a> { let source_type = SourceType::default(); let ret = Parser::new(allocator, source_text, source_type).parse(); - SemanticBuilder::new().with_build_jsdoc(true).build(&ret.program).semantic + SemanticBuilder::new().with_build_jsdoc(true).build(ret.program).semantic } #[test] diff --git a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs index 6f309d4ee756d..5282c13573c3c 100644 --- a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs +++ b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs @@ -194,7 +194,7 @@ mod test { fn build_semantic<'a>(allocator: &'a Allocator, source_text: &'a str) -> Semantic<'a> { let source_type = SourceType::default(); let ret = Parser::new(allocator, source_text, source_type).parse(); - SemanticBuilder::new().with_build_jsdoc(true).build(&ret.program).semantic + SemanticBuilder::new().with_build_jsdoc(true).build(ret.program).semantic } #[test] diff --git a/crates/oxc_semantic/src/lib.rs b/crates/oxc_semantic/src/lib.rs index 42b624429a67b..ed7cae62a97e9 100644 --- a/crates/oxc_semantic/src/lib.rs +++ b/crates/oxc_semantic/src/lib.rs @@ -247,7 +247,7 @@ mod tests { ) -> Semantic<'s> { let parse = oxc_parser::Parser::new(allocator, source, source_type).parse(); assert!(parse.errors.is_empty()); - let semantic = SemanticBuilder::new().build(&parse.program); + let semantic = SemanticBuilder::new().build(parse.program); assert!(semantic.errors.is_empty(), "Parse error: {}", semantic.errors[0]); semantic.semantic } diff --git a/crates/oxc_semantic/tests/integration/util/mod.rs b/crates/oxc_semantic/tests/integration/util/mod.rs index cc87ca60c462c..c7983e90cd21e 100644 --- a/crates/oxc_semantic/tests/integration/util/mod.rs +++ b/crates/oxc_semantic/tests/integration/util/mod.rs @@ -171,7 +171,7 @@ impl<'a> SemanticTester<'a> { .with_check_syntax_error(true) .with_cfg(self.cfg) .with_scope_tree_child_ids(self.scope_tree_child_ids) - .build(&parse.program) + .build(parse.program) } pub fn basic_blocks_count(&self) -> usize { diff --git a/crates/oxc_semantic/tests/main.rs b/crates/oxc_semantic/tests/main.rs index 4de4a3e9b3bf9..afcac47045b77 100644 --- a/crates/oxc_semantic/tests/main.rs +++ b/crates/oxc_semantic/tests/main.rs @@ -123,8 +123,7 @@ fn analyze( let allocator = Allocator::default(); let source_type = SourceType::from_path(path).unwrap(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let semantic = - SemanticBuilder::new().with_check_syntax_error(true).build(&ret.program).semantic; + let semantic = SemanticBuilder::new().with_check_syntax_error(true).build(ret.program).semantic; let ctx = TestContext { path, semantic }; let scope_snapshot = run_scope_snapshot_test(&ctx); let conformance_snapshot = conformance_suite.run_on_source(&ctx); diff --git a/crates/oxc_transformer/examples/transformer.rs b/crates/oxc_transformer/examples/transformer.rs index 19b56e6085f71..2307250124bbb 100644 --- a/crates/oxc_transformer/examples/transformer.rs +++ b/crates/oxc_transformer/examples/transformer.rs @@ -40,12 +40,12 @@ fn main() { println!("Original:\n"); println!("{source_text}\n"); - let mut program = ret.program; + let program = ret.program; let ret = SemanticBuilder::new() // Estimate transformer will triple scopes, symbols, references .with_excess_capacity(2.0) - .build(&program); + .build(program); if !ret.errors.is_empty() { println!("Semantic Errors:"); @@ -74,11 +74,8 @@ fn main() { transform_options.helper_loader.mode = HelperLoaderMode::External; - let ret = Transformer::new(&allocator, path, &transform_options).build_with_symbols_and_scopes( - symbols, - scopes, - &mut program, - ); + let ret = Transformer::new(&allocator, path, &transform_options) + .build_with_symbols_and_scopes(symbols, scopes, program); if !ret.errors.is_empty() { println!("Transformer Errors:"); @@ -88,7 +85,7 @@ fn main() { } } - let printed = CodeGenerator::new().build(&program).code; + let printed = CodeGenerator::new().build(program).code; println!("Transformed:\n"); println!("{printed}"); } diff --git a/crates/oxc_transformer/tests/integrations/main.rs b/crates/oxc_transformer/tests/integrations/main.rs index c7726c8e8c338..b6a5a5469d755 100644 --- a/crates/oxc_transformer/tests/integrations/main.rs +++ b/crates/oxc_transformer/tests/integrations/main.rs @@ -17,7 +17,7 @@ pub fn codegen(source_text: &str, source_type: SourceType) -> String { let ret = Parser::new(&allocator, source_text, source_type).parse(); CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) - .build(&ret.program) + .build(ret.program) .code } @@ -28,20 +28,17 @@ pub(crate) fn test( let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); - let ret = Transformer::new(&allocator, Path::new(""), options).build_with_symbols_and_scopes( - symbols, - scopes, - &mut program, - ); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); + let ret = Transformer::new(&allocator, Path::new(""), options) + .build_with_symbols_and_scopes(symbols, scopes, program); if !ret.errors.is_empty() { return Err(ret.errors); } let code = CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code; Ok(code) } diff --git a/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs b/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs index 140c8642ea52f..82c48e4f105e2 100644 --- a/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs +++ b/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs @@ -15,13 +15,13 @@ pub(crate) fn test(source_text: &str, expected: &str, config: InjectGlobalVariab let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); - let _ = InjectGlobalVariables::new(&allocator, config).build(symbols, scopes, &mut program); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); + let _ = InjectGlobalVariables::new(&allocator, config).build(symbols, scopes, program); let result = CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code; let expected = codegen(expected, source_type); assert_eq!(result, expected, "for source {source_text}"); diff --git a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs index 2a7c8f9edb6e3..2e838c981c8fb 100644 --- a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs +++ b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs @@ -12,13 +12,13 @@ pub(crate) fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefin let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); - let _ = ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, &mut program); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); + let _ = ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, program); let result = CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) - .build(&program) + .build(program) .code; let expected = codegen(expected, source_type); assert_eq!(result, expected, "for source {source_text}"); @@ -266,17 +266,17 @@ log(__MEMBER__); let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); - let _ = ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, &mut program); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); + let _ = ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, program); let result = CodeGenerator::new() .with_options(CodegenOptions { single_quote: true, source_map_path: Some(std::path::Path::new(&"test.js.map").to_path_buf()), ..CodegenOptions::default() }) - .build(&program); + .build(program); let output = result.code; let output_map = result.map.unwrap(); diff --git a/crates/oxc_wasm/src/lib.rs b/crates/oxc_wasm/src/lib.rs index 0eb2ef59dbbfc..239715c258c0c 100644 --- a/crates/oxc_wasm/src/lib.rs +++ b/crates/oxc_wasm/src/lib.rs @@ -198,7 +198,7 @@ impl Oxc { .preserve_parens .unwrap_or(default_parser_options.preserve_parens), }; - let ParserReturn { mut program, errors, module_record, .. } = + let ParserReturn { program, errors, module_record, .. } = Parser::new(&allocator, source_text, source_type) .with_options(oxc_parser_options) .parse(); @@ -213,7 +213,7 @@ impl Oxc { semantic_builder = semantic_builder.with_excess_capacity(2.0); } let semantic_ret = - semantic_builder.with_check_syntax_error(true).with_cfg(true).build(&program); + semantic_builder.with_check_syntax_error(true).with_cfg(true).build(program); let semantic = semantic_ret.semantic; self.control_flow_graph = semantic.cfg().map_or_else(String::default, |cfg| { @@ -229,7 +229,7 @@ impl Oxc { } let module_record = Arc::new(ModuleRecord::new(&path, &module_record, &semantic)); - self.run_linter(&run_options, &path, &program, &module_record); + self.run_linter(&run_options, &path, program, &module_record); self.run_prettier(&run_options, source_text, source_type); @@ -237,7 +237,7 @@ impl Oxc { if !source_type.is_typescript_definition() { if run_options.scope.unwrap_or_default() { - self.scope_text = Self::get_scope_text(&program, &symbols, &scopes); + self.scope_text = Self::get_scope_text(program, &symbols, &scopes); } if run_options.symbol.unwrap_or_default() { self.symbols = self.get_symbols_text(&symbols)?; @@ -259,7 +259,7 @@ impl Oxc { }) .unwrap_or_default(); let result = Transformer::new(&allocator, &path, &options) - .build_with_symbols_and_scopes(symbols, scopes, &mut program); + .build_with_symbols_and_scopes(symbols, scopes, program); if !result.errors.is_empty() { self.save_diagnostics(result.errors.into_iter().collect::>()); } @@ -281,7 +281,7 @@ impl Oxc { CompressOptions::all_false() }, }; - Minifier::new(options).build(&allocator, &mut program).mangler + Minifier::new(options).build(&allocator, program).mangler } else { None }; @@ -292,7 +292,7 @@ impl Oxc { minify: minifier_options.whitespace.unwrap_or_default(), ..CodegenOptions::default() }) - .build(&program) + .build(program) .code; Ok(()) @@ -338,14 +338,14 @@ impl Oxc { let mut prettier = Prettier::new(&allocator, PrettierOptions::default()); if run_options.prettier_format.unwrap_or_default() { - self.prettier_formatted_text = prettier.build(&ret.program); + self.prettier_formatted_text = prettier.build(ret.program); } if run_options.prettier_ir.unwrap_or_default() { - let prettier_doc = prettier.doc(&ret.program).to_string(); + 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, PrettierOptions::default()).build(&ret.program) + Prettier::new(&allocator, PrettierOptions::default()).build(ret.program) }; } } diff --git a/napi/minify/src/lib.rs b/napi/minify/src/lib.rs index 6ddeecfa90af0..4271fb62340da 100644 --- a/napi/minify/src/lib.rs +++ b/napi/minify/src/lib.rs @@ -12,18 +12,18 @@ pub fn minify(filename: String, source_text: String) -> String { let allocator = Allocator::default(); let source_type = SourceType::from_path(&filename).unwrap_or_default().with_typescript(true); - let mut program = Parser::new(&allocator, &source_text, source_type).parse().program; + let program = Parser::new(&allocator, &source_text, source_type).parse().program; let mangler = Minifier::new(MinifierOptions { mangle: Some(MangleOptions::default()), compress: CompressOptions::default(), }) - .build(&allocator, &mut program) + .build(&allocator, program) .mangler; Codegen::new() .with_options(CodegenOptions { minify: true, ..CodegenOptions::default() }) .with_mangler(mangler) - .build(&program) + .build(program) .code } diff --git a/napi/transform/src/isolated_declaration.rs b/napi/transform/src/isolated_declaration.rs index ffbaf37263fb0..7cce5bb105d39 100644 --- a/napi/transform/src/isolated_declaration.rs +++ b/napi/transform/src/isolated_declaration.rs @@ -60,7 +60,7 @@ pub fn isolated_declaration( strip_internal: options.strip_internal.unwrap_or(false), }, ) - .build(&ret.program); + .build(ret.program); let source_map_path = match options.sourcemap { Some(true) => Some(source_path.to_path_buf()), diff --git a/tasks/benchmark/benches/codegen.rs b/tasks/benchmark/benches/codegen.rs index d761ec33736ff..d40fe28f5f807 100644 --- a/tasks/benchmark/benches/codegen.rs +++ b/tasks/benchmark/benches/codegen.rs @@ -19,22 +19,22 @@ fn bench_codegen(criterion: &mut Criterion) { // Codegen let parser_ret = Parser::new(&allocator, source_text, source_type).parse(); assert!(parser_ret.errors.is_empty()); - let mut program = parser_ret.program; + let program = parser_ret.program; let mut group = criterion.benchmark_group("codegen"); group.bench_function(id.clone(), |b| { - b.iter_with_large_drop(|| CodeGenerator::new().build(&program).map); + b.iter_with_large_drop(|| CodeGenerator::new().build(program).map); }); group.finish(); // Codegen sourcemap let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); let transform_options = TransformOptions::enable_all(); let transformer_ret = Transformer::new(&allocator, Path::new(&file.file_name), &transform_options) - .build_with_symbols_and_scopes(symbols, scopes, &mut program); + .build_with_symbols_and_scopes(symbols, scopes, program); assert!(transformer_ret.errors.is_empty()); let mut group = criterion.benchmark_group("codegen_sourcemap"); @@ -45,7 +45,7 @@ fn bench_codegen(criterion: &mut Criterion) { source_map_path: Some(PathBuf::from(&file.file_name)), ..CodegenOptions::default() }) - .build(&program) + .build(program) }); }); group.finish(); diff --git a/tasks/benchmark/benches/isolated_declarations.rs b/tasks/benchmark/benches/isolated_declarations.rs index 6f638b9877b60..fa41ea525ad93 100644 --- a/tasks/benchmark/benches/isolated_declarations.rs +++ b/tasks/benchmark/benches/isolated_declarations.rs @@ -25,7 +25,7 @@ fn bench_isolated_declarations(criterion: &mut Criterion) { &allocator, IsolatedDeclarationsOptions { strip_internal: true }, ) - .build(&program); + .build(program); }); }); diff --git a/tasks/benchmark/benches/linter.rs b/tasks/benchmark/benches/linter.rs index cf1d096287265..735be54ee82ad 100644 --- a/tasks/benchmark/benches/linter.rs +++ b/tasks/benchmark/benches/linter.rs @@ -35,7 +35,7 @@ fn bench_linter(criterion: &mut Criterion) { .with_build_jsdoc(true) .with_scope_tree_child_ids(true) .with_cfg(true) - .build(&ret.program); + .build(ret.program); let semantic = semantic_ret.semantic; let module_record = Arc::new(ModuleRecord::new(path, &ret.module_record, &semantic)); let semantic = Rc::new(semantic); diff --git a/tasks/benchmark/benches/minifier.rs b/tasks/benchmark/benches/minifier.rs index 486a5f119c727..315ee7e268b38 100644 --- a/tasks/benchmark/benches/minifier.rs +++ b/tasks/benchmark/benches/minifier.rs @@ -24,20 +24,17 @@ fn bench_minifier(criterion: &mut Criterion) { allocator.reset(); // Create fresh AST + semantic data for each iteration - let mut program = Parser::new(&allocator, source_text, source_type).parse().program; + let program = Parser::new(&allocator, source_text, source_type).parse().program; let (symbols, scopes) = SemanticBuilder::new() - .build(&program) + .build(program) .semantic .into_symbol_table_and_scope_tree(); let options = CompressOptions::all_true(); runner.run(|| { - Compressor::new(&allocator, options).build_with_symbols_and_scopes( - symbols, - scopes, - &mut program, - ); + Compressor::new(&allocator, options) + .build_with_symbols_and_scopes(symbols, scopes, program); }); }); }); diff --git a/tasks/benchmark/benches/prettier.rs b/tasks/benchmark/benches/prettier.rs index 99ad05811ba7c..61dd52dfa1e63 100644 --- a/tasks/benchmark/benches/prettier.rs +++ b/tasks/benchmark/benches/prettier.rs @@ -16,7 +16,7 @@ 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, PrettierOptions::default()).build(&ret.program); + let _ = Prettier::new(&allocator2, PrettierOptions::default()).build(ret.program); }); }); } diff --git a/tasks/benchmark/benches/semantic.rs b/tasks/benchmark/benches/semantic.rs index 37583f02469e7..59063171cd186 100644 --- a/tasks/benchmark/benches/semantic.rs +++ b/tasks/benchmark/benches/semantic.rs @@ -19,7 +19,7 @@ fn bench_semantic(criterion: &mut Criterion) { // We return `error`s to be dropped outside of the measured section, as usually // code would have no errors. One of our benchmarks `cal.com.tsx` has a lot of errors, // but that's atypical, so don't want to include it in benchmark time. - let ret = SemanticBuilder::new().with_build_jsdoc(true).build(&ret.program); + let ret = SemanticBuilder::new().with_build_jsdoc(true).build(ret.program); let ret = black_box(ret); ret.errors }); diff --git a/tasks/benchmark/benches/transformer.rs b/tasks/benchmark/benches/transformer.rs index f12d4e872d7b2..615705f5949dd 100644 --- a/tasks/benchmark/benches/transformer.rs +++ b/tasks/benchmark/benches/transformer.rs @@ -31,12 +31,12 @@ fn bench_transformer(criterion: &mut Criterion) { allocator.reset(); // Create fresh AST + semantic data for each iteration - let ParserReturn { mut program, .. } = + let ParserReturn { program, .. } = Parser::new(&allocator, source_text, source_type).parse(); let (symbols, scopes) = SemanticBuilder::new() // Estimate transformer will triple scopes, symbols, references .with_excess_capacity(2.0) - .build(&program) + .build(program) .semantic .into_symbol_table_and_scope_tree(); @@ -46,11 +46,7 @@ fn bench_transformer(criterion: &mut Criterion) { Path::new(&file.file_name), &transform_options, ) - .build_with_symbols_and_scopes( - symbols, - scopes, - &mut program, - ); + .build_with_symbols_and_scopes(symbols, scopes, program); // Return the `TransformerReturn`, so it's dropped outside of the measured section. // `TransformerReturn` contains `ScopeTree` and `SymbolTable` which are costly to drop. diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index bec0b0bbfa511..904b3cae5cd44 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -1,10 +1,10 @@ -use std::{ops::ControlFlow, path::PathBuf}; +use std::{hint::unreachable_unchecked, ops::ControlFlow, path::PathBuf}; use rustc_hash::FxHashSet; use oxc::{ allocator::Allocator, - ast::{ast::Program, Comment}, + ast::{ast::Program, AstKind, Comment}, codegen::{CodegenOptions, CodegenReturn}, diagnostics::OxcDiagnostic, minifier::CompressOptions, @@ -80,12 +80,12 @@ impl CompilerInterface for Driver { ControlFlow::Continue(()) } - fn after_semantic( - &mut self, - program: &mut Program<'_>, - ret: &mut SemanticBuilderReturn, - ) -> ControlFlow<()> { + fn after_semantic(&mut self, ret: &mut SemanticBuilderReturn) -> ControlFlow<()> { if self.check_semantic { + let AstKind::Program(program) = ret.semantic.nodes().root_node().unwrap().kind() else { + // SAFETY: root_node is guaranteed to be Program + unsafe { unreachable_unchecked() }; + }; if let Some(errors) = check_semantic_ids(program) { self.errors.extend(errors); return ControlFlow::Break(()); diff --git a/tasks/coverage/src/runtime/mod.rs b/tasks/coverage/src/runtime/mod.rs index 5840095154b04..0c9d009d9b8f5 100644 --- a/tasks/coverage/src/runtime/mod.rs +++ b/tasks/coverage/src/runtime/mod.rs @@ -181,25 +181,22 @@ impl Test262RuntimeCase { let is_only_strict = self.base.is_only_strict(); let source_type = SourceType::cjs().with_module(is_module); let allocator = Allocator::default(); - let mut program = Parser::new(&allocator, source_text, source_type).parse().program; + let program = Parser::new(&allocator, source_text, source_type).parse().program; if transform { let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); let mut options = TransformOptions::enable_all(); options.jsx.refresh = None; options.helper_loader.mode = HelperLoaderMode::External; options.typescript.only_remove_type_imports = true; - Transformer::new(&allocator, self.path(), &options).build_with_symbols_and_scopes( - symbols, - scopes, - &mut program, - ); + Transformer::new(&allocator, self.path(), &options) + .build_with_symbols_and_scopes(symbols, scopes, program); } let mangler = if minify { Minifier::new(MinifierOptions { mangle: None, ..MinifierOptions::default() }) - .build(&allocator, &mut program) + .build(&allocator, program) .mangler } else { None @@ -208,7 +205,7 @@ impl Test262RuntimeCase { let mut text = CodeGenerator::new() .with_options(CodegenOptions { minify, ..CodegenOptions::default() }) .with_mangler(mangler) - .build(&program) + .build(program) .code; if is_only_strict { text = format!("\"use strict\";\n{text}"); diff --git a/tasks/coverage/src/tools/prettier.rs b/tasks/coverage/src/tools/prettier.rs index aaf9f1750728c..0b1c40f861ce7 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, 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, options).build(&program); + let source_text2 = Prettier::new(&allocator, options).build(program); if source_text1 == source_text2 { TestResult::Passed diff --git a/tasks/coverage/src/typescript/meta.rs b/tasks/coverage/src/typescript/meta.rs index 368b2ef6edf55..af6f657260a12 100644 --- a/tasks/coverage/src/typescript/meta.rs +++ b/tasks/coverage/src/typescript/meta.rs @@ -203,7 +203,7 @@ impl Baseline { let allocator = Allocator::default(); let source_type = SourceType::from_path(Path::new(&self.name)).unwrap(); let ret = Parser::new(&allocator, &self.original, source_type).parse(); - let printed = CodeGenerator::new().build(&ret.program).code; + let printed = CodeGenerator::new().build(ret.program).code; self.oxc_printed = printed; } diff --git a/tasks/coverage/src/typescript/transpile_runner.rs b/tasks/coverage/src/typescript/transpile_runner.rs index 30118f019dc79..8c22a6349a4da 100644 --- a/tasks/coverage/src/typescript/transpile_runner.rs +++ b/tasks/coverage/src/typescript/transpile_runner.rs @@ -180,7 +180,7 @@ fn transpile(path: &Path, source_text: &str) -> (String, Vec) { let ret = Parser::new(&allocator, source_text, source_type).parse(); let ret = IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions { strip_internal: true }) - .build(&ret.program); + .build(ret.program); let printed = CodeGenerator::new().build(&ret.program).code; (printed, ret.errors) } diff --git a/tasks/minsize/src/lib.rs b/tasks/minsize/src/lib.rs index 516e503c813fc..1bf2b81e8d8f8 100644 --- a/tasks/minsize/src/lib.rs +++ b/tasks/minsize/src/lib.rs @@ -135,19 +135,19 @@ fn minify_twice(file: &TestFile) -> String { fn minify(source_text: &str, source_type: SourceType) -> String { let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); - let mut program = ret.program; + let program = ret.program; let (symbols, scopes) = - SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); + SemanticBuilder::new().build(program).semantic.into_symbol_table_and_scope_tree(); let _ = ReplaceGlobalDefines::new( &allocator, ReplaceGlobalDefinesConfig::new(&[("process.env.NODE_ENV", "'development'")]).unwrap(), ) - .build(symbols, scopes, &mut program); - let ret = Minifier::new(MinifierOptions::default()).build(&allocator, &mut program); + .build(symbols, scopes, program); + let ret = Minifier::new(MinifierOptions::default()).build(&allocator, program); CodeGenerator::new() .with_options(CodegenOptions { minify: true, comments: false, ..CodegenOptions::default() }) .with_mangler(ret.mangler) - .build(&program) + .build(program) .code } diff --git a/tasks/prettier_conformance/src/lib.rs b/tasks/prettier_conformance/src/lib.rs index fe4c61ef3699e..785828860634a 100644 --- a/tasks/prettier_conformance/src/lib.rs +++ b/tasks/prettier_conformance/src/lib.rs @@ -365,5 +365,5 @@ fn run_oxc_prettier( let ret = Parser::new(&allocator, source_text, source_type) .with_options(ParseOptions { preserve_parens: false, ..ParseOptions::default() }) .parse(); - Prettier::new(&allocator, prettier_options).build(&ret.program) + Prettier::new(&allocator, prettier_options).build(ret.program) } diff --git a/tasks/prettier_conformance/src/spec.rs b/tasks/prettier_conformance/src/spec.rs index 3f0b82c8a948a..191990ea33b5b 100644 --- a/tasks/prettier_conformance/src/spec.rs +++ b/tasks/prettier_conformance/src/spec.rs @@ -37,8 +37,8 @@ impl SpecParser { let allocator = Allocator::default(); let source_type = SourceType::from_path(spec).unwrap_or_default(); - let mut ret = Parser::new(&allocator, &spec_content, source_type).parse(); - self.visit_program(&mut ret.program); + let ret = Parser::new(&allocator, &spec_content, source_type).parse(); + self.visit_program(ret.program); } } diff --git a/tasks/rulegen/src/main.rs b/tasks/rulegen/src/main.rs index c819ed24218ea..be14012c45c76 100644 --- a/tasks/rulegen/src/main.rs +++ b/tasks/rulegen/src/main.rs @@ -685,7 +685,7 @@ fn main() { let ret = Parser::new(&allocator, &body, source_type).parse(); let mut state = State::new(&body); - state.visit_program(&ret.program); + state.visit_program(ret.program); let pass_cases = state.pass_cases(); let fail_cases = state.fail_cases(); diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 7ca647d79fab4..8d2af12a67452 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -311,7 +311,7 @@ impl TestCase { comments: false, ..CodegenOptions::default() }) - .build(&ret.program) + .build(ret.program) .code }, );