mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
refactor: remove usages of map_or
/ map_or_else
(#18212)
These methods are confusing because the arguments are backwards. I feel like they should have never been added to `Option<T>` and that clippy should suggest rewriting to `map(...).unwrap_or(...)`/`map(...).unwrap_or_else(|| ...)` https://github.com/rust-lang/rfcs/issues/1025
This commit is contained in:
parent
ca51f4f6c0
commit
fb021d7cef
21 changed files with 179 additions and 141 deletions
|
@ -45,7 +45,8 @@ pub fn format_location(frame: &JsStackFrame) -> String {
|
|||
let _internal = frame
|
||||
.file_name
|
||||
.as_ref()
|
||||
.map_or(false, |f| f.starts_with("ext:"));
|
||||
.map(|f| f.starts_with("ext:"))
|
||||
.unwrap_or(false);
|
||||
if frame.is_native {
|
||||
return cyan("native").to_string();
|
||||
}
|
||||
|
@ -73,7 +74,8 @@ fn format_frame(frame: &JsStackFrame) -> String {
|
|||
let _internal = frame
|
||||
.file_name
|
||||
.as_ref()
|
||||
.map_or(false, |f| f.starts_with("ext:"));
|
||||
.map(|f| f.starts_with("ext:"))
|
||||
.unwrap_or(false);
|
||||
let is_method_call =
|
||||
!(frame.is_top_level.unwrap_or_default() || frame.is_constructor);
|
||||
let mut result = String::new();
|
||||
|
@ -252,7 +254,10 @@ fn format_js_error_inner(
|
|||
if let Some(aggregated) = &js_error.aggregated {
|
||||
let aggregated_message = format_aggregated_error(
|
||||
aggregated,
|
||||
circular.as_ref().map_or(0, |circular| circular.index),
|
||||
circular
|
||||
.as_ref()
|
||||
.map(|circular| circular.index)
|
||||
.unwrap_or(0),
|
||||
);
|
||||
s.push_str(&aggregated_message);
|
||||
}
|
||||
|
@ -274,9 +279,12 @@ fn format_js_error_inner(
|
|||
write!(s, "\n at {}", format_frame(frame)).unwrap();
|
||||
}
|
||||
if let Some(cause) = &js_error.cause {
|
||||
let is_caused_by_circular = circular.as_ref().map_or(false, |circular| {
|
||||
errors_are_equal_without_cause(circular.reference.from, js_error)
|
||||
});
|
||||
let is_caused_by_circular = circular
|
||||
.as_ref()
|
||||
.map(|circular| {
|
||||
errors_are_equal_without_cause(circular.reference.from, js_error)
|
||||
})
|
||||
.unwrap_or(false);
|
||||
|
||||
let error_string = if is_caused_by_circular {
|
||||
cyan(format!("[Circular *{}]", circular.unwrap().index)).to_string()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue