From 989c72313078e71b60e22902f8a3abc67d085187 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Mon, 11 Jul 2022 19:43:47 +0100 Subject: [PATCH] perf(cli/proc_state): Get error source lines from memory (#15031) --- cli/proc_state.rs | 30 +++++++++---------- cli/tests/integration/run_tests.rs | 6 ---- .../eval_context_conflicting_source.ts | 1 - ...l_context_throw_with_conflicting_source.ts | 6 ---- ...ntext_throw_with_conflicting_source.ts.out | 5 ---- 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 cli/tests/testdata/eval_context_conflicting_source.ts delete mode 100644 cli/tests/testdata/eval_context_throw_with_conflicting_source.ts delete mode 100644 cli/tests/testdata/eval_context_throw_with_conflicting_source.ts.out diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 7154693daa..1a32b01a4f 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -663,22 +663,22 @@ impl SourceMapGetter for ProcState { file_name: &str, line_number: usize, ) -> Option { - if let Ok(specifier) = resolve_url(file_name) { - self.file_fetcher.get_source(&specifier).map(|out| { - // Do NOT use .lines(): it skips the terminating empty line. - // (due to internally using_terminator() instead of .split()) - let lines: Vec<&str> = out.source.split('\n').collect(); - if line_number >= lines.len() { - format!( - "{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)", - crate::colors::yellow("Warning"), line_number + 1, - ) - } else { - lines[line_number].to_string() - } - }) + let graph_data = self.graph_data.read(); + let specifier = graph_data.follow_redirect(&resolve_url(file_name).ok()?); + let code = match graph_data.get(&specifier) { + Some(ModuleEntry::Module { code, .. }) => code, + _ => return None, + }; + // Do NOT use .lines(): it skips the terminating empty line. + // (due to internally using_terminator() instead of .split()) + let lines: Vec<&str> = code.split('\n').collect(); + if line_number >= lines.len() { + Some(format!( + "{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)", + crate::colors::yellow("Warning"), line_number + 1, + )) } else { - None + Some(lines[line_number].to_string()) } } } diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 1cd1db0ef6..d9c20907dd 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2357,12 +2357,6 @@ itest!(long_data_url_formatting { exit_code: 1, }); -itest!(eval_context_throw_with_conflicting_source { - args: "run eval_context_throw_with_conflicting_source.ts", - output: "eval_context_throw_with_conflicting_source.ts.out", - exit_code: 1, -}); - itest!(eval_context_throw_dom_exception { args: "run eval_context_throw_dom_exception.js", output: "eval_context_throw_dom_exception.js.out", diff --git a/cli/tests/testdata/eval_context_conflicting_source.ts b/cli/tests/testdata/eval_context_conflicting_source.ts deleted file mode 100644 index 6717401136..0000000000 --- a/cli/tests/testdata/eval_context_conflicting_source.ts +++ /dev/null @@ -1 +0,0 @@ -throw new Error("foo"); diff --git a/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts b/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts deleted file mode 100644 index c5bc21e482..0000000000 --- a/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts +++ /dev/null @@ -1,6 +0,0 @@ -// deno-lint-ignore no-explicit-any -const [, errorInfo] = (Deno as any).core.evalContext( - '/* aaaaaaaaaaaaaaaaa */ throw new Error("foo")', - new URL("eval_context_conflicting_source.ts", import.meta.url).href, -); -throw errorInfo.thrown; diff --git a/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts.out b/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts.out deleted file mode 100644 index 8dfbd0431c..0000000000 --- a/cli/tests/testdata/eval_context_throw_with_conflicting_source.ts.out +++ /dev/null @@ -1,5 +0,0 @@ -[WILDCARD]error: Uncaught Error: foo -Warning Couldn't format source line: Column 31 is out of bounds (source may have changed at runtime) - at file:///[WILDCARD]/eval_context_conflicting_source.ts:1:31 - at [WILDCARD] - at file:///[WILDCARD]/eval_context_throw_with_conflicting_source.ts:[WILDCARD]