Skip to content
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
1 change: 0 additions & 1 deletion mordant-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"parallel_vecs:src/js_printer/lib.rs" = 1

[bun_jsc]
"bare_bool_args:src/jsc/ZigStackFrame.rs" = 1
"defaulted_failure:src/jsc/ConsoleObject.rs" = 4
"narrowed_two_ways:src/jsc/RuntimeTranspilerCache.rs" = 1
"reimplemented_helper:src/jsc/webcore_types.rs" = 1
Expand Down
10 changes: 6 additions & 4 deletions src/jsc/VirtualMachine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5361,6 +5361,7 @@ impl VirtualMachine {
trace: &crate::ZigStackTrace,
allow_ansi_colors: bool,
) -> crate::CrateResult<()> {
use crate::zig_stack_frame::LineColumn;
let stack = trace.frames();
if stack.is_empty() {
return Ok(());
Expand Down Expand Up @@ -5406,12 +5407,12 @@ impl VirtualMachine {
pretty_write!(
"<r> <d>at <r>{}<d> (<r>{}<d>)<r>\n",
frame.name_formatter(allow_ansi_colors),
frame.source_url_formatter(dir, origin, false, allow_ansi_colors)
frame.source_url_formatter(dir, origin, LineColumn::Include, allow_ansi_colors)
)?;
} else if !frame.position.is_invalid() {
pretty_write!(
"<r> <d>at <r>{}\n",
frame.source_url_formatter(dir, origin, false, allow_ansi_colors)
frame.source_url_formatter(dir, origin, LineColumn::Include, allow_ansi_colors)
)?;
} else if has_name {
pretty_write!(
Expand All @@ -5421,7 +5422,7 @@ impl VirtualMachine {
} else {
pretty_write!(
"<r> <d>at <r>{}<d>\n",
frame.source_url_formatter(dir, origin, false, allow_ansi_colors)
frame.source_url_formatter(dir, origin, LineColumn::Include, allow_ansi_colors)
)?;
}
}
Expand Down Expand Up @@ -6588,6 +6589,7 @@ impl VirtualMachine {
#[cold]
#[inline(never)]
pub(crate) fn print_github_annotation(exception: &ZigException) {
use crate::zig_stack_frame::LineColumn;
let name = &exception.name;
let message = &exception.message;
let frames = exception.stack.frames();
Expand Down Expand Up @@ -6677,7 +6679,7 @@ impl VirtualMachine {
let _ = write!(
loc_str,
"{}",
frame.source_url_formatter(file, origin, false, false)
frame.source_url_formatter(file, origin, LineColumn::Include, false)
);
(name_str, loc_str)
};
Expand Down
19 changes: 13 additions & 6 deletions src/jsc/ZigStackFrame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ZigStackFrame {
write!(
&mut file,
"{}",
self.source_url_formatter(root_path, origin, true, false)
self.source_url_formatter(root_path, origin, LineColumn::Exclude, false)
)
.expect("Vec<u8> write is infallible");
}
Expand Down Expand Up @@ -88,12 +88,12 @@ impl ZigStackFrame {
&self,
root_path: &'a [u8],
origin: Option<&'a ZigURL<'a>>,
exclude_line_column: bool,
line_column: LineColumn,
enable_color: bool,
) -> SourceURLFormatter<'a> {
SourceURLFormatter {
source_url: self.source_url,
exclude_line_column,
line_column,
origin,
root_path,
position: self.position,
Expand All @@ -103,12 +103,19 @@ impl ZigStackFrame {
}
}

/// Whether [`SourceURLFormatter`] appends the frame's `:line:column` to the source URL.
#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum LineColumn {
Include,
Exclude,
}

pub struct SourceURLFormatter<'a> {
pub(crate) source_url: BunString,
pub(crate) position: ZigStackFramePosition,
pub(crate) enable_color: bool,
pub(crate) origin: Option<&'a ZigURL<'a>>,
pub(crate) exclude_line_column: bool,
pub(crate) line_column: LineColumn,
pub(crate) remapped: bool,
pub(crate) root_path: &'a [u8],
}
Expand Down Expand Up @@ -164,7 +171,7 @@ impl<'a> fmt::Display for SourceURLFormatter<'a> {
}
}

if !self.exclude_line_column
if self.line_column == LineColumn::Include
&& !source_slice.is_empty()
&& (self.position.line.is_valid() || self.position.column.is_valid())
{
Expand All @@ -179,7 +186,7 @@ impl<'a> fmt::Display for SourceURLFormatter<'a> {
f.write_str(Output::pretty_fmt!("<r>", true))?;
}

if !self.exclude_line_column {
if self.line_column == LineColumn::Include {
if self.position.line.is_valid() && self.position.column.is_valid() {
if self.enable_color {
write!(
Expand Down
Loading