Skip to content

Commit

Permalink
refactor(semantic): change build_module_record to accept &Path inst…
Browse files Browse the repository at this point in the history
…ead of PathBuf
  • Loading branch information
Boshen committed Aug 30, 2024
1 parent 946c867 commit 3ae94b8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/oxc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub trait CompilerInterface {
) -> SemanticBuilderReturn<'a> {
SemanticBuilder::new(source_text, source_type)
.with_check_syntax_error(self.check_semantic_error())
.build_module_record(source_path.to_path_buf(), program)
.build_module_record(source_path, program)
.build(program)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Runtime {
.with_build_jsdoc(true)
.with_trivias(trivias)
.with_check_syntax_error(check_syntax_errors)
.build_module_record(path.to_path_buf(), program);
.build_module_record(path, program);
let module_record = semantic_builder.module_record();

if self.linter.options().plugins.import {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_semantic/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() -> std::io::Result<()> {
let program = allocator.alloc(parser_ret.program);

let semantic = SemanticBuilder::new(&source_text, source_type)
.build_module_record(path.to_path_buf(), program)
.build_module_record(path, program)
// Enable additional syntax checks not performed by the parser
.with_check_syntax_error(true)
// Inform Semantic about comments found while parsing
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{
cell::{Cell, RefCell},
path::PathBuf,
path::Path,
sync::Arc,
};

Expand Down Expand Up @@ -195,10 +195,11 @@ impl<'a> SemanticBuilder<'a> {
#[must_use]
pub fn build_module_record(
mut self,
resolved_absolute_path: PathBuf,
resolved_absolute_path: &Path,
program: &Program<'a>,
) -> Self {
let mut module_record_builder = ModuleRecordBuilder::new(resolved_absolute_path);
let mut module_record_builder =
ModuleRecordBuilder::new(resolved_absolute_path.to_path_buf());
module_record_builder.visit(program);
self.module_record = Arc::new(module_record_builder.build());
self
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_semantic/src/module_record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use builder::ModuleRecordBuilder;

#[cfg(test)]
mod module_record_tests {
use std::{path::PathBuf, sync::Arc};
use std::{path::Path, sync::Arc};

use oxc_allocator::Allocator;
use oxc_parser::Parser;
Expand All @@ -21,7 +21,7 @@ mod module_record_tests {
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(ret.trivias)
.build_module_record(PathBuf::new(), program)
.build_module_record(Path::new(""), program)
.build(program);
Arc::clone(&semantic_ret.semantic.module_record)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Oxc {
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(trivias.clone())
.with_check_syntax_error(true)
.build_module_record(path.clone(), &program)
.build_module_record(&path, &program)
.build(&program);

if run_options.syntax.unwrap_or_default() {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl Oxc {
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_cfg(true)
.with_trivias(trivias.clone())
.build_module_record(path.to_path_buf(), program)
.build_module_record(path, program)
.build(program);
let semantic = Rc::new(semantic_ret.semantic);
let linter_ret = Linter::default().run(path, Rc::clone(&semantic));
Expand Down
8 changes: 2 additions & 6 deletions tasks/benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
env,
path::{Path, PathBuf},
rc::Rc,
};
use std::{env, path::Path, rc::Rc};

use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
Expand Down Expand Up @@ -35,7 +31,7 @@ fn bench_linter(criterion: &mut Criterion) {
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(ret.trivias)
.with_cfg(true)
.build_module_record(PathBuf::new(), program)
.build_module_record(Path::new(""), program)
.build(program);
let filter = vec![
(AllowWarnDeny::Deny, "all".into()),
Expand Down
4 changes: 2 additions & 2 deletions tasks/benchmark/benches/semantic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_benchmark::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
Expand Down Expand Up @@ -26,7 +26,7 @@ fn bench_semantic(criterion: &mut Criterion) {
let ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(ret.trivias.clone())
.with_build_jsdoc(true)
.build_module_record(PathBuf::new(), program)
.build_module_record(Path::new(""), program)
.build(program);
let ret = black_box(ret);
ret.errors
Expand Down

0 comments on commit 3ae94b8

Please sign in to comment.