mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix misaligned error reporting on tab char (#5032)
This commit is contained in:
parent
fa396c0a22
commit
25b765c123
5 changed files with 31 additions and 2 deletions
|
@ -74,7 +74,11 @@ fn format_maybe_source_line(
|
|||
'~'
|
||||
};
|
||||
for _i in 0..start_column {
|
||||
s.push(' ');
|
||||
if source_line.chars().nth(_i as usize).unwrap() == '\t' {
|
||||
s.push('\t');
|
||||
} else {
|
||||
s.push(' ');
|
||||
}
|
||||
}
|
||||
for _i in 0..(end_column - start_column) {
|
||||
s.push(underline_char);
|
||||
|
|
9
cli/tests/error_025_tab_indent
Normal file
9
cli/tests/error_025_tab_indent
Normal file
|
@ -0,0 +1,9 @@
|
|||
function foo() {
|
||||
throw Error("bad");
|
||||
}
|
||||
|
||||
function bar() {
|
||||
foo();
|
||||
}
|
||||
|
||||
bar();
|
6
cli/tests/error_025_tab_indent.out
Normal file
6
cli/tests/error_025_tab_indent.out
Normal file
|
@ -0,0 +1,6 @@
|
|||
[WILDCARD]error: Uncaught Error: bad
|
||||
throw Error("bad");
|
||||
^
|
||||
at foo ([WILDCARD]tests/error_025_tab_indent:2:8)
|
||||
at bar ([WILDCARD]tests/error_025_tab_indent:6:2)
|
||||
at [WILDCARD]tests/error_025_tab_indent:9:1
|
|
@ -1429,6 +1429,13 @@ itest!(error_024_stack_promise_all {
|
|||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(error_025_tab_indent {
|
||||
args: "error_025_tab_indent",
|
||||
output: "error_025_tab_indent.out",
|
||||
check_stderr: true,
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(error_syntax {
|
||||
args: "run --reload error_syntax.js",
|
||||
check_stderr: true,
|
||||
|
|
|
@ -274,11 +274,14 @@ impl fmt::Display for JSError {
|
|||
write!(f, "{}", source_loc)?;
|
||||
}
|
||||
if self.source_line.is_some() {
|
||||
write!(f, "\n{}\n", self.source_line.as_ref().unwrap())?;
|
||||
let source_line = self.source_line.as_ref().unwrap();
|
||||
write!(f, "\n{}\n", source_line)?;
|
||||
let mut s = String::new();
|
||||
for i in 0..self.end_column.unwrap() {
|
||||
if i >= self.start_column.unwrap() {
|
||||
s.push('^');
|
||||
} else if source_line.chars().nth(i as usize).unwrap() == '\t' {
|
||||
s.push('\t');
|
||||
} else {
|
||||
s.push(' ');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue