diff --git a/crates/oxc_resolver/README.md b/crates/oxc_resolver/README.md index b129984b5..3ecc073c2 100644 --- a/crates/oxc_resolver/README.md +++ b/crates/oxc_resolver/README.md @@ -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~ diff --git a/crates/oxc_resolver/src/package_json.rs b/crates/oxc_resolver/src/package_json.rs index 572cc08b0..3dc969f94 100644 --- a/crates/oxc_resolver/src/package_json.rs +++ b/crates/oxc_resolver/src/package_json.rs @@ -43,7 +43,7 @@ pub struct PackageJson { /// /// #[serde(default)] - pub imports: MatchObject, + pub imports: Box, /// 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, diff --git a/crates/oxc_resolver/src/path.rs b/crates/oxc_resolver/src/path.rs index ec93b37f9..7ac0b8e3b 100644 --- a/crates/oxc_resolver/src/path.rs +++ b/crates/oxc_resolver/src/path.rs @@ -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}"); + } +}