diff --git a/crates/oxc_linter/src/service.rs b/crates/oxc_linter/src/service.rs index ba14df56f7a208..9587cb646a2551 100644 --- a/crates/oxc_linter/src/service.rs +++ b/crates/oxc_linter/src/service.rs @@ -269,6 +269,7 @@ impl Runtime { // Build the module record to unblock other threads from waiting for too long. // The semantic model is not built at this stage. let semantic_builder = SemanticBuilder::new(source_text, source_type) + .with_cfg(true) .with_trivias(trivias) .with_check_syntax_error(check_syntax_errors) .build_module_record(path.to_path_buf(), program); diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index e65b3037e9b2f0..3d416c47d4f752 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -115,7 +115,7 @@ impl<'a> SemanticBuilder<'a> { label_builder: LabelBuilder::default(), jsdoc: JSDocBuilder::new(source_text, trivias), check_syntax_error: false, - cfg: Some(ControlFlowGraphBuilder::default()), + cfg: None, class_table_builder: ClassTableBuilder::new(), ast_nodes_records: Vec::new(), } diff --git a/crates/oxc_semantic/tests/integration/cfg.rs b/crates/oxc_semantic/tests/integration/cfg.rs index fd3c157fae9d62..f0176b721b0204 100644 --- a/crates/oxc_semantic/tests/integration/cfg.rs +++ b/crates/oxc_semantic/tests/integration/cfg.rs @@ -8,7 +8,8 @@ use crate::util::SemanticTester; fn test_cfg_files() { insta::glob!("cfg_fixtures/*.js", |path| { let code = fs::read_to_string(path).unwrap(); - let output = SemanticTester::new(&code, SourceType::from_path(path).unwrap()); + let output = + SemanticTester::new(&code, SourceType::from_path(path).unwrap()).with_cfg(true); insta::assert_snapshot!(output.basic_blocks_printed()); insta::assert_snapshot!(output.cfg_dot_diagram()); }); diff --git a/crates/oxc_semantic/tests/integration/util/mod.rs b/crates/oxc_semantic/tests/integration/util/mod.rs index bd21d01a98d57b..23773afee129b8 100644 --- a/crates/oxc_semantic/tests/integration/util/mod.rs +++ b/crates/oxc_semantic/tests/integration/util/mod.rs @@ -18,6 +18,7 @@ pub struct SemanticTester<'a> { allocator: Allocator, source_type: SourceType, source_text: &'a str, + cfg: bool, } impl<'a> SemanticTester<'a> { @@ -36,7 +37,7 @@ impl<'a> SemanticTester<'a> { } pub fn new(source_text: &'a str, source_type: SourceType) -> Self { - Self { allocator: Allocator::default(), source_type, source_text } + Self { allocator: Allocator::default(), source_type, source_text, cfg: false } } /// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`) @@ -59,6 +60,12 @@ impl<'a> SemanticTester<'a> { self } + #[must_use] + pub fn with_cfg(mut self, yes: bool) -> Self { + self.cfg = yes; + self + } + /// Parse the source text and produce a new [`Semantic`] /// # Panics #[allow(unstable_name_collisions)] @@ -83,6 +90,7 @@ impl<'a> SemanticTester<'a> { .with_check_syntax_error(true) .with_trivias(parse.trivias) .build_module_record(PathBuf::new(), program) + .with_cfg(self.cfg) .build(program); if !semantic_ret.errors.is_empty() {