diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 6821e81835..bed42b9b45 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -30,6 +30,7 @@ use crate::npm::NpmPackageResolver; use crate::resolver::ImportMapResolver; use crate::resolver::JsxResolver; +use deno_ast::MediaType; use deno_core::anyhow::anyhow; use deno_core::anyhow::bail; use deno_core::anyhow::Context; @@ -598,15 +599,25 @@ impl ProcState { code, media_type, .. } = entry { - emit_parsed_source( - &self.emit_cache, - &self.parsed_source_cache, - specifier, - *media_type, - code, - &self.emit_options, - self.emit_options_hash, - )?; + let is_emittable = matches!( + media_type, + MediaType::TypeScript + | MediaType::Mts + | MediaType::Cts + | MediaType::Jsx + | MediaType::Tsx + ); + if is_emittable { + emit_parsed_source( + &self.emit_cache, + &self.parsed_source_cache, + specifier, + *media_type, + code, + &self.emit_options, + self.emit_options_hash, + )?; + } } } Ok(()) diff --git a/cli/tests/integration/cache_tests.rs b/cli/tests/integration/cache_tests.rs index aaae62531d..54aea81069 100644 --- a/cli/tests/integration/cache_tests.rs +++ b/cli/tests/integration/cache_tests.rs @@ -92,3 +92,8 @@ itest!(check_local_by_default2 { output: "cache/check_local_by_default2.out", http_server: true, }); + +itest!(json_import { + // should not error + args: "cache --quiet cache/json_import/main.ts", +}); diff --git a/cli/tests/testdata/cache/json_import/main.ts b/cli/tests/testdata/cache/json_import/main.ts new file mode 100644 index 0000000000..78273558f1 --- /dev/null +++ b/cli/tests/testdata/cache/json_import/main.ts @@ -0,0 +1,2 @@ +import asdf from "./test.json" assert { type: "json" }; +console.log(asdf); diff --git a/cli/tests/testdata/cache/json_import/test.json b/cli/tests/testdata/cache/json_import/test.json new file mode 100644 index 0000000000..258849a686 --- /dev/null +++ b/cli/tests/testdata/cache/json_import/test.json @@ -0,0 +1,5 @@ +{ + "foo": { + "bar": 1 + } +} diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index d15538e545..038045a5cf 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1904,6 +1904,8 @@ impl<'a> CheckOutputIntegrationTest<'a> { let expected = if let Some(s) = self.output_str { s.to_owned() + } else if self.output.is_empty() { + String::new() } else { let output_path = testdata_dir.join(self.output); println!("output path {}", output_path.display());