diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 4f822dc2ce9b42..a74e4a0966e791 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -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()) }) diff --git a/cli/tests/error_syntax_empty_trailing_line.mjs b/cli/tests/error_syntax_empty_trailing_line.mjs new file mode 100644 index 00000000000000..5bc6b1c239409d --- /dev/null +++ b/cli/tests/error_syntax_empty_trailing_line.mjs @@ -0,0 +1,2 @@ +// Deliberately using .mjs to avoid triggering prettier +setTimeout(() => {}), diff --git a/cli/tests/error_syntax_empty_trailing_line.mjs.out b/cli/tests/error_syntax_empty_trailing_line.mjs.out new file mode 100644 index 00000000000000..1f1c96cd3172bb --- /dev/null +++ b/cli/tests/error_syntax_empty_trailing_line.mjs.out @@ -0,0 +1,2 @@ +error: Uncaught SyntaxError: Unexpected end of input +► file:///[WILDCARD]cli/tests/error_syntax_empty_trailing_line.mjs:[WILDCARD] diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index ed516056524fca..93f929771e3464 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -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,