mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
fix(resolver): fix a case with multi-dot file extensions (#704)
This commit is contained in:
parent
09761b4f8b
commit
341c678b2f
2 changed files with 29 additions and 0 deletions
|
|
@ -350,6 +350,13 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
|||
if let Some(path) = self.load_alias_or_file(&cached_path, ctx)? {
|
||||
return Ok(Some(path));
|
||||
}
|
||||
|
||||
// `std::path::PathBuf::set_extension` only removes 1 dot.
|
||||
// This removes multi-dot extensions such as `.d.ts`.
|
||||
let num_dots = extension.chars().filter(|c| *c == '.').count();
|
||||
for _ in 0..num_dots {
|
||||
path_with_extension.set_extension("");
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,3 +73,25 @@ fn respect_enforce_extension() {
|
|||
assert_eq!(resolved.map(Resolution::into_path_buf), Ok(f.join("foo.ts")));
|
||||
// TODO: need to match missingDependencies returned from the resolve function
|
||||
}
|
||||
|
||||
// Test for `.d.ts`, not part of enhanced-resolve.
|
||||
#[test]
|
||||
fn multi_dot_extension() {
|
||||
let f = fixture();
|
||||
|
||||
let resolver = Resolver::new(ResolveOptions {
|
||||
extensions: vec![".a.b.c".into(), ".d.ts".into(), ".ts".into(), ".js".into()],
|
||||
..ResolveOptions::default()
|
||||
});
|
||||
|
||||
#[rustfmt::skip]
|
||||
let pass = [
|
||||
("should resolve according to order of provided extensions", "./foo", "foo.ts"),
|
||||
];
|
||||
|
||||
for (comment, request, expected_path) in pass {
|
||||
let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path());
|
||||
let expected = f.join(expected_path);
|
||||
assert_eq!(resolved_path, Ok(expected), "{comment} {request} {expected_path}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue