Fixed a bug where variable initializations inside for loops were being compiled as...
authorVladimir Sedach <vsedach@gmail.com>
Sun, 8 Feb 2009 07:24:17 +0000 (00:24 -0700)
committerVladimir Sedach <vsedach@gmail.com>
Sun, 8 Feb 2009 07:24:17 +0000 (00:24 -0700)
src/special-forms.lisp
t/ps-tests.lisp

index 7ef4d26..f088b66 100644 (file)
@@ -645,7 +645,7 @@ lambda-list::=
 (defun make-for-vars/inits (init-forms)
   (mapcar (lambda (x)
             (cons (compile-parenscript-form (if (atom x) x (first x)) :expecting :symbol)
-                  (compile-parenscript-form (if (atom x) nil (second x)))))
+                  (compile-parenscript-form (if (atom x) nil (second x)) :expecting :expression)))
           init-forms))
 
 (define-ps-special-form labeled-for (expecting label init-forms cond-forms step-forms &rest body)
index 2889725..51c358a 100644 (file)
@@ -721,3 +721,17 @@ try {
     };
     return foo(3);
 })()")
+
+(test-ps-js for-loop-var-init-exp
+  ((lambda (x)
+     (return (do* ((y (if x 0 1) (1+ y))
+                   (z 0 (1+ z)))
+                  ((= y 3) z))))
+   true)
+  "(function (x) {
+    return (function () {
+        for (var y = x ? 0 : 1, z = 0; y != 3; y += 1, z += 1) {
+        };
+        return z;
+    })();
+})(true)")