Skip to content

Commit

Permalink
fix(es/modules): Do not call Path::parent() for FileName::Anon (#…
Browse files Browse the repository at this point in the history
…8662)

**Related issue:**

 - Closes #8660
  • Loading branch information
kdy1 authored Feb 26, 2024
1 parent 1603569 commit 1bc4cb7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions crates/swc_ecma_transforms_module/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
sync::Arc,
};

use anyhow::{Context, Error};
use anyhow::{anyhow, Context, Error};
use path_clean::PathClean;
use pathdiff::diff_paths;
use swc_atoms::JsWord;
Expand Down Expand Up @@ -276,7 +276,10 @@ where
}
};
let mut base = match base {
FileName::Real(v) => Cow::Borrowed(v),
FileName::Real(v) => Cow::Borrowed(
v.parent()
.ok_or_else(|| anyhow!("failed to get parent of {:?}", v))?,
),
FileName::Anon => {
if cfg!(target_arch = "wasm32") {
panic!("Please specify `filename`")
Expand All @@ -303,13 +306,7 @@ where
target.display()
);

let rel_path = diff_paths(
&target,
match base.parent() {
Some(v) => v,
None => &base,
},
);
let rel_path = diff_paths(&target, &*base);

let rel_path = match rel_path {
Some(v) => v,
Expand Down

0 comments on commit 1bc4cb7

Please sign in to comment.