fix(es/modules): Do not call Path::parent() for FileName::Anon (#8662)

**Related issue:**

 - Closes #8660
This commit is contained in:
Donny/강동윤 2024-02-26 16:01:32 +09:00 committed by GitHub
parent 1603569a75
commit 1bc4cb7c05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use anyhow::{Context, Error}; use anyhow::{anyhow, Context, Error};
use path_clean::PathClean; use path_clean::PathClean;
use pathdiff::diff_paths; use pathdiff::diff_paths;
use swc_atoms::JsWord; use swc_atoms::JsWord;
@ -276,7 +276,10 @@ where
} }
}; };
let mut base = match base { 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 => { FileName::Anon => {
if cfg!(target_arch = "wasm32") { if cfg!(target_arch = "wasm32") {
panic!("Please specify `filename`") panic!("Please specify `filename`")
@ -303,13 +306,7 @@ where
target.display() target.display()
); );
let rel_path = diff_paths( let rel_path = diff_paths(&target, &*base);
&target,
match base.parent() {
Some(v) => v,
None => &base,
},
);
let rel_path = match rel_path { let rel_path = match rel_path {
Some(v) => v, Some(v) => v,