-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make parsing and resolution errors cause resolution to throw
After this change, all errors, found either at parsing or resolution time, result in the resolution processing throwing errors. Previously, errors found at parsing time, namely: * Non-string values, including null, [], etc. * Invalid URLs * Entries with keys with trailing "/" and values without trailing "/" were ignored, allowing fallback to the next candidate at resolution time. Thus, they could not be used as a definitive way to block particular resolution. After this change, such entries are kept in the parsed specifier maps as entries with null value, and cause resolution to fail (without further fallback) by throwing errors. Also, before this change, relative URL resolution failures at prefix matching in "resolve a module specifier" didn't allow fallback to less-specific prefixes, but did allow fallback to less-specific scopes. This PR makes errors which would have caused such fallbacks always throw errors, so fallback is not allowed in either case. With this change, all resolution failures are surfaced via thrown errors, and resolution is definitively blocked. Fallback to less-specific scopes only occurs when there are no matching entries in a scope; errored entries no longer cause fallbacks. Fixes #184.
- Loading branch information
1 parent
6cb173d
commit ca1a398
Showing
10 changed files
with
167 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
reference-implementation/__tests__/json/resolving-null.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"importMapBaseURL": "https://example.com/app/index.html", | ||
"baseURL": "https://example.com/js/app.mjs", | ||
"name": "Entries with errors shouldn't allow fallback", | ||
"tests": { | ||
"No fallback to less-specific prefixes": { | ||
"importMap": { | ||
"imports": { | ||
"null/": "/1/", | ||
"null/b/": null, | ||
"null/b/c/": "/1/2/", | ||
"invalid-url/": "/1/", | ||
"invalid-url/b/": "https://:invalid-url:/", | ||
"invalid-url/b/c/": "/1/2/", | ||
"without-trailing-slashes/": "/1/", | ||
"without-trailing-slashes/b/": "/x", | ||
"without-trailing-slashes/b/c/": "/1/2/", | ||
"prefix-resolution-error/": "/1/", | ||
"prefix-resolution-error/b/": "data:text/javascript,/", | ||
"prefix-resolution-error/b/c/": "/1/2/" | ||
} | ||
}, | ||
"expectedResults": { | ||
"null/x": "https://example.com/1/x", | ||
"null/b/x": null, | ||
"null/b/c/x": "https://example.com/1/2/x", | ||
"invalid-url/x": "https://example.com/1/x", | ||
"invalid-url/b/x": null, | ||
"invalid-url/b/c/x": "https://example.com/1/2/x", | ||
"without-trailing-slashes/x": "https://example.com/1/x", | ||
"without-trailing-slashes/b/x": null, | ||
"without-trailing-slashes/b/c/x": "https://example.com/1/2/x", | ||
"prefix-resolution-error/x": "https://example.com/1/x", | ||
"prefix-resolution-error/b/x": null, | ||
"prefix-resolution-error/b/c/x": "https://example.com/1/2/x" | ||
} | ||
}, | ||
"No fallback to less-specific scopes": { | ||
"importMap": { | ||
"imports": { | ||
"null": "https://example.com/a", | ||
"invalid-url": "https://example.com/b", | ||
"without-trailing-slashes/": "https://example.com/c/", | ||
"prefix-resolution-error/": "https://example.com/d/" | ||
}, | ||
"scopes": { | ||
"/js/": { | ||
"null": null, | ||
"invalid-url": "https://:invalid-url:/", | ||
"without-trailing-slashes/": "/x", | ||
"prefix-resolution-error/": "data:text/javascript,/" | ||
} | ||
} | ||
}, | ||
"expectedResults": { | ||
"null": null, | ||
"invalid-url": null, | ||
"without-trailing-slashes/x": null, | ||
"prefix-resolution-error/x": null | ||
} | ||
}, | ||
"No fallback to absolute URL parsing": { | ||
"importMap": { | ||
"imports": {}, | ||
"scopes": { | ||
"/js/": { | ||
"https://example.com/null": null, | ||
"https://example.com/invalid-url": "https://:invalid-url:/", | ||
"https://example.com/without-trailing-slashes/": "/x", | ||
"https://example.com/prefix-resolution-error/": "data:text/javascript,/" | ||
} | ||
} | ||
}, | ||
"expectedResults": { | ||
"https://example.com/null": null, | ||
"https://example.com/invalid-url": null, | ||
"https://example.com/without-trailing-slashes/x": null, | ||
"https://example.com/prefix-resolution-error/x": null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters