Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(semantic)!: no longer generate CFG by default. #3738

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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