Skip to content

Commit c0e72ef

Browse files
authoredJan 28, 2023
fix(es/minifier): Track reassign in parent scope (#6865)
**Related issue:** - Closes #6864.
1 parent 33dab56 commit c0e72ef

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
 

‎crates/swc_ecma_minifier/src/program_data.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,12 @@ impl ProgramData {
619619

620620
if is_first {
621621
e.ref_count += 1;
622+
// If it is inited in some child scope, but referenced in current scope
622623
if !inited && e.var_initialized {
624+
e.reassigned = true;
623625
if !is_modify {
624626
e.var_initialized = false;
625627
e.assign_count += 1;
626-
e.reassigned = true
627628
}
628629
}
629630
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export function removeFromMatrix(matrix, id) {
2+
var newMatrix;
3+
var indexOfIdToRemove;
4+
5+
var row = _.find(matrix, (entry, index) => {
6+
if (_.includes(entry, id)) {
7+
indexOfIdToRemove = index;
8+
return entry;
9+
}
10+
});
11+
12+
if (!row) {
13+
return matrix;
14+
}
15+
16+
if (row.length === 1) {
17+
newMatrix = _.without(matrix, row);
18+
19+
if (newMatrix[0].length === 2) {
20+
const remainingEntry = newMatrix[0];
21+
newMatrix = [[remainingEntry[0]], [remainingEntry[1]]];
22+
}
23+
} else {
24+
newMatrix = [...matrix];
25+
newMatrix[indexOfIdToRemove] = _.without(row, id);
26+
}
27+
28+
return newMatrix || matrix;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function removeFromMatrix(matrix, id) {
2+
var newMatrix, indexOfIdToRemove, row = _.find(matrix, (entry, index)=>{
3+
if (_.includes(entry, id)) return indexOfIdToRemove = index, entry;
4+
});
5+
if (!row) return matrix;
6+
if (1 === row.length) {
7+
if (2 === (newMatrix = _.without(matrix, row))[0].length) {
8+
const remainingEntry = newMatrix[0];
9+
newMatrix = [
10+
[
11+
remainingEntry[0]
12+
],
13+
[
14+
remainingEntry[1]
15+
]
16+
];
17+
}
18+
} else (newMatrix = [
19+
...matrix
20+
])[indexOfIdToRemove] = _.without(row, id);
21+
return newMatrix || matrix;
22+
}

1 commit comments

Comments
 (1)

github-actions[bot] commented on Jan 28, 2023

@github-actions[bot]

Benchmark

Benchmark suite Current: c0e72ef Previous: 39c75fd Ratio
es/full/bugs-1 302076 ns/iter (± 10229) 307310 ns/iter (± 7141) 0.98
es/full/minify/libraries/antd 1722388271 ns/iter (± 31178604) 1775438096 ns/iter (± 29670486) 0.97
es/full/minify/libraries/d3 309423598 ns/iter (± 8151676) 320412755 ns/iter (± 10008443) 0.97
es/full/minify/libraries/echarts 1309745468 ns/iter (± 11903421) 1369806138 ns/iter (± 6708576) 0.96
es/full/minify/libraries/jquery 91024682 ns/iter (± 1195309) 93944088 ns/iter (± 1502872) 0.97
es/full/minify/libraries/lodash 107232339 ns/iter (± 797941) 110657938 ns/iter (± 699265) 0.97
es/full/minify/libraries/moment 53281175 ns/iter (± 325284) 54126863 ns/iter (± 366070) 0.98
es/full/minify/libraries/react 19198990 ns/iter (± 94892) 19849433 ns/iter (± 181909) 0.97
es/full/minify/libraries/terser 255196660 ns/iter (± 2421711) 270740946 ns/iter (± 1996805) 0.94
es/full/minify/libraries/three 473706043 ns/iter (± 5279168) 495582457 ns/iter (± 7166054) 0.96
es/full/minify/libraries/typescript 3262471679 ns/iter (± 22087194) 3314590921 ns/iter (± 18576229) 0.98
es/full/minify/libraries/victory 706385120 ns/iter (± 12320628) 772722472 ns/iter (± 14628241) 0.91
es/full/minify/libraries/vue 133447180 ns/iter (± 853284) 141210759 ns/iter (± 1846699) 0.95
es/full/codegen/es3 26598 ns/iter (± 74) 26032 ns/iter (± 259) 1.02
es/full/codegen/es5 26532 ns/iter (± 51) 26048 ns/iter (± 45) 1.02
es/full/codegen/es2015 26556 ns/iter (± 46) 26014 ns/iter (± 38) 1.02
es/full/codegen/es2016 26532 ns/iter (± 45) 26016 ns/iter (± 34) 1.02
es/full/codegen/es2017 26529 ns/iter (± 47) 26014 ns/iter (± 41) 1.02
es/full/codegen/es2018 26481 ns/iter (± 56) 26047 ns/iter (± 34) 1.02
es/full/codegen/es2019 26518 ns/iter (± 49) 26080 ns/iter (± 43) 1.02
es/full/codegen/es2020 26513 ns/iter (± 30) 26075 ns/iter (± 34) 1.02
es/full/all/es3 167714400 ns/iter (± 3267148) 167153820 ns/iter (± 4353250) 1.00
es/full/all/es5 164662224 ns/iter (± 2233133) 159351259 ns/iter (± 2396729) 1.03
es/full/all/es2015 125454902 ns/iter (± 1433243) 122602625 ns/iter (± 486726) 1.02
es/full/all/es2016 123729275 ns/iter (± 1277655) 122464996 ns/iter (± 702741) 1.01
es/full/all/es2017 122806882 ns/iter (± 1211959) 121048292 ns/iter (± 776505) 1.01
es/full/all/es2018 119959563 ns/iter (± 856615) 118666999 ns/iter (± 793195) 1.01
es/full/all/es2019 118687782 ns/iter (± 1213558) 118190304 ns/iter (± 901041) 1.00
es/full/all/es2020 114835423 ns/iter (± 1259851) 113207174 ns/iter (± 816576) 1.01
es/full/parser 549119 ns/iter (± 9905) 536425 ns/iter (± 10541) 1.02
es/full/base/fixer 21843 ns/iter (± 31) 21873 ns/iter (± 63) 1.00
es/full/base/resolver_and_hygiene 79397 ns/iter (± 124) 79624 ns/iter (± 89) 1.00
serialization of ast node 127 ns/iter (± 0) 127 ns/iter (± 0) 1
serialization of serde 129 ns/iter (± 0) 129 ns/iter (± 0) 1
css/minify/libraries/bootstrap 28240882 ns/iter (± 115187) 28391707 ns/iter (± 258127) 0.99
css/visitor/compare/clone 2067904 ns/iter (± 18036) 2050487 ns/iter (± 20495) 1.01
css/visitor/compare/visit_mut_span 2288804 ns/iter (± 9904) 2290409 ns/iter (± 11379) 1.00
css/visitor/compare/visit_mut_span_panic 2289724 ns/iter (± 6036) 2319043 ns/iter (± 11296) 0.99
css/visitor/compare/fold_span 3045976 ns/iter (± 42372) 3045012 ns/iter (± 15773) 1.00
css/visitor/compare/fold_span_panic 3150347 ns/iter (± 21672) 3201156 ns/iter (± 18560) 0.98
css/lexer/bootstrap_5_1_3 5210526 ns/iter (± 1576) 5203486 ns/iter (± 52950) 1.00
css/lexer/foundation_6_7_4 4382758 ns/iter (± 1272) 4383149 ns/iter (± 3723) 1.00
css/lexer/tailwind_3_1_1 833770 ns/iter (± 651) 830003 ns/iter (± 320) 1.00
css/parser/bootstrap_5_1_3 21791011 ns/iter (± 102804) 21623208 ns/iter (± 108628) 1.01
css/parser/foundation_6_7_4 17339568 ns/iter (± 14015) 17305626 ns/iter (± 45495) 1.00
css/parser/tailwind_3_1_1 3328877 ns/iter (± 4049) 3304339 ns/iter (± 1648) 1.01
es/codegen/colors 325370 ns/iter (± 183787) 326272 ns/iter (± 184450) 1.00
es/codegen/large 1192829 ns/iter (± 615582) 1191343 ns/iter (± 613436) 1.00
es/codegen/with-parser/colors 48406 ns/iter (± 327) 48274 ns/iter (± 482) 1.00
es/codegen/with-parser/large 533576 ns/iter (± 1363) 536740 ns/iter (± 2703) 0.99
es/minify/libraries/antd 1514933054 ns/iter (± 11380506) 1528782713 ns/iter (± 17573217) 0.99
es/minify/libraries/d3 257197899 ns/iter (± 4098326) 258468160 ns/iter (± 2091149) 1.00
es/minify/libraries/echarts 1136625178 ns/iter (± 6313896) 1136247344 ns/iter (± 9660464) 1.00
es/minify/libraries/jquery 79257372 ns/iter (± 479930) 78929260 ns/iter (± 369614) 1.00
es/minify/libraries/lodash 95613083 ns/iter (± 835255) 96633165 ns/iter (± 745333) 0.99
es/minify/libraries/moment 46489847 ns/iter (± 245428) 46254360 ns/iter (± 248783) 1.01
es/minify/libraries/react 17165437 ns/iter (± 75233) 17135630 ns/iter (± 112663) 1.00
es/minify/libraries/terser 215542897 ns/iter (± 2038921) 219574791 ns/iter (± 4634906) 0.98
es/minify/libraries/three 376351262 ns/iter (± 8310638) 386403588 ns/iter (± 7492599) 0.97
es/minify/libraries/typescript 2771893705 ns/iter (± 15291733) 2798016025 ns/iter (± 10001474) 0.99
es/minify/libraries/victory 614558064 ns/iter (± 9577509) 612604411 ns/iter (± 13449516) 1.00
es/minify/libraries/vue 118075731 ns/iter (± 2228309) 117642481 ns/iter (± 775934) 1.00
es/visitor/compare/clone 2416068 ns/iter (± 17803) 2378637 ns/iter (± 12781) 1.02
es/visitor/compare/visit_mut_span 2812076 ns/iter (± 13078) 2761926 ns/iter (± 11808) 1.02
es/visitor/compare/visit_mut_span_panic 2865700 ns/iter (± 5415) 2832950 ns/iter (± 17658) 1.01
es/visitor/compare/fold_span 3933286 ns/iter (± 14282) 3934690 ns/iter (± 22973) 1.00
es/visitor/compare/fold_span_panic 4126796 ns/iter (± 15171) 4103723 ns/iter (± 14463) 1.01
es/lexer/colors 17293 ns/iter (± 66) 17372 ns/iter (± 19) 1.00
es/lexer/angular 8256280 ns/iter (± 11234) 8256757 ns/iter (± 2508) 1.00
es/lexer/backbone 1079470 ns/iter (± 809) 1083476 ns/iter (± 499) 1.00
es/lexer/jquery 5972745 ns/iter (± 3376) 5975665 ns/iter (± 3841) 1.00
es/lexer/jquery mobile 9211005 ns/iter (± 2934) 9219562 ns/iter (± 5207) 1.00
es/lexer/mootools 4692775 ns/iter (± 7844) 4692146 ns/iter (± 4637) 1.00
es/lexer/underscore 899754 ns/iter (± 852) 901643 ns/iter (± 819) 1.00
es/lexer/three 27991433 ns/iter (± 25552) 28132666 ns/iter (± 29613) 0.99
es/lexer/yui 5043579 ns/iter (± 3161) 5059350 ns/iter (± 9757) 1.00
es/parser/colors 31297 ns/iter (± 192) 31299 ns/iter (± 246) 1.00
es/parser/angular 16025678 ns/iter (± 152205) 16452273 ns/iter (± 152489) 0.97
es/parser/backbone 2361050 ns/iter (± 12182) 2335583 ns/iter (± 11803) 1.01
es/parser/jquery 12568887 ns/iter (± 73513) 12685899 ns/iter (± 70875) 0.99
es/parser/jquery mobile 19967483 ns/iter (± 127258) 20133766 ns/iter (± 172748) 0.99
es/parser/mootools 9617936 ns/iter (± 22837) 9634366 ns/iter (± 70250) 1.00
es/parser/underscore 1995173 ns/iter (± 12983) 1978292 ns/iter (± 11868) 1.01
es/parser/three 59587628 ns/iter (± 390216) 58940694 ns/iter (± 625558) 1.01
es/parser/yui 9758665 ns/iter (± 93110) 9722571 ns/iter (± 80942) 1.00
es/preset-env/usage/builtin_type 138332 ns/iter (± 30629) 138150 ns/iter (± 30603) 1.00
es/preset-env/usage/property 20952 ns/iter (± 77) 21020 ns/iter (± 77) 1.00
es/resolver/typescript 122400536 ns/iter (± 2291631) 118717393 ns/iter (± 1747991) 1.03
es/fixer/typescript 93941561 ns/iter (± 6210838) 96633750 ns/iter (± 1546640) 0.97
es/hygiene/typescript 196747618 ns/iter (± 1145771) 199095890 ns/iter (± 1498220) 0.99
es/resolver_with_hygiene/typescript 333915061 ns/iter (± 2315215) 338599478 ns/iter (± 4592477) 0.99
es/visitor/base-perf/module_clone 75088 ns/iter (± 1291) 75461 ns/iter (± 1429) 1.00
es/visitor/base-perf/fold_empty 86182 ns/iter (± 1294) 84775 ns/iter (± 1472) 1.02
es/visitor/base-perf/fold_noop_impl_all 86345 ns/iter (± 1603) 85499 ns/iter (± 1219) 1.01
es/visitor/base-perf/fold_noop_impl_vec 85850 ns/iter (± 2193) 85778 ns/iter (± 979) 1.00
es/visitor/base-perf/boxing_boxed_clone 56 ns/iter (± 0) 59 ns/iter (± 0) 0.95
es/visitor/base-perf/boxing_unboxed_clone 59 ns/iter (± 0) 59 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 104 ns/iter (± 0) 105 ns/iter (± 0) 0.99
es/visitor/base-perf/boxing_unboxed 102 ns/iter (± 0) 103 ns/iter (± 0) 0.99
es/visitor/base-perf/visit_contains_this 3410 ns/iter (± 36) 3442 ns/iter (± 35) 0.99
es/base/parallel/resolver/typescript 5411652517 ns/iter (± 528794129) 5760295923 ns/iter (± 532047171) 0.94
es/base/parallel/hygiene/typescript 2369685568 ns/iter (± 26290610) 2389699161 ns/iter (± 21274405) 0.99
misc/visitors/time-complexity/time 5 93 ns/iter (± 0) 93 ns/iter (± 0) 1
misc/visitors/time-complexity/time 10 309 ns/iter (± 4) 311 ns/iter (± 4) 0.99
misc/visitors/time-complexity/time 15 667 ns/iter (± 0) 648 ns/iter (± 0) 1.03
misc/visitors/time-complexity/time 20 1208 ns/iter (± 0) 1208 ns/iter (± 0) 1
misc/visitors/time-complexity/time 40 6194 ns/iter (± 7) 6193 ns/iter (± 1) 1.00
misc/visitors/time-complexity/time 60 15594 ns/iter (± 42) 15575 ns/iter (± 5) 1.00
es/full-target/es2016 184510 ns/iter (± 1635) 187828 ns/iter (± 487) 0.98
es/full-target/es2017 178615 ns/iter (± 229) 182819 ns/iter (± 465) 0.98
es/full-target/es2018 167918 ns/iter (± 231) 171908 ns/iter (± 599) 0.98
es2020_nullish_coalescing 65438 ns/iter (± 355) 66793 ns/iter (± 159) 0.98
es2020_optional_chaining 93297 ns/iter (± 4021) 95622 ns/iter (± 308) 0.98
es2022_class_properties 91800 ns/iter (± 142) 93769 ns/iter (± 192) 0.98
es2018_object_rest_spread 69982 ns/iter (± 77) 71335 ns/iter (± 138) 0.98
es2019_optional_catch_binding 60137 ns/iter (± 68) 61295 ns/iter (± 82) 0.98
es2017_async_to_generator 60600 ns/iter (± 57) 61820 ns/iter (± 110) 0.98
es2016_exponentiation 63885 ns/iter (± 54) 64969 ns/iter (± 135) 0.98
es2015_arrow 68391 ns/iter (± 102) 70158 ns/iter (± 154) 0.97
es2015_block_scoped_fn 65018 ns/iter (± 100) 66004 ns/iter (± 109) 0.99
es2015_block_scoping 133673 ns/iter (± 9230) 157273 ns/iter (± 9068) 0.85
es2015_classes 113515 ns/iter (± 365) 117243 ns/iter (± 488) 0.97
es2015_computed_props 59834 ns/iter (± 89) 61086 ns/iter (± 92) 0.98
es2015_destructuring 112581 ns/iter (± 179) 115779 ns/iter (± 191) 0.97
es2015_duplicate_keys 62968 ns/iter (± 183) 63788 ns/iter (± 109) 0.99
es2015_parameters 78339 ns/iter (± 246) 79511 ns/iter (± 274) 0.99
es2015_fn_name 65945 ns/iter (± 579) 66822 ns/iter (± 503) 0.99
es2015_for_of 63308 ns/iter (± 194) 64670 ns/iter (± 136) 0.98
es2015_instanceof 61974 ns/iter (± 124) 63141 ns/iter (± 202) 0.98
es2015_shorthand_property 60166 ns/iter (± 174) 61155 ns/iter (± 127) 0.98
es2015_spread 60172 ns/iter (± 93) 61034 ns/iter (± 77) 0.99
es2015_sticky_regex 61052 ns/iter (± 96) 62186 ns/iter (± 79) 0.98
es2015_typeof_symbol 61058 ns/iter (± 128) 62280 ns/iter (± 188) 0.98
es/transform/baseline/base 50766 ns/iter (± 88) 51780 ns/iter (± 265) 0.98
es/transform/baseline/common_reserved_word 61703 ns/iter (± 64) 62733 ns/iter (± 145) 0.98
es/transform/baseline/common_typescript 166148 ns/iter (± 223) 142972 ns/iter (± 905) 1.16
es/target/es3 167291 ns/iter (± 351) 169385 ns/iter (± 1303) 0.99
es/target/es2015 602550 ns/iter (± 912) 600574 ns/iter (± 793) 1.00
es/target/es2016 63889 ns/iter (± 94) 63765 ns/iter (± 81) 1.00
es/target/es2017 60592 ns/iter (± 58) 60584 ns/iter (± 80) 1.00
es/target/es2018 79683 ns/iter (± 71) 79766 ns/iter (± 79) 1.00
es/target/es2020 129783 ns/iter (± 132) 128938 ns/iter (± 144) 1.01
babelify-only 667897 ns/iter (± 1454) 671140 ns/iter (± 1582) 1.00
parse_and_babelify_angular 46130260 ns/iter (± 909596) 48048052 ns/iter (± 1494730) 0.96
parse_and_babelify_backbone 5733306 ns/iter (± 188325) 5703378 ns/iter (± 68751) 1.01
parse_and_babelify_jquery 32826122 ns/iter (± 268578) 33719882 ns/iter (± 330880) 0.97
parse_and_babelify_jquery_mobile 55911361 ns/iter (± 741657) 57685855 ns/iter (± 755620) 0.97
parse_and_babelify_mootools 33769533 ns/iter (± 394488) 34969493 ns/iter (± 445430) 0.97
parse_and_babelify_underscore 4386620 ns/iter (± 21827) 4432410 ns/iter (± 20873) 0.99
parse_and_babelify_yui 33669347 ns/iter (± 719574) 34802239 ns/iter (± 637378) 0.97
html/minify/document/css_spec 42198141 ns/iter (± 309689) 45013382 ns/iter (± 797181) 0.94
html/minify/document/github 17486717 ns/iter (± 43933) 18214368 ns/iter (± 86758) 0.96
html/minify/document/stackoverflow 15630895 ns/iter (± 54924) 16573824 ns/iter (± 64967) 0.94
html/minify/document_fragment/css_spec 40454448 ns/iter (± 257771) 41051626 ns/iter (± 287768) 0.99
html/minify/document_fragment/github 16788888 ns/iter (± 26880) 16883401 ns/iter (± 28941) 0.99
html/minify/document_fragment/stackoverflow 15234606 ns/iter (± 19997) 15397700 ns/iter (± 44024) 0.99
html/document/visitor/compare/clone 348127 ns/iter (± 2044) 341703 ns/iter (± 1863) 1.02
html/document/visitor/compare/visit_mut_span 369194 ns/iter (± 2903) 375336 ns/iter (± 2147) 0.98
html/document/visitor/compare/visit_mut_span_panic 377578 ns/iter (± 1649) 378883 ns/iter (± 1096) 1.00
html/document/visitor/compare/fold_span 407734 ns/iter (± 2591) 406583 ns/iter (± 2328) 1.00
html/document/visitor/compare/fold_span_panic 459448 ns/iter (± 2582) 462469 ns/iter (± 2299) 0.99
html/document_fragment/visitor/compare/clone 339197 ns/iter (± 1504) 341249 ns/iter (± 1532) 0.99
html/document_fragment/visitor/compare/visit_mut_span 365694 ns/iter (± 1655) 368585 ns/iter (± 2699) 0.99
html/document_fragment/visitor/compare/visit_mut_span_panic 381684 ns/iter (± 2346) 373619 ns/iter (± 2279) 1.02
html/document_fragment/visitor/compare/fold_span 402857 ns/iter (± 2185) 405879 ns/iter (± 2517) 0.99
html/document_fragment/visitor/compare/fold_span_panic 460486 ns/iter (± 2189) 459831 ns/iter (± 1890) 1.00
html/lexer/css_2021_spec 15514664 ns/iter (± 167197) 15655265 ns/iter (± 140011) 0.99
html/lexer/github_com_17_05_2022 6020018 ns/iter (± 4547) 6063251 ns/iter (± 3763) 0.99
html/lexer/stackoverflow_com_17_05_2022 5624463 ns/iter (± 6752) 5685322 ns/iter (± 3243) 0.99
html/parser/parser_document/css_2021_spec 25435484 ns/iter (± 142057) 25737322 ns/iter (± 162170) 0.99
html/parser/parser_document/github_com_17_05_2022 8734552 ns/iter (± 12749) 8766869 ns/iter (± 9113) 1.00
html/parser/parser_document/stackoverflow_com_17_05_2022 7727198 ns/iter (± 4694) 7713336 ns/iter (± 4019) 1.00
html/parser/parser_document_fragment/css_2021_spec 25564352 ns/iter (± 93133) 26056013 ns/iter (± 121316) 0.98
html/parser/parser_document_fragment/github_com_17_05_2022 8736505 ns/iter (± 6356) 8798545 ns/iter (± 14459) 0.99
html/parser/parser_document_fragment/stackoverflow_com_17_05_2022 7753669 ns/iter (± 3907) 7722655 ns/iter (± 6412) 1.00

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

Please sign in to comment.