aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen@experty.com>2016-05-18 18:49:55 +0200
committerRichard van Velzen <rvanvelzen@experty.com>2016-05-24 17:50:29 +0200
commitbc49dfd27a800cfa2070464c236a1d56ed30bfca (patch)
treef750690fdd02b07b04ad86449271df776a093e8d /lib
parent27eedbc302dea6a2af558bbf6bc8865fd2410837 (diff)
downloadtracifyjs-bc49dfd27a800cfa2070464c236a1d56ed30bfca.tar.gz
tracifyjs-bc49dfd27a800cfa2070464c236a1d56ed30bfca.zip
Completely allow evaluating -0
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e8c42c04..419c6a25 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -183,9 +183,18 @@ merge(Compressor.prototype, {
value: val
}).optimize(compressor);
case "number":
- return make_node(isNaN(val) ? AST_NaN : AST_Number, orig, {
- value: val
- }).optimize(compressor);
+ if (isNaN(val)) {
+ return make_node(AST_NaN, orig);
+ }
+
+ if ((1 / val) < 0) {
+ return make_node(AST_UnaryPrefix, orig, {
+ operator: "-",
+ expression: make_node(AST_Number, null, { value: -val })
+ });
+ }
+
+ return make_node(AST_Number, orig, { value: val }).optimize(compressor);
case "boolean":
return make_node(val ? AST_True : AST_False, orig).optimize(compressor);
case "undefined":
@@ -1028,10 +1037,7 @@ merge(Compressor.prototype, {
return typeof e;
case "void": return void ev(e, compressor);
case "~": return ~ev(e, compressor);
- case "-":
- e = -ev(e, compressor);
- if (e === -0) throw def;
- return e;
+ case "-": return -ev(e, compressor);
case "+": return +ev(e, compressor);
}
throw def;