1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix(cli): check for inline source maps before external ones (#9394)

Fixes #6965
This commit is contained in:
Nayeem Rahman 2021-02-07 23:14:05 +00:00 committed by GitHub
parent 45b465f839
commit 0cac243a83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View file

@ -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 {

View file

@ -0,0 +1,2 @@
// -
throw new Error("foo");

View file

@ -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",