Skip to content

Commit

Permalink
perf(cli/proc_state): Get error source lines from memory (denoland#15031
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nayeemrmn committed Jul 11, 2022
1 parent 687c712 commit 989c723
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 33 deletions.
30 changes: 15 additions & 15 deletions cli/proc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,22 +663,22 @@ impl SourceMapGetter for ProcState {
file_name: &str,
line_number: usize,
) -> Option<String> {
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())
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion cli/tests/testdata/eval_context_conflicting_source.ts

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 989c723

Please sign in to comment.