Fixed bug with incorrectly parenthesized if expressions.
authorVladimir Sedach <vsedach@gmail.com>
Wed, 29 Apr 2009 02:17:34 +0000 (20:17 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Wed, 29 Apr 2009 02:17:34 +0000 (20:17 -0600)
Thanks to Daniel Gackle for the bug report.

src/printer.lisp
t/ps-tests.lisp

index dbeea7a..a4526ed 100644 (file)
@@ -230,7 +230,9 @@ arguments, defines a printer for that form using the given body."
                 (return)))))
 
 (defprinter js:? (test then else)
-  (ps-print test)
+  (if (>= (expression-precedence test) (op-precedence 'js:?))
+      (parenthesize-print test)
+      (ps-print test))
   (psw " ? ")
   (if (>= (expression-precedence then) (op-precedence 'js:?))
       (parenthesize-print then)
index 6d4ab8a..65f377b 100644 (file)
@@ -819,3 +819,11 @@ try {
     var baz = -1 == x2 ? null : arguments[x2 + 1];
 }"
   :js-target-version 1.6)
+
+(test-ps-js nested-if-expressions1
+  (return (if (if x y z) a b))
+  "return (x ? y : z) ? a : b")
+
+(test-ps-js nested-if-expressions2
+  (return (if x y (if z a b)))
+  "return x ? y : (z ? a : b)")