New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[regression] Side-effect-free Array.filter() prevents unused const from being removed #4100
Comments
This is unfortunately not easily avoidable at the moment because we do not track if you mutate individual array elements via the filtered array. This was a bug in the previous implementation. While of course this is not a problem for an array of numbers, it would be a problem for other array elements, e.g. const foo = [{value: false}, {value: false}];
const bar = foo.filter((v, i) => i % 1 == 0);
for (const element of bar) {
bar.value = true;
}
console.log(foo); Here you cannot remove the filter expression because that would change the result. |
So the current approach is to just assume that using array.filter mutates all array elements. |
but in your example, |
Yes, I am just saying it is hard to track this without making mistakes. This would require a thorough rework of the Array builtin method handling logic and someone needs to do that. There is no one-line quick fix. |
ok, thanks! |
Ok, I should not reply to thinks late in the evening. There is at least a partial improvement possible, see #4103. This will not fix your example, but the reason here is that passing the array to |
no worries, guilty of this myself on a regular basis.
this is the actual unused const that i had to remove manually that rollup removed previously: leeoniya/uPlot@cc28fd0 as you mentioned, #4103 doesn't have an effect on this. |
i keep rollup updated, so this regressed pretty recently.
Input
Expected Behavior
Actual Behavior
thanks!
The text was updated successfully, but these errors were encountered: