diff options
Diffstat (limited to 'core/module_specifier.rs')
-rw-r--r-- | core/module_specifier.rs | 17 |
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)? } |