Skip to content

Commit

Permalink
errors: replace .lines with explicit .split newline (#4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo authored Mar 25, 2020
1 parent eeedb41 commit 3938071
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/compilers/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/error_syntax_empty_trailing_line.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Deliberately using .mjs to avoid triggering prettier
setTimeout(() => {}),
2 changes: 2 additions & 0 deletions cli/tests/error_syntax_empty_trailing_line.mjs.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: Uncaught SyntaxError: Unexpected end of input
► file:///[WILDCARD]cli/tests/error_syntax_empty_trailing_line.mjs:[WILDCARD]
7 changes: 7 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3938071

Please sign in to comment.