mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): add parens to left of instanceof (#1602)
This commit is contained in:
parent
66452c95f5
commit
f4f392e19f
3 changed files with 32 additions and 4 deletions
|
|
@ -153,10 +153,23 @@ impl<'a> Prettier<'a> {
|
|||
// idx = self.skip_inline_comment(idx);
|
||||
idx = self.skip_spaces(idx, /* backwards */ false);
|
||||
}
|
||||
// idx = self.skip_trailing_comment(idx);
|
||||
idx = self.skip_trailing_comment(idx);
|
||||
idx = self.skip_newline(idx, /* backwards */ false);
|
||||
idx.is_some_and(|idx| self.has_newline(idx, /* backwards */ false))
|
||||
// self.source_text[end as usize..].chars().nth(1).is_some_and(|c| c == '\n')
|
||||
}
|
||||
|
||||
fn skip_trailing_comment(&self, start_index: Option<u32>) -> Option<u32> {
|
||||
let start_index = start_index?;
|
||||
let mut chars = self.source_text[start_index as usize..].chars();
|
||||
let c = chars.next()?;
|
||||
if c != '/' {
|
||||
return Some(start_index);
|
||||
}
|
||||
let c = chars.next()?;
|
||||
if c != '/' {
|
||||
return Some(start_index);
|
||||
}
|
||||
self.skip_everything_but_new_line(Some(start_index), /* backwards */ false)
|
||||
}
|
||||
|
||||
fn skip_to_line_end(&self, start_index: Option<u32>) -> Option<u32> {
|
||||
|
|
@ -167,6 +180,14 @@ impl<'a> Prettier<'a> {
|
|||
self.skip(start_index, backwards, |c| matches!(c, ' ' | '\t'))
|
||||
}
|
||||
|
||||
fn skip_everything_but_new_line(
|
||||
&self,
|
||||
start_index: Option<u32>,
|
||||
backwards: bool,
|
||||
) -> Option<u32> {
|
||||
self.skip(start_index, backwards, |c| !is_line_terminator(c))
|
||||
}
|
||||
|
||||
fn skip<F>(&self, start_index: Option<u32>, backwards: bool, f: F) -> Option<u32>
|
||||
where
|
||||
F: Fn(char) -> bool,
|
||||
|
|
|
|||
|
|
@ -219,6 +219,15 @@ impl<'a> Prettier<'a> {
|
|||
|| self.should_wrap_function_for_export_default();
|
||||
}
|
||||
}
|
||||
AstKind::BinaryExpression(binary_expr) => {
|
||||
if binary_expr.operator.is_relational() {
|
||||
if let AstKind::UnaryExpression(unary_expr) = kind {
|
||||
if binary_expr.left.span() == unary_expr.span {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ Compatibility: 212/561 (37.79%)
|
|||
* binary-expressions/arrow.js
|
||||
* binary-expressions/call.js
|
||||
* binary-expressions/comment.js
|
||||
* binary-expressions/in_instanceof.js
|
||||
* binary-expressions/inline-jsx.js
|
||||
* binary-expressions/inline-object-array.js
|
||||
* binary-expressions/jsx_parent.js
|
||||
|
|
@ -258,7 +257,6 @@ Compatibility: 212/561 (37.79%)
|
|||
* functional-composition/pipe-function-calls-with-comments.js
|
||||
* functional-composition/pipe-function-calls.js
|
||||
* functional-composition/ramda_compose.js
|
||||
* functional-composition/ramda_pipe.js
|
||||
* functional-composition/redux_connect.js
|
||||
* functional-composition/reselect_createselector.js
|
||||
* functional-composition/rxjs_pipe.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue