Fixed the CHAIN macro to correctly chain plain slot values.
authorVladimir Sedach <vsedach@gmail.com>
Sun, 13 Sep 2009 22:19:11 +0000 (16:19 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Sun, 13 Sep 2009 22:19:11 +0000 (16:19 -0600)
Thanks to Daniel White <daniel@whitehouse.id.au> for the patch.

src/lib/ps-macro-lib.lisp
t/ps-tests.lisp

index be90b79..2ef7d82 100644 (file)
@@ -84,7 +84,9 @@
 (defpsmacro chain (&rest method-calls)
   (labels ((do-chain (method-calls)
              (if (cdr method-calls)
-                 `((@ ,(do-chain (cdr method-calls)) ,(caar method-calls)) ,@(cdar method-calls))
+                 (if (listp (car method-calls))
+                     `((@ ,(do-chain (cdr method-calls)) ,(caar method-calls)) ,@(cdar method-calls))
+                     `(@ ,(do-chain (cdr method-calls)) ,(car method-calls)))
                  (car method-calls))))
     (do-chain (reverse method-calls))))
 
index 1064aa8..2350f03 100644 (file)
@@ -1193,3 +1193,15 @@ x1 - x1;
     var _cmp1;
     return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
 };")
+
+(test-ps-js chain-slot-value1
+  (chain ($ "foo") (bar x z) frob (baz 5))
+  "$('foo').bar(x, z).frob.baz(5);")
+
+(test-ps-js chain-slot-value2
+  (chain ($ "foo") bar baz)
+  "$('foo').bar.baz;")
+
+(test-ps-js chain-slot-value3
+  (chain ($ "foo") bar (x y) baz)
+  "$('foo').bar.x(y).baz;")