Skip to content

Commit 172c71a

Browse files
authored
feat: Add a temporary way to warn on import assertions (denoland#873)
This commit adds a `ModuleLoader::purge_and_prevent_code_cache` method that is called when a V8 warning for import assertions is received. This is a temporary method, that will be removed after Deno 2 when requirement for import assertion support is dropped completely.
1 parent 60516fd commit 172c71a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

core/modules/loaders.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ pub trait ModuleLoader {
9696
async {}.boxed_local()
9797
}
9898

99+
/// Called when V8 code cache should be ignored for this module. This can happen
100+
/// if eg. module causes a V8 warning, like when using deprecated import assertions.
101+
/// Implementors should make sure that the code cache for this module is purged and not saved anymore.
102+
///
103+
/// It's not required to implement this method.
104+
fn purge_and_prevent_code_cache(&self, _module_specifier: &str) {}
105+
99106
/// Returns a source map for given `file_name`.
100107
///
101108
/// This function will soon be deprecated or renamed.

core/runtime/jsruntime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,14 @@ extern "C" fn isolate_message_listener(
602602
let start_column = message.get_start_column();
603603

604604
let js_runtime_state = JsRuntime::state_from(scope);
605+
if let Some(specifier) = maybe_script_resource_name.as_ref() {
606+
let module_map = JsRealm::module_map_from(scope);
607+
module_map
608+
.loader
609+
.borrow()
610+
.purge_and_prevent_code_cache(specifier);
611+
}
612+
605613
match &js_runtime_state.import_assertions_support {
606614
ImportAssertionsSupport::Warning => {
607615
let mut msg = "⚠️ Import assertions are deprecated. Use `with` keyword, instead of 'assert' keyword.".to_string();

0 commit comments

Comments
 (0)