1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

errors: replace .lines with explicit .split newline (#4483)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2020-03-24 20:55:54 -07:00 committed by GitHub
parent eeedb416c0
commit 3938071e91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 1 deletions

View file

@ -553,7 +553,9 @@ impl SourceMapGetter for TsCompiler {
.try_resolve_and_get_source_file(script_name)
.and_then(|out| {
str::from_utf8(&out.source_code).ok().and_then(|v| {
let lines: Vec<&str> = v.lines().collect();
// Do NOT use .lines(): it skips the terminating empty line.
// (due to internally using .split_terminator() instead of .split())
let lines: Vec<&str> = v.split('\n').collect();
assert!(lines.len() > line);
Some(lines[line].to_string())
})

View file

@ -0,0 +1,2 @@
// Deliberately using .mjs to avoid triggering prettier
setTimeout(() => {}),

View file

@ -0,0 +1,2 @@
error: Uncaught SyntaxError: Unexpected end of input
► file:///[WILDCARD]cli/tests/error_syntax_empty_trailing_line.mjs:[WILDCARD]

View file

@ -1302,6 +1302,13 @@ itest!(error_syntax {
output: "error_syntax.js.out",
});
itest!(error_syntax_empty_trailing_line {
args: "run --reload error_syntax_empty_trailing_line.mjs",
check_stderr: true,
exit_code: 1,
output: "error_syntax_empty_trailing_line.mjs.out",
});
itest!(error_type_definitions {
args: "run --reload error_type_definitions.ts",
check_stderr: true,