summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-01-15 02:28:46 +0100
committerGitHub <noreply@github.com>2024-01-14 18:28:46 -0700
commitbc8d00c880756a46b0ce4c8bf0c89407a2de669c (patch)
tree03f41df566a3f171f9eec2a63e44ec0f5c25057a /cli
parent5143b9e7d3f72e6cc23f8381295df17ff1235f53 (diff)
chore: upgrade deno_core to 0.246.0 (#21904)
Diffstat (limited to 'cli')
-rw-r--r--cli/module_loader.rs22
-rw-r--r--cli/standalone/mod.rs2
-rw-r--r--cli/tests/testdata/import_attributes/dynamic_error.out2
-rw-r--r--cli/tests/unit/console_test.ts8
4 files changed, 25 insertions, 9 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index dc7b2b9b6..21ceee109 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -41,6 +41,7 @@ use deno_core::ModuleSource;
use deno_core::ModuleSourceCode;
use deno_core::ModuleSpecifier;
use deno_core::ModuleType;
+use deno_core::RequestedModuleType;
use deno_core::ResolutionKind;
use deno_core::SourceMapGetter;
use deno_graph::source::ResolutionMode;
@@ -471,6 +472,7 @@ impl CliModuleLoader {
specifier: &ModuleSpecifier,
maybe_referrer: Option<&ModuleSpecifier>,
is_dynamic: bool,
+ requested_module_type: RequestedModuleType,
) -> Result<ModuleSource, AnyError> {
let permissions = if is_dynamic {
&self.dynamic_permissions
@@ -498,11 +500,21 @@ impl CliModuleLoader {
// because we don't need it
code_without_source_map(code_source.code)
};
+ let module_type = match code_source.media_type {
+ MediaType::Json => ModuleType::Json,
+ _ => ModuleType::JavaScript,
+ };
+
+ // If we loaded a JSON file, but the "requested_module_type" (that is computed from
+ // import attributes) is not JSON we need to fail.
+ if module_type == ModuleType::Json
+ && requested_module_type != RequestedModuleType::Json
+ {
+ return Err(generic_error("Attempted to load JSON module without specifying \"type\": \"json\" attribute in the import statement."));
+ }
+
Ok(ModuleSource::new_with_redirect(
- match code_source.media_type {
- MediaType::Json => ModuleType::Json,
- _ => ModuleType::JavaScript,
- },
+ module_type,
ModuleSourceCode::String(code),
specifier,
&code_source.found_url,
@@ -640,6 +652,7 @@ impl ModuleLoader for CliModuleLoader {
specifier: &ModuleSpecifier,
maybe_referrer: Option<&ModuleSpecifier>,
is_dynamic: bool,
+ requested_module_type: RequestedModuleType,
) -> Pin<Box<deno_core::ModuleSourceFuture>> {
// NOTE: this block is async only because of `deno_core` interface
// requirements; module was already loaded when constructing module graph
@@ -648,6 +661,7 @@ impl ModuleLoader for CliModuleLoader {
specifier,
maybe_referrer,
is_dynamic,
+ requested_module_type,
)))
}
diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs
index 47a660fe1..55c3db48c 100644
--- a/cli/standalone/mod.rs
+++ b/cli/standalone/mod.rs
@@ -41,6 +41,7 @@ use deno_core::ModuleLoader;
use deno_core::ModuleSourceCode;
use deno_core::ModuleSpecifier;
use deno_core::ModuleType;
+use deno_core::RequestedModuleType;
use deno_core::ResolutionKind;
use deno_runtime::deno_fs;
use deno_runtime::deno_node::analyze::NodeCodeTranslator;
@@ -148,6 +149,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
original_specifier: &ModuleSpecifier,
maybe_referrer: Option<&ModuleSpecifier>,
is_dynamic: bool,
+ _requested_module_type: RequestedModuleType,
) -> Pin<Box<deno_core::ModuleSourceFuture>> {
let is_data_uri = get_source_from_data_url(original_specifier).ok();
if let Some((source, _)) = is_data_uri {
diff --git a/cli/tests/testdata/import_attributes/dynamic_error.out b/cli/tests/testdata/import_attributes/dynamic_error.out
index 3dc79ba6b..24f29de72 100644
--- a/cli/tests/testdata/import_attributes/dynamic_error.out
+++ b/cli/tests/testdata/import_attributes/dynamic_error.out
@@ -1,4 +1,4 @@
-error: Uncaught (in promise) TypeError: Expected a "None" module but loaded a "JSON" module.
+error: Uncaught (in promise) TypeError: Attempted to load JSON module without specifying "type": "json" attribute in the import statement.
const data = await import("./data.json");
^
at async [WILDCARD]dynamic_error.ts:1:14
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 031512f79..219b6ab07 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -490,12 +490,12 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() {
[some]: [Function: some] { [length]: 1, [name]: "some" },
[reduce]: [Function: reduce] { [length]: 1, [name]: "reduce" },
[reduceRight]: [Function: reduceRight] { [length]: 1, [name]: "reduceRight" },
- [toLocaleString]: [Function: toLocaleString] { [length]: 0, [name]: "toLocaleString" },
- [toString]: [Function: toString] { [length]: 0, [name]: "toString" },
[toReversed]: [Function: toReversed] { [length]: 0, [name]: "toReversed" },
[toSorted]: [Function: toSorted] { [length]: 1, [name]: "toSorted" },
[toSpliced]: [Function: toSpliced] { [length]: 2, [name]: "toSpliced" },
[with]: [Function: with] { [length]: 2, [name]: "with" },
+ [toLocaleString]: [Function: toLocaleString] { [length]: 0, [name]: "toLocaleString" },
+ [toString]: [Function: toString] { [length]: 0, [name]: "toString" },
[Symbol(Symbol.iterator)]: [Function: values] { [length]: 0, [name]: "values" },
[Symbol(Symbol.unscopables)]: [Object: null prototype] {
at: true,
@@ -510,10 +510,10 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() {
flatMap: true,
includes: true,
keys: true,
- values: true,
toReversed: true,
toSorted: true,
- toSpliced: true
+ toSpliced: true,
+ values: true
}
],
[isArray]: [Function: isArray] { [length]: 1, [name]: "isArray" },