Skip to content

Commit cfbeb24

Browse files
committed
test: add test cases for package imports starting with # or #/
1 parent 943bb39 commit cfbeb24

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
15981598
) -> Result<Option<CachedPath>, ResolveError> {
15991599
// 1. Assert: specifier begins with "#".
16001600
debug_assert!(specifier.starts_with('#'), "{specifier}");
1601-
// 2. If specifier is exactly equal to "#" or starts with "#/", then
1601+
// 2. If _specifier_ is exactly equal to _"#"_, then
16021602
// 1. Throw an Invalid Module Specifier error.
16031603
// 3. Let packageURL be the result of LOOKUP_PACKAGE_SCOPE(parentURL).
16041604
// 4. If packageURL is not null, then
@@ -1611,7 +1611,6 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
16111611
for imports in package_json.imports_fields(&self.options.imports_fields) {
16121612
if !has_imports {
16131613
has_imports = true;
1614-
// TODO: fill in test case for this case
16151614
if specifier == "#" || specifier.starts_with("#/") {
16161615
return Err(ResolveError::InvalidModuleSpecifier(
16171616
specifier.to_string(),

src/tests/imports_field.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ fn test_simple() {
4545
let fail = [
4646
("should disallow resolve out of package scope", f.clone(), "#b", ResolveError::InvalidPackageTarget("../b.js".to_string(), "#b".to_string(), f.join("package.json"))),
4747
("should resolve package #2", f.clone(), "#a", ResolveError::PackageImportNotDefined("#a".to_string(), f.join("package.json"))),
48+
("# is not allowed", f.clone(), "#", ResolveError::InvalidModuleSpecifier("#".to_string(), f.join("package.json"))),
49+
("#/ is not allowed", f.clone(), "#/", ResolveError::InvalidModuleSpecifier("#/".to_string(), f.join("package.json"))),
50+
("#/foo is not allowed", f.clone(), "#/foo", ResolveError::InvalidModuleSpecifier("#/foo".to_string(), f.join("package.json")))
4851
];
4952

5053
for (comment, path, request, error) in fail {

0 commit comments

Comments
 (0)