Minify calls to Math, Number, etc. with Terser

112 views Asked by At

The code that Terser produces for my project contains many calls to the Javascript Math object and I am wondering if there is an easy way to minify these calls.

Here is a screenshot of part of the minfied code with Math highlighted (altogether there are almost a thousand calls to Math):

enter image description here

I could certainly do the optimization in my original code by setting const min = Math.min etc, but this would be hard to maintain and generally an abominal micro optimization.

As I see it properties in the mangle options cannot be used for this, as properties explicitly will NOT work for built-in Javascript properties.

Does anybody have an idea how calls to Math, Number, etc. can be minified with Terser?

1

There are 1 answers

0
Waruyama On

I could not find a solution for this using Terser.

BUT I came to the conclusion, that it would not make much sense to minify all calls to Math for the following reasons:

  • Obfuscation does not really improve. The mapping would be visible inside the file, so unmapping would be very easy for anyone determined to unobfuscate the code.
  • File size may be smaller, but since files are sent gzipped over the internet, the actual difference would be very small or none, since multiple string occurences like calls to 'Math' will be compressed by gzipping.

So in conclusion this seems to be neither possible nor necessary.