diff --git a/crates/backend/src/encode.rs b/crates/backend/src/encode.rs index 086ff284452..41d3c8b773a 100644 --- a/crates/backend/src/encode.rs +++ b/crates/backend/src/encode.rs @@ -77,10 +77,10 @@ impl Interner { /// /// Note that repeated invocations of this function will be memoized, so the /// same `id` will always return the same resulting unique `id`. - fn resolve_import_module(&self, id: &str, span: Span) -> Result<&str, Diagnostic> { + fn resolve_import_module(&self, id: &str, span: Span) -> Result { let mut files = self.files.borrow_mut(); if let Some(file) = files.get(id) { - return Ok(self.intern_str(&file.new_identifier)); + return Ok(ImportModule::Named(self.intern_str(&file.new_identifier))); } self.check_for_package_json(); let path = if id.starts_with("/") { @@ -89,7 +89,7 @@ impl Interner { let msg = "relative module paths aren't supported yet"; return Err(Diagnostic::span_error(span, msg)); } else { - return Ok(self.intern_str(&id)); + return Ok(ImportModule::RawNamed(self.intern_str(id))); }; // Generate a unique ID which is somewhat readable as well, so mix in @@ -254,9 +254,7 @@ fn shared_module<'a>( intern: &'a Interner, ) -> Result, Diagnostic> { Ok(match m { - ast::ImportModule::Named(m, span) => { - ImportModule::Named(intern.resolve_import_module(m, *span)?) - } + ast::ImportModule::Named(m, span) => intern.resolve_import_module(m, *span)?, ast::ImportModule::RawNamed(m, _span) => ImportModule::RawNamed(intern.intern_str(m)), ast::ImportModule::Inline(idx, _) => ImportModule::Inline(*idx as u32), }) diff --git a/crates/cli-support/src/wit/mod.rs b/crates/cli-support/src/wit/mod.rs index 7b8e81721c2..f5b56e0079d 100644 --- a/crates/cli-support/src/wit/mod.rs +++ b/crates/cli-support/src/wit/mod.rs @@ -880,13 +880,6 @@ impl<'a> Context<'a> { } fn determine_import(&self, import: &decode::Import<'_>, item: &str) -> Result { - let is_local_snippet = match import.module { - Some(decode::ImportModule::Named(s)) => self.aux.local_modules.contains_key(s), - Some(decode::ImportModule::RawNamed(_)) => false, - Some(decode::ImportModule::Inline(_)) => true, - None => false, - }; - // Similar to `--target no-modules`, only allow vendor prefixes // basically for web apis, shouldn't be necessary for things like npm // packages or other imported items. @@ -894,7 +887,9 @@ impl<'a> Context<'a> { if let Some(vendor_prefixes) = vendor_prefixes { assert!(vendor_prefixes.len() > 0); - if is_local_snippet { + if let Some(decode::ImportModule::Inline(_) | decode::ImportModule::Named(_)) = + &import.module + { bail!( "local JS snippets do not support vendor prefixes for \ the import of `{}` with a polyfill of `{}`", @@ -902,7 +897,7 @@ impl<'a> Context<'a> { &vendor_prefixes[0] ); } - if let Some(decode::ImportModule::Named(module)) = &import.module { + if let Some(decode::ImportModule::RawNamed(module)) = &import.module { bail!( "import of `{}` from `{}` has a polyfill of `{}` listed, but vendor prefixes aren't supported when importing from modules", @@ -938,18 +933,14 @@ impl<'a> Context<'a> { }; let name = match import.module { - Some(decode::ImportModule::Named(module)) if is_local_snippet => { - JsImportName::LocalModule { - module: module.to_string(), - name: name.to_string(), - } - } - Some(decode::ImportModule::Named(module) | decode::ImportModule::RawNamed(module)) => { - JsImportName::Module { - module: module.to_string(), - name: name.to_string(), - } - } + Some(decode::ImportModule::Named(module)) => JsImportName::LocalModule { + module: module.to_string(), + name: name.to_string(), + }, + Some(decode::ImportModule::RawNamed(module)) => JsImportName::Module { + module: module.to_string(), + name: name.to_string(), + }, Some(decode::ImportModule::Inline(idx)) => { let offset = self .aux