From b34ef4f07a2a9c36f789f6098767ef81cebd4069 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 27 Jul 2023 12:35:01 +0800 Subject: [PATCH] chore: reformat --- crates/oxc_ast/src/ast/literal.rs | 6 +- crates/oxc_hir/src/hir.rs | 12 +++- crates/oxc_hir/src/hir_util.rs | 24 ++++++-- crates/oxc_hir/src/precedence.rs | 12 +++- crates/oxc_minifier/src/compressor/fold.rs | 6 +- crates/oxc_minifier/src/printer/context.rs | 12 +++- crates/oxc_minifier/src/printer/gen.rs | 6 +- crates/oxc_minifier/tests/tdewolff/mod.rs | 6 +- crates/oxc_parser/src/context.rs | 12 +++- crates/oxc_parser/src/lexer/mod.rs | 66 ++++++++++++++++++---- crates/oxc_query/src/edges.rs | 6 +- crates/oxc_query/src/vertex.rs | 36 ++++++++++-- crates/oxc_resolver/src/lib.rs | 6 +- crates/oxc_syntax/src/scope.rs | 6 +- 14 files changed, 177 insertions(+), 39 deletions(-) diff --git a/crates/oxc_ast/src/ast/literal.rs b/crates/oxc_ast/src/ast/literal.rs index 805048127..7fe8ab75c 100644 --- a/crates/oxc_ast/src/ast/literal.rs +++ b/crates/oxc_ast/src/ast/literal.rs @@ -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" + } } } diff --git a/crates/oxc_hir/src/hir.rs b/crates/oxc_hir/src/hir.rs index d23edc656..e76dd2e8b 100644 --- a/crates/oxc_hir/src/hir.rs +++ b/crates/oxc_hir/src/hir.rs @@ -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 + } } } diff --git a/crates/oxc_hir/src/hir_util.rs b/crates/oxc_hir/src/hir_util.rs index ee18d2977..97c584b6e 100644 --- a/crates/oxc_hir/src/hir_util.rs +++ b/crates/oxc_hir/src/hir_util.rs @@ -350,8 +350,10 @@ pub fn get_bigint_value(expr: &Expression) -> Option { } } 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 { // 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 { // 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> { 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, diff --git a/crates/oxc_hir/src/precedence.rs b/crates/oxc_hir/src/precedence.rs index 6af108f47..58a4c219d 100644 --- a/crates/oxc_hir/src/precedence.rs +++ b/crates/oxc_hir/src/precedence.rs @@ -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 + } } } diff --git a/crates/oxc_minifier/src/compressor/fold.rs b/crates/oxc_minifier/src/compressor/fold.rs index 6c40648c9..a8d387d02 100644 --- a/crates/oxc_minifier/src/compressor/fold.rs +++ b/crates/oxc_minifier/src/compressor/fold.rs @@ -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 { diff --git a/crates/oxc_minifier/src/printer/context.rs b/crates/oxc_minifier/src/printer/context.rs index 5aee6db48..feb187504 100644 --- a/crates/oxc_minifier/src/printer/context.rs +++ b/crates/oxc_minifier/src/printer/context.rs @@ -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 + } } } diff --git a/crates/oxc_minifier/src/printer/gen.rs b/crates/oxc_minifier/src/printer/gen.rs index c265ee90c..e02b9568a 100644 --- a/crates/oxc_minifier/src/printer/gen.rs +++ b/crates/oxc_minifier/src/printer/gen.rs @@ -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) } diff --git a/crates/oxc_minifier/tests/tdewolff/mod.rs b/crates/oxc_minifier/tests/tdewolff/mod.rs index db9a84cd7..0e2a04e91 100644 --- a/crates/oxc_minifier/tests/tdewolff/mod.rs +++ b/crates/oxc_minifier/tests/tdewolff/mod.rs @@ -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 } diff --git a/crates/oxc_parser/src/context.rs b/crates/oxc_parser/src/context.rs index ef8fbae6a..4a8649895 100644 --- a/crates/oxc_parser/src/context.rs +++ b/crates/oxc_parser/src/context.rs @@ -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 + } } } diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index 17289f27d..e36adaa85 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -536,7 +536,11 @@ impl<'a> Lexer<'a> { /// returns None for `SingleLineHTMLOpenComment` `