Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1288,6 +1288,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