Skip to content

Commit

Permalink
refactor(es/lint): Remove usage of box_patterns (#7966)
Browse files Browse the repository at this point in the history
**Related issue:**
 
 - Closes #7964
  • Loading branch information
magic-akari authored Sep 18, 2023
1 parent 1079daa commit f7b5e16
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
1 change: 0 additions & 1 deletion crates/swc_ecma_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg_attr(feature = "non_critical_lints", deny(unused))]
#![cfg_attr(feature = "non_critical_lints", deny(clippy::all))]
#![feature(box_patterns)]

pub mod config;
pub mod rule;
Expand Down
68 changes: 35 additions & 33 deletions crates/swc_ecma_lints/src/rules/no_alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,48 @@ impl NoAlert {
}
}

fn handle_member_expr(&mut self, member_expr: &MemberExpr) {
let MemberExpr { obj, prop, .. } = member_expr;

match obj.as_ref() {
Expr::Ident(obj) => {
if !self.is_satisfying_indent(obj) {
return;
}

self.obj = Some(obj.sym.clone());

self.handle_member_prop(prop);
}
Expr::This(_) => {
let inside_arrow_fn = self.is_inside_arrow_fn();
let inside_class = self.is_inside_class();

if inside_arrow_fn && inside_class {
return;
}

if !inside_arrow_fn && (inside_class || self.is_inside_object()) {
return;
}

self.handle_member_prop(prop);
}
_ => {}
}
}

fn handle_callee(&mut self, expr: &Expr) {
match expr {
Expr::Ident(ident) => {
if self.is_satisfying_indent(ident) {
self.prop = Some(ident.sym.clone());
}
}
Expr::Member(member_expr)
| Expr::OptChain(OptChainExpr {
base: box OptChainBase::Member(member_expr),
..
}) => {
let MemberExpr { obj, prop, .. } = member_expr;

match obj.as_ref() {
Expr::Ident(obj) => {
if !self.is_satisfying_indent(obj) {
return;
}

self.obj = Some(obj.sym.clone());

self.handle_member_prop(prop);
}
Expr::This(_) => {
let inside_arrow_fn = self.is_inside_arrow_fn();
let inside_class = self.is_inside_class();

if inside_arrow_fn && inside_class {
return;
}

if !inside_arrow_fn && (inside_class || self.is_inside_object()) {
return;
}

self.handle_member_prop(prop);
}
_ => {}
}
Expr::Member(member_expr) => self.handle_member_expr(member_expr),
Expr::OptChain(OptChainExpr { base, .. }) if base.is_member() => {
let member_expr = base.as_member().unwrap();
self.handle_member_expr(member_expr);
}
Expr::OptChain(opt_chain) => {
opt_chain.visit_children_with(self);
Expand Down
9 changes: 4 additions & 5 deletions crates/swc_ecma_lints/src/rules/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,10 @@ impl Radix {
Expr::Member(member_expr) => {
return self.extract_obj_and_prop_member_case(member_expr);
}
Expr::OptChain(OptChainExpr {
base: box OptChainBase::Member(member_expr),
..
}) => {
return self.extract_obj_and_prop_member_case(member_expr);
Expr::OptChain(OptChainExpr { base, .. }) => {
if let OptChainBase::Member(member_expr) = &**base {
return self.extract_obj_and_prop_member_case(member_expr);
}
}
Expr::Paren(ParenExpr { expr, .. }) => {
return self.extract_obj_and_prop(expr.as_ref());
Expand Down

1 comment on commit f7b5e16

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f7b5e16 Previous: 0759779 Ratio
es/full/bugs-1 284743 ns/iter (± 7868) 284288 ns/iter (± 4333) 1.00
es/full/minify/libraries/antd 1313235591 ns/iter (± 15345601) 1339990923 ns/iter (± 29802002) 0.98
es/full/minify/libraries/d3 276298446 ns/iter (± 7585789) 277767508 ns/iter (± 7013031) 0.99
es/full/minify/libraries/echarts 1061833949 ns/iter (± 10642084) 1063175059 ns/iter (± 6487519) 1.00
es/full/minify/libraries/jquery 84105130 ns/iter (± 465966) 85244523 ns/iter (± 303383) 0.99
es/full/minify/libraries/lodash 97085100 ns/iter (± 388218) 97759696 ns/iter (± 343111) 0.99
es/full/minify/libraries/moment 49667450 ns/iter (± 124838) 50156287 ns/iter (± 353677) 0.99
es/full/minify/libraries/react 17955915 ns/iter (± 47207) 18146674 ns/iter (± 91084) 0.99
es/full/minify/libraries/terser 217459782 ns/iter (± 1156951) 218243657 ns/iter (± 798963) 1.00
es/full/minify/libraries/three 385390790 ns/iter (± 1916992) 384779742 ns/iter (± 1873928) 1.00
es/full/minify/libraries/typescript 2650716874 ns/iter (± 10964539) 2632700624 ns/iter (± 11201493) 1.01
es/full/minify/libraries/victory 572730867 ns/iter (± 7389882) 570264678 ns/iter (± 6561647) 1.00
es/full/minify/libraries/vue 119277268 ns/iter (± 568642) 120548306 ns/iter (± 339272) 0.99
es/full/codegen/es3 34080 ns/iter (± 104) 34017 ns/iter (± 100) 1.00
es/full/codegen/es5 34092 ns/iter (± 87) 34084 ns/iter (± 450) 1.00
es/full/codegen/es2015 34080 ns/iter (± 64) 33881 ns/iter (± 870) 1.01
es/full/codegen/es2016 34014 ns/iter (± 53) 33895 ns/iter (± 160) 1.00
es/full/codegen/es2017 34085 ns/iter (± 61) 33943 ns/iter (± 88) 1.00
es/full/codegen/es2018 34078 ns/iter (± 64) 33982 ns/iter (± 143) 1.00
es/full/codegen/es2019 34146 ns/iter (± 89) 33916 ns/iter (± 83) 1.01
es/full/codegen/es2020 34096 ns/iter (± 96) 34023 ns/iter (± 170) 1.00
es/full/all/es3 167257045 ns/iter (± 1355179) 167426210 ns/iter (± 1268935) 1.00
es/full/all/es5 159442846 ns/iter (± 710608) 159507694 ns/iter (± 722208) 1.00
es/full/all/es2015 119648299 ns/iter (± 715897) 120558959 ns/iter (± 884583) 0.99
es/full/all/es2016 119104202 ns/iter (± 791731) 119422964 ns/iter (± 576822) 1.00
es/full/all/es2017 118385550 ns/iter (± 798100) 119406252 ns/iter (± 907664) 0.99
es/full/all/es2018 115925522 ns/iter (± 944352) 117510833 ns/iter (± 641603) 0.99
es/full/all/es2019 115835074 ns/iter (± 1071377) 116468668 ns/iter (± 644604) 0.99
es/full/all/es2020 111123700 ns/iter (± 985741) 113262982 ns/iter (± 818260) 0.98
es/full/parser 493227 ns/iter (± 4955) 487203 ns/iter (± 5011) 1.01
es/full/base/fixer 17578 ns/iter (± 92) 18057 ns/iter (± 128) 0.97
es/full/base/resolver_and_hygiene 81435 ns/iter (± 166) 79667 ns/iter (± 213) 1.02
serialization of serde 300 ns/iter (± 0) 292 ns/iter (± 0) 1.03
css/minify/libraries/bootstrap 28831828 ns/iter (± 86769) 28774419 ns/iter (± 47848) 1.00
css/visitor/compare/clone 1703525 ns/iter (± 7514) 1650922 ns/iter (± 2289) 1.03
css/visitor/compare/visit_mut_span 1789249 ns/iter (± 4497) 1777042 ns/iter (± 2349) 1.01
css/visitor/compare/visit_mut_span_panic 1892564 ns/iter (± 4742) 1840262 ns/iter (± 2621) 1.03
css/visitor/compare/fold_span 2596404 ns/iter (± 13685) 2578886 ns/iter (± 10798) 1.01
css/visitor/compare/fold_span_panic 2784111 ns/iter (± 7634) 2756228 ns/iter (± 15845) 1.01
css/lexer/bootstrap_5_1_3 4467949 ns/iter (± 9364) 4424578 ns/iter (± 3069) 1.01
css/lexer/foundation_6_7_4 3758477 ns/iter (± 4106) 3727482 ns/iter (± 2239) 1.01
css/lexer/tailwind_3_1_1 714930 ns/iter (± 657) 709367 ns/iter (± 405) 1.01
css/parser/bootstrap_5_1_3 19157947 ns/iter (± 50638) 19362948 ns/iter (± 22529) 0.99
css/parser/foundation_6_7_4 15366125 ns/iter (± 20530) 15315620 ns/iter (± 957788) 1.00
css/parser/tailwind_3_1_1 2946291 ns/iter (± 2055) 3013019 ns/iter (± 4132) 0.98
es/codegen/colors 727970 ns/iter (± 397243) 728220 ns/iter (± 397135) 1.00
es/codegen/large 3123801 ns/iter (± 1651723) 2887875 ns/iter (± 1524407) 1.08
es/codegen/with-parser/colors 44654 ns/iter (± 483) 45072 ns/iter (± 584) 0.99
es/codegen/with-parser/large 490026 ns/iter (± 606) 488595 ns/iter (± 966) 1.00
es/minify/libraries/antd 1150763630 ns/iter (± 11426710) 1128106730 ns/iter (± 7995833) 1.02
es/minify/libraries/d3 240021202 ns/iter (± 883551) 239565251 ns/iter (± 1714996) 1.00
es/minify/libraries/echarts 910842258 ns/iter (± 8736735) 894182503 ns/iter (± 6125861) 1.02
es/minify/libraries/jquery 73236250 ns/iter (± 143091) 73737946 ns/iter (± 219780) 0.99
es/minify/libraries/lodash 87033183 ns/iter (± 184563) 87452260 ns/iter (± 336768) 1.00
es/minify/libraries/moment 43232130 ns/iter (± 54915) 43527107 ns/iter (± 53101) 0.99
es/minify/libraries/react 15967695 ns/iter (± 60598) 16126644 ns/iter (± 354895) 0.99
es/minify/libraries/terser 184900593 ns/iter (± 700055) 186577612 ns/iter (± 606353) 0.99
es/minify/libraries/three 321652536 ns/iter (± 3481787) 320492858 ns/iter (± 1294011) 1.00
es/minify/libraries/typescript 2206397526 ns/iter (± 12141534) 2213979380 ns/iter (± 8309090) 1.00
es/minify/libraries/victory 468861923 ns/iter (± 3019218) 466938822 ns/iter (± 2031587) 1.00
es/minify/libraries/vue 106012319 ns/iter (± 337809) 106363143 ns/iter (± 164776) 1.00
es/visitor/compare/clone 1948337 ns/iter (± 2933) 1948741 ns/iter (± 96169) 1.00
es/visitor/compare/visit_mut_span 2291581 ns/iter (± 3471) 2297335 ns/iter (± 2139) 1.00
es/visitor/compare/visit_mut_span_panic 2323406 ns/iter (± 3228) 2337293 ns/iter (± 6892) 0.99
es/visitor/compare/fold_span 3381186 ns/iter (± 6459) 3378172 ns/iter (± 7547) 1.00
es/visitor/compare/fold_span_panic 3489932 ns/iter (± 6005) 3516657 ns/iter (± 8311) 0.99
es/lexer/colors 13199 ns/iter (± 9) 12905 ns/iter (± 37) 1.02
es/lexer/angular 6131710 ns/iter (± 3423) 5987730 ns/iter (± 5438) 1.02
es/lexer/backbone 801440 ns/iter (± 4019) 771646 ns/iter (± 654) 1.04
es/lexer/jquery 4541784 ns/iter (± 2919) 4408600 ns/iter (± 5422) 1.03
es/lexer/jquery mobile 6954808 ns/iter (± 18010) 6773187 ns/iter (± 10142) 1.03
es/lexer/mootools 3596741 ns/iter (± 10464) 3518276 ns/iter (± 2863) 1.02
es/lexer/underscore 672096 ns/iter (± 1110) 648645 ns/iter (± 1171) 1.04
es/lexer/three 21651715 ns/iter (± 75150) 20986825 ns/iter (± 33408) 1.03
es/lexer/yui 3881428 ns/iter (± 2392) 3767300 ns/iter (± 7712) 1.03
es/parser/colors 27856 ns/iter (± 46) 27217 ns/iter (± 164) 1.02
es/parser/angular 13599652 ns/iter (± 50307) 13487693 ns/iter (± 55096) 1.01
es/parser/backbone 2000218 ns/iter (± 7129) 1989711 ns/iter (± 20106) 1.01
es/parser/jquery 10926354 ns/iter (± 31659) 10850720 ns/iter (± 61004) 1.01
es/parser/jquery mobile 16654593 ns/iter (± 55219) 16552003 ns/iter (± 57123) 1.01
es/parser/mootools 8405927 ns/iter (± 32009) 8341680 ns/iter (± 22142) 1.01
es/parser/underscore 1714534 ns/iter (± 9623) 1709840 ns/iter (± 10967) 1.00
es/parser/three 47047077 ns/iter (± 206357) 48971040 ns/iter (± 395738) 0.96
es/parser/yui 8361038 ns/iter (± 29311) 8362840 ns/iter (± 31723) 1.00
es/preset-env/usage/builtin_type 138068 ns/iter (± 32832) 138151 ns/iter (± 33373) 1.00
es/preset-env/usage/property 16746 ns/iter (± 80) 17087 ns/iter (± 38) 0.98
es/resolver/typescript 90856322 ns/iter (± 1494330) 91486948 ns/iter (± 2667177) 0.99
es/fixer/typescript 64366384 ns/iter (± 480036) 63743385 ns/iter (± 662702) 1.01
es/hygiene/typescript 134282950 ns/iter (± 956600) 131281388 ns/iter (± 862446) 1.02
es/resolver_with_hygiene/typescript 245294317 ns/iter (± 1300411) 241714333 ns/iter (± 691799) 1.01
es/visitor/base-perf/module_clone 58215 ns/iter (± 311) 58888 ns/iter (± 241) 0.99
es/visitor/base-perf/fold_empty 62795 ns/iter (± 216) 62954 ns/iter (± 350) 1.00
es/visitor/base-perf/fold_noop_impl_all 62865 ns/iter (± 122) 63134 ns/iter (± 284) 1.00
es/visitor/base-perf/fold_noop_impl_vec 63075 ns/iter (± 812) 63836 ns/iter (± 293) 0.99
es/visitor/base-perf/boxing_boxed_clone 57 ns/iter (± 0) 57 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 39 ns/iter (± 0) 47 ns/iter (± 0) 0.83
es/visitor/base-perf/boxing_boxed 108 ns/iter (± 0) 108 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed 78 ns/iter (± 0) 82 ns/iter (± 0) 0.95
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2544 ns/iter (± 11) 2507 ns/iter (± 9) 1.01
es/base/parallel/resolver/typescript 4250136100 ns/iter (± 240919946) 4532750892 ns/iter (± 302430037) 0.94
es/base/parallel/hygiene/typescript 1475465122 ns/iter (± 21050100) 1451490803 ns/iter (± 22062989) 1.02
misc/visitors/time-complexity/time 5 152 ns/iter (± 3) 150 ns/iter (± 0) 1.01
misc/visitors/time-complexity/time 10 454 ns/iter (± 15) 452 ns/iter (± 0) 1.00
misc/visitors/time-complexity/time 15 790 ns/iter (± 3) 787 ns/iter (± 6) 1.00
misc/visitors/time-complexity/time 20 1309 ns/iter (± 2) 1280 ns/iter (± 0) 1.02
misc/visitors/time-complexity/time 40 4380 ns/iter (± 4) 4348 ns/iter (± 7) 1.01
misc/visitors/time-complexity/time 60 9049 ns/iter (± 8) 9002 ns/iter (± 5) 1.01
es/full-target/es2016 229636 ns/iter (± 1024) 230035 ns/iter (± 822) 1.00
es/full-target/es2017 218289 ns/iter (± 959) 218277 ns/iter (± 772) 1.00
es/full-target/es2018 206824 ns/iter (± 931) 206665 ns/iter (± 478) 1.00
es2020_nullish_coalescing 69862 ns/iter (± 342) 69318 ns/iter (± 215) 1.01
es2020_optional_chaining 75957 ns/iter (± 191) 75164 ns/iter (± 191) 1.01
es2022_class_properties 115318 ns/iter (± 580) 115364 ns/iter (± 426) 1.00
es2018_object_rest_spread 74168 ns/iter (± 200) 72827 ns/iter (± 220) 1.02
es2019_optional_catch_binding 64433 ns/iter (± 266) 63539 ns/iter (± 255) 1.01
es2017_async_to_generator 63576 ns/iter (± 140) 62711 ns/iter (± 130) 1.01
es2016_exponentiation 67269 ns/iter (± 231) 67158 ns/iter (± 214) 1.00
es2015_arrow 70856 ns/iter (± 171) 69762 ns/iter (± 171) 1.02
es2015_block_scoped_fn 67913 ns/iter (± 213) 67254 ns/iter (± 648) 1.01
es2015_block_scoping 119210 ns/iter (± 607) 119977 ns/iter (± 494) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.