eslint-plugin-tree-shaking icon indicating copy to clipboard operation
eslint-plugin-tree-shaking copied to clipboard

Be smarter about side effects of builtins

Open freaktechnik opened this issue 6 years ago • 4 comments

Object.freeze({}) or Object.values({}) assigned to a module global triggers "Cannot determine side-effects of calling member function", while the rule should know, that these methods themselves don't have any side effects for literals (or Object.values for any argument, since it does not modify it).

Interestingly Array.from doesn't seem to trigger the rule, at least not in the case of Array.from(Object.values({})).

freaktechnik avatar Feb 25 '18 16:02 freaktechnik

For this particular functionality, this plugin currently uses a copy of Rollup's internal list of pure builtin functions. Object.freeze is missing from this list because it mutates its arguments. Even though there is no side-effect when the argument is an object literal, this in fact mirrors at least Rollup's current logic. Object.values is probably missing because this list is rather old and Object.values was only added in ES2017. As the prime goal of this plugin is to identify situations in which bundlers (in particular rollup) fail to remove statements, I guess this problem needs to be solved in rollup first before this plugin should change its behaviour. Which is in fact on the informal roadmap (I am the main person working on these things 😉)

lukastaegert avatar Feb 25 '18 16:02 lukastaegert

I guess this couple cases is fitting this issue: Screenshot 2020-01-11 18 13 06 Screenshot 2020-01-11 18 13 51

JustFly1984 avatar Jan 11 '20 15:01 JustFly1984

Screenshot 2020-01-11 18 18 06 Screenshot 2020-01-11 18 18 47

JustFly1984 avatar Jan 11 '20 15:01 JustFly1984

PS my last 2 comments happen while testing plugin 1.8.0 with typescript 3.7.4

JustFly1984 avatar Jan 11 '20 15:01 JustFly1984