refactor(semantic): change build_module_record to accept &Path instead of PathBuf

This commit is contained in:
Boshen 2024-08-30 12:19:59 +08:00
parent 946c867b27
commit 3ae94b8801
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
8 changed files with 15 additions and 18 deletions

View file

@ -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)
}

View file

@ -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 {

View file

@ -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

View file

@ -2,7 +2,7 @@
use std::{
cell::{Cell, RefCell},
path::PathBuf,
path::Path,
sync::Arc,
};
@ -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

View file

@ -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;
@ -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)
}

View file

@ -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() {
@ -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));

View file

@ -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};
@ -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()),

View file

@ -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};
@ -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