summaryrefslogtreecommitdiff
path: root/core/module_specifier.rs
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-08-09 16:33:59 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-08-09 16:33:59 -0700
commit286ee1d8b68b54d39e698f3b78e3ce9e257fa674 (patch)
tree550ee67d44d9a1e920e5010bb7b1551943c008ff /core/module_specifier.rs
parent83d5362f1d7d8589b862de57912135067a8278c7 (diff)
Fix dynamic import base path problem for REPL and eval (#2757)
Diffstat (limited to 'core/module_specifier.rs')
-rw-r--r--core/module_specifier.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/core/module_specifier.rs b/core/module_specifier.rs
index 3cfabd03f..9194b9082 100644
--- a/core/module_specifier.rs
+++ b/core/module_specifier.rs
@@ -46,6 +46,10 @@ impl fmt::Display for ModuleResolutionError {
pub struct ModuleSpecifier(Url);
impl ModuleSpecifier {
+ fn is_dummy_specifier(specifier: &str) -> bool {
+ specifier == "<unknown>"
+ }
+
pub fn as_url(&self) -> &Url {
&self.0
}
@@ -80,7 +84,18 @@ impl ModuleSpecifier {
// 3. Return the result of applying the URL parser to specifier with base
// URL as the base URL.
Err(ParseError::RelativeUrlWithoutBase) => {
- let base = Url::parse(base).map_err(InvalidBaseUrl)?;
+ let base = if ModuleSpecifier::is_dummy_specifier(base) {
+ // Handle <unknown> case, happening under e.g. repl.
+ // Use CWD for such case.
+
+ // Forcefully join base to current dir.
+ // Otherwise, later joining in Url would be interpreted in
+ // the parent directory (appending trailing slash does not work)
+ let path = current_dir().unwrap().join(base);
+ Url::from_file_path(path).unwrap()
+ } else {
+ Url::parse(base).map_err(InvalidBaseUrl)?
+ };
base.join(&specifier).map_err(InvalidUrl)?
}