It appears that the minifier is incorrectly removing functions and classes that are reused within a for statement.
In the following example, both function x and class y are used inside for statements, and therefore should not be removed by the minifier. However, the minifier removes them, causing the code to break.
Input code
"use strict";
let k = function() {
function x() {}
class y{}
for (x of ['']);
for (y in ['']);
}();
"use strict";
let k = function() {
function x() {} // These should be preserved
class y{} // These should be preserved
for (x of ['']);
for(y in ['']);
}();
Actual behavior
"use strict";
let k = function() {
for (x of [
''
]);
for(y in [
''
]);
}();
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
It appears that the minifier is incorrectly removing functions and classes that are reused within a
for
statement.In the following example, both
function x
andclass y
are used insidefor
statements, and therefore should not be removed by the minifier. However, the minifier removes them, causing the code to break.Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.7.14&code=H4sIAAAAAAAAA1MqLU5VKC4pykwuUbLmykktUchWsFVIK81LLsnMz9PQVKjmUgACmIBCBUioFiyWnJNYXKxQCeWl5RcpaFQo5KcpRKurx2paIwQrFTLzYIK1GprWAH7VDnNzAAAA&config=H4sIAAAAAAAAA32VO5LbMAyG%2B5zCozpFxkWKHCCzTc7AoUlQppcPDQF6rdnx3QNR8mPXkDoLH36ABED488du153QdH92n%2FyTPwZdEMr9my04JtIXtnRgokZT%2FEDdzxs94YScDgjNdJ1JR7r0QE2F%2B1%2F7%2FaLoQs4IN8Viiz55Nz7nNDkOBRCfbGzlkDVCIvyqX1jJHxOgUp%2Fth5wD6LRBlEblE0EPRQpscgh6QFBnXYQo00l18ZilFBOsBFYNJQ8iT9aTz4lzvlIL2iqTLQjIFzDkzyDJOBfLEvL1hPs0bOFQ%2B771%2BZsazjpUTUJOuLSW8GmFqMfskZSrSSrhDFdqMMOluN%2BV3qkCVEt61Z2yTys9eQfgCgSNmHQEKW7zcDxPa2q3qfTJ8cjSKHCeb%2BmWCXouqvLeCZWdKgOFvNTNArYamCprpOMseKV86C0ocI5nRQiNH57MUUpK4wDZCYD7q500VTNQ91e4wqcHsYH%2F8i1JHrDFI2o6rlMc4yGHjQQR6JjthgO3gvI6LrwlLsM6r8kCjwZY0aViA69LgB8AZRXavnyZDX4eHFH1IR8ea2JxuN73cNSpf7z3L6sYLgSFV8wbhAHKU4Tm0MVsa1Mu%2FwBT8%2Be9%2Fbt7ON1W9P1Wncd%2FN%2BWc8%2FofsXtHPU4GAAA%3D
SWC Info output
No response
Expected behavior
Actual behavior
Version
1.7.14
Additional context
No response