Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 13, 2024
1 parent fa5d7bf commit 15ce120
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions crates/compilers/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl ItemLocation {
}
}

/// Checks if the given path is a test/script file.
fn is_test_or_script<L>(path: &Path, paths: &ProjectPathsConfig<L>) -> bool {
let test_dir = paths.tests.strip_prefix(&paths.root).unwrap_or(&paths.root);
let script_dir = paths.scripts.strip_prefix(&paths.root).unwrap_or(&paths.root);
Expand Down Expand Up @@ -318,14 +319,6 @@ impl BytecodeDependencyOptimizer<'_> {
BytecodeDependencyOptimizer { asts, paths, sources }
}

/// Returns true if the file is not a test or script file.
fn is_src_file(&self, file: &Path) -> bool {
let tests = self.paths.tests.strip_prefix(&self.paths.root).unwrap_or(&self.paths.root);
let scripts = self.paths.scripts.strip_prefix(&self.paths.root).unwrap_or(&self.paths.root);

!file.starts_with(tests) && !file.starts_with(scripts)
}

fn process(self) -> Result<()> {
let mut updates = Updates::default();

Expand All @@ -348,7 +341,7 @@ impl BytecodeDependencyOptimizer<'_> {
for (path, ast) in &self.asts {
let src = self.sources.get(path).unwrap().content.as_str();

if !self.is_src_file(path) {
if is_test_or_script(path, &self.paths) {
continue;
}

Expand Down Expand Up @@ -412,7 +405,7 @@ impl BytecodeDependencyOptimizer<'_> {
updates: &mut Updates,
) -> Result<()> {
for (path, ast) in &self.asts {
if self.is_src_file(path) {
if !is_test_or_script(path, &self.paths) {
continue;
}
let src = self.sources.get(path).unwrap().content.as_str();
Expand Down

0 comments on commit 15ce120

Please sign in to comment.