mirror of
https://github.com/swc-project/swc.git
synced 2024-12-18 11:11:30 +03:00
fix(es/modules): Do not call Path::parent()
for FileName::Anon
(#8662)
**Related issue:** - Closes #8660
This commit is contained in:
parent
1603569a75
commit
1bc4cb7c05
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user