diff --git a/crates/oxc/src/compiler.rs b/crates/oxc/src/compiler.rs index 2c8e170d53549..17430cd86a75e 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(()) } @@ -148,7 +144,7 @@ pub trait CompilerInterface { 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; } @@ -235,7 +231,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_linter/src/service/runtime.rs b/crates/oxc_linter/src/service/runtime.rs index 62b4060c4f896..5a7d63eb2f1d5 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(allocator.alloc(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_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 7a98ecb01f443..dfe5a4b892d8b 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -223,7 +223,7 @@ impl<'a> SemanticBuilder<'a> { /// Finalize the builder. /// /// # Panics - pub fn build(mut self, program: &Program<'a>) -> SemanticBuilderReturn<'a> { + pub fn build(mut self, program: &'a Program<'a>) -> SemanticBuilderReturn<'a> { self.source_text = program.source_text; self.source_type = program.source_type; if self.build_jsdoc { diff --git a/crates/oxc_semantic/src/jsdoc/builder.rs b/crates/oxc_semantic/src/jsdoc/builder.rs index 82be8c41bb8bb..0ecafbeba654c 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(allocator.alloc(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..249b93608314f 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(allocator.alloc(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..e575282b78c96 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(allocator.alloc(ret.program)).semantic } #[test] diff --git a/crates/oxc_semantic/src/lib.rs b/crates/oxc_semantic/src/lib.rs index 42b624429a67b..3bb10b9fe8652 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(allocator.alloc(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..de0547de5e6a3 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(self.allocator.alloc(parse.program)) } pub fn basic_blocks_count(&self) -> usize { diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index bec0b0bbfa511..b3bd1e4e76ca1 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -4,7 +4,7 @@ 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,14 @@ 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 Some(root_node) = ret.semantic.nodes().root_node() else { + return ControlFlow::Break(()); + }; + let AstKind::Program(program) = root_node.kind() else { + return ControlFlow::Break(()); + }; if let Some(errors) = check_semantic_ids(program) { self.errors.extend(errors); return ControlFlow::Break(());