mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(es/module): Fix logic for exact matches in jsc.paths
(#7860)
**Related issue:** - Closes #7829
This commit is contained in:
parent
e47f1c2bf7
commit
52a1ee78da
24
crates/swc/tests/fixture/issues-7xxx/7829/1/input/.swcrc
Normal file
24
crates/swc/tests/fixture/issues-7xxx/7829/1/input/.swcrc
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"jsc": {
|
||||
"baseUrl": ".",
|
||||
"target": "es2020",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"importMeta": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
},
|
||||
"keepClassNames": true,
|
||||
"paths": {
|
||||
"@my/pkg": [
|
||||
"libs/pkg/src/index.ts"
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
4
crates/swc/tests/fixture/issues-7xxx/7829/1/input/1.js
Normal file
4
crates/swc/tests/fixture/issues-7xxx/7829/1/input/1.js
Normal file
@ -0,0 +1,4 @@
|
||||
import { fn } from '@my/pkg';
|
||||
|
||||
|
||||
console.log(fn)
|
2
crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js
Normal file
2
crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js
Normal file
@ -0,0 +1,2 @@
|
||||
import { fn } from "./libs/pkg/src";
|
||||
console.log(fn);
|
24
crates/swc/tests/fixture/issues-7xxx/7829/2/input/.swcrc
Normal file
24
crates/swc/tests/fixture/issues-7xxx/7829/2/input/.swcrc
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"jsc": {
|
||||
"baseUrl": ".",
|
||||
"target": "es2020",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"importMeta": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
},
|
||||
"keepClassNames": true,
|
||||
"paths": {
|
||||
"@my/pkg": [
|
||||
"libs/pkg/src/index.js"
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
4
crates/swc/tests/fixture/issues-7xxx/7829/2/input/1.js
Normal file
4
crates/swc/tests/fixture/issues-7xxx/7829/2/input/1.js
Normal file
@ -0,0 +1,4 @@
|
||||
import { fn } from '@my/pkg';
|
||||
|
||||
|
||||
console.log(fn)
|
2
crates/swc/tests/fixture/issues-7xxx/7829/2/output/1.js
Normal file
2
crates/swc/tests/fixture/issues-7xxx/7829/2/output/1.js
Normal file
@ -0,0 +1,2 @@
|
||||
import { fn } from "./libs/pkg/src/index.js";
|
||||
console.log(fn);
|
@ -259,27 +259,12 @@ where
|
||||
return Ok(FileName::Real(tp.into()));
|
||||
}
|
||||
|
||||
if self.base_url_filename == *base {
|
||||
// Prevent infinite loop
|
||||
|
||||
let replaced = self.base_url.join(&to[0]);
|
||||
if replaced.exists() {
|
||||
return Ok(FileName::Real(replaced));
|
||||
}
|
||||
|
||||
return self
|
||||
.invoke_inner_resolver(base, &format!("./{}", &to[0]))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"tried to resolve `{}` because `{}` was exactly matched",
|
||||
to[0], from
|
||||
)
|
||||
});
|
||||
} else {
|
||||
return self
|
||||
.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
|
||||
.context("failed to resolve using jsc.baseUrl as base");
|
||||
if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
|
||||
{
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
return Ok(FileName::Real(self.base_url.join(&to[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user