compress numerical expressions (#1513)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 3 Mar 2017 10:04:32 +0000 (18:04 +0800)
committerGitHub <noreply@github.com>
Fri, 3 Mar 2017 10:04:32 +0000 (18:04 +0800)
commit18059cc94fdc037e296a1cb1b08143d5e3aae570
treed8b787fba1df5fe5c5052354008084c9f74e58d3
parentb5e0e8c2038c7c0ea13771891eb84f6e6f7bcbc3
compress numerical expressions (#1513)

safe operations
- `a === b` => `a == b`
- `a + -b`  => `a - b`
- `-a + b`  => `b - a`
- `a+ +b`   => `+b+a`

associative operations
(bit-wise operations are safe, otherwise `unsafe_math`)
- `a + (b + c)`       => `(a + b) + c`
- `(n + 2) + 3`       => `5 + n`
- `(2 * n) * 3`       => `6 * n`
- `(a | 1) | (2 | d)` => `(3 | a) | b`

fixes #412
README.md
lib/compress.js
test/compress/numbers.js