Repository: denoland/deno_core
Pull request #401 (2023-12-29 20:29:20)

refactor: rename "AssertedImportType" to "RequestedModuleType"
This better aligns us with the new semantics of import attributes proposal.

Required for supporting custom module type loading.


Patch:
diff --git a/core/modules/map.rs b/core/modules/map.rs
index c6188ba..ca4e4d2 100644
--- a/core/modules/map.rs
+++ b/core/modules/map.rs
@@ -5,10 +5,10 @@ use crate::error::throw_type_error;
 use crate::error::to_v8_type_error;
 use crate::error::AnyError;
 use crate::error::JsError;
-use crate::modules::get_asserted_module_type_from_assertions;
-use crate::modules::parse_import_assertions;
+use crate::modules::get_requested_module_type_from_attributes;
+use crate::modules::parse_import_attributes;
 use crate::modules::recursive_load::RecursiveModuleLoad;
-use crate::modules::ImportAssertionsKind;
+use crate::modules::ImportAttributesKind;
 use crate::modules::ModuleCode;
 use crate::modules::ModuleError;
 use crate::modules::ModuleId;
@@ -48,8 +48,8 @@ use std::task::Poll;
 use tokio::sync::oneshot;
 
 use super::module_map_data::ModuleMapData;
-use super::AssertedModuleType;
 use super::LazyEsmModuleLoader;
+use super::RequestedModuleType;
 
 type PrepareLoadFuture =
   dyn Future<Output = (ModuleLoadId, Result<RecursiveModuleLoad, Error>)>;
@@ -182,8 +182,8 @@ impl ModuleMap {
     name: impl AsRef<str>,
   ) -> Option<v8::Global<v8::Module>> {
     let id = self
-      .get_id(name.as_ref(), AssertedModuleType::JavaScriptOrWasm)
-      .or_else(|| self.get_id(name.as_ref(), AssertedModuleType::Json))?;
+      .get_id(name.as_ref(), RequestedModuleType::None)
+      .or_else(|| self.get_id(name.as_ref(), RequestedModuleType::Json))?;
     self.get_handle(id)
   }
 
@@ -192,9 +192,9 @@ impl ModuleMap {
   pub(crate) fn get_id(
     &self,
     name: impl AsRef<str>,
-    asserted_module_type: impl AsRef<AssertedModuleType>,
+    requested_module_type: impl AsRef<RequestedModuleType>,
   ) -> Option<ModuleId> {
-    self.data.borrow().get_id(name, asserted_module_type)
+    self.data.borrow().get_id(name, requested_module_type)
   }
 
   pub(crate) fn is_main_module(&self, global: &v8::Global<v8::Module>) -> bool {
@@ -230,9 +230,9 @@ impl ModuleMap {
   pub fn is_alias(
     &self,
     name: &str,
-    asserted_module_type: impl AsRef<AssertedModuleType>,
+    requested_module_type: impl AsRef<RequestedModuleType>,
   ) -> bool {
-    self.data.borrow().is_alias(name, asserted_module_type)
+    self.data.borrow().is_alias(name, requested_module_type)
   }
 
   #[cfg(test)]
@@ -269,8 +269,8 @@ impl ModuleMap {
       module_url_specified
     };
 
-    let asserted_module_type = AssertedModuleType::from(module_type);
-    let maybe_module_id = self.get_id(&module_url_found, asserted_module_type);
+    let requested_module_type = RequestedModuleType::from(module_type);
+    let maybe_module_id = self.get_id(&module_url_found, requested_module_type);
 
     if let Some(module_id) = maybe_module_id {
       debug!(
@@ -370,19 +370,19 @@ impl ModuleMap {
         .get_specifier()
         .to_rust_string_lossy(tc_scope);
 
-      let import_assertions = module_request.get_import_assertions();
+      let import_attributes = module_request.get_import_assertions();
 
-      let assertions = parse_import_assertions(
+      let attributes = parse_import_attributes(
         tc_scope,
-        import_assertions,
-        ImportAssertionsKind::StaticImport,
+        import_attributes,
+        ImportAttributesKind::StaticImport,
       );
 
       // FIXME(bartomieju): there are no stack frames if exception
       // is thrown here
       {
         let state = JsRuntime::state_from(tc_scope);
-        (state.validate_import_attributes_cb)(tc_scope, &assertions);
+        (state.validate_import_attributes_cb)(tc_scope, &attributes);
       }
 
       if tc_scope.has_caught() {
@@ -403,11 +403,11 @@ impl ModuleMap {
         Ok(s) => s,
         Err(e) => return Err(ModuleError::Other(e)),
       };
-      let asserted_module_type =
-        get_asserted_module_type_from_assertions(&assertions);
+      let requested_module_type =
+        get_requested_module_type_from_attributes(&attributes);
       let request = ModuleRequest {
         specifier: module_specifier.to_string(),
-        asserted_module_type,
+        requested_module_type,
       };
       requests.push(request);
     }
@@ -495,7 +495,7 @@ impl ModuleMap {
   fn module_resolve_callback<'s>(
     context: v8::Local<'s, v8::Context>,
     specifier: v8::Local<'s, v8::String>,
-    import_assertions: v8::Local<'s, v8::FixedArray>,
+    import_attributes: v8::Local<'s, v8::FixedArray>,
     referrer: v8::Local<'s, v8::Module>,
   ) -> Option<v8::Local<'s, v8::Module>> {
     // SAFETY: `CallbackScope` can be safely constructed from `Local<Context>`
@@ -515,10 +515,10 @@ impl ModuleMap {
 
     let specifier_str = specifier.to_rust_string_lossy(scope);
 
-    let assertions = parse_import_assertions(
+    let assertions = parse_import_attributes(
       scope,
-      import_assertions,
-      ImportAssertionsKind::StaticImport,
+      import_attributes,
+      ImportAttributesKind::StaticImport,
     );
     let maybe_module = module_map.resolve_callback(
       scope,
@@ -570,7 +570,7 @@ impl ModuleMap {
     scope: &mut v8::HandleScope<'s>,
     specifier: &str,
     referrer: &str,
-    import_assertions: HashMap<String, String>,
+    import_attributes: HashMap<String, String>,
   ) -> Option<v8::Local<'s, v8::Module>> {
     let resolved_specifier =
       match self.resolve(specifier, referrer, ResolutionKind::Import) {
@@ -582,7 +582,7 @@ impl ModuleMap {
       };
 
     let module_type =
-      get_asserted_module_type_from_assertions(&import_assertions);
+      get_requested_module_type_from_attributes(&import_attributes);
 
     if let Some(id) = self.get_id(resolved_specifier.as_str(), module_type) {
       if let Some(handle) = self.get_handle(id) {
@@ -641,13 +641,13 @@ impl ModuleMap {
     self: Rc<Self>,
     specifier: &str,
     referrer: &str,
-    asserted_module_type: AssertedModuleType,
+    requested_module_type: RequestedModuleType,
     resolver_handle: v8::Global<v8::PromiseResolver>,
   ) {
     let load = RecursiveModuleLoad::dynamic_import(
       specifier,
       referrer,
-      asserted_module_type.clone(),
+      requested_module_type.clone(),
       self.clone(),
     );
 
@@ -663,7 +663,7 @@ impl ModuleMap {
         if self
           .data
           .borrow()
-          .is_registered(module_specifier, asserted_module_type)
+          .is_registered(module_specifier, requested_module_type)
         {
           async move { (load.id, Ok(load)) }.boxed_local()
         } else {
@@ -1366,8 +1366,8 @@ impl ModuleMap {
     // Check if this module has already been loaded.
     {
       let module_map_data = self.data.borrow();
-      if let Some(id) = module_map_data
-        .get_id(module_specifier, AssertedModuleType::JavaScriptOrWasm)
+      if let Some(id) =
+        module_map_data.get_id(module_specifier, RequestedModuleType::None)
       {
         let handle = module_map_data.get_handle(id).unwrap();
         let handle_local = v8::Local::new(scope, handle);
diff --git a/core/modules/mod.rs b/core/modules/mod.rs
index 7b53436..7903af1 100644
--- a/core/modules/mod.rs
+++ b/core/modules/mod.rs
@@ -101,34 +101,32 @@ pub(crate) fn validate_import_attributes(
 }
 
 #[derive(Debug)]
-pub(crate) enum ImportAssertionsKind {
+pub(crate) enum ImportAttributesKind {
   StaticImport,
   DynamicImport,
 }
 
-pub(crate) fn parse_import_assertions(
+pub(crate) fn parse_import_attributes(
   scope: &mut v8::HandleScope,
-  import_assertions: v8::Local<v8::FixedArray>,
-  kind: ImportAssertionsKind,
+  attributes: v8::Local<v8::FixedArray>,
+  kind: ImportAttributesKind,
 ) -> HashMap<String, String> {
   let mut assertions: HashMap<String, String> = HashMap::default();
 
   let assertions_per_line = match kind {
     // For static imports, assertions are triples of (keyword, value and source offset)
     // Also used in `module_resolve_callback`.
-    ImportAssertionsKind::StaticImport => 3,
+    ImportAttributesKind::StaticImport => 3,
     // For dynamic imports, assertions are tuples of (keyword, value)
-    ImportAssertionsKind::DynamicImport => 2,
+    ImportAttributesKind::DynamicImport => 2,
   };
-  assert_eq!(import_assertions.length() % assertions_per_line, 0);
-  let no_of_assertions = import_assertions.length() / assertions_per_line;
+  assert_eq!(attributes.length() % assertions_per_line, 0);
+  let no_of_assertions = attributes.length() / assertions_per_line;
 
   for i in 0..no_of_assertions {
-    let assert_key = import_assertions
-      .get(scope, assertions_per_line * i)
-      .unwrap();
+    let assert_key = attributes.get(scope, assertions_per_line * i).unwrap();
     let assert_key_val = v8::Local::<v8::Value>::try_from(assert_key).unwrap();
-    let assert_value = import_assertions
+    let assert_value = attributes
       .get(scope, (assertions_per_line * i) + 1)
       .unwrap();
     let assert_value_val =
@@ -142,19 +140,18 @@ pub(crate) fn parse_import_assertions(
   assertions
 }
 
-pub(crate) fn get_asserted_module_type_from_assertions(
-  assertions: &HashMap<String, String>,
-) -> AssertedModuleType {
-  assertions
-    .get("type")
-    .map(|ty| {
-      if ty == "json" {
-        AssertedModuleType::Json
-      } else {
-        AssertedModuleType::JavaScriptOrWasm
-      }
-    })
-    .unwrap_or(AssertedModuleType::JavaScriptOrWasm)
+pub(crate) fn get_requested_module_type_from_attributes(
+  attributes: &HashMap<String, String>,
+) -> RequestedModuleType {
+  let Some(ty) = attributes.get("type") else {
+    return RequestedModuleType::None;
+  };
+
+  if ty == "json" {
+    RequestedModuleType::Json
+  } else {
+    RequestedModuleType::Other(Cow::Owned(ty.to_string()))
+  }
 }
 
 /// A type of module to be executed.
@@ -309,10 +306,13 @@ pub enum ResolutionKind {
 
 #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
 #[repr(u8)]
-pub(crate) enum AssertedModuleType {
-  /// JavaScript or WASM.
-  JavaScriptOrWasm,
-  /// JSON.
+pub(crate) enum RequestedModuleType {
+  /// There was no attribute specified in the import statement.
+  None,
+
+  /// `type` attribute had value `json`. This is the only known module type
+  /// in `deno_core`. Embedders should use `Other` variant for custom module
+  /// types like `wasm`, `bytes` or `text`.
   Json,
 
   // IMPORTANT: If you add any additional enum values here, you must update `to_v8`` below!
@@ -320,15 +320,15 @@ pub(crate) enum AssertedModuleType {
   Other(Cow<'static, str>),
 }
 
-impl AssertedModuleType {
+impl RequestedModuleType {
   pub fn to_v8<'s>(
     &self,
     scope: &mut v8::HandleScope<'s>,
   ) -> v8::Local<'s, v8::Value> {
     match self {
-      AssertedModuleType::JavaScriptOrWasm => v8::Integer::new(scope, 0).into(),
-      AssertedModuleType::Json => v8::Integer::new(scope, 1).into(),
-      AssertedModuleType::Other(ty) => {
+      RequestedModuleType::None => v8::Integer::new(scope, 0).into(),
+      RequestedModuleType::Json => v8::Integer::new(scope, 1).into(),
+      RequestedModuleType::Other(ty) => {
         v8::String::new(scope, ty).unwrap().into()
       }
     }
@@ -340,46 +340,46 @@ impl AssertedModuleType {
   ) -> Option<Self> {
     Some(if let Some(int) = value.to_integer(scope) {
       match int.int32_value(scope).unwrap_or_default() {
-        0 => AssertedModuleType::JavaScriptOrWasm,
-        1 => AssertedModuleType::Json,
+        0 => RequestedModuleType::None,
+        1 => RequestedModuleType::Json,
         _ => return None,
       }
     } else if let Ok(str) = v8::Local::<v8::String>::try_from(value) {
-      AssertedModuleType::Other(Cow::Owned(str.to_rust_string_lossy(scope)))
+      RequestedModuleType::Other(Cow::Owned(str.to_rust_string_lossy(scope)))
     } else {
       return None;
     })
   }
 }
 
-impl AsRef<AssertedModuleType> for AssertedModuleType {
-  fn as_ref(&self) -> &AssertedModuleType {
+impl AsRef<RequestedModuleType> for RequestedModuleType {
+  fn as_ref(&self) -> &RequestedModuleType {
     self
   }
 }
 
-impl PartialEq<ModuleType> for AssertedModuleType {
+impl PartialEq<ModuleType> for RequestedModuleType {
   fn eq(&self, other: &ModuleType) -> bool {
     match other {
-      ModuleType::JavaScript => self == &AssertedModuleType::JavaScriptOrWasm,
-      ModuleType::Json => self == &AssertedModuleType::Json,
+      ModuleType::JavaScript => self == &RequestedModuleType::None,
+      ModuleType::Json => self == &RequestedModuleType::Json,
     }
   }
 }
 
-impl From<ModuleType> for AssertedModuleType {
-  fn from(module_type: ModuleType) -> AssertedModuleType {
+impl From<ModuleType> for RequestedModuleType {
+  fn from(module_type: ModuleType) -> RequestedModuleType {
     match module_type {
-      ModuleType::JavaScript => AssertedModuleType::JavaScriptOrWasm,
-      ModuleType::Json => AssertedModuleType::Json,
+      ModuleType::JavaScript => RequestedModuleType::None,
+      ModuleType::Json => RequestedModuleType::Json,
     }
   }
 }
 
-impl std::fmt::Display for AssertedModuleType {
+impl std::fmt::Display for RequestedModuleType {
   fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
     match self {
-      Self::JavaScriptOrWasm => write!(f, "JavaScriptOrWasm"),
+      Self::None => write!(f, "None"),
       Self::Json => write!(f, "JSON"),
       Self::Other(ty) => write!(f, "Other({ty})"),
     }
@@ -389,11 +389,11 @@ impl std::fmt::Display for AssertedModuleType {
 /// Describes a request for a module as parsed from the source code.
 /// Usually executable (`JavaScriptOrWasm`) is used, except when an
 /// import assertions explicitly constrains an import to JSON, in
-/// which case this will have a `AssertedModuleType::Json`.
+/// which case this will have a `RequestedModuleType::Json`.
 #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
 pub(crate) struct ModuleRequest {
   pub specifier: String,
-  pub asserted_module_type: AssertedModuleType,
+  pub requested_module_type: RequestedModuleType,
 }
 
 #[derive(Debug, PartialEq)]
@@ -403,7 +403,7 @@ pub(crate) struct ModuleInfo {
   pub main: bool,
   pub name: ModuleName,
   pub requests: Vec<ModuleRequest>,
-  pub module_type: AssertedModuleType,
+  pub module_type: RequestedModuleType,
 }
 
 #[derive(Debug)]
diff --git a/core/modules/module_map_data.rs b/core/modules/module_map_data.rs
index 63a75e6..4482d5c 100644
--- a/core/modules/module_map_data.rs
+++ b/core/modules/module_map_data.rs
@@ -1,5 +1,5 @@
 // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use super::AssertedModuleType;
+use super::RequestedModuleType;
 use crate::fast_string::FastString;
 use crate::modules::ModuleId;
 use crate::modules::ModuleInfo;
@@ -24,10 +24,10 @@ pub(crate) enum SymbolicModule {
   Mod(ModuleId),
 }
 
-/// Map of [`ModuleName`] and [`AssertedModuleType`] to a data field.
+/// Map of [`ModuleName`] and [`RequestedModuleType`] to a data field.
 struct ModuleNameTypeMap<T> {
   submaps: Vec<HashMap<ModuleName, T>>,
-  map_index: HashMap<AssertedModuleType, usize>,
+  map_index: HashMap<RequestedModuleType, usize>,
   len: usize,
 }
 
@@ -46,11 +46,11 @@ impl<T> ModuleNameTypeMap<T> {
     self.len
   }
 
-  fn map_index(&self, ty: &AssertedModuleType) -> Option<usize> {
+  fn map_index(&self, ty: &RequestedModuleType) -> Option<usize> {
     self.map_index.get(ty).copied()
   }
 
-  pub fn get<Q>(&self, ty: &AssertedModuleType, name: &Q) -> Option<&T>
+  pub fn get<Q>(&self, ty: &RequestedModuleType, name: &Q) -> Option<&T>
   where
     ModuleName: std::borrow::Borrow<Q>,
     Q: std::cmp::Eq + std::hash::Hash + ?Sized,
@@ -72,7 +72,7 @@ impl<T> ModuleNameTypeMap<T> {
 
   pub fn insert(
     &mut self,
-    module_type: &AssertedModuleType,
+    module_type: &RequestedModuleType,
     name: FastString,
     module: T,
   ) {
@@ -101,7 +101,7 @@ impl<T> ModuleNameTypeMap<T> {
   /// doesn't have generators.
   pub fn walk(
     &self,
-    mut f: impl FnMut(usize, &AssertedModuleType, &ModuleName, &T),
+    mut f: impl FnMut(usize, &RequestedModuleType, &ModuleName, &T),
   ) {
     let mut i = 0;
     for (ty, value) in self.map_index.iter() {
@@ -172,18 +172,18 @@ impl ModuleMapData {
   pub fn get_id(
     &self,
     name: impl AsRef<str>,
-    asserted_module_type: impl AsRef<AssertedModuleType>,
+    requested_module_type: impl AsRef<RequestedModuleType>,
   ) -> Option<ModuleId> {
     let map = &self.by_name;
     let first_symbolic_module =
-      map.get(asserted_module_type.as_ref(), name.as_ref())?;
+      map.get(requested_module_type.as_ref(), name.as_ref())?;
     let mut mod_name = match first_symbolic_module {
       SymbolicModule::Mod(mod_id) => return Some(*mod_id),
       SymbolicModule::Alias(target) => target,
     };
     loop {
       let symbolic_module =
-        map.get(asserted_module_type.as_ref(), mod_name.as_ref())?;
+        map.get(requested_module_type.as_ref(), mod_name.as_ref())?;
       match symbolic_module {
         SymbolicModule::Alias(target) => {
           debug_assert!(mod_name != target);
@@ -197,22 +197,22 @@ impl ModuleMapData {
   pub fn is_registered(
     &self,
     specifier: impl AsRef<str>,
-    asserted_module_type: impl AsRef<AssertedModuleType>,
+    requested_module_type: impl AsRef<RequestedModuleType>,
   ) -> bool {
     self
-      .get_id(specifier.as_ref(), asserted_module_type.as_ref())
+      .get_id(specifier.as_ref(), requested_module_type.as_ref())
       .is_some()
   }
 
   pub(crate) fn alias(
     &mut self,
     name: FastString,
-    asserted_module_type: &AssertedModuleType,
+    requested_module_type: &RequestedModuleType,
     target: FastString,
   ) {
     debug_assert_ne!(name, target);
     self.by_name.insert(
-      asserted_module_type,
+      requested_module_type,
       name,
       SymbolicModule::Alias(target),
     );
@@ -222,10 +222,10 @@ impl ModuleMapData {
   pub(crate) fn is_alias(
     &self,
     name: &str,
-    asserted_module_type: impl AsRef<AssertedModuleType>,
+    requested_module_type: impl AsRef<RequestedModuleType>,
   ) -> bool {
     let map = &self.by_name;
-    let entry = map.get(asserted_module_type.as_ref(), name);
+    let entry = map.get(requested_module_type.as_ref(), name);
     matches!(entry, Some(SymbolicModule::Alias(_)))
   }
 
@@ -294,7 +294,7 @@ impl ModuleMapData {
         )
         .unwrap();
         requests_arr.set_index(scope, 2 * i as u32, specifier.into());
-        let value = request.asserted_module_type.to_v8(scope);
+        let value = request.requested_module_type.to_v8(scope);
         requests_arr.set_index(scope, (2 * i) as u32 + 1, value);
       }
       module_info_arr.set_index(scope, 2, requests_arr.into());
@@ -413,17 +413,17 @@ impl ModuleMapData {
             .to_rust_string_lossy(scope);
           let value =
             requests_arr.get_index(scope, (2 * i + 1) as u32).unwrap();
-          let asserted_module_type =
-            AssertedModuleType::try_from_v8(scope, value).unwrap();
+          let requested_module_type =
+            RequestedModuleType::try_from_v8(scope, value).unwrap();
           requests.push(ModuleRequest {
             specifier,
-            asserted_module_type,
+            requested_module_type,
           });
         }
 
         let value = module_info_arr.get_index(scope, 3).unwrap();
         let module_type =
-          AssertedModuleType::try_from_v8(scope, value).unwrap();
+          RequestedModuleType::try_from_v8(scope, value).unwrap();
 
         let main = self.main_module_id == Some(id);
         let module_info = ModuleInfo {
@@ -455,15 +455,15 @@ impl ModuleMapData {
 
         let specifier =
           arr.get_index(scope, 0).unwrap().to_rust_string_lossy(scope);
-        let asserted_module_type = match arr
+        let requested_module_type = match arr
           .get_index(scope, 1)
           .unwrap()
           .to_integer(scope)
           .unwrap()
           .value()
         {
-          0 => AssertedModuleType::JavaScriptOrWasm,
-          1 => AssertedModuleType::Json,
+          0 => RequestedModuleType::None,
+          1 => RequestedModuleType::Json,
           _ => unreachable!(),
         };
 
@@ -485,7 +485,7 @@ impl ModuleMapData {
 
         self
           .by_name
-          .insert(&asserted_module_type, specifier.into(), val);
+          .insert(&requested_module_type, specifier.into(), val);
       }
     }
 
diff --git a/core/modules/recursive_load.rs b/core/modules/recursive_load.rs
index 685c188..8cb02a3 100644
--- a/core/modules/recursive_load.rs
+++ b/core/modules/recursive_load.rs
@@ -2,11 +2,11 @@
 use crate::error::generic_error;
 use crate::module_specifier::ModuleSpecifier;
 use crate::modules::map::ModuleMap;
-use crate::modules::AssertedModuleType;
 use crate::modules::ModuleError;
 use crate::modules::ModuleId;
 use crate::modules::ModuleLoadId;
 use crate::modules::ModuleRequest;
+use crate::modules::RequestedModuleType;
 use crate::modules::ResolutionKind;
 use crate::resolve_url;
 use crate::ModuleLoader;
@@ -37,7 +37,7 @@ enum LoadInit {
   Side(String),
   /// Dynamic import specifier with referrer and expected
   /// module type (which is determined by import assertion).
-  DynamicImport(String, String, AssertedModuleType),
+  DynamicImport(String, String, RequestedModuleType),
 }
 
 #[derive(Debug, Eq, PartialEq)]
@@ -53,7 +53,7 @@ pub(crate) struct RecursiveModuleLoad {
   pub id: ModuleLoadId,
   pub root_module_id: Option<ModuleId>,
   init: LoadInit,
-  root_asserted_module_type: Option<AssertedModuleType>,
+  root_asserted_module_type: Option<RequestedModuleType>,
   state: LoadState,
   module_map_rc: Rc<ModuleMap>,
   pending: FuturesUnordered<Pin<Box<ModuleLoadFuture>>>,
@@ -83,14 +83,14 @@ impl RecursiveModuleLoad {
   pub(crate) fn dynamic_import(
     specifier: &str,
     referrer: &str,
-    asserted_module_type: AssertedModuleType,
+    requested_module_type: RequestedModuleType,
     module_map_rc: Rc<ModuleMap>,
   ) -> Self {
     Self::new(
       LoadInit::DynamicImport(
         specifier.to_string(),
         referrer.to_string(),
-        asserted_module_type,
+        requested_module_type,
       ),
       module_map_rc,
     )
@@ -99,9 +99,9 @@ impl RecursiveModuleLoad {
   fn new(init: LoadInit, module_map_rc: Rc<ModuleMap>) -> Self {
     let id = module_map_rc.next_load_id();
     let loader = module_map_rc.loader.borrow().clone();
-    let asserted_module_type = match &init {
+    let requested_module_type = match &init {
       LoadInit::DynamicImport(_, _, module_type) => module_type.clone(),
-      _ => AssertedModuleType::JavaScriptOrWasm,
+      _ => RequestedModuleType::None,
     };
     let mut load = Self {
       id,
@@ -119,10 +119,10 @@ impl RecursiveModuleLoad {
     // Ignore the error here, let it be hit in `Stream::poll_next()`.
     if let Ok(root_specifier) = load.resolve_root() {
       if let Some(module_id) =
-        module_map_rc.get_id(root_specifier, &asserted_module_type)
+        module_map_rc.get_id(root_specifier, &requested_module_type)
       {
         load.root_module_id = Some(module_id);
-        load.root_asserted_module_type = Some(asserted_module_type);
+        load.root_asserted_module_type = Some(requested_module_type);
       }
     }
     load
@@ -195,11 +195,11 @@ impl RecursiveModuleLoad {
     module_request: &ModuleRequest,
     module_source: ModuleSource,
   ) -> Result<(), ModuleError> {
-    let asserted_module_type = module_request.asserted_module_type.clone();
-    if asserted_module_type != module_source.module_type {
+    let requested_module_type = module_request.requested_module_type.clone();
+    if requested_module_type != module_source.module_type {
       return Err(ModuleError::Other(generic_error(format!(
         "Expected a \"{}\" module but loaded a \"{}\" module.",
-        asserted_module_type, module_source.module_type,
+        requested_module_type, module_source.module_type,
       ))));
     }
 
@@ -215,7 +215,7 @@ impl RecursiveModuleLoad {
     // Update `self.state` however applicable.
     if self.state == LoadState::LoadingRoot {
       self.root_module_id = Some(module_id);
-      self.root_asserted_module_type = Some(asserted_module_type);
+      self.root_asserted_module_type = Some(requested_module_type);
       self.state = LoadState::LoadingImports;
     }
     if self.pending.is_empty() {
@@ -258,7 +258,7 @@ impl RecursiveModuleLoad {
         {
           if let Some(module_id) = self.module_map_rc.get_id(
             module_request.specifier.as_str(),
-            &module_request.asserted_module_type,
+            &module_request.requested_module_type,
           ) {
             already_registered.push_back((module_id, module_request.clone()));
           } else {
@@ -314,13 +314,13 @@ impl Stream for RecursiveModuleLoad {
           Ok(url) => url,
           Err(error) => return Poll::Ready(Some(Err(error))),
         };
-        let asserted_module_type = match &inner.init {
+        let requested_module_type = match &inner.init {
           LoadInit::DynamicImport(_, _, module_type) => module_type.clone(),
-          _ => AssertedModuleType::JavaScriptOrWasm,
+          _ => RequestedModuleType::None,
         };
         let module_request = ModuleRequest {
           specifier: module_specifier.to_string(),
-          asserted_module_type,
+          requested_module_type,
         };
         let load_fut = if let Some(module_id) = inner.root_module_id {
           // If the inner future is already in the map, we might be done (assuming there are no pending
diff --git a/core/runtime/bindings.rs b/core/runtime/bindings.rs
index 47e463d..3b19c5c 100644
--- a/core/runtime/bindings.rs
+++ b/core/runtime/bindings.rs
@@ -9,9 +9,9 @@ use crate::error::has_call_site;
 use crate::error::is_instance_of_error;
 use crate::error::throw_type_error;
 use crate::error::JsStackFrame;
-use crate::modules::get_asserted_module_type_from_assertions;
-use crate::modules::parse_import_assertions;
-use crate::modules::ImportAssertionsKind;
+use crate::modules::get_requested_module_type_from_attributes;
+use crate::modules::parse_import_attributes;
+use crate::modules::ImportAttributesKind;
 use crate::modules::ModuleMap;
 use crate::ops::OpCtx;
 use crate::runtime::InitMode;
@@ -266,7 +266,7 @@ pub fn host_import_module_dynamically_callback<'s>(
   _host_defined_options: v8::Local<'s, v8::Data>,
   resource_name: v8::Local<'s, v8::Value>,
   specifier: v8::Local<'s, v8::String>,
-  import_assertions: v8::Local<'s, v8::FixedArray>,
+  import_attributes: v8::Local<'s, v8::FixedArray>,
 ) -> Option<v8::Local<'s, v8::Promise>> {
   // NOTE(bartlomieju): will crash for non-UTF-8 specifier
   let specifier_str = specifier
@@ -281,10 +281,10 @@ pub fn host_import_module_dynamically_callback<'s>(
   let resolver = v8::PromiseResolver::new(scope).unwrap();
   let promise = resolver.get_promise(scope);
 
-  let assertions = parse_import_assertions(
+  let assertions = parse_import_attributes(
     scope,
-    import_assertions,
-    ImportAssertionsKind::DynamicImport,
+    import_attributes,
+    ImportAttributesKind::DynamicImport,
   );
 
   {
@@ -299,8 +299,8 @@ pub fn host_import_module_dynamically_callback<'s>(
       resolver.reject(tc_scope, e);
     }
   }
-  let asserted_module_type =
-    get_asserted_module_type_from_assertions(&assertions);
+  let requested_module_type =
+    get_requested_module_type_from_attributes(&assertions);
 
   let resolver_handle = v8::Global::new(scope, resolver);
   {
@@ -315,7 +315,7 @@ pub fn host_import_module_dynamically_callback<'s>(
       module_map_rc,
       &specifier_str,
       &referrer_name_str,
-      asserted_module_type,
+      requested_module_type,
       resolver_handle,
     );
     state.notify_new_dynamic_import();
diff --git a/core/runtime/jsruntime.rs b/core/runtime/jsruntime.rs
index 4705384..5290e2c 100644
--- a/core/runtime/jsruntime.rs
+++ b/core/runtime/jsruntime.rs
@@ -15,13 +15,13 @@ use crate::include_js_files;
 use crate::inspector::JsRuntimeInspector;
 use crate::module_specifier::ModuleSpecifier;
 use crate::modules::default_import_meta_resolve_cb;
-use crate::modules::AssertedModuleType;
 use crate::modules::ExtModuleLoader;
 use crate::modules::ImportMetaResolveCallback;
 use crate::modules::ModuleCode;
 use crate::modules::ModuleId;
 use crate::modules::ModuleLoader;
 use crate::modules::ModuleMap;
+use crate::modules::RequestedModuleType;
 use crate::modules::ValidateImportAttributesCb;
 use crate::ops::*;
 use crate::ops_metrics::dispatch_metrics_async;
@@ -1015,7 +1015,7 @@ impl JsRuntime {
       for specifier in esm_entrypoints {
         let mod_id = {
           module_map
-            .get_id(specifier, AssertedModuleType::JavaScriptOrWasm)
+            .get_id(specifier, RequestedModuleType::None)
             .unwrap_or_else(|| {
               panic!("{} not present in the module map", specifier)
             })


Test patch:
diff --git a/core/modules/tests.rs b/core/modules/tests.rs
index 197a91c..3f92994 100644
--- a/core/modules/tests.rs
+++ b/core/modules/tests.rs
@@ -4,10 +4,10 @@ use crate::error::exception_to_err_result;
 use crate::modules::loaders::ModuleLoadEventCounts;
 use crate::modules::loaders::TestingModuleLoader;
 use crate::modules::loaders::*;
-use crate::modules::AssertedModuleType;
 use crate::modules::ModuleError;
 use crate::modules::ModuleRequest;
 use crate::modules::ModuleSourceCode;
+use crate::modules::RequestedModuleType;
 use crate::resolve_import;
 use crate::resolve_url;
 use crate::runtime::JsRuntime;
@@ -277,28 +277,28 @@ fn test_recursive_load() {
   let modules = module_map_rc;
 
   assert_eq!(
-    modules.get_id("file:///a.js", AssertedModuleType::JavaScriptOrWasm),
+    modules.get_id("file:///a.js", RequestedModuleType::None),
     Some(a_id)
   );
   let b_id = modules
-    .get_id("file:///b.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///b.js", RequestedModuleType::None)
     .unwrap();
   let c_id = modules
-    .get_id("file:///c.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///c.js", RequestedModuleType::None)
     .unwrap();
   let d_id = modules
-    .get_id("file:///d.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///d.js", RequestedModuleType::None)
     .unwrap();
   assert_eq!(
     modules.get_requested_modules(a_id),
     Some(vec![
       ModuleRequest {
         specifier: "file:///b.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       },
       ModuleRequest {
         specifier: "file:///c.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       },
     ])
   );
@@ -306,14 +306,14 @@ fn test_recursive_load() {
     modules.get_requested_modules(b_id),
     Some(vec![ModuleRequest {
       specifier: "file:///c.js".to_string(),
-      asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+      requested_module_type: RequestedModuleType::None,
     },])
   );
   assert_eq!(
     modules.get_requested_modules(c_id),
     Some(vec![ModuleRequest {
       specifier: "file:///d.js".to_string(),
-      asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+      requested_module_type: RequestedModuleType::None,
     },])
   );
   assert_eq!(modules.get_requested_modules(d_id), Some(vec![]));
@@ -382,7 +382,7 @@ fn test_mods() {
       imports,
       Some(vec![ModuleRequest {
         specifier: "file:///b.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       },])
     );
 
@@ -484,7 +484,7 @@ fn test_json_module() {
       imports,
       Some(vec![ModuleRequest {
         specifier: "file:///c.json".to_string(),
-        asserted_module_type: AssertedModuleType::Json,
+        requested_module_type: RequestedModuleType::Json,
       },])
     );
 
@@ -509,7 +509,7 @@ fn test_json_module() {
       imports,
       Some(vec![ModuleRequest {
         specifier: "file:///c.json".to_string(),
-        asserted_module_type: AssertedModuleType::Json,
+        requested_module_type: RequestedModuleType::Json,
       },])
     );
 
@@ -856,19 +856,18 @@ fn test_circular_load() {
     let modules = module_map_rc;
 
     assert_eq!(
-      modules
-        .get_id("file:///circular1.js", AssertedModuleType::JavaScriptOrWasm),
+      modules.get_id("file:///circular1.js", RequestedModuleType::None),
       Some(circular1_id)
     );
     let circular2_id = modules
-      .get_id("file:///circular2.js", AssertedModuleType::JavaScriptOrWasm)
+      .get_id("file:///circular2.js", RequestedModuleType::None)
       .unwrap();
 
     assert_eq!(
       modules.get_requested_modules(circular1_id),
       Some(vec![ModuleRequest {
         specifier: "file:///circular2.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       }])
     );
 
@@ -876,26 +875,26 @@ fn test_circular_load() {
       modules.get_requested_modules(circular2_id),
       Some(vec![ModuleRequest {
         specifier: "file:///circular3.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       }])
     );
 
     assert!(modules
-      .get_id("file:///circular3.js", AssertedModuleType::JavaScriptOrWasm)
+      .get_id("file:///circular3.js", RequestedModuleType::None)
       .is_some());
     let circular3_id = modules
-      .get_id("file:///circular3.js", AssertedModuleType::JavaScriptOrWasm)
+      .get_id("file:///circular3.js", RequestedModuleType::None)
       .unwrap();
     assert_eq!(
       modules.get_requested_modules(circular3_id),
       Some(vec![
         ModuleRequest {
           specifier: "file:///circular1.js".to_string(),
-          asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+          requested_module_type: RequestedModuleType::None,
         },
         ModuleRequest {
           specifier: "file:///circular2.js".to_string(),
-          asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+          requested_module_type: RequestedModuleType::None,
         }
       ])
     );
@@ -914,69 +913,61 @@ fn test_redirect_load() {
     ..Default::default()
   });
 
-  let fut = async move {
-    let spec = resolve_url("file:///redirect1.js").unwrap();
-    let result = runtime.load_main_module(&spec, None).await;
-    assert!(result.is_ok());
-    let redirect1_id = result.unwrap();
-    #[allow(clippy::let_underscore_future)]
-    let _ = runtime.mod_evaluate(redirect1_id);
-    runtime.run_event_loop(Default::default()).await.unwrap();
-    let l = loads.lock();
-    assert_eq!(
-      l.to_vec(),
-      vec![
-        "file:///redirect1.js",
-        "file:///redirect2.js",
-        "file:///dir/redirect3.js"
-      ]
-    );
+  let fut =
+    async move {
+      let spec = resolve_url("file:///redirect1.js").unwrap();
+      let result = runtime.load_main_module(&spec, None).await;
+      assert!(result.is_ok());
+      let redirect1_id = result.unwrap();
+      #[allow(clippy::let_underscore_future)]
+      let _ = runtime.mod_evaluate(redirect1_id);
+      runtime.run_event_loop(Default::default()).await.unwrap();
+      let l = loads.lock();
+      assert_eq!(
+        l.to_vec(),
+        vec![
+          "file:///redirect1.js",
+          "file:///redirect2.js",
+          "file:///dir/redirect3.js"
+        ]
+      );
 
-    let module_map_rc = runtime.module_map();
-    let modules = module_map_rc;
+      let module_map_rc = runtime.module_map();
+      let modules = module_map_rc;
 
-    assert_eq!(
-      modules
-        .get_id("file:///redirect1.js", AssertedModuleType::JavaScriptOrWasm),
-      Some(redirect1_id)
-    );
+      assert_eq!(
+        modules.get_id("file:///redirect1.js", RequestedModuleType::None),
+        Some(redirect1_id)
+      );
 
-    let redirect2_id = modules
-      .get_id(
-        "file:///dir/redirect2.js",
-        AssertedModuleType::JavaScriptOrWasm,
-      )
-      .unwrap();
-    assert!(modules
-      .is_alias("file:///redirect2.js", AssertedModuleType::JavaScriptOrWasm));
-    assert!(!modules.is_alias(
-      "file:///dir/redirect2.js",
-      AssertedModuleType::JavaScriptOrWasm
-    ));
-    assert_eq!(
-      modules
-        .get_id("file:///redirect2.js", AssertedModuleType::JavaScriptOrWasm),
-      Some(redirect2_id)
-    );
+      let redirect2_id = modules
+        .get_id("file:///dir/redirect2.js", RequestedModuleType::None)
+        .unwrap();
+      assert!(
+        modules.is_alias("file:///redirect2.js", RequestedModuleType::None)
+      );
+      assert!(!modules
+        .is_alias("file:///dir/redirect2.js", RequestedModuleType::None));
+      assert_eq!(
+        modules.get_id("file:///redirect2.js", RequestedModuleType::None),
+        Some(redirect2_id)
+      );
 
-    let redirect3_id = modules
-      .get_id("file:///redirect3.js", AssertedModuleType::JavaScriptOrWasm)
-      .unwrap();
-    assert!(modules.is_alias(
-      "file:///dir/redirect3.js",
-      AssertedModuleType::JavaScriptOrWasm
-    ));
-    assert!(!modules
-      .is_alias("file:///redirect3.js", AssertedModuleType::JavaScriptOrWasm));
-    assert_eq!(
-      modules.get_id(
-        "file:///dir/redirect3.js",
-        AssertedModuleType::JavaScriptOrWasm
-      ),
-      Some(redirect3_id)
-    );
-  }
-  .boxed_local();
+      let redirect3_id = modules
+        .get_id("file:///redirect3.js", RequestedModuleType::None)
+        .unwrap();
+      assert!(
+        modules.is_alias("file:///dir/redirect3.js", RequestedModuleType::None)
+      );
+      assert!(
+        !modules.is_alias("file:///redirect3.js", RequestedModuleType::None)
+      );
+      assert_eq!(
+        modules.get_id("file:///dir/redirect3.js", RequestedModuleType::None),
+        Some(redirect3_id)
+      );
+    }
+    .boxed_local();
 
   futures::executor::block_on(fut);
 }
@@ -1088,20 +1079,17 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error();
   let modules = module_map_rc;
 
   assert_eq!(
-    modules.get_id(
-      "file:///main_with_code.js",
-      AssertedModuleType::JavaScriptOrWasm
-    ),
+    modules.get_id("file:///main_with_code.js", RequestedModuleType::None),
     Some(main_id)
   );
   let b_id = modules
-    .get_id("file:///b.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///b.js", RequestedModuleType::None)
     .unwrap();
   let c_id = modules
-    .get_id("file:///c.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///c.js", RequestedModuleType::None)
     .unwrap();
   let d_id = modules
-    .get_id("file:///d.js", AssertedModuleType::JavaScriptOrWasm)
+    .get_id("file:///d.js", RequestedModuleType::None)
     .unwrap();
 
   assert_eq!(
@@ -1109,11 +1097,11 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error();
     Some(vec![
       ModuleRequest {
         specifier: "file:///b.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       },
       ModuleRequest {
         specifier: "file:///c.js".to_string(),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       }
     ])
   );
@@ -1121,14 +1109,14 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error();
     modules.get_requested_modules(b_id),
     Some(vec![ModuleRequest {
       specifier: "file:///c.js".to_string(),
-      asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+      requested_module_type: RequestedModuleType::None,
     }])
   );
   assert_eq!(
     modules.get_requested_modules(c_id),
     Some(vec![ModuleRequest {
       specifier: "file:///d.js".to_string(),
-      asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+      requested_module_type: RequestedModuleType::None,
     }])
   );
   assert_eq!(modules.get_requested_modules(d_id), Some(vec![]));
diff --git a/core/runtime/tests/snapshot.rs b/core/runtime/tests/snapshot.rs
index c83274f..5ec5c69 100644
--- a/core/runtime/tests/snapshot.rs
+++ b/core/runtime/tests/snapshot.rs
@@ -1,7 +1,7 @@
 // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
 use crate::extensions::Op;
-use crate::modules::AssertedModuleType;
 use crate::modules::ModuleInfo;
+use crate::modules::RequestedModuleType;
 use crate::modules::TestingModuleLoader;
 use crate::*;
 use anyhow::Error;
@@ -161,9 +161,9 @@ fn es_snapshot() {
       name: specifier.into(),
       requests: vec![crate::modules::ModuleRequest {
         specifier: format!("file:///{prev}.js"),
-        asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
+        requested_module_type: RequestedModuleType::None,
       }],
-      module_type: AssertedModuleType::JavaScriptOrWasm,
+      module_type: RequestedModuleType::None,
     }
   }
 
@@ -201,7 +201,7 @@ fn es_snapshot() {
     main: false,
     name: specifier.into(),
     requests: vec![],
-    module_type: AssertedModuleType::JavaScriptOrWasm,
+    module_type: RequestedModuleType::None,
   });
 
   modules.extend((1..200).map(|i| create_module(&mut runtime, i, false)));