diff --git a/cli/program_state.rs b/cli/program_state.rs index 03ad526178..684d33a8e6 100644 --- a/cli/program_state.rs +++ b/cli/program_state.rs @@ -296,12 +296,8 @@ impl SourceMapGetter for ProgramState { fn get_source_map(&self, file_name: &str) -> Option> { if let Ok(specifier) = ModuleSpecifier::resolve_url(file_name) { if let Some((code, maybe_map)) = self.get_emit(&specifier.as_url()) { - if maybe_map.is_some() { - maybe_map - } else { - let code = String::from_utf8(code).unwrap(); - source_map_from_code(code) - } + let code = String::from_utf8(code).unwrap(); + source_map_from_code(code).or(maybe_map) } else if let Ok(source) = self.load(specifier, None) { source_map_from_code(source.code) } else { diff --git a/cli/tests/083_legacy_external_source_map.ts b/cli/tests/083_legacy_external_source_map.ts new file mode 100644 index 0000000000..73d267b87b --- /dev/null +++ b/cli/tests/083_legacy_external_source_map.ts @@ -0,0 +1,2 @@ +// - +throw new Error("foo"); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index c79988412d..db09aa421c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2656,6 +2656,35 @@ console.log("finish"); exit_code: 1, }); + #[test] + fn _083_legacy_external_source_map() { + let _g = util::http_server(); + let deno_dir = TempDir::new().expect("tempdir fail"); + let module_url = url::Url::parse( + "http://localhost:4545/cli/tests/083_legacy_external_source_map.ts", + ) + .unwrap(); + // Write a faulty old external source map. + let faulty_map_path = deno_dir.path().join("gen/http/localhost_PORT4545/9576bd5febd0587c5c4d88d57cb3ac8ebf2600c529142abe3baa9a751d20c334.js.map"); + std::fs::create_dir_all(faulty_map_path.parent().unwrap()) + .expect("Failed to create faulty source map dir."); + std::fs::write(faulty_map_path, "{\"version\":3,\"file\":\"\",\"sourceRoot\":\"\",\"sources\":[\"http://localhost:4545/cli/tests/083_legacy_external_source_map.ts\"],\"names\":[],\"mappings\":\";AAAA,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC\"}").expect("Failed to write faulty source map."); + let output = Command::new(util::deno_exe_path()) + .env("DENO_DIR", deno_dir.path()) + .current_dir(util::root_path()) + .arg("run") + .arg(module_url.to_string()) + .output() + .expect("Failed to spawn script"); + // Before https://github.com/denoland/deno/issues/6965 was fixed, the faulty + // old external source map would cause a panic while formatting the error + // and the exit code would be 101. The external source map should be ignored + // in favor of the inline one. + assert_eq!(output.status.code(), Some(1)); + let out = std::str::from_utf8(&output.stdout).unwrap(); + assert_eq!(out, ""); + } + itest!(js_import_detect { args: "run --quiet --reload js_import_detect.ts", output: "js_import_detect.ts.out",