refactor(resolver): clean up some code and tests

This commit is contained in:
Boshen 2023-08-09 23:19:27 +08:00
parent f8358a148a
commit 909d037f0d
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
3 changed files with 25 additions and 6 deletions

View file

@ -43,21 +43,21 @@ Crossed out test files are irrelevant.
- [x] ~CachedInputFileSystem.test.js~
- [x] ~SyncAsyncFileSystemDecorator.test.js~
- [x] alias.test.js (need to fix a todo)
- [x] alias.test.js
- [x] browserField.test.js (reading the browser field is currently static - not read from the `browserField` option)
- [ ] dependencies.test.js
- [x] exportsField.test.js
- [x] extension-alias.test.js
- [x] extensions.test.js
- [x] fallback.test.js (need to fix a todo)
- [x] fallback.test.js
- [x] ~forEachBail.test.js~
- [x] fullSpecified.test.js
- [ ] getPaths.test.js
- [x] ~getPaths.test.js~
- [x] identifier.test.js (see unit test in `crates/oxc_resolver/src/request.rs`)
- [x] importsField.test.js
- [x] incorrect-description-file.test.js (need to add ctx.fileDependencies)
- [ ] missing.test.js
- [ ] path.test.js
- [x] path.test.js (see unit test in `crates/oxc_resolver/src/path.rs`)
- [ ] plugins.test.js
- [ ] pnp.test.js
- [x] ~pr-53.test.js~

View file

@ -43,7 +43,7 @@ pub struct PackageJson {
///
/// <https://nodejs.org/api/packages.html#subpath-imports>
#[serde(default)]
pub imports: MatchObject,
pub imports: Box<MatchObject>,
/// The "browser" field is provided by a module author as a hint to javascript bundlers or component tools when packaging modules for client side use.
///
@ -71,7 +71,6 @@ impl ExportsField {
}
}
// TODO: use compact string for these String fields
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ExportsKey {
Main,

View file

@ -89,3 +89,23 @@ impl PathUtil for Path {
})
}
}
// https://github.com/webpack/enhanced-resolve/blob/main/test/path.test.js
#[test]
fn is_invalid_exports_target() {
let test_cases = [
"../a.js",
"../",
"./a/b/../../../c.js",
"./a/b/../../../",
"./../../c.js",
"./../../",
"./a/../b/../../c.js",
"./a/../b/../../",
"./././../",
];
for case in test_cases {
assert!(Path::new(case).is_invalid_exports_target(), "{case}");
}
}