summaryrefslogtreecommitdiff
path: root/cli/fmt_errors.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-13 15:54:16 +0100
committerGitHub <noreply@github.com>2020-04-13 10:54:16 -0400
commit0ea6eb83a906bff543be4c3301f23444986b022b (patch)
tree923e5b1c7608839c9a7be545f8973ae751ee7e73 /cli/fmt_errors.rs
parent5105c6839904f35351481137160459fdc2edadd2 (diff)
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.
Diffstat (limited to 'cli/fmt_errors.rs')
-rw-r--r--cli/fmt_errors.rs47
1 files changed, 23 insertions, 24 deletions
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<String>,
+ file_name: Option<String>,
line_number: Option<i64>,
- column: Option<i64>,
+ column_number: Option<i64>,
) -> 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"
);
}