Skip to content

Commit

Permalink
chore(semantic)!: no longer generate CFG by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jun 18, 2024
1 parent ccb7d32 commit 535b3b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_semantic/tests/integration/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand Down
10 changes: 9 additions & 1 deletion crates/oxc_semantic/tests/integration/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct SemanticTester<'a> {
allocator: Allocator,
source_type: SourceType,
source_text: &'a str,
cfg: bool,
}

impl<'a> SemanticTester<'a> {
Expand All @@ -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`)
Expand All @@ -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)]
Expand All @@ -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() {
Expand Down

0 comments on commit 535b3b9

Please sign in to comment.