chore: reformat

This commit is contained in:
Boshen 2023-07-27 12:35:01 +08:00
parent 9cb34e0021
commit b34ef4f07a
14 changed files with 177 additions and 39 deletions

View file

@ -22,7 +22,11 @@ pub struct BooleanLiteral {
impl BooleanLiteral {
pub fn as_str(&self) -> &'static str {
if self.value { "true" } else { "false" }
if self.value {
"true"
} else {
"false"
}
}
}

View file

@ -234,7 +234,11 @@ pub struct BooleanLiteral {
impl BooleanLiteral {
pub fn as_str(&self) -> &'static str {
if self.value { "true" } else { "false" }
if self.value {
"true"
} else {
"false"
}
}
}
@ -283,7 +287,11 @@ impl<'a> NumberLiteral<'a> {
let int32bit = pos_int % 2f64.powi(32);
// step5
if int32bit >= 2f64.powi(31) { (int32bit - 2f64.powi(32)) as i32 } else { int32bit as i32 }
if int32bit >= 2f64.powi(31) {
(int32bit - 2f64.powi(32)) as i32
} else {
int32bit as i32
}
}
}

View file

@ -350,8 +350,10 @@ pub fn get_bigint_value(expr: &Expression) -> Option<BigInt> {
}
}
Expression::UnaryExpression(unary_expr) => match unary_expr.operator {
UnaryOperator::LogicalNot => get_boolean_value(expr)
.map(|boolean| if boolean { BigInt::one() } else { BigInt::zero() }),
UnaryOperator::LogicalNot => {
get_boolean_value(expr)
.map(|boolean| if boolean { BigInt::one() } else { BigInt::zero() })
}
UnaryOperator::UnaryNegation => {
get_bigint_value(&unary_expr.argument).map(std::ops::Neg::neg)
}
@ -377,7 +379,11 @@ pub fn get_side_free_number_value(expr: &Expression) -> Option<NumberValue> {
// and there are only a very few cases where we can compute a number value, but there could
// also be side effects. e.g. `void doSomething()` has value NaN, regardless of the behavior
// of `doSomething()`
if value.is_some() && expr.may_have_side_effects() { None } else { value }
if value.is_some() && expr.may_have_side_effects() {
None
} else {
value
}
}
/// port from [closure compiler](https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/AbstractPeepholeOptimization.java#L121)
@ -387,7 +393,11 @@ pub fn get_side_free_bigint_value(expr: &Expression) -> Option<BigInt> {
// and there are only a very few cases where we can compute a bigint value, but there could
// also be side effects. e.g. `void doSomething()` has value NaN, regardless of the behavior
// of `doSomething()`
if value.is_some() && expr.may_have_side_effects() { None } else { value }
if value.is_some() && expr.may_have_side_effects() {
None
} else {
value
}
}
/// port from [closure compiler](https://github.com/google/closure-compiler/blob/a4c880032fba961f7a6c06ef99daa3641810bfdd/src/com/google/javascript/jscomp/NodeUtil.java#L109)
@ -538,7 +548,11 @@ fn get_string_value<'a>(expr: &'a Expression) -> Option<Cow<'a, str>> {
UnaryOperator::LogicalNot => {
get_boolean_value(&unary_expr.argument).map(|boolean| {
// need reversed.
if boolean { Cow::Borrowed("false") } else { Cow::Borrowed("true") }
if boolean {
Cow::Borrowed("false")
} else {
Cow::Borrowed("true")
}
})
}
_ => None,

View file

@ -112,7 +112,11 @@ impl<'a> GetPrecedence for AwaitExpression<'a> {
impl<'a> GetPrecedence for UpdateExpression<'a> {
fn precedence(&self) -> Precedence {
if self.prefix { Precedence::Prefix } else { Precedence::Postfix }
if self.prefix {
Precedence::Prefix
} else {
Precedence::Postfix
}
}
}
@ -124,7 +128,11 @@ impl<'a> GetPrecedence for CallExpression<'a> {
impl<'a> GetPrecedence for NewExpression<'a> {
fn precedence(&self) -> Precedence {
if self.arguments.is_empty() { Precedence::NewWithoutArgs } else { Precedence::Call }
if self.arguments.is_empty() {
Precedence::NewWithoutArgs
} else {
Precedence::Call
}
}
}

View file

@ -49,7 +49,11 @@ impl Tri {
}
pub fn for_boolean(boolean: bool) -> Self {
if boolean { Self::True } else { Self::False }
if boolean {
Self::True
} else {
Self::False
}
}
pub fn value(self) -> i8 {

View file

@ -29,7 +29,11 @@ impl Context {
#[inline]
fn and(self, flag: Self, set: bool) -> Self {
if set { self | flag } else { self - flag }
if set {
self | flag
} else {
self - flag
}
}
#[inline]
@ -39,6 +43,10 @@ impl Context {
#[inline]
fn union_if(self, other: Self, include: bool) -> Self {
if include { self.union(other) } else { self }
if include {
self.union(other)
} else {
self
}
}
}

View file

@ -826,7 +826,11 @@ impl<'a> Gen for NumberLiteral<'a> {
} else if (1_000_000_000_000..=0xFFFF_FFFF_FFFF_F800).contains(&value) {
let hex = format!("{value:#x}");
let result = print_non_negative_float(abs_value, p);
if hex.len() < result.len() { hex } else { result }
if hex.len() < result.len() {
hex
} else {
result
}
} else {
print_non_negative_float(abs_value, p)
}

View file

@ -786,7 +786,7 @@ fn ignore() {
// bugs
test("var a=/\\s?auto?\\s?/i\nvar b;a,b", "var b,a=/\\s?auto?\\s?/i;a,b"); // #14
// expect("false"string"", "(!1)"string""); // #181
// expect("false"string"", "(!1)"string""); // #181
test("x / /\\d+/.exec(s)[0]", "x/ /\\d+/.exec(s)[0]"); // #183
test("()=>{return{a}}", "()=>({a})"); // #333
test("()=>({a})", "()=>({a})"); // #333
@ -794,7 +794,7 @@ fn ignore() {
"function f(){if(a){return 1}else if(b){return 2}return 3}",
"function f(){return a?1:b?2:3}",
); // #335
// expect("new RegExp("\xAA\xB5")", "new RegExp("\xAA\xB5")"); // #341
// expect("new RegExp("\xAA\xB5")", "new RegExp("\xAA\xB5")"); // #341
test("for(var a;;)a();var b=5", "for(;;)a();var a,b=5"); // #346
test("if(e?0:n=1,o=2){o.a}", "(e?0:n=1,o=2)&&o.a"); // #347
test("const a=(a,b)=>({...a,b})", "const a=(a,b)=>({...a,b})"); // #369
@ -822,5 +822,5 @@ fn ignore() {
"export default function Foo(){a}Foo.prototype.bar=b",
); // #525
test("(e=1,e=2)", "e=1,e=2"); // #528
// expect(""\x00\x31 \0\u0000"", "\"\x001 \x00\x00\""); // #577
// expect(""\x00\x31 \0\u0000"", "\"\x001 \x00\x00\""); // #577
}

View file

@ -97,7 +97,11 @@ impl Context {
#[inline]
fn union_if(self, other: Self, include: bool) -> Self {
if include { self.union(other) } else { self }
if include {
self.union(other)
} else {
self
}
}
#[inline]
@ -127,7 +131,11 @@ impl Context {
#[inline]
fn and(self, flag: Self, set: bool) -> Self {
if set { self | flag } else { self - flag }
if set {
self | flag
} else {
self - flag
}
}
}

View file

@ -536,7 +536,11 @@ impl<'a> Lexer<'a> {
/// returns None for `SingleLineHTMLOpenComment` `<!--` in script mode
fn read_left_angle(&mut self) -> Option<Kind> {
if self.next_eq('<') {
if self.next_eq('=') { Some(Kind::ShiftLeftEq) } else { Some(Kind::ShiftLeft) }
if self.next_eq('=') {
Some(Kind::ShiftLeftEq)
} else {
Some(Kind::ShiftLeft)
}
} else if self.next_eq('=') {
Some(Kind::LtEq)
} else if self.peek() == '!'
@ -553,7 +557,11 @@ impl<'a> Lexer<'a> {
fn read_right_angle(&mut self) -> Kind {
if self.next_eq('>') {
if self.next_eq('>') {
if self.next_eq('=') { Kind::ShiftRight3Eq } else { Kind::ShiftRight3 }
if self.next_eq('=') {
Kind::ShiftRight3Eq
} else {
Kind::ShiftRight3
}
} else if self.next_eq('=') {
Kind::ShiftRightEq
} else {
@ -568,7 +576,11 @@ impl<'a> Lexer<'a> {
fn read_equal(&mut self) -> Kind {
if self.next_eq('=') {
if self.next_eq('=') { Kind::Eq3 } else { Kind::Eq2 }
if self.next_eq('=') {
Kind::Eq3
} else {
Kind::Eq2
}
} else if self.next_eq('>') {
Kind::Arrow
} else {
@ -578,7 +590,11 @@ impl<'a> Lexer<'a> {
fn read_exclamation(&mut self) -> Kind {
if self.next_eq('=') {
if self.next_eq('=') { Kind::Neq2 } else { Kind::Neq }
if self.next_eq('=') {
Kind::Neq2
} else {
Kind::Neq
}
} else {
Kind::Bang
}
@ -614,16 +630,28 @@ impl<'a> Lexer<'a> {
}
fn read_caret(&mut self) -> Kind {
if self.next_eq('=') { Kind::CaretEq } else { Kind::Caret }
if self.next_eq('=') {
Kind::CaretEq
} else {
Kind::Caret
}
}
fn read_percent(&mut self) -> Kind {
if self.next_eq('=') { Kind::PercentEq } else { Kind::Percent }
if self.next_eq('=') {
Kind::PercentEq
} else {
Kind::Percent
}
}
fn read_star(&mut self) -> Kind {
if self.next_eq('*') {
if self.next_eq('=') { Kind::Star2Eq } else { Kind::Star2 }
if self.next_eq('=') {
Kind::Star2Eq
} else {
Kind::Star2
}
} else if self.next_eq('=') {
Kind::StarEq
} else {
@ -633,7 +661,11 @@ impl<'a> Lexer<'a> {
fn read_ampersand(&mut self) -> Kind {
if self.next_eq('&') {
if self.next_eq('=') { Kind::Amp2Eq } else { Kind::Amp2 }
if self.next_eq('=') {
Kind::Amp2Eq
} else {
Kind::Amp2
}
} else if self.next_eq('=') {
Kind::AmpEq
} else {
@ -643,7 +675,11 @@ impl<'a> Lexer<'a> {
fn read_pipe(&mut self) -> Kind {
if self.next_eq('|') {
if self.next_eq('=') { Kind::Pipe2Eq } else { Kind::Pipe2 }
if self.next_eq('=') {
Kind::Pipe2Eq
} else {
Kind::Pipe2
}
} else if self.next_eq('=') {
Kind::PipeEq
} else {
@ -653,7 +689,11 @@ impl<'a> Lexer<'a> {
fn read_question(&mut self) -> Kind {
if self.next_eq('?') {
if self.next_eq('=') { Kind::Question2Eq } else { Kind::Question2 }
if self.next_eq('=') {
Kind::Question2Eq
} else {
Kind::Question2
}
} else if self.peek() == '.' {
// parse `?.1` as `?` `.1`
if self.peek2().is_ascii_digit() {
@ -668,7 +708,11 @@ impl<'a> Lexer<'a> {
}
fn read_slash(&mut self) -> Kind {
if self.next_eq('=') { Kind::SlashEq } else { Kind::Slash }
if self.next_eq('=') {
Kind::SlashEq
} else {
Kind::Slash
}
}
fn private_identifier(&mut self, mut builder: AutoCow<'a>) -> Kind {

View file

@ -1673,7 +1673,11 @@ mod object_literal {
.map_or(false, |key_from_iter| key_from_iter == key.as_str()),
};
if has_right_key_name { Some(Vertex::from(&prop.value)) } else { None }
if has_right_key_name {
Some(Vertex::from(&prop.value))
} else {
None
}
}))
})
}

View file

@ -235,7 +235,11 @@ pub struct ClassVertex<'a> {
impl<'a> Typename for ClassVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "ClassAST" } else { "Class" }
if self.ast_node.is_some() {
"ClassAST"
} else {
"Class"
}
}
}
@ -262,7 +266,11 @@ pub struct ImportVertex<'a> {
impl<'a> Typename for ImportVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "ImportAST" } else { "Import" }
if self.ast_node.is_some() {
"ImportAST"
} else {
"Import"
}
}
}
@ -275,7 +283,11 @@ pub struct InterfaceVertex<'a> {
impl<'a> Typename for InterfaceVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "InterfaceAST" } else { "Interface" }
if self.ast_node.is_some() {
"InterfaceAST"
} else {
"Interface"
}
}
}
@ -309,7 +321,11 @@ pub struct JSXElementVertex<'a> {
impl<'a> Typename for JSXElementVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "JSXElementAST" } else { "JSXElement" }
if self.ast_node.is_some() {
"JSXElementAST"
} else {
"JSXElement"
}
}
}
@ -329,7 +345,11 @@ pub struct TypeAnnotationVertex<'a> {
impl<'a> Typename for TypeAnnotationVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "TypeAnnotationAST" } else { "TypeAnnotation" }
if self.ast_node.is_some() {
"TypeAnnotationAST"
} else {
"TypeAnnotation"
}
}
}
@ -349,6 +369,10 @@ pub struct VariableDeclarationVertex<'a> {
impl<'a> Typename for VariableDeclarationVertex<'a> {
fn typename(&self) -> &'static str {
if self.ast_node.is_some() { "VariableDeclarationAST" } else { "VariableDeclaration" }
if self.ast_node.is_some() {
"VariableDeclarationAST"
} else {
"VariableDeclaration"
}
}
}

View file

@ -211,7 +211,11 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
}
fn load_symlink(&self, cache_value: &CacheValue) -> Option<PathBuf> {
if self.options.symlinks { cache_value.symlink(&self.cache.fs) } else { None }
if self.options.symlinks {
cache_value.symlink(&self.cache.fs)
} else {
None
}
}
fn load_index(&self, cache_value: &CacheValue) -> ResolveState {

View file

@ -27,7 +27,11 @@ bitflags! {
impl ScopeFlags {
#[must_use]
pub fn with_strict_mode(self, yes: bool) -> Self {
if yes { self | Self::StrictMode } else { self }
if yes {
self | Self::StrictMode
} else {
self
}
}
pub fn is_strict_mode(&self) -> bool {