Fix parens for negative numbers
authorMihai Bazon <mihai@bazon.net>
Wed, 6 Feb 2013 09:36:04 +0000 (11:36 +0200)
committerMihai Bazon <mihai@bazon.net>
Wed, 6 Feb 2013 09:36:04 +0000 (11:36 +0200)
Close #115

lib/output.js

index 27b35fe..ab9b82b 100644 (file)
@@ -514,6 +514,12 @@ function OutputStream(options) {
             return true;
     });
 
+    PARENS(AST_Number, function(output){
+        var p = output.parent();
+        if (this.getValue() < 0 && p instanceof AST_PropAccess && p.expression === this)
+            return true;
+    });
+
     function assign_and_conditional_paren_rules(output) {
         var p = output.parent();
         // !(a = false) → true
@@ -942,7 +948,7 @@ function OutputStream(options) {
     DEFPRINT(AST_Dot, function(self, output){
         var expr = self.expression;
         expr.print(output);
-        if (expr instanceof AST_Number) {
+        if (expr instanceof AST_Number && expr.getValue() >= 0) {
             if (!/[xa-f.]/i.test(output.last())) {
                 output.print(".");
             }