silverwind / cidr-tools

Tools to work with IPv4 and IPv6 CIDR
98 stars 10 forks source link

Unexpected behavior when built for production via webpack #11

Closed STLMikey closed 3 years ago

STLMikey commented 3 years ago

When building for production with Webpack, the Uglification process breaks a few checks within cidr-tools resulting in some unexpected behavior.

Specifically:

if (number.constructor.name !== "BigInteger") if (a.constructor.name !== "BigInteger") if (b.constructor.name !== "BigInteger")

When uglified, the name of the constructor gets uglified along with the reference, and no longer is equivalent to the string 'BigInteger'.

Changing these checks to number instanceof BigInteger would likely achieve the same thing, although I'm not certain enough without BigInteger-esque tests to make a PR affecting others too.

silverwind commented 3 years ago

Should probably be fixable by setting some option (I think --keep-fnames in terser) in the minifier to prevent such destructive minifaction but I'm pretty sure we can fix this with your suggestion too.

Edit: it seems not that simple, some existing test cases do not pass instanceof BigInteger for some reason.

silverwind commented 3 years ago

https://github.com/ortexx/ip-cidr/issues/25