1 (in-package "PARENSCRIPT-TEST")
5 (test-ps-js plus-is-not-commutative
6 (setf x
(+ "before" x
"after"))
7 "x = 'before' + x + 'after';")
9 (test-ps-js plus-works-if-first
10 (setf x
(+ x
"middle" "after"))
11 "x += 'middle' + 'after';")
13 (test-ps-js setf-side-effects
19 (setf x
(+ 2 (side-effect) x
5))))
21 function sideEffect() {
25 x = 2 + sideEffect() + x + 5;")
27 (test-ps-js method-call-op-form
28 ((@ (+ "" x
) to-string
))
29 "('' + x).toString();")
31 (test-ps-js method-call-op-form-args
32 ((@ (+ "" x
) to-string
) 1 2 :baz
3)
33 "('' + x).toString(1, 2, 'baz', 3);")
35 (test-ps-js method-call-number
39 (test-ps-js method-call-string
43 (test-ps-js method-call-lit-object
44 ((@ (create to-string
(lambda () (return "it works"))) to-string
))
45 "( { toString : function () { return 'it works'; } } ).toString();")
47 (test-ps-js method-call-conditional
51 (test-ps-js method-call-variable
55 (test-ps-js method-call-array
56 ((@ (list 10 20) to-string
))
57 "[ 10, 20 ].toString();")
59 (test-ps-js method-call-fn-call
63 (test-ps-js method-call-lambda-fn
64 ((@ (lambda () (alert 10)) to-string
))
65 "( function () { return alert(10); } ).toString();")
67 (test-ps-js method-call-lambda-call
68 ((@ ((lambda (x) (return x
)) 10) to-string
))
69 "(function (x) { return x; })(10).toString();")
71 (test no-whitespace-before-dot
72 (let* ((str (ps* '((@ ((lambda (x) (return x
)) 10) to-string
))))
73 (dot-pos (position #\. str
:test
#'char
=))
74 (char-before (elt str
(1- dot-pos
)))
76 (is (char= char-before a-parenthesis
))))
78 (test-ps-js simple-getprop
79 (let ((foo (create a
1)))
80 (alert (getprop foo
'a
)))
84 (test-ps-js buggy-getprop
85 (let ((foo (create a
1))
87 (alert (getprop foo slot-name
)))
88 " var foo = { a : 1 };
91 "); Last line was alert(foo.slotName) before bug-fix.
93 (test-ps-js buggy-getprop-two
94 (getprop foo
(get-slot-name))
95 "foo[getSlotName()];")
97 (test-ps-js old-case-is-now-switch
98 ;; Switch was "case" before, but that was very non-lispish.
99 ;; For example, this code makes three messages and not one
100 ;; which may have been expected. This is because a switch
101 ;; statment must have a break statement for it to return
102 ;; after the alert. Otherwise it continues on the next
104 (switch (aref blorg i
)
107 (default (alert "default clause")))
109 case 1: alert('one');
110 case 2: alert('two');
111 default: alert('default clause');
114 (test-ps-js lisp-like-case
118 (default (alert "default clause")))
126 default: alert('default clause');
130 (test-ps-js even-lispier-case
132 ((1 2) (alert "Below three"))
134 (t (alert "Something else")))
138 alert('Below three');
143 default: alert('Something else');
146 (test-ps-js otherwise-case
149 (otherwise (alert "default clause")))
154 default: alert('default clause');
157 (test escape-sequences-in-string
158 (let ((escapes `((#\\ .
#\\)
160 (#\f .
,(code-char 12))
161 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
164 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
166 ("u001F" .
,(code-char #x001f
));; character below 32
167 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
168 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
169 (loop for
(js-escape . lisp-char
) in escapes
170 for generated
= (ps-doc* `(let ((x ,(format nil
"hello~ahi" lisp-char
)))))
171 for wanted
= (format nil
"var x = 'hello\\~ahi';" js-escape
)
172 do
(is (string= (normalize-js-code generated
) wanted
)))))
174 (test-ps-js getprop-setf
175 (setf (getprop x
'y
) (+ (+ a
3) 4))
176 "x.y = (a + 3) + 4;")
178 (test-ps-js getprop-conditional1
179 (getprop (if zoo foo bar
) 'x
)
180 "(zoo ? foo : bar).x;")
182 (test-ps-js getprop-conditional2
183 (getprop (if (not zoo
) foo bar
) 'x
)
184 "(!zoo ? foo : bar).x;")
186 (test script-star-eval1
187 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x
1) '(setf y
2))))))
189 (test script-star-eval2
190 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x
1))))))
192 (test-ps-js list-with-single-nil
196 (test-ps-js quoted-nil-is-array
201 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
206 setBaz(_js2, _js3, _js1);")
208 (test-ps-js setf-macroexpands1
209 (macrolet ((bar (x y
)
211 (setf (bar foo
2) 3))
214 (test-ps-js defsetf-short
215 (progn (defsetf baz set-baz
"docstring")
216 (setf (baz 1 2 3) "foo"))
217 "setBaz(1, 2, 3, 'foo');")
219 (test-ps-js defun-setf1
220 (progn (defun (setf some-thing
) (new-val i1 i2
)
221 (setf (aref *some-thing
* i1 i2
) new-val
))
222 (setf (some-thing 1 2) "foo"))
223 "function __setf_someThing(newVal, i1, i2) {
224 return SOMETHING[i1][i2] = newVal;
226 __setf_someThing('foo', 1, 2);")
228 (test-ps-js defun-optional1
229 (defun test-opt (&optional x
)
231 "function testOpt(x) {
232 if (x === undefined) {
242 (test-ps-js defun-optional2
243 (defun foo (x &optional y
)
245 "function foo(x, y) {
246 if (y === undefined) {
252 (test-ps-js defun-optional3
253 (defun blah (&optional
(x 0))
256 if (x === undefined) {
262 (test-ps-js return-nothing
266 (test-ps-js set-timeout
267 (do-set-timeout (10) (alert "foo"))
268 "setTimeout(function () { return alert('foo'); }, 10);")
270 (test-ps-js operator-precedence
274 (test-ps-js operators-1
294 (test-ps-js setf-conditional
295 (setf foo
(if x
1 2))
298 (test-ps-js obj-literal-numbers
302 (test-ps-js obj-literal-strings
306 (test-ps-js getprop-string
310 (test-ps-js getprop-string1
311 (getprop "bar" 'length
)
314 (test-ps-js getprop-progn
315 (getprop (progn (some-fun "abc") "123") "length")
316 "(someFun('abc'), '123')['length'];")
318 (test-ps-js method-call-block
319 ((@ (progn (some-fun "abc") "123") to-string
))
320 "(someFun('abc'), '123').toString();")
322 (test-ps-js create-blank
326 (test-ps-js blank-object-literal
330 (test-ps-js array-literal1
334 (test-ps-js array-literal2
338 (test-ps-js array-literal3
342 (test-ps-js array-literal4
346 (test-ps-js array-literal5
348 "[[1, 2], ['a', 'b']];")
350 (test-ps-js defun-rest1
351 (defun foo (&rest bar
)
352 (alert (aref bar
1)))
355 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
356 bar[i1] = arguments[i1 + 0];
358 return alert(bar[1]);
361 (test-ps-js defun-rest2
362 (defun foo (baz &rest bar
) (return (+ baz
(aref bar
1))))
365 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
366 bar[i1] = arguments[i1 + 1];
371 (test-ps-js defun-keyword1
372 (defun zoo (foo bar
&key baz
) (return (+ foo bar baz
)))
373 "function zoo(foo, bar) {
375 var _js2 = arguments.length;
376 for (var n1 = 2; n1 < _js2; n1 += 2) {
377 switch (arguments[n1]) {
379 baz = arguments[n1 + 1];
382 if (baz === undefined) {
385 return foo + bar + baz;
388 (test-ps-js defun-keyword2
389 (defun zoo (&key baz
) (return (* baz baz
)))
392 var _js2 = arguments.length;
393 for (var n1 = 0; n1 < _js2; n1 += 2) {
394 switch (arguments[n1]) {
396 baz = arguments[n1 + 1];
399 if (baz === undefined) {
405 (test-ps-js defun-keyword3
406 (defun zoo (&key baz
(bar 4)) (return (* baz bar
)))
410 var _js2 = arguments.length;
411 for (var n1 = 0; n1 < _js2; n1 += 2) {
412 switch (arguments[n1]) {
414 baz = arguments[n1 + 1];
417 bar = arguments[n1 + 1];
420 if (baz === undefined) {
423 if (bar === undefined) {
429 (test-ps-js defun-keyword4
430 (defun hello-world (&key
((:my-name-key my-name
) 1))
432 "function helloWorld() {
434 var _js2 = arguments.length;
435 for (var n1 = 0; n1 < _js2; n1 += 2) {
436 switch (arguments[n1]) {
438 myName = arguments[n1 + 1];
441 if (myName === undefined) {
447 (test-ps-js keyword-funcall1
451 (test-ps-js keyword-funcall2
452 (func :baz
1 :bar foo
)
453 "func('baz', 1, 'bar', foo);")
455 (test-ps-js keyword-funcall3
457 "fun(a, b, 'baz', c);")
467 ((= y
(* x
4)) (foo "blah") (* x y
)))
470 } else if (y == x * 4) {
475 (test-ps-js if-exp-without-else-return
481 (test-ps-js progn-expression-single-statement
482 (return (progn (* x y
)))
485 (test-ps-js cond-expression1
487 (cond ((< 1 2) (bar "foo") (* 4 5))))
495 (test-ps-js cond-expression2
497 (cond ((< 2 1) "foo")
507 (test-ps-js cond-expression-final-t-clause
509 (cond ((< 1 2) (bar "foo") (* 4 5))
522 } else if ((_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5)) {
529 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
542 (test-ps-js funcall-if-expression
544 (if (= *linkornot
* 1)
545 (ps-html ((:a
:href
"#"
546 :onclick
(ps-inline (transport)))
549 "document.write(LINKORNOT == 1 ? '<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport()') + '\">' + img + '</A>' : img);")
551 (test-ps-js negate-number-literal
555 (test macro-environment1
556 (is (string= (normalize-js-code (let* ((macroname (gensym)))
557 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
559 (macrolet ((,macroname
(x) `(aref data
,x
)))
561 (setf (,macroname x
) 123)))))))
565 return data[x] = 123;
569 (test macro-environment2
570 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
571 (defpsmacro macro-environment2-macro
(x)
572 `(+ ,outer-lexical-variable
,x
))
573 (ps* '(macro-environment2-macro 2))))
574 (normalize-js-code "1 + 2;"))))
576 (test-ps-js ampersand-whole-1
577 (macrolet ((foo (&whole foo bar baz
)
578 (declare (ignore bar baz
))
579 (format nil
"~a" foo
)))
583 (test-ps-js keyword-consistent
587 (test-ps-js simple-symbol-macrolet
588 (symbol-macrolet ((x 1)) x
)
591 (test-ps-js compound-symbol-macrolet
592 (symbol-macrolet ((x 123)
597 (test-ps-js define-symbol-macro
598 (progn (define-symbol-macro tst-sym-macro
2)
602 (test-ps-js define-symbol-macro1
603 (progn (define-symbol-macro tst-sym-macro1
2)
604 (foo tst-sym-macro1
))
607 (test-ps-js expression-progn
608 (1+ (progn (foo) (if x
1 2)))
609 "(foo(), x ? 1 : 2) + 1;")
611 (test-ps-js let-decl-in-expression
613 (if x
1 (let* ((foo x
))
624 (test-ps-js special-var1
625 (progn (defvar *foo
*)
638 (test-ps-js special-var2
639 (progn (defvar *foo
*)
662 (test-ps-js setf-dec1
666 (test-ps-js setf-dec2
670 (test-ps-js special-char-equals
674 (test-ps-js setf-operator-priority
675 (return (or (getprop cache id
)
676 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
677 "return cache[id] || (cache[id] = document.getElementById(id));")
679 (test-ps-js aref-operator-priority
680 (aref (if (and x
(> (length x
) 0))
684 "(x && x.length > 0 ? x[0] : y)[z];")
686 (test-ps-js aref-operator-priority1
687 (aref (or (getprop x
'y
)
692 (test-ps-js aref-operator-priority2
696 (test-ps-js negative-operator-priority
705 (delete (if a
(or b c
) d
))
706 "delete (a ? b || c : d);")
709 (not (if (or x
(not y
)) z
))
710 "!(x || !y ? z : null);")
717 (instanceof (or a b
) (if x y z
))
718 "((a || b) instanceof (x ? y : z));")
721 (or x
(if (= x
0) "zero" "empty"))
722 "x || (x == 0 ? 'zero' : 'empty');")
724 (test-ps-js named-op-expression
728 (test-ps-js named-op-expression1
732 (test-ps-js aref-array-expression
736 (test-ps-js getprop-operator
737 (getprop (or a b c
) 'd
)
740 (test-ps-js getprop-parens
741 (getprop (getprop foo
'bar
) 'baz
)
744 (test-ps-js funcall-funcall
748 (test-ps-js expression-funcall
749 ((or (@ window eval
) eval
) foo nil
)
750 "(window.eval || eval)(foo, null);")
752 (test-ps-js expression-funcall1
753 (((or (@ window eval
) eval
) foo nil
))
754 "(window.eval || eval)(foo, null)();")
756 (test-ps-js expression-funcall2
757 (((or (@ window eval
) eval
)) foo nil
)
758 "(window.eval || eval)()(foo, null);")
760 (test-ps-js getprop-object-literal
761 (getprop (create a
1) 'a
)
764 (test-ps-js getprop-lambda
765 (getprop (lambda ()) 'prototype
)
766 "(function () { return null; }).prototype;")
768 (test-ps-js who-html1
769 (who-ps-html (:span
:class
"ticker-symbol"
770 :ticker-symbol symbol
771 (:a
:href
"http://foo.com"
773 (:span
:class
"ticker-symbol-popup")))
774 "'<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"' + symbol + '\"><A HREF=\"http://foo.com\">' + symbol + '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>';")
777 ((lambda () (flet ((foo (x)
781 var foo = function (x) {
788 (flet ((foo (x) (return (1+ x
)))
789 (bar (y) (return (+ 2 y
))))
791 "var foo = function (x) {
794 var bar = function (y) {
800 (flet ((foo (x) (+ 2 x
)))
801 (flet ((foo (x) (1+ x
))
802 (bar (y) (+ 2 (foo y
))))
804 "var foo = function (x) {
807 var foo1 = function (x) {
810 var bar = function (y) {
816 ((lambda () (labels ((foo (x)
819 (+ x
(foo (1- x
))))))
822 var foo = function (x) {
826 return x + foo(x - 1);
833 (labels ((foo (x) (return (1+ (bar x
))))
834 (bar (y) (return (+ 2 (foo y
)))))
836 "var foo = function (x) {
839 var bar = function (y) {
845 (labels ((foo (x) (return (1+ x
)))
846 (bar (y) (return (+ 2 (foo y
)))))
848 "var foo = function (x) {
851 var bar = function (y) {
856 (test-ps-js for-loop-var-init-exp
858 (return (do* ((y (if x
0 1) (1+ y
))
863 return (function () {
864 for (var y = x ? 0 : 1, z = 0; y != 3; y += 1, z += 1) {
874 (test-ps-js literal-array
878 (test-ps-js literal-array-1
882 (test ps-lisp-expands-in-lexical-environment
883 (is (string= "5;" (let ((x 5)) (ps (lisp x
))))))
885 (test ps
*-lisp-expands-in-null-lexical-environment
886 (signals error
(let ((x 5)) (declare (ignore x
)) (ps* '(lisp x
)))))
888 (test ps
*-lisp-expands-in-dynamic-environment
889 (is (string= "1 + 2;" (let ((*print-level
* 2)) (ps* '(+ 1 (lisp *print-level
*)))))))
891 (test ps-lisp-dynamic-environment
892 (is (string= "1 + 2;" (let ((*print-level
* 2)) (ps (+ 1 (lisp *print-level
*)))))))
894 (test-ps-js ps-js-target-version-keyword-test1
895 (defun foo (x y
&key bar baz
))
896 "function foo(x, y) {
898 var x1 = Array.prototype.indexOf.call(arguments, 'bar', 2);
899 var bar = -1 == x1 ? null : arguments[x1 + 1];
900 var x2 = Array.prototype.indexOf.call(arguments, 'baz', 2);
901 return baz = -1 == x2 ? null : arguments[x2 + 1];
903 :js-target-version
1.6)
905 (test-ps-js nested-if-expressions1
906 (return (if (if x y z
) a b
))
913 (test-ps-js nested-if-expressions2
914 (return (if x y
(if z a b
)))
1024 (test-ps-js symbol-macrolet-var
1025 (symbol-macrolet ((x y
))
1029 (test-ps-js setf-conditional1
1030 (setf x
(unless (null a
) (1+ a
)))
1031 "x = a != null ? a + 1 : null;")
1033 (test-ps-js setf-let1
1034 (setf x
(let ((a 1)) a
))
1037 (test-ps-js setf-let2
1038 (setf x
(let ((a (foo)))
1041 "x = (a = foo(), a != null ? a + 1 : null);")
1043 (test-ps-js symbol-macro-env1
1044 (symbol-macrolet ((bar 1))
1045 (macrolet ((bar (x y
) `(+ ,x
,y
)))
1049 (test-ps-js symbol-macrolet-fun1
1050 (symbol-macrolet ((baz +))
1054 (test-ps-js lisp2-namespaces1
1056 (setf list
(list 1 2 3)))
1060 (test-ps-js let-shadows-symbol-macrolet
1061 (symbol-macrolet ((x y
))
1069 (test-ps-js let-rename-optimization1
1075 (test-ps-js let-rename-optimization2
1084 (test-ps-js symbol-macro-array
1085 (symbol-macrolet ((x 1))
1089 (test-ps-js symbol-macro-obj
1090 (symbol-macrolet ((x y
))
1094 (test-ps-js symbol-macro-conditional1
1095 (symbol-macrolet ((x y
))
1103 (test-ps-js symbol-macro-conditional2
1104 (symbol-macrolet ((x y
))
1105 (return (if x x x
)))
1112 (test-ps-js flet-apply
1113 (flet ((foo () 'bar
))
1114 (apply (function foo
) nil
))
1115 "var foo = function () {
1118 foo.apply(this, null);")
1120 (test-ps-js let-apply
1121 (let ((foo (lambda () (return 1))))
1122 (let ((foo (lambda () (return 2))))
1124 "var foo = function () {
1127 var foo1 = function () {
1130 foo1.apply(this, null);")
1132 (test-ps-js flet-let
1133 (flet ((x (x) (return (1+ x
))))
1136 "var x = function (x) {
1142 (test-ps-js let-flet
1144 (flet ((x (x) (return (1+ x
))))
1147 var x1 = function (x) {
1152 (test-ps-js labels-let
1153 (labels ((x (x) (return (1+ x
))))
1156 "var x = function (x) {
1162 (test-ps-js let-labels
1164 (labels ((x (x) (return (1+ x
))))
1167 var x1 = function (x) {
1172 (test-ps-js macrolet-let-inteference
1173 (macrolet ((a (n) `(+ ,n
5)))
1175 (let ((b (a (- a
4))))
1178 var b = (a - 4) + 5;
1181 (test-ps-js let-subtract-add
1195 (test-ps-js create-reserved-word
1197 "{ 'default' : 1 };")
1199 (test-ps-js getprop-reserved-word
1200 (getprop foo
:default
)
1203 (test-ps-js eval-when-ps-side
1204 (eval-when (:execute
)
1208 (defvar *lisp-output
* nil
)
1210 (test eval-when-lisp-side
()
1211 (setf *lisp-output
* 'original-value
)
1212 (let ((js-output (normalize-js-code
1213 (ps-doc* `(eval-when (:compile-toplevel
)
1214 (setf *lisp-output
* 'it-works
))))))
1215 (is (eql 'it-works
*lisp-output
*))
1216 (is (string= "" js-output
))))
1218 (defpsmacro my-in-package
(package-name)
1219 `(eval-when (:compile-toplevel
)
1220 (setf *lisp-output
* ,package-name
)))
1222 (test eval-when-macro-expansion
()
1223 (setf *lisp-output
* 'original-value
)
1224 (let ((js-output (normalize-js-code
1226 (my-in-package :cl-user
)
1228 (declare (ignore js-output
))
1229 (is (eql :cl-user
*lisp-output
*))))
1231 (test eval-when-macrolet-expansion
()
1232 (setf *lisp-output
* 'original-value
)
1233 (let ((js-output (normalize-js-code
1234 (ps-doc* `(macrolet ((my-in-package2 (package-name)
1235 `(eval-when (:compile-toplevel
)
1236 (setf *lisp-output
* ,package-name
))))
1237 (my-in-package2 :cl-user
)
1239 (declare (ignore js-output
))
1240 (is (eql :cl-user
*lisp-output
*))))
1242 (test-ps-js getprop-keyword
1246 (test-ps-js nary-comparison1
1247 (lambda () (return (< 1 2 3)))
1250 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
1253 (test-ps-js chain-getprop1
1254 (chain ($
"foo") (bar x z
) frob
(baz 5))
1255 "$('foo').bar(x, z).frob.baz(5);")
1257 (test-ps-js chain-getprop2
1258 (chain ($
"foo") bar baz
)
1259 "$('foo').bar.baz;")
1261 (test-ps-js chain-getprop3
1262 (chain ($
"foo") bar
(x y
) baz
)
1263 "$('foo').bar.x(y).baz;")
1265 (test-ps-js flet-expression
1266 (1+ (flet ((foo (x) (1+ x
)))
1268 "(foo = function (x) {
1272 (test-ps-js return-case-break-elimination
1283 (test-ps-js aplusplus
1287 (test-ps-js astarstar
1291 (test-ps-js switch-return-fallthrough
1306 (test-ps-js return-last-case
1318 (test-ps-js return-macrolet
1320 (macrolet ((x () 1))
1331 (test-ps-js mv-bind1
1332 (multiple-value-bind (a b
)
1339 var prevmv2 = arguments['callee']['mv'];
1341 arguments['callee']['mv'] = true;
1343 var mv1 = typeof arguments['callee']['mv'] == 'object' ? arguments['callee']['mv'] : new Array(1);
1348 if (undefined === prevmv2) {
1349 delete arguments['callee']['mv'];
1351 arguments['callee']['mv'] = prevmv2;
1356 (lambda () (values))
1369 if (undefined !== arguments['callee']['caller']['mv']) {
1370 arguments['callee']['caller']['mv'] = valrest2;
1377 var valrest2 = [y, z];
1378 if (undefined !== arguments['callee']['caller']['mv']) {
1379 arguments['callee']['caller']['mv'] = valrest2;
1383 (test-ps-js values-return
1384 (return (values x y
))
1387 if (undefined !== arguments['callee']['caller']['mv']) {
1388 arguments['callee']['caller']['mv'] = valrest2;
1392 (test-ps-js return-macrolet
1394 (symbol-macrolet ((x 2))
1401 (test-ps-js return-cond
1403 (cond ((foo? x
) (loop for y in x do
(foo y
)))
1407 var _js2 = x.length;
1421 } else if (barwhat(x)) {
1427 (test-ps-js switch-loop
1432 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
1437 (test-ps-js switch-folds-blocks
1439 (1 (loop repeat
3 do
(alert "foo"))))
1442 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
1448 (test-ps-js setf-places-before-macros
1450 (defsetf left
(el) (offset)
1451 `(setf (@ ,el style left
) ,offset
))
1452 (macrolet ((left (el)
1453 `(@ ,el offset-left
)))
1458 _js2.style.left = _js1;
1461 (test-ps-js for-return
1462 (return (dolist (arg args
) (foo arg
)))
1463 "for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
1464 arg = args[_js_idx1];
1468 (test-ps-js try-catch-return
1482 (test-ps-js defun-setf-optional
1483 (defun (setf foo
) (new-value b
&optional c
)
1484 (setf (aref b
(or c
0)) new-value
))
1485 "function __setf_foo(newValue, b, c) {
1486 if (c === undefined) {
1489 return b[c || 0] = newValue;
1492 (test-ps-js defun-setf-rest
1493 (progn (defun (setf foo
) (new-value b
&rest foo
)
1494 (do-something b foo new-value
))
1495 (setf (foo x
1 2 3 4) 5))
1496 "function __setf_foo(newValue, b) {
1498 for (var i1 = 0; i1 < arguments.length - 2; i1 += 1) {
1499 foo[i1] = arguments[i1 + 2];
1501 return doSomething(b, foo, newValue);
1503 __setf_foo(5, x, 1, 2, 3, 4);")
1505 (test-ps-js return-null
1509 (test-ps-js implicit-return-null
1516 (test-ps-js implicit-return-null
1523 (test-ps-js return-conditional-neste
1524 (defun blep (ss x y
)
1528 (destructuring-bind (a b
) pair
1529 (unless (or (null a
) (null b
))
1530 (let ((val (baz a b
)))
1535 "function blep(ss, x, y) {
1541 if (!(a == null || b == null)) {
1542 var val = baz(a, b);
1555 (test-ps-js return-case-conditional
1558 (123 (when (bar) t
))
1571 (test-ps-js return-try-conditional
1588 (test-ps-js function-declare-special
1590 (declare (special *foo
*))
1596 FOO_TMPSTACK1 = FOO;
1600 FOO = FOO_TMPSTACK1;
1604 (test-ps-js declare-special-let
1606 (declare (special *foo
*))
1610 FOO_TMPSTACK1 = FOO;
1614 FOO = FOO_TMPSTACK1;
1617 (test-ps-js macro-null-toplevel
1619 (defmacro macro-null-toplevel
()
1621 (macro-null-toplevel))
1624 (test-ps-js define-symbol-macro-let
1626 (define-symbol-macro test-symbol-macro
1)
1627 (let ((test-symbol-macro 2))
1628 (1+ test-symbol-macro
))
1629 (1+ test-symbol-macro
))
1630 "var testSymbolMacro1 = 2;
1631 testSymbolMacro1 + 1;
1634 (test-ps-js define-symbol-macro-flet
1636 (define-symbol-macro test-symbol-macro1
1)
1637 (flet ((test-symbol-macro1 () 2))
1638 (1+ test-symbol-macro1
)
1639 (test-symbol-macro1))
1640 (1+ test-symbol-macro1
))
1641 "var testSymbolMacro1_1 = function () {
1645 testSymbolMacro1_1();
1648 (test compile-stream-nulls
1651 (with-input-from-string (s "
1652 (defmacro macro-null-toplevel ()
1654 (macro-null-toplevel)")
1655 (ps-compile-stream s
)))))