summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-02-07 23:14:05 +0000
committerGitHub <noreply@github.com>2021-02-08 10:14:05 +1100
commit0cac243a835d86ad5f37d50bdd1634bd4fe2d2d6 (patch)
tree1dc1a5a7b124f65017487bd322f6cf41cee288b1
parent45b465f8392b58f3cc524502737e98feecdf2c25 (diff)
fix(cli): check for inline source maps before external ones (#9394)
Fixes #6965
-rw-r--r--cli/program_state.rs8
-rw-r--r--cli/tests/083_legacy_external_source_map.ts2
-rw-r--r--cli/tests/integration_tests.rs29
3 files changed, 33 insertions, 6 deletions
diff --git a/cli/program_state.rs b/cli/program_state.rs
index 03ad52617..684d33a8e 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<Vec<u8>> {
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 000000000..73d267b87
--- /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 c79988412..db09aa421 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",