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

refactor(semantic): call with_trivias before build_with_jsdoc #5875

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
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ impl Runtime {
// The semantic model is not built at this stage.
let semantic_builder = SemanticBuilder::new(source_text)
.with_cfg(true)
.with_build_jsdoc(true)
.with_trivias(trivias)
.with_build_jsdoc(true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ask the linter whether there are jsdoc rules enabled. cc @DonIsaac

.with_check_syntax_error(check_syntax_errors)
.build_module_record(path, program);
let module_record = semantic_builder.module_record();
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ impl<'a> SemanticBuilder<'a> {

#[must_use]
pub fn with_trivias(mut self, trivias: Trivias) -> Self {
self.trivias = trivias.clone();
self.jsdoc = JSDocBuilder::new(self.source_text, trivias);
self.trivias = trivias;
self
}

Expand All @@ -176,8 +175,10 @@ impl<'a> SemanticBuilder<'a> {
}

/// Enable/disable JSDoc parsing.
/// `with_trivias` must be called prior to this call.
#[must_use]
pub fn with_build_jsdoc(mut self, yes: bool) -> Self {
self.jsdoc = JSDocBuilder::new(self.source_text, self.trivias.clone());
self.build_jsdoc = yes;
self
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_semantic/src/module_record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod module_record_tests {
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(source_text)
.with_trivias(ret.trivias)
.build_module_record(Path::new(""), program)
.build(program);
Arc::clone(&semantic_ret.semantic.module_record)
Expand Down
1 change: 1 addition & 0 deletions tasks/benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn bench_linter(criterion: &mut Criterion) {
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(source_text)
.with_trivias(ret.trivias)
.with_build_jsdoc(true)
.with_cfg(true)
.build_module_record(Path::new(""), program)
.build(program);
Expand Down