From 0ea6eb83a906bff543be4c3301f23444986b022b Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Mon, 13 Apr 2020 15:54:16 +0100 Subject: refactor(core/js_error): Align JSStackFrame with CallSite (#4715) Renames and adds missing fields to JSStackFrame from CallSite. Fixes #4705. Cleans up base changes for line and column numbers. --- cli/fmt_errors.rs | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'cli/fmt_errors.rs') diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 784bcc9c9..19e6616ca 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -21,34 +21,34 @@ pub trait DisplayFormatter { } fn format_source_name( - script_name: String, + file_name: String, line_number: i64, - column: i64, + column_number: i64, ) -> String { - let line_number = line_number + 1; - let column = column + 1; - let script_name_c = colors::cyan(script_name); + let line_number = line_number; + let column_number = column_number; + let file_name_c = colors::cyan(file_name); let line_c = colors::yellow(line_number.to_string()); - let column_c = colors::yellow(column.to_string()); - format!("{}:{}:{}", script_name_c, line_c, column_c) + let column_c = colors::yellow(column_number.to_string()); + format!("{}:{}:{}", file_name_c, line_c, column_c) } -/// Formats optional source, line number and column into a single string. +/// Formats optional source, line and column numbers into a single string. pub fn format_maybe_source_name( - script_name: Option, + file_name: Option, line_number: Option, - column: Option, + column_number: Option, ) -> String { - if script_name.is_none() { + if file_name.is_none() { return "".to_string(); } assert!(line_number.is_some()); - assert!(column.is_some()); + assert!(column_number.is_some()); format_source_name( - script_name.unwrap(), + file_name.unwrap(), line_number.unwrap(), - column.unwrap(), + column_number.unwrap(), ) } @@ -76,7 +76,7 @@ pub fn format_maybe_source_line( assert!(start_column.is_some()); assert!(end_column.is_some()); - let line_number = (1 + line_number.unwrap()).to_string(); + let line_number = line_number.unwrap().to_string(); let line_color = colors::black_on_white(line_number.to_string()); let line_number_len = line_number.len(); let line_padding = @@ -93,12 +93,11 @@ pub fn format_maybe_source_line( } else { '~' }; - for i in 0..end_column { - if i >= start_column { - s.push(underline_char); - } else { - s.push(' '); - } + for _i in 0..start_column { + s.push(' '); + } + for _i in 0..(end_column - start_column) { + s.push(underline_char); } let color_underline = if is_error { colors::red(s).to_string() @@ -181,7 +180,7 @@ impl DisplayFormatter for JSError { format_maybe_source_name( e.script_resource_name.clone(), e.line_number, - e.start_column, + e.start_column.map(|n| n + 1), ) ) } @@ -223,7 +222,7 @@ mod tests { Some(1), Some(2), ); - assert_eq!(strip_ansi_codes(&actual), "file://foo/bar.ts:2:3"); + assert_eq!(strip_ansi_codes(&actual), "file://foo/bar.ts:1:2"); } #[test] @@ -244,7 +243,7 @@ mod tests { ); assert_eq!( strip_ansi_codes(&actual), - "\n\n9 console.log(\'foo\');\n ~~~\n" + "\n\n8 console.log(\'foo\');\n ~~~\n" ); } -- cgit v1.2.3