aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-19 20:04:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-19 20:04:38 -0700
commitbcbce4709178f424c26564f44a9ae499173d74fa (patch)
tree23818445fa5483bc7afde2aeffd1c697c97b2ec4 /tools/js-optimizer.js
parent7eda11db7c57aa4d231e468f87ded2d703034225 (diff)
handle negative zero; fixes #921
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js11
1 files changed, 4 insertions, 7 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 48ab5a1f..5ede0ce8 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -2287,19 +2287,16 @@ function minifyGlobals(ast) {
function prepDotZero(ast) {
traverse(ast, function(node, type) {
if (type == 'unary-prefix' && node[1] == '+') {
- if (node[2][0] == 'num') {
+ if (node[2][0] == 'num' ||
+ (node[2][0] == 'unary-prefix' && node[2][1] == '-' && node[2][2][0] == 'num')) {
return ['call', ['name', 'DOT$ZERO'], [node[2]]];
- } else if (node[2][0] == 'unary-prefix' && node[2][1] == '-' && node[2][2][0] == 'num') {
- node[2][2][1] = -node[2][2][1];
- return ['call', ['name', 'DOT$ZERO'], [node[2][2]]];
}
}
});
}
function fixDotZero(js) {
- return js.replace(/DOT\$ZERO\(((0x)?[-+]?[0-9a-f]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) {
- if (num.substr(0, 2) == '0x') {
- if (num[2] == '-') num = '-0x' + num.substr(3); // uglify generates 0x-8000 for some reason
+ return js.replace(/DOT\$ZERO\(([-+]?(0x)?[0-9a-f]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) {
+ if (num.substr(0, 2) == '0x' || num.substr(0, 3) == '-0x') {
return eval(num) + '.0';
}
if (num.indexOf('.') >= 0) return num;