-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/minifier): Improve simplification of
?.
(#6681)
**Related issue:** - Closes #6492.
- Loading branch information
Showing
10 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6492/1/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const obj = { key: 42 }; | ||
const val = obj?.[null || 'key'] | ||
console.log('val', val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('val', 42); |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6492/2/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const obj = { key: 42 }; | ||
const val = obj?.key.toString() | ||
console.log('val', val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('val', "42"); |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6492/3/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const obj = { key: 42 }; | ||
const val = obj?.key?.toString() | ||
console.log('val', val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('val', "42"); |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6492/4/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const obj = { key: 42 }; | ||
const val = obj.key?.toString() | ||
console.log('val', val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('val', "42"); |
707b1e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
327593
ns/iter (± 13761
)302843
ns/iter (± 7280
)1.08
es/full/minify/libraries/antd
1879294433
ns/iter (± 51329987
)1723045291
ns/iter (± 32460545
)1.09
es/full/minify/libraries/d3
354004712
ns/iter (± 8680110
)303614755
ns/iter (± 6708953
)1.17
es/full/minify/libraries/echarts
1371677431
ns/iter (± 18722436
)1298334353
ns/iter (± 14723118
)1.06
es/full/minify/libraries/jquery
94270302
ns/iter (± 1719817
)90753124
ns/iter (± 696389
)1.04
es/full/minify/libraries/lodash
120093094
ns/iter (± 2576260
)107638842
ns/iter (± 813301
)1.12
es/full/minify/libraries/moment
57456271
ns/iter (± 1632443
)52715897
ns/iter (± 402240
)1.09
es/full/minify/libraries/react
20439897
ns/iter (± 415736
)18987035
ns/iter (± 118708
)1.08
es/full/minify/libraries/terser
285812165
ns/iter (± 8738547
)250501635
ns/iter (± 2738023
)1.14
es/full/minify/libraries/three
505176029
ns/iter (± 11080438
)459294786
ns/iter (± 4153631
)1.10
es/full/minify/libraries/typescript
3423658772
ns/iter (± 80162755
)3235582608
ns/iter (± 12152018
)1.06
es/full/minify/libraries/victory
750660856
ns/iter (± 12993719
)710275725
ns/iter (± 9450002
)1.06
es/full/minify/libraries/vue
139112670
ns/iter (± 3374664
)132852980
ns/iter (± 1078689
)1.05
es/full/codegen/es3
27082
ns/iter (± 58
)27611
ns/iter (± 163
)0.98
es/full/codegen/es5
27092
ns/iter (± 63
)27639
ns/iter (± 48
)0.98
es/full/codegen/es2015
27084
ns/iter (± 51
)27574
ns/iter (± 49
)0.98
es/full/codegen/es2016
27112
ns/iter (± 55
)27602
ns/iter (± 66
)0.98
es/full/codegen/es2017
27081
ns/iter (± 42
)27587
ns/iter (± 50
)0.98
es/full/codegen/es2018
27072
ns/iter (± 40
)27599
ns/iter (± 79
)0.98
es/full/codegen/es2019
27066
ns/iter (± 29
)27608
ns/iter (± 45
)0.98
es/full/codegen/es2020
27073
ns/iter (± 43
)27581
ns/iter (± 67
)0.98
es/full/all/es3
177445796
ns/iter (± 2302123
)163312359
ns/iter (± 3534433
)1.09
es/full/all/es5
166540572
ns/iter (± 3790227
)153121241
ns/iter (± 3391626
)1.09
es/full/all/es2015
125806018
ns/iter (± 2295495
)118042262
ns/iter (± 764743
)1.07
es/full/all/es2016
124384914
ns/iter (± 3467874
)117444032
ns/iter (± 524722
)1.06
es/full/all/es2017
124190475
ns/iter (± 1676517
)115980575
ns/iter (± 946575
)1.07
es/full/all/es2018
120896068
ns/iter (± 1095551
)114714175
ns/iter (± 586900
)1.05
es/full/all/es2019
119973463
ns/iter (± 1736349
)113764583
ns/iter (± 722106
)1.05
es/full/all/es2020
115827498
ns/iter (± 2119988
)109649188
ns/iter (± 1162521
)1.06
es/full/parser
516731
ns/iter (± 9867
)502537
ns/iter (± 7229
)1.03
es/full/base/fixer
21841
ns/iter (± 19
)22066
ns/iter (± 35
)0.99
es/full/base/resolver_and_hygiene
78271
ns/iter (± 75
)77715
ns/iter (± 74
)1.01
serialization of ast node
118
ns/iter (± 0
)119
ns/iter (± 0
)0.99
serialization of serde
124
ns/iter (± 0
)124
ns/iter (± 0
)1
css/minify/libraries/bootstrap
27955915
ns/iter (± 111092
)26827893
ns/iter (± 133781
)1.04
css/visitor/compare/clone
2079889
ns/iter (± 26384
)2085610
ns/iter (± 13202
)1.00
css/visitor/compare/visit_mut_span
2259923
ns/iter (± 10822
)2249047
ns/iter (± 4686
)1.00
css/visitor/compare/visit_mut_span_panic
2304790
ns/iter (± 10239
)2303935
ns/iter (± 7806
)1.00
css/visitor/compare/fold_span
2981514
ns/iter (± 25067
)2998789
ns/iter (± 27094
)0.99
css/visitor/compare/fold_span_panic
3182184
ns/iter (± 49523
)3118083
ns/iter (± 18227
)1.02
css/lexer/bootstrap_5_1_3
5180364
ns/iter (± 1932
)5178678
ns/iter (± 1434
)1.00
css/lexer/foundation_6_7_4
4379508
ns/iter (± 3770
)4355084
ns/iter (± 2516
)1.01
css/lexer/tailwind_3_1_1
831175
ns/iter (± 1189
)827409
ns/iter (± 1509
)1.00
css/parser/bootstrap_5_1_3
21173923
ns/iter (± 218096
)20783355
ns/iter (± 69493
)1.02
css/parser/foundation_6_7_4
17112235
ns/iter (± 264111
)16534879
ns/iter (± 30123
)1.03
css/parser/tailwind_3_1_1
3206854
ns/iter (± 4310
)3202702
ns/iter (± 4041
)1.00
es/codegen/colors
324365
ns/iter (± 181723
)333159
ns/iter (± 187221
)0.97
es/codegen/large
1242664
ns/iter (± 638837
)1077868
ns/iter (± 549422
)1.15
es/codegen/with-parser/colors
46430
ns/iter (± 367
)46075
ns/iter (± 262
)1.01
es/codegen/with-parser/large
519298
ns/iter (± 3195
)515727
ns/iter (± 1794
)1.01
es/minify/libraries/antd
1629597814
ns/iter (± 23705722
)1505844239
ns/iter (± 26897697
)1.08
es/minify/libraries/d3
288255513
ns/iter (± 8470546
)256456162
ns/iter (± 3365684
)1.12
es/minify/libraries/echarts
1209729709
ns/iter (± 24211699
)1127607755
ns/iter (± 9941444
)1.07
es/minify/libraries/jquery
85080296
ns/iter (± 2917469
)78529747
ns/iter (± 404657
)1.08
es/minify/libraries/lodash
103126331
ns/iter (± 1051170
)94826988
ns/iter (± 884518
)1.09
es/minify/libraries/moment
50028949
ns/iter (± 1438005
)46189842
ns/iter (± 259937
)1.08
es/minify/libraries/react
17970081
ns/iter (± 198475
)16740508
ns/iter (± 74006
)1.07
es/minify/libraries/terser
230752394
ns/iter (± 4062459
)214891458
ns/iter (± 1272267
)1.07
es/minify/libraries/three
456250840
ns/iter (± 23807965
)384676410
ns/iter (± 8159281
)1.19
es/minify/libraries/typescript
2916366036
ns/iter (± 27574480
)2733600962
ns/iter (± 24131813
)1.07
es/minify/libraries/victory
684008932
ns/iter (± 15974650
)589260404
ns/iter (± 8779888
)1.16
es/minify/libraries/vue
130354583
ns/iter (± 6926008
)116776681
ns/iter (± 749375
)1.12
es/visitor/compare/clone
2513363
ns/iter (± 18659
)2419140
ns/iter (± 5224
)1.04
es/visitor/compare/visit_mut_span
2956312
ns/iter (± 30946
)2812898
ns/iter (± 3429
)1.05
es/visitor/compare/visit_mut_span_panic
2914279
ns/iter (± 21175
)2865075
ns/iter (± 3694
)1.02
es/visitor/compare/fold_span
4004219
ns/iter (± 17811
)3968315
ns/iter (± 12193
)1.01
es/visitor/compare/fold_span_panic
4259262
ns/iter (± 85704
)4121378
ns/iter (± 7850
)1.03
es/lexer/colors
17410
ns/iter (± 17
)17328
ns/iter (± 32
)1.00
es/lexer/angular
8208407
ns/iter (± 2552
)8213544
ns/iter (± 2665
)1.00
es/lexer/backbone
1069149
ns/iter (± 366
)1070329
ns/iter (± 685
)1.00
es/lexer/jquery
5935524
ns/iter (± 3692
)5933284
ns/iter (± 4526
)1.00
es/lexer/jquery mobile
9151722
ns/iter (± 5670
)9114890
ns/iter (± 8279
)1.00
es/lexer/mootools
4648318
ns/iter (± 937
)4643199
ns/iter (± 2635
)1.00
es/lexer/underscore
892468
ns/iter (± 359
)893419
ns/iter (± 1755
)1.00
es/lexer/three
27830988
ns/iter (± 6071
)27607135
ns/iter (± 12496
)1.01
es/lexer/yui
5029570
ns/iter (± 1563
)5045214
ns/iter (± 3447
)1.00
es/parser/colors
30896
ns/iter (± 159
)30770
ns/iter (± 260
)1.00
es/parser/angular
16893011
ns/iter (± 244243
)15577497
ns/iter (± 100432
)1.08
es/parser/backbone
2333752
ns/iter (± 11838
)2306206
ns/iter (± 9443
)1.01
es/parser/jquery
13433849
ns/iter (± 207178
)12505208
ns/iter (± 58819
)1.07
es/parser/jquery mobile
21857379
ns/iter (± 438182
)19867086
ns/iter (± 267847
)1.10
es/parser/mootools
9641910
ns/iter (± 31411
)9589804
ns/iter (± 26451
)1.01
es/parser/underscore
1962758
ns/iter (± 11500
)1959248
ns/iter (± 11956
)1.00
es/parser/three
62004811
ns/iter (± 621284
)58831527
ns/iter (± 838893
)1.05
es/parser/yui
9992090
ns/iter (± 52980
)9607207
ns/iter (± 50324
)1.04
es/preset-env/usage/builtin_type
142604
ns/iter (± 32846
)143908
ns/iter (± 33737
)0.99
es/preset-env/usage/property
21732
ns/iter (± 104
)21680
ns/iter (± 70
)1.00
es/resolver/typescript
121163818
ns/iter (± 4107788
)116727632
ns/iter (± 2629148
)1.04
es/fixer/typescript
100009174
ns/iter (± 1070574
)95921067
ns/iter (± 1149141
)1.04
es/hygiene/typescript
199526123
ns/iter (± 4337813
)187543572
ns/iter (± 1207473
)1.06
es/resolver_with_hygiene/typescript
332458258
ns/iter (± 2494168
)320022745
ns/iter (± 1935664
)1.04
es/visitor/base-perf/module_clone
75856
ns/iter (± 1321
)76116
ns/iter (± 1021
)1.00
es/visitor/base-perf/fold_empty
85789
ns/iter (± 888
)85562
ns/iter (± 1559
)1.00
es/visitor/base-perf/fold_noop_impl_all
85912
ns/iter (± 1335
)85879
ns/iter (± 979
)1.00
es/visitor/base-perf/fold_noop_impl_vec
86185
ns/iter (± 1887
)86588
ns/iter (± 2240
)1.00
es/visitor/base-perf/boxing_boxed_clone
56
ns/iter (± 0
)56
ns/iter (± 0
)1
es/visitor/base-perf/boxing_unboxed_clone
59
ns/iter (± 0
)60
ns/iter (± 0
)0.98
es/visitor/base-perf/boxing_boxed
104
ns/iter (± 0
)103
ns/iter (± 0
)1.01
es/visitor/base-perf/boxing_unboxed
102
ns/iter (± 0
)101
ns/iter (± 0
)1.01
es/visitor/base-perf/visit_contains_this
3516
ns/iter (± 88
)3532
ns/iter (± 54
)1.00
es/base/parallel/resolver/typescript
5243881409
ns/iter (± 460493701
)5663909412
ns/iter (± 518171900
)0.93
es/base/parallel/hygiene/typescript
2263019292
ns/iter (± 41429871
)2205971525
ns/iter (± 31968284
)1.03
misc/visitors/time-complexity/time 5
102
ns/iter (± 0
)102
ns/iter (± 0
)1
misc/visitors/time-complexity/time 10
330
ns/iter (± 1
)316
ns/iter (± 0
)1.04
misc/visitors/time-complexity/time 15
668
ns/iter (± 1
)646
ns/iter (± 0
)1.03
misc/visitors/time-complexity/time 20
1262
ns/iter (± 11
)1243
ns/iter (± 14
)1.02
misc/visitors/time-complexity/time 40
6636
ns/iter (± 16
)6695
ns/iter (± 23
)0.99
misc/visitors/time-complexity/time 60
17130
ns/iter (± 14
)17142
ns/iter (± 69
)1.00
es/full-target/es2016
188310
ns/iter (± 524
)188716
ns/iter (± 788
)1.00
es/full-target/es2017
183962
ns/iter (± 688
)183349
ns/iter (± 860
)1.00
es/full-target/es2018
174442
ns/iter (± 591
)172697
ns/iter (± 761
)1.01
es2020_nullish_coalescing
67065
ns/iter (± 152
)67392
ns/iter (± 120
)1.00
es2020_optional_chaining
96800
ns/iter (± 1920
)96075
ns/iter (± 409
)1.01
es2022_class_properties
94689
ns/iter (± 145
)93696
ns/iter (± 142
)1.01
es2018_object_rest_spread
71837
ns/iter (± 150
)71659
ns/iter (± 131
)1.00
es2019_optional_catch_binding
61644
ns/iter (± 115
)61801
ns/iter (± 147
)1.00
es2017_async_to_generator
61795
ns/iter (± 111
)62113
ns/iter (± 117
)0.99
es2016_exponentiation
65624
ns/iter (± 139
)65577
ns/iter (± 241
)1.00
es2015_arrow
70833
ns/iter (± 277
)70831
ns/iter (± 167
)1.00
es2015_block_scoped_fn
66504
ns/iter (± 85
)66247
ns/iter (± 124
)1.00
es2015_block_scoping
139896
ns/iter (± 9466
)149333
ns/iter (± 8940
)0.94
es2015_classes
116684
ns/iter (± 389
)116597
ns/iter (± 385
)1.00
es2015_computed_props
61599
ns/iter (± 113
)61514
ns/iter (± 93
)1.00
es2015_destructuring
116742
ns/iter (± 191
)116319
ns/iter (± 237
)1.00
es2015_duplicate_keys
64370
ns/iter (± 105
)64647
ns/iter (± 79
)1.00
es2015_parameters
79784
ns/iter (± 184
)79812
ns/iter (± 237
)1.00
es2015_fn_name
67667
ns/iter (± 741
)67061
ns/iter (± 540
)1.01
es2015_for_of
65011
ns/iter (± 114
)64882
ns/iter (± 105
)1.00
es2015_instanceof
62977
ns/iter (± 769
)63795
ns/iter (± 114
)0.99
es2015_shorthand_property
59805
ns/iter (± 87
)61367
ns/iter (± 103
)0.97
es2015_spread
59927
ns/iter (± 69
)61553
ns/iter (± 109
)0.97
es2015_sticky_regex
60997
ns/iter (± 71
)62593
ns/iter (± 98
)0.97
es2015_typeof_symbol
61369
ns/iter (± 85
)62613
ns/iter (± 73
)0.98
es/transform/baseline/base
51024
ns/iter (± 99
)52372
ns/iter (± 110
)0.97
es/transform/baseline/common_reserved_word
61743
ns/iter (± 93
)62808
ns/iter (± 109
)0.98
es/transform/baseline/common_typescript
139079
ns/iter (± 1753
)168695
ns/iter (± 9701
)0.82
es/target/es3
165953
ns/iter (± 1515
)169559
ns/iter (± 160
)0.98
es/target/es2015
601201
ns/iter (± 4135
)626662
ns/iter (± 1363
)0.96
es/target/es2016
63988
ns/iter (± 85
)65569
ns/iter (± 153
)0.98
es/target/es2017
60429
ns/iter (± 82
)62311
ns/iter (± 120
)0.97
es/target/es2018
80002
ns/iter (± 78
)82022
ns/iter (± 85
)0.98
es/target/es2020
129689
ns/iter (± 108
)133388
ns/iter (± 480
)0.97
babelify-only
670897
ns/iter (± 1222
)680562
ns/iter (± 1496
)0.99
parse_and_babelify_angular
50352764
ns/iter (± 1367408
)43593527
ns/iter (± 912958
)1.16
parse_and_babelify_backbone
5992010
ns/iter (± 139534
)5322693
ns/iter (± 34459
)1.13
parse_and_babelify_jquery
37003769
ns/iter (± 408041
)32262250
ns/iter (± 481678
)1.15
parse_and_babelify_jquery_mobile
59922453
ns/iter (± 580946
)54604649
ns/iter (± 660305
)1.10
parse_and_babelify_mootools
37040028
ns/iter (± 709885
)33571698
ns/iter (± 530632
)1.10
parse_and_babelify_underscore
4545061
ns/iter (± 121050
)4272272
ns/iter (± 29631
)1.06
parse_and_babelify_yui
38525994
ns/iter (± 660442
)33100982
ns/iter (± 381982
)1.16
html/minify/document/css_spec
44658197
ns/iter (± 356775
)41484365
ns/iter (± 169540
)1.08
html/minify/document/github
17622032
ns/iter (± 112296
)17326646
ns/iter (± 50167
)1.02
html/minify/document/stackoverflow
15929186
ns/iter (± 66309
)15493484
ns/iter (± 24783
)1.03
html/minify/document_fragment/css_spec
41766737
ns/iter (± 703034
)39717165
ns/iter (± 119225
)1.05
html/minify/document_fragment/github
17095392
ns/iter (± 71475
)16642910
ns/iter (± 21255
)1.03
html/minify/document_fragment/stackoverflow
15644094
ns/iter (± 114227
)15018719
ns/iter (± 19253
)1.04
html/document/visitor/compare/clone
341421
ns/iter (± 2612
)341709
ns/iter (± 1266
)1.00
html/document/visitor/compare/visit_mut_span
365665
ns/iter (± 2164
)369573
ns/iter (± 2332
)0.99
html/document/visitor/compare/visit_mut_span_panic
375776
ns/iter (± 2443
)377834
ns/iter (± 1607
)0.99
html/document/visitor/compare/fold_span
402967
ns/iter (± 1744
)408843
ns/iter (± 2537
)0.99
html/document/visitor/compare/fold_span_panic
459862
ns/iter (± 2145
)465409
ns/iter (± 3118
)0.99
html/document_fragment/visitor/compare/clone
341890
ns/iter (± 2523
)339246
ns/iter (± 2093
)1.01
html/document_fragment/visitor/compare/visit_mut_span
371061
ns/iter (± 1528
)363781
ns/iter (± 2014
)1.02
html/document_fragment/visitor/compare/visit_mut_span_panic
378361
ns/iter (± 1860
)375710
ns/iter (± 1877
)1.01
html/document_fragment/visitor/compare/fold_span
406541
ns/iter (± 2574
)405310
ns/iter (± 2832
)1.00
html/document_fragment/visitor/compare/fold_span_panic
458187
ns/iter (± 2095
)460192
ns/iter (± 1707
)1.00
html/lexer/css_2021_spec
15594477
ns/iter (± 97705
)15596391
ns/iter (± 16565
)1.00
html/lexer/github_com_17_05_2022
6050537
ns/iter (± 5579
)6025020
ns/iter (± 2174
)1.00
html/lexer/stackoverflow_com_17_05_2022
5660536
ns/iter (± 2432
)5634222
ns/iter (± 4813
)1.00
html/parser/parser_document/css_2021_spec
26732454
ns/iter (± 309540
)25780436
ns/iter (± 234292
)1.04
html/parser/parser_document/github_com_17_05_2022
8795833
ns/iter (± 9685
)8818410
ns/iter (± 12172
)1.00
html/parser/parser_document/stackoverflow_com_17_05_2022
7795730
ns/iter (± 11858
)7757448
ns/iter (± 5309
)1.00
html/parser/parser_document_fragment/css_2021_spec
27424937
ns/iter (± 402616
)25535133
ns/iter (± 91383
)1.07
html/parser/parser_document_fragment/github_com_17_05_2022
8860619
ns/iter (± 12337
)8801488
ns/iter (± 9222
)1.01
html/parser/parser_document_fragment/stackoverflow_com_17_05_2022
7779974
ns/iter (± 9383
)7762645
ns/iter (± 5515
)1.00
This comment was automatically generated by workflow using github-action-benchmark.