1 ;; Copying and distribution of this file, with or without
2 ;; modification, are permitted in any medium without royalty. This
3 ;; file is offered as-is, without any warranty.
6 (named-readtables:in-readtable
:parenscript
)
8 (in-suite output-tests
)
10 (test-ps-js statements-and-expressions-1
14 (test-ps-js statements-and-expressions-2
22 (test-ps-js symbol-conversion-1
24 "bangwhathashatpercent;")
26 (test-ps-js symbol-conversion-2
30 (test-ps-js symbol-conversion-3
34 (test-ps-js symbol-conversion-4
38 (test-ps-js symbol-conversion-5
40 "encodeURIComponent;")
42 (test-ps-js symbol-conversion-6
46 (test-ps-js number-literals-1
50 (test-ps-js number-literals-2
54 (test-ps-js number-literals-3
58 (test-ps-js string-literals-1
62 (test-ps-js string-literals-2
66 (test-ps-js string-literals-3
70 (test-ps-js array-literals-1
74 (test-ps-js array-literals-2
78 (test-ps-js array-literals-3
80 (array "foobar" "bratzel bub"))
81 "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ];")
83 (test-ps-js array-literals-4
87 (test-ps-js array-literals-5
89 "new Array(1, 2, 3);")
91 (test-ps-js array-literals-6
94 (make-array "foobar" "bratzel bub"))
95 "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'));")
97 (test-ps-js object-literals-1
98 (create foo
"bar" :blorg
1)
99 "({ foo : 'bar', 'blorg' : 1 });")
101 (test-ps-js object-literals-2
104 another-object
(create :schtrunz
1))
107 anotherObject : { 'schtrunz' : 1 } });")
109 (test-ps-js object-literals-3
110 (getprop an-object
'foo
)
113 (test-ps-js object-literals-4
114 (@ an-object foo bar
)
117 (test-ps-js object-literals-5
118 (with-slots (a b c
) this
120 "this.a + this.b + this.c;")
122 (test-ps-js regular-expression-literals-1
126 (test-ps-js regular-expression-literals-2
130 (test-ps-js literal-symbols-1
134 (test-ps-js literal-symbols-2
138 (test-ps-js literal-symbols-3
142 (test-ps-js literal-symbols-4
148 (test-ps-js literal-symbols-5
152 (test-ps-js literal-symbols-6
156 (test-ps-js variables-1
160 (test-ps-js variables-2
164 (test-ps-js variables-3
168 (test-ps-js function-calls-and-method-calls-1
172 (test-ps-js function-calls-and-method-calls-2
173 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
174 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ]);")
176 (test-ps-js function-calls-and-method-calls-3
177 ((getprop this
'blorg
) 1 2)
180 (test-ps-js function-calls-and-method-calls-4
184 (test-ps-js function-calls-and-method-calls-5
185 ((getprop (aref foobar
1) 'blorg
) nil t
)
186 "foobar[1].blorg(null, true);")
188 (test-ps-js operator-expressions-1
192 (test-ps-js operator-expressions-2
196 (test-ps-js operator-expressions-3
197 (* 1 (+ 2 3 4) 4 (/ 6 7))
198 "1 * (2 + 3 + 4) * 4 * (6 / 7);")
200 (test-ps-js operator-expressions-4
204 (test-ps-js operator-expressions-5
208 (test-ps-js operator-expressions-6
212 (test-ps-js operator-expressions-7
216 (test-ps-js operator-expressions-8
220 (test-ps-js body-forms-1
221 (progn (blorg i
) (blafoo i
))
225 (test-ps-js body-forms-2
226 (+ i
(progn (blorg i
) (blafoo i
)))
227 "i + (blorg(i), blafoo(i));")
229 (test-ps-js function-definition-1
230 (defun a-function (a b
)
232 "function aFunction(a, b) {
236 (test-ps-js lambda-definition-2
237 (lambda (a b
) (+ a b
))
242 (test-ps-js assignment-1
246 (test-ps-js assignment-2
247 (setf a
2 b
3 c
4 x
(+ a b c
))
253 (test-ps-js assignment-3
254 (setf a
(+ a
2 3 4 a
))
255 "a = a + 2 + 3 + 4 + a;")
257 (test-ps-js assignment-4
261 (test-ps-js assignment-5
273 (test-ps-js assignment-6
277 (test-ps-js assignment-8
279 (defun (setf color
) (new-color el
)
280 (setf (getprop (getprop el
'style
) 'color
) new-color
))
281 (setf (color some-div
) (+ 23 "em")))
282 "function __setf_color(newColor, el) {
283 return el.style.color = newColor;
285 __setf_color(23 + 'em', someDiv);")
287 (test-ps-js assignment-10
289 (defsetf left
(el) (offset)
290 `(setf (getprop (getprop ,el
'style
) 'left
) ,offset
))
291 (setf (left some-div
) (+ 123 "px")))
294 var _js1 = 123 + 'px';
295 return _js2.style.left = _js1;
298 (test-ps-js assignment-12
299 (macrolet ((left (el)
300 `(getprop ,el
'offset-left
)))
302 "someDiv.offsetLeft;")
304 (test-ps-js nil-block-return-1
310 (test-ps-js single-argument-statements-2
314 (test-ps-js single-argument-expression-1
315 (delete (new (*foobar
2 3 4)))
316 "delete new Foobar(2, 3, 4);")
318 (test-ps-js single-argument-expression-2
319 (if (= (typeof blorg
) *string
)
320 (alert (+ "blorg is a string: " blorg
))
321 (alert "blorg is not a string"))
322 "if (typeof blorg === String) {
323 alert('blorg is a string: ' + blorg);
325 alert('blorg is not a string');
328 (test-ps-js conditional-statements-1
330 (if ((@ blorg is-correct
))
331 (progn (carry-on) (return-from foo i
))
332 (alert "blorg is not correct!")))
334 if (blorg.isCorrect()) {
338 return alert('blorg is not correct!');
342 (test-ps-js conditional-statements-2
343 (+ i
(if ((@ blorg add-one
)) 1 2))
344 "i + (blorg.addOne() ? 1 : 2);")
346 (test-ps-js conditional-statements-3
348 (when ((@ blorg is-correct
))
350 (return-from foo i
)))
352 if (blorg.isCorrect()) {
358 (test-ps-js conditional-statements-4
359 (unless ((@ blorg is-correct
))
360 (alert "blorg is not correct!"))
361 "if (!blorg.isCorrect()) {
362 alert('blorg is not correct!');
365 (test-ps-js variable-declaration-1
366 (defvar *a
* (array 1 2 3))
367 "var A = [ 1, 2, 3 ];")
369 (test-ps-js variable-declaration-2
370 (progn (defvar *a
* 4)
391 (test-ps-js iteration-constructs-1
392 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
394 (e (aref c d
) (aref c d
)))
395 ((or (= d
(@ c length
)) (string= e
"x")))
397 (funcall (@ document write
) (+ "a: " a
" b: " b
"<br/>")))
398 "for (var a = null, b = null, c = ['a', 'b', 'c', 'd', 'e'], d = 0, e = c[d]; !(d === c.length || e === 'x'); d += 1, e = c[d]) {
401 document.write('a: ' + a + ' b: ' + b + '<br/>');
404 (test-ps-js iteration-constructs-2
406 (s 0 (+ s i
(1+ i
))))
408 (funcall (@ document write
) (+ "i: " i
" s: " s
"<br/>")))
413 document.write('i: ' + i + ' s: ' + s + '<br/>');
415 var _js2 = s + i + i + 1;
421 (test-ps-js iteration-constructs-3
423 (s 0 (+ s i
(1- i
))))
425 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
426 "for (var i = 0, s = 0; i <= 10; i += 1, s = s + i + (i - 1)) {
427 document.write('i: ' + i + ' s: ' + s + '<br/>');
430 (test-ps-js iteration-constructs-4
431 (let ((arr (array "a" "b" "c" "d" "e")))
432 (dotimes (i (@ arr length
))
433 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
435 var arr = ['a', 'b', 'c', 'd', 'e'];
436 for (var i = 0; i < arr.length; i += 1) {
437 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
441 (test-ps-js iteration-constructs-5
443 (alert (+ "Summation to 10 is "
445 (incf res
(1+ i
))))))
448 return alert('Summation to 10 is ' + (function () {
449 for (var i = 0; i < 10; i += 1) {
456 (test-ps-js iteration-constructs-6
457 (let ((l (list 1 2 4 8 16 32)))
459 ((@ document write
) (+ "c: " c
"<br/>"))))
461 var l = [1, 2, 4, 8, 16, 32];
462 for (var c = null, _js_idx1 = 0; _js_idx1 < l.length; _js_idx1 += 1) {
464 document.write('c: ' + c + '<br/>');
468 (test-ps-js iteration-constructs-7
469 (let ((l '(1 2 4 8 16 32))
471 (alert (+ "Sum of " l
" is: "
475 var l = [1, 2, 4, 8, 16, 32];
477 return alert('Sum of ' + l + ' is: ' + (function () {
478 for (var c = null, _js_idx1 = 0; _js_idx1 < l.length; _js_idx1 += 1) {
486 (test-ps-js iteration-constructs-8
487 (let ((obj (create a
1 b
2 c
3)))
489 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
491 var obj = { a : 1, b : 2, c : 3 };
493 document.write(i + ': ' + obj[i] + '<br/>');
497 (test-ps-js iteration-constructs-9
498 (while ((@ film is-not-finished
))
499 ((@ this eat
) (new *popcorn
)))
500 "while (film.isNotFinished()) {
501 this.eat(new Popcorn);
504 (test-ps-js the-case-statement-1
506 ((1 "one") (alert "one"))
508 (t (alert "default clause")))
518 alert('default clause');
521 (test-ps-js the-case-statement-2
522 (switch (aref blorg i
)
523 (1 (alert "If I get here"))
524 (2 (alert "I also get here"))
525 (default (alert "I always get here")))
527 case 1: alert('If I get here');
528 case 2: alert('I also get here');
529 default: alert('I always get here');
532 (test-ps-js the-try-statement-1
535 (alert (+ "an error happened: " error
)))
537 (alert "Leaving the try form")))
541 alert('an error happened: ' + error);
543 alert('Leaving the try form');
546 (test-ps-js the-html-generator-1
547 (ps-html ((:a
:href
"foobar") "blorg"))
548 "'<A HREF=\"foobar\">blorg</A>';")
550 (test-ps-js the-html-generator-2
551 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
552 "['<A HREF=\"', generateALink(), '\">blorg</A>']['join']('');")
554 (test-ps-js the-html-generator-3
555 (funcall (getprop document
'write
)
556 (ps-html ((:a
:href
"#"
557 :onclick
(ps-inline (transport))) "link")))
558 "document.write(['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">link</A>']['join'](''));")
560 (test-ps-js the-html-generator-4
563 (setf (getprop element
'inner-h-t-m-l
)
564 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
568 var authorized = true;
569 return element.innerHTML = ['<TEXTAREA', disabled || !authorized ? [' DISABLED=\"', 'disabled', '\"']['join']('') : '', '>Edit me</TEXTAREA>']['join']('');
572 (test-ps-js plus-is-not-commutative
573 (setf x
(+ "before" x
"after"))
574 "x = 'before' + x + 'after';")
576 (test-ps-js plus-works-if-first
577 (setf x
(+ x
"middle" "after"))
578 "x = x + 'middle' + 'after';")
580 (test-ps-js setf-side-effects
586 (setf x
(+ 2 (side-effect) x
5))))
589 function sideEffect() {
593 return x = 2 + sideEffect() + x + 5;
596 (test-ps-js method-call-op-form
597 (funcall (getprop (+ "" x
) 'to-string
))
598 "('' + x).toString();")
600 (test-ps-js method-call-op-form-args
601 (funcall (getprop (+ "" x
) 'foo
) 1 2 :baz
3)
602 "('' + x).foo(1, 2, 'baz', 3);")
604 (test-ps-js method-call-string
605 ((getprop "hi" 'to-string
))
608 (test-ps-js method-call-conditional
612 (test-ps-js method-call-variable
616 (test-ps-js method-call-array
617 ((@ (list 10 20) to-string
))
618 "[ 10, 20 ].toString();")
620 (test-ps-js method-call-lambda-call
621 (funcall (getprop (funcall (lambda (x) x
) 10) 'to-string
))
622 "(function (x) { return x; })(10).toString();")
624 (test no-whitespace-before-dot
625 (let* ((str (ps* '((@ ((lambda (x) x
) 10) to-string
))))
626 (dot-pos (position #\. str
:test
#'char
=))
627 (char-before (elt str
(1- dot-pos
)))
629 (is (char= char-before a-parenthesis
))))
631 (test-ps-js simple-getprop
632 (let ((foo (create a
1)))
633 (alert (getprop foo
'a
)))
639 (test-ps-js buggy-getprop
640 (getprop foo slot-name
)
643 (test-ps-js buggy-getprop-two
644 (getprop foo
(get-slot-name))
645 "foo[getSlotName()];")
647 (test-ps-js old-case-is-now-switch
648 ;; Switch was "case" before, but that was very non-lispish.
649 ;; For example, this code makes three messages and not one
650 ;; which may have been expected. This is because a switch
651 ;; statment must have a break statement for it to return
652 ;; after the alert. Otherwise it continues on the next
654 (switch (aref blorg i
)
657 (default (alert "default clause")))
659 case 1: alert('one');
660 case 2: alert('two');
661 default: alert('default clause');
664 (test-ps-js lisp-like-case
668 (default (alert "default clause")))
676 default: alert('default clause');
680 (test-ps-js even-lispier-case
682 ((1 2) (alert "Below three"))
684 (t (alert "Something else")))
688 alert('Below three');
693 default: alert('Something else');
696 (test-ps-js otherwise-case
699 (otherwise (alert "default clause")))
704 default: alert('default clause');
707 (test escape-sequences-in-string
708 (let ((escapes `((#\\ .
#\\)
710 (#\f .
,(code-char 12))
711 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
714 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
716 ("u001F" .
,(code-char #x001f
));; character below 32
717 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
718 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
719 (loop for
(js-escape . lisp-char
) in escapes
720 for generated
= (ps-doc* (format nil
"hello~ahi" lisp-char
))
721 for wanted
= (format nil
"'hello\\~ahi';" js-escape
)
722 do
(is (string= (normalize-js-code generated
) wanted
)))))
724 (test-ps-js getprop-setf
725 (setf (getprop x
'y
) (+ (+ a
3) 4))
728 (test-ps-js getprop-conditional1
729 (getprop (if zoo foo bar
) 'x
)
730 "(zoo ? foo : bar).x;")
732 (test-ps-js getprop-conditional2
733 (getprop (if (not zoo
) foo bar
) 'x
)
734 "(!zoo ? foo : bar).x;")
736 (test script-star-eval1
737 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x
1) '(setf y
2))))))
739 (test script-star-eval2
740 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x
1))))))
742 (test-ps-js list-with-single-nil
746 (test-ps-js quoted-nil-is-array
751 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
757 return setBaz(_js2, _js3, _js1);
760 (test-ps-js setf-macroexpands1
761 (macrolet ((bar (x y
)
763 (setf (bar foo
2) 3))
766 (test-ps-js defsetf-short
767 (progn (defsetf baz set-baz
"docstring")
768 (setf (baz 1 2 3) "foo"))
769 "setBaz(1, 2, 3, 'foo');")
771 (test-ps-js defun-setf1
772 (progn (defun (setf some-thing
) (new-val i1 i2
)
773 (setf (aref *some-thing
* i1 i2
) new-val
))
774 (setf (some-thing 1 2) "foo"))
775 "function __setf_someThing(newVal, i1, i2) {
776 return SOMETHING[i1][i2] = newVal;
778 __setf_someThing('foo', 1, 2);")
780 (test-ps-js defun-optional1
781 (defun test-opt (&optional x
)
783 "function testOpt(x) {
784 return x ? 'yes' : 'no';
787 (test-ps-js defun-optional2
788 (defun foo (x &optional y
)
790 "function foo(x, y) {
794 (test-ps-js defun-optional3
795 (defun blah (&optional
(x 0))
798 if (x === undefined) {
804 (test-ps-js arglist-optional4
805 (lambda (&optional
(x 0 supplied?
))
808 var suppliedwhat = x !== undefined;
815 (test-ps-js return-nothing
816 (defun foo () (return-from foo
))
821 (test-ps-js set-timeout
822 (set-timeout (lambda () (alert "foo")) 10)
823 "setTimeout(function () { return alert('foo'); }, 10);")
825 (test-ps-js operator-precedence
829 (test-ps-js operators-1
849 (test-ps-js setf-conditional
850 (setf foo
(if x
1 2))
853 (test-ps-js obj-literal-numbers
857 (test-ps-js obj-literal-strings
861 (test-ps-js getprop-string
865 (test-ps-js getprop-string1
866 (getprop "bar" 'length
)
869 (test-ps-js getprop-progn
870 (getprop (progn (some-fun "abc") "123") "length")
871 "(someFun('abc'), '123')['length'];")
873 (test-ps-js method-call-block
874 ((@ (progn (some-fun "abc") "123") to-string
))
875 "(someFun('abc'), '123').toString();")
877 (test-ps-js create-blank
881 (test-ps-js blank-object-literal
885 (test-ps-js array-literal1
889 (test-ps-js array-literal2
893 (test-ps-js array-literal3
897 (test-ps-js array-literal4
901 (test-ps-js array-literal5
903 "[[1, 2], ['a', 'b']];")
905 (test-ps-js defun-rest1
906 (defun foo (&rest bar
)
907 (alert (aref bar
1)))
910 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
911 bar[i1] = arguments[i1 + 0];
913 return alert(bar[1]);
916 (test-ps-js defun-rest2
917 (defun foo (baz &rest bar
) (+ baz
(aref bar
1)))
920 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
921 bar[i1] = arguments[i1 + 1];
926 (test-ps-js defun-keyword1
927 (defun zoo (foo bar
&key baz
) (+ foo bar baz
))
928 "function zoo(foo, bar) {
929 var _js2 = arguments.length;
930 for (var n1 = 2; n1 < _js2; n1 += 2) {
931 switch (arguments[n1]) {
933 baz = arguments[n1 + 1];
937 return foo + bar + baz;
940 (test-ps-js defun-keyword2
941 (defun zoo (&key baz
) (* baz baz
))
943 var _js2 = arguments.length;
944 for (var n1 = 0; n1 < _js2; n1 += 2) {
945 switch (arguments[n1]) {
947 baz = arguments[n1 + 1];
954 (test-ps-js defun-keyword3
955 (defun zoo (&key baz
(bar 4)) (* baz bar
))
957 var _js2 = arguments.length;
958 for (var n1 = 0; n1 < _js2; n1 += 2) {
959 switch (arguments[n1]) {
961 baz = arguments[n1 + 1];
964 bar = arguments[n1 + 1];
968 var bar = undefined === bar ? 4 : bar;
972 (test-ps-js defun-keyword4
973 (defun hello-world (&key
((:my-name-key my-name
) 1))
975 "function helloWorld() {
976 var _js2 = arguments.length;
977 for (var n1 = 0; n1 < _js2; n1 += 2) {
978 switch (arguments[n1]) {
980 myName = arguments[n1 + 1];
983 var myName = undefined === myName ? 1 : myName;
987 (test-ps-js arglist-keyword-supplied
988 (lambda (&key
(foo 1 supplied?
))
991 var _js2 = arguments.length;
992 for (var n1 = 0; n1 < _js2; n1 += 2) {
993 switch (arguments[n1]) {
995 foo = arguments[n1 + 1];
1000 var foo = undefined === foo ? 1 : foo;
1004 (test-ps-js keyword-funcall1
1008 (test-ps-js keyword-funcall2
1009 (func :baz
1 :bar foo
)
1010 "func('baz', 1, 'bar', foo);")
1012 (test-ps-js keyword-funcall3
1014 "fun(a, b, 'baz', c);")
1024 ((= y
(* x
4)) (foo "blah") (* x y
)))
1027 } else if (y === x * 4) {
1032 (test-ps-js if-exp-without-else-return
1033 (defun foo () (return-from foo
(if x
1)))
1035 return x ? 1 : null;
1038 (test-ps-js progn-expression-single-statement
1039 (defun foo () (return-from foo
(progn (* x y
))))
1044 (test-ps-js cond-expression1
1046 (cond ((< 1 2) (bar "foo") (* 4 5))))
1054 (test-ps-js cond-expression2
1056 (cond ((< 2 1) "foo")
1061 } else if (7 === 7) {
1066 (test-ps-js cond-expression-final-t-clause
1068 (cond ((< 1 2) (bar "foo") (* 4 5))
1079 } else if (a === b) {
1081 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
1088 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
1101 (test-ps-js funcall-if-expression
1102 (funcall (getprop document
'write
)
1103 (if (= *linkornot
* 1)
1104 (ps-html ((:a
:href
"#"
1105 :onclick
(ps-inline (transport)))
1108 "document.write(LINKORNOT === 1 ? ['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">', img, '</A>']['join']('') : img);")
1110 (test-ps-js negate-number-literal
1114 (test macro-environment1
1115 (is (string= (normalize-js-code (let* ((macroname (gensym)))
1116 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
1118 (macrolet ((,macroname
(x) `(aref data
,x
)))
1119 (when (,macroname x
)
1120 (setf (,macroname x
) 123)))))))
1123 return data[x] ? (data[x] = 123) : null;
1126 (test macro-environment2
1127 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
1128 (defpsmacro macro-environment2-macro
(x)
1129 `(+ ,outer-lexical-variable
,x
))
1130 (ps* '(macro-environment2-macro 2))))
1131 (normalize-js-code "1 + 2;"))))
1133 (test-ps-js ampersand-whole-1
1134 (macrolet ((foo (&whole foo bar baz
)
1135 (declare (ignore bar baz
))
1136 (with-standard-io-syntax (format nil
"~a" foo
))))
1140 (test-ps-js keyword-consistent
1144 (test-ps-js simple-symbol-macrolet
1145 (symbol-macrolet ((x 1)) x
)
1148 (test-ps-js compound-symbol-macrolet
1149 (symbol-macrolet ((x 123)
1154 (test-ps-js define-symbol-macro
1155 (progn (define-symbol-macro tst-sym-macro
2)
1159 (test-ps-js define-symbol-macro1
1160 (progn (define-symbol-macro tst-sym-macro1
2)
1161 (foo tst-sym-macro1
))
1164 (test-ps-js expression-progn
1165 (1+ (progn (foo) (if x
1 2)))
1166 "(foo(), x ? 1 : 2) + 1;")
1168 (test-ps-js let-decl-in-expression
1170 (if x
1 (let* ((foo x
)) foo
)))
1180 (test-ps-js special-var1
1181 (progn (defvar *foo
*)
1188 FOO_TMPSTACK1 = FOO;
1192 FOO = FOO_TMPSTACK1;
1196 (test-ps-js special-var2
1197 (progn (defvar *foo
*)
1206 FOO_TMPSTACK1 = FOO;
1208 return FOO * 2 * BAZ;
1210 FOO = FOO_TMPSTACK1;
1214 (test-ps-js literal1
1218 (test-ps-js literal2
1222 (test-ps-js setf-dec1
1226 (test-ps-js setf-dec2
1230 (test-ps-js special-char-equals
1234 (test-ps-js setf-operator-priority
1236 (or (getprop cache id
)
1237 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
1239 return cache[id] || (cache[id] = document.getElementById(id));
1242 (test-ps-js aref-operator-priority
1243 (aref (if (and x
(> (length x
) 0))
1247 "(x && x.length > 0 ? x[0] : y)[z];")
1249 (test-ps-js aref-operator-priority1
1250 (aref (or (getprop x
'y
)
1255 (test-ps-js aref-operator-priority2
1259 (test-ps-js negate-operator-priority
1268 (delete (if a
(or b c
) d
))
1269 "delete (a ? b || c : d);")
1272 (not (if (or x
(not y
)) z
))
1273 "!(x || !y ? z : null);")
1280 (instanceof (or a b
) (if x y z
))
1281 "((a || b) instanceof (x ? y : z));")
1284 (or x
(if (= x
0) "zero" "empty"))
1285 "x || (x === 0 ? 'zero' : 'empty');")
1287 (test-ps-js named-op-expression
1291 (test-ps-js named-op-expression1
1295 (test-ps-js aref-array-expression
1297 "(a || b || c)[0];")
1299 (test-ps-js getprop-operator
1300 (getprop (or a b c
) 'd
)
1303 (test-ps-js getprop-parens
1304 (getprop (getprop foo
'bar
) 'baz
)
1307 (test-ps-js funcall-funcall
1311 (test-ps-js expression-funcall
1312 ((or (@ window eval
) eval
) foo nil
)
1313 "(window.eval || eval)(foo, null);")
1315 (test-ps-js expression-funcall1
1316 (((or (@ window eval
) eval
) foo nil
))
1317 "(window.eval || eval)(foo, null)();")
1319 (test-ps-js expression-funcall2
1320 (((or (@ window eval
) eval
)) foo nil
)
1321 "(window.eval || eval)()(foo, null);")
1323 (test-ps-js who-html1
1324 (who-ps-html (:span
:class
"ticker-symbol"
1325 :ticker-symbol symbol
1326 (:a
:href
"http://foo.com"
1328 (:span
:class
"ticker-symbol-popup")))
1329 "['<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"', symbol, '\"><A HREF=\"http://foo.com\">', symbol, '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>']['join']('');")
1331 (test-ps-js who-html2
1332 (who-ps-html (:p
"t0" (:span
"t1")))
1333 "'<P>t0<SPAN>t1</SPAN></P>';")
1336 ((lambda () (flet ((foo (x)
1340 var foo = function (x) {
1347 (flet ((foo (x) (1+ x
))
1350 "var foo = function (x) {
1353 var bar = function (y) {
1359 (flet ((foo (x) (+ 2 x
)))
1360 (flet ((foo (x) (1+ x
))
1361 (bar (y) (+ 2 (foo y
))))
1363 "var foo = function (x) {
1366 var foo1 = function (x) {
1369 var bar = function (y) {
1375 ((lambda () (labels ((foo (x)
1378 (+ x
(foo (1- x
))))))
1381 var foo = function (x) {
1382 return 0 === x ? 0 : x + foo(x - 1);
1388 (labels ((foo (x) (1+ (bar x
)))
1389 (bar (y) (+ 2 (foo y
))))
1391 "var foo = function (x) {
1394 var bar = function (y) {
1400 (labels ((foo (x) (1+ x
))
1401 (bar (y) (+ 2 (foo y
))))
1403 "var foo = function (x) {
1406 var bar = function (y) {
1411 (test-ps-js labels-lambda-list
1412 (labels ((foo (x &optional
(y 0))
1415 "var foo = function (x, y) {
1416 if (y === undefined) {
1423 (test-ps-js for-loop-var-init-exp
1425 (do* ((y (if x
0 1) (1+ y
))
1430 return (function () {
1431 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
1441 (test-ps-js literal-array
1445 (test-ps-js literal-array-1
1449 (test ps-lisp-expands-in-lexical-environment
1450 (is (string= "5;" (let ((x 5)) (ps (lisp x
))))))
1452 (test ps
*-lisp-expands-in-null-lexical-environment
;; ccl only does a warning
1453 (signals unbound-variable
(let ((x 5)) (declare (ignore x
)) (ps* '(lisp x
)))))
1455 (test ps
*-lisp-expands-in-dynamic-environment
1456 (is (string= "1 + 2;" (let ((foo 2)) (declare (special foo
)) (ps* '(+ 1 (lisp (locally (declare (special foo
)) foo
))))))))
1458 (test ps-lisp-dynamic-environment
1459 (is (string= "1 + 2;" (let ((foo 2)) (declare (special foo
)) (ps (+ 1 (lisp foo
)))))))
1461 (test-ps-js nested-if-expressions1
1463 (return-from foo
(if (if x y z
) a b
)))
1472 (test-ps-js nested-if-expressions2
1474 (if x y
(if z a b
)))
1553 (test-ps-js let-exp1
1604 (test-ps-js symbol-macrolet-var
1605 (symbol-macrolet ((x y
))
1609 (test-ps-js setf-conditional1
1610 (setf x
(unless (null a
) (1+ a
)))
1611 "x = a != null ? a + 1 : null;")
1613 (test-ps-js setf-let1
1614 (setf x
(let ((a 1)) a
))
1620 (test-ps-js setf-let2
1621 (setf x
(let ((a (foo)))
1626 return a != null ? a + 1 : null;
1629 (test-ps-js symbol-macro-env1
1630 (symbol-macrolet ((bar 1))
1631 (macrolet ((bar (x y
) `(+ ,x
,y
)))
1635 (test-ps-js symbol-macrolet-fun1
1636 (symbol-macrolet ((baz +))
1640 (test-ps-js lisp2-namespaces1
1642 (setf list
(list 1 2 3)))
1645 return list = [1, 2, 3];
1648 (test-ps-js let-shadows-symbol-macrolet
1649 (symbol-macrolet ((x y
))
1659 (test-ps-js let-rename-optimization1
1667 (test-ps-js let-rename-optimization2
1676 (test-ps-js symbol-macro-array
1677 (symbol-macrolet ((x 1))
1681 (test-ps-js symbol-macro-obj
1682 (symbol-macrolet ((x y
))
1686 (test-ps-js symbol-macro-conditional1
1687 (symbol-macrolet ((x y
))
1695 (test-ps-js symbol-macro-conditional2
1696 (symbol-macrolet ((x y
))
1700 (test-ps-js flet-apply
1701 (flet ((foo () 'bar
))
1702 (apply (function foo
) nil
))
1703 "var foo = function () {
1706 foo.apply(this, null);")
1708 (test-ps-js let-apply
1709 (let ((foo (lambda () 1)))
1710 (let ((foo (lambda () 2)))
1713 var foo = function () {
1716 var foo1 = function () {
1719 return foo1.apply(this, null);
1722 (test-ps-js flet-let
1723 (flet ((x (x) (1+ x
)))
1726 "var x = function (x) {
1732 (test-ps-js let-flet
1734 (flet ((x (x) (1+ x
)))
1738 var x1 = function (x) {
1744 (test-ps-js labels-let
1745 (labels ((x (x) (1+ x
)))
1748 "var x = function (x) {
1754 (test-ps-js let-labels
1756 (labels ((x (x) (1+ x
)))
1760 var x1 = function (x) {
1766 (test-ps-js macrolet-let-inteference
1767 (macrolet ((a (n) `(+ ,n
5)))
1769 (let ((b (a (- a
4))))
1773 var b = (a - 4) + 5;
1777 (test-ps-js let-subtract-add
1793 (test-ps-js create-reserved-word
1795 "({ 'default' : 1 });")
1797 (test-ps-js getprop-reserved-word
1798 (getprop foo
:default
)
1801 (test-ps-js getprop-reserved-word1
1802 (getprop foo
'default
)
1805 (test-ps-js eval-when-ps-side
1806 (eval-when (:execute
)
1810 (defvar *lisp-output
* nil
)
1812 (test eval-when-lisp-side
()
1813 (setf *lisp-output
* 'original-value
)
1814 (let ((js-output (normalize-js-code
1815 (ps-doc* `(eval-when (:compile-toplevel
)
1816 (setf *lisp-output
* 'it-works
))))))
1817 (is (eql 'it-works
*lisp-output
*))
1818 (is (string= "" js-output
))))
1820 (defpsmacro my-in-package
(package-name)
1821 `(eval-when (:compile-toplevel
)
1822 (setf *lisp-output
* ,package-name
)))
1824 (test eval-when-macro-expansion
()
1825 (setf *lisp-output
* 'original-value
)
1826 (let ((js-output (normalize-js-code
1828 (my-in-package :cl-user
)
1830 (declare (ignore js-output
))
1831 (is (eql :cl-user
*lisp-output
*))))
1833 (test eval-when-macrolet-expansion
()
1834 (setf *lisp-output
* 'original-value
)
1835 (let ((js-output (normalize-js-code
1836 (ps-doc* `(macrolet ((my-in-package2 (package-name)
1837 `(eval-when (:compile-toplevel
)
1838 (setf *lisp-output
* ,package-name
))))
1839 (my-in-package2 :cl-user
)
1841 (declare (ignore js-output
))
1842 (is (eql :cl-user
*lisp-output
*))))
1844 (test-ps-js getprop-keyword
1848 (test-ps-js nary-comparison1
1849 (lambda () (< 1 2 3))
1852 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
1855 (test-ps-js chain-getprop1
1856 (chain ($
"foo") (bar x z
) frob
(baz 5))
1857 "$('foo').bar(x, z).frob.baz(5);")
1859 (test-ps-js chain-getprop2
1860 (chain ($
"foo") bar baz
)
1861 "$('foo').bar.baz;")
1863 (test-ps-js chain-getprop3
1864 (chain ($
"foo") bar
(x y
) baz
)
1865 "$('foo').bar.x(y).baz;")
1867 (test-ps-js flet-expression
1868 (1+ (flet ((foo (x) (1+ x
)))
1870 "(foo = function (x) {
1874 (test-ps-js flet-lambda-list
1875 (labels ((foo (x &key
(y 0))
1878 "var foo = function (x) {
1879 var _js2 = arguments.length;
1880 for (var n1 = 1; n1 < _js2; n1 += 2) {
1881 switch (arguments[n1]) {
1883 y = arguments[n1 + 1];
1886 var y = undefined === y ? 0 : y;
1891 (test-ps-js return-case-break-elimination
1906 (test-ps-js aplusplus
1910 (test-ps-js astarstar
1914 (test-ps-js switch-return-fallthrough
1932 (test-ps-js return-last-case
1947 (test-ps-js return-macrolet
1950 (macrolet ((x () 1))
1963 (test-ps-js mv-bind1
1964 (multiple-value-bind (a b
)
1973 prevMv2 = arguments['callee']['mv'];
1975 arguments['callee']['mv'] = true;
1977 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
1982 if (undefined === prevMv2) {
1983 delete arguments['callee']['mv'];
1985 arguments['callee']['mv'] = prevMv2;
1990 (test-ps-js mv-bind2
1991 (multiple-value-bind (a b
)
2001 prevMv2 = arguments['callee']['mv'];
2003 arguments['callee']['mv'] = true;
2005 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
2010 if (undefined === prevMv2) {
2011 delete arguments['callee']['mv'];
2013 arguments['callee']['mv'] = prevMv2;
2018 (test-ps-js multiple-value-bind-simple
2019 (multiple-value-bind (a b
) (blah)
2023 prevMv2 = arguments['callee']['mv'];
2025 arguments['callee']['mv'] = true;
2027 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
2031 if (undefined === prevMv2) {
2032 delete arguments['callee']['mv'];
2034 arguments['callee']['mv'] = prevMv2;
2040 (lambda () (values))
2054 if (undefined !== arguments['callee']['caller']['mv']) {
2055 arguments['callee']['caller']['mv'] = valrest2;
2064 var valrest2 = [y, z];
2065 if (undefined !== arguments['callee']['caller']['mv']) {
2066 arguments['callee']['caller']['mv'] = valrest2;
2071 (test-ps-js values-return
2073 (return-from foo
(values x y
)))
2077 if (undefined !== arguments['callee']['caller']['mv']) {
2078 arguments['callee']['caller']['mv'] = valrest2;
2083 (test-ps-js return-macrolet
2086 (symbol-macrolet ((x 2))
2087 (loop do
(+ x x
)))))
2095 (test-ps-js return-cond
2098 (cond ((foo? x
) (loop for y in x do
(foo y
)))
2103 var _js2 = x.length;
2117 } else if (barwhat(x)) {
2124 (test-ps-js switch-loop
2129 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
2134 (test-ps-js switch-folds-blocks
2136 (1 (loop repeat
3 do
(alert "foo"))))
2139 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
2144 (test-ps-js setf-places-before-macros
2146 (defsetf left
(el) (offset)
2147 `(setf (@ ,el style left
) ,offset
))
2148 (macrolet ((left (el)
2149 `(@ ,el offset-left
)))
2155 _js2.style.left = _js1;
2156 return x.offsetLeft;
2159 (test-ps-js for-return
2160 (lambda () (dolist (arg args
) (foo arg
)))
2162 for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
2163 arg = args[_js_idx1];
2168 (test-ps-js try-catch-return
2186 (test-ps-js defun-setf-optional
2187 (defun (setf foo
) (new-value b
&optional c
)
2188 (setf (aref b
(or c
0)) new-value
))
2189 "function __setf_foo(newValue, b, c) {
2190 return b[c || 0] = newValue;
2193 (test-ps-js defun-setf-rest
2194 (progn (defun (setf foo
) (new-value b
&rest foo
)
2195 (do-something b foo new-value
))
2196 (setf (foo x
1 2 3 4) 5))
2197 "function __setf_foo(newValue, b) {
2199 for (var i1 = 0; i1 < arguments.length - 2; i1 += 1) {
2200 foo[i1] = arguments[i1 + 2];
2202 return doSomething(b, foo, newValue);
2204 __setf_foo(5, x, 1, 2, 3, 4);")
2206 (test-ps-js return-null
2207 (defun foo () (return-from foo nil
))
2212 (test-ps-js implicit-return-null
2219 (test-ps-js implicit-return-null
2226 (test-ps-js return-conditional-nested
2227 (defun blep (ss x y
)
2231 (destructuring-bind (a b
) pair
2232 (unless (or (null a
) (null b
))
2233 (let ((val (baz a b
)))
2238 "function blep(ss, x, y) {
2244 if (!(a == null || b == null)) {
2245 var val = baz(a, b);
2248 return !blee() ? true : null;
2256 ;; this test needs to be rewritten when named blocks are implemented!!!!
2257 (test-ps-js return-when-returns-broken-return
2259 (return-from foo
(when x
1))
2262 return x ? 1 : null;
2266 (test-ps-js return-case-conditional
2270 (123 (when (bar) t
))
2275 return bar() ? true : null;
2282 (test-ps-js return-try-conditional
2290 return x ? 1 : null;
2298 (test-ps-js function-declare-special
2300 (declare (special *foo
*))
2306 FOO_TMPSTACK1 = FOO;
2310 FOO = FOO_TMPSTACK1;
2314 (test-ps-js declare-special-let
2316 (declare (special *foo
*))
2321 FOO_TMPSTACK1 = FOO;
2325 FOO = FOO_TMPSTACK1;
2329 (test-ps-js macro-null-toplevel
2331 (defmacro macro-null-toplevel
()
2333 (macro-null-toplevel))
2336 (test-ps-js define-symbol-macro-let
2338 (define-symbol-macro test-symbol-macro
1)
2339 (let ((test-symbol-macro 2))
2340 (1+ test-symbol-macro
))
2341 (1+ test-symbol-macro
))
2343 var testSymbolMacro1 = 2;
2344 return testSymbolMacro1 + 1;
2348 (test-ps-js define-symbol-macro-flet
2350 (define-symbol-macro test-symbol-macro1
1)
2351 (flet ((test-symbol-macro1 () 2))
2352 (foo test-symbol-macro1
)
2353 (test-symbol-macro1))
2354 (bar test-symbol-macro1
))
2355 "var testSymbolMacro1_1 = function () {
2359 testSymbolMacro1_1();
2362 (test compile-stream-nulls
2365 (with-input-from-string (s "
2366 (defmacro macro-null-toplevel ()
2368 (macro-null-toplevel)")
2369 (ps-compile-stream s
)))))
2371 (test compile-stream1
2373 "var testSymbolMacro1_1 = function () {
2377 testSymbolMacro1_1();
2380 (with-input-from-string (s "
2381 (define-symbol-macro test-symbol-macro1 1)
2382 (flet ((test-symbol-macro1 () 2))
2383 (foo test-symbol-macro1)
2384 (test-symbol-macro1))
2385 (bar test-symbol-macro1)")
2386 (ps::with-blank-compilation-environment
(ps-compile-stream s
))))))
2388 (test-ps-js equality-nary1
2389 (let ((x 10) (y 10) (z 10))
2396 return (_cmp1 = y, x === _cmp1 && _cmp1 === z);
2399 (test-ps-js equality1
2410 (test-ps-js getprop-quote-reserved
2411 (getprop foo
':break
)
2414 (test-ps-js defun-block-return-from
2425 (test-ps-js block-return-from
2429 (return-from scope
))
2439 (test-ps-js block-return-from1
2444 (return-from scope
))
2458 (test-ps-js block-return-from2
2464 (return-from scope
6))
2475 (test-ps-js let-funcall
2489 (test-ps-js symbol-macrolet-funcall
2490 (symbol-macrolet ((foo bar
))
2491 (funcall foo
1 2 3))
2494 (test-ps-js times-assign
2498 (test-ps-js vector-literal
2503 (+ 1 (rem 2 (+ 3 4)))
2506 (test-ps-js non-associative
2507 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
2508 "1 / (2 / 3) + (1 - (2 - 3));")
2510 (test-ps-js lambda-apply
2512 (apply (lambda (y) (bar (1+ y
))) x
))
2514 return (function (y) {
2519 (test-ps-js operator-expressions-nested-let
2520 (let ((x (let ((y 1))
2529 (test-ps-js operator-expressions-array-nested-let
2530 (list (let ((y 1)) y
) 2)
2536 (test-ps-js add-subtract-precedence
2540 (test-ps-js ps-inline-toplevel
2542 "'javascript:' + 'foo()';")
2544 (test-ps-js no-clause-progn-exp
2548 (test-ps-js no-clause-progn-return
2550 (return-from foo
(progn)))
2555 (test-ps-js empty-cond-clause
2556 (setf x
(cond ((foo))))
2557 "x = foo() ? null : null;")
2559 (test-ps-js empty-cond-clause1
2560 (setf x
(cond ((foo) 123)
2563 "x = foo() ? 123 : (bar() ? null : 456);")
2565 (test-ps-js let-no-body
2567 (return-from foo
(let ((foo bar
)))))
2573 (test-ps-js rename-lexical-dupes
2575 (list (let ((foo 12)) (* foo
2))
2576 (let ((foo 13)) (* foo
3))))
2580 return [(foo = 12, foo * 2), (foo1 = 13, foo1 * 3)];
2583 (test-ps-js defun-comment1
2585 "BARBAR is a revolutionary new foobar.
2589 * BARBAR is a revolutionary new foobar.
2596 (test-ps-js var-comment
2601 (test-ps-js case-return-break-broken-return
2604 ("bar" (if y
(return-from foo t
) nil
))
2618 (test-ps-js case-return-break1-broken-return
2621 ("bar" (if y
(return-from foo t
)))
2635 (test-ps-js setf-progn
2636 (setf foo
(progn (bar) (baz) 3))
2641 ;; (test-ps-js var-progn
2642 ;; (var x (progn (foo) (bar)))
2646 (test-ps-js implicit-return-loop
2650 (loop :repeat
100 :do
(bar))
2656 for (var _js2 = 0; _js2 < 100; _js2 += 1) {
2663 ;; closures in loops need a new binding per loop iteration (idea borrowed from Scheme2JS)
2664 (test-ps-js loop-closures
2665 (dotimes (i 10) (lambda () (+ i
1)))
2666 "for (var i = 0; i < 10; i += 1) {
2674 (test-ps-js loop-closures-let
2677 (lambda () (+ i x
))))
2678 "for (var i = 0; i < 10; i += 1) {
2679 with ({ i : i, x : null }) {
2687 (test-ps-js loop-closures-flet
2688 (dotimes (i 10) (flet ((foo (x) (+ i x
))) (lambda () (foo i
))))
2689 "for (var i = 0; i < 10; i += 1) {
2690 with ({ foo : null, i : i }) {
2691 var foo = function (x) {
2700 (test-ps-js while-closures-let
2703 (lambda () (+ 1 x
))))
2705 with ({ x : null }) {
2713 (test-ps-js dotted-list-form
2716 (destructuring-bind (b . c
)
2722 var c = bar.length > 1 ? bar.slice(1) : [];
2727 (test-ps-js return-from-loop
2728 (dolist (x '(2 1 3))
2731 (chain console
(log x
)))
2732 "for (var x = null, _js_arrvar2 = [2, 1, 3], _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
2733 x = _js_arrvar2[_js_idx1];
2740 (test-ps-js explicit-nil-block
2741 (block nil
(return) (+ 1 2))
2747 (test-ps-js dynamic-extent-function-return
2748 (defun foo () ((lambda () (return-from foo
6))))
2751 return (function () {
2752 throw { 'ps-block-tag' : 'foo', 'ps-return-value' : 6 };
2755 if (err && 'foo' === err['ps-block-tag']) {
2756 return err['ps-return-value'];
2763 (test-ps-js block-dynamic-return
2764 (var foo
((lambda ()
2766 ((lambda () (return 6)))
2768 "var foo = (function () {
2771 throw { 'ps-block-tag' : 'nilBlock', 'ps-return-value' : 6 };
2775 if (err && 'nilBlock' === err['ps-block-tag']) {
2776 return err['ps-return-value'];
2783 (test-ps-js block-dynamic-return1
2784 (var foo
((lambda ()
2786 ((lambda () (return 6)))
2789 "var foo = (function () {
2796 return foobar(1, 2);
2799 (test-ps-js iteration-lambda-capture-no-need
2800 (dolist (x y
) (lambda (x) (1+ x
))) ;; there's really no need to create a 'with' scope in this case
2801 "for (var x = null, _js_idx1 = 0; _js_idx1 < y.length; _js_idx1 += 1) {
2810 (test-ps-js case-invert1
2811 (encodeURIComponent fooBar
)
2812 "encodeURIComponent(fooBar);")
2814 (test-ps-js simple-ash
2815 (+ (ash 4 1) (ash 4 -
1))
2816 "(4 << 1) + (4 >> 1);")
2818 (test-ps-js progn-nil-expression
2819 (bar (progn (foo) nil
))
2820 "bar((foo(), null));")
2822 (test-ps-js other-progn-nil-exp
2824 (or (foo) (progn (bar) nil
)))
2826 return foo() || (bar(), null);
2829 (test-ps-js lambda-nil-return
2842 (test-ps-js lambda-nil-return-implicit-nested
2854 for (var i = 0; i < 4; i += 1) {
2861 (test-ps-js throw-is-a-statement
2863 (let ((result (foo)))
2864 (unless (null result
)
2868 if (result != null) {
2873 (test-ps-js expressify1
2875 (when (some-condition)
2880 if (someCondition()) {
2887 (test-ps-js case-when-return
2890 ("a" (when (foo) (return-from blah
111)))
2904 (test-ps-js flet-return-from
2907 (return-from foo
123)))
2910 var foo = function () {
2916 (test-ps-js flet-return-from1
2918 (return-from foo
123)))
2920 "var foo = function () {
2925 (test-ps-js lambda-docstring-declarations
2927 "This is a docstring"
2928 (declare (ignore x
))
2934 (test-ps-js setf-let-exp
2935 (setf foo
(let ((x (+ 1 2)))
2937 "foo = (function () {
2939 return x ? 123 : 456;
2942 (test-ps-js create-let-exp
2943 (create :abc
(let ((x (+ 1 2)))
2945 "({ 'abc' : (function () {
2947 return x ? 123 : 456;
2950 (test-ps-js eql-eql-eql-precedence
2951 (unless (equal (= 3 3) (= 3 4))
2952 (chain console
(log 1)))
2953 "if ((3 === 3) != (3 === 4)) {
2957 (test-ps-js case-cond-breaks
2960 (123 (cond ((foo1) (when (foo2)
2962 (return-from blah nil
))
2982 (test-ps-js let-let-funcall-lambda
2985 (funcall (lambda (x) (+ x
9)) x
)))
2989 return (function (x) {
2994 (test-ps-js let-let-lambda
2997 (lambda (x) (+ x
9))))
3001 return function (x) {
3006 (test-ps-js let-lambda
3008 (lambda (x) (+ x
9)))
3011 return function (x) {
3016 (test-ps-js symbol-macrolet-no-shadow-lambda
3017 (symbol-macrolet ((x y
))
3018 (lambda (x) (+ x x
)))
3023 (test-ps-js divide-one-arg-reciprocal
3027 (test-ps-js division-not-associative
3031 (test-ps-js divide-expressions
3035 (test-ps-js divide-expressions1
3037 "Math.floor((x - 1) / y);")
3039 (test-ps-js lexical-funargs-shadow1
3050 (test-ps-js times-rem
3054 (test-ps-js rem-divide
3058 (test-ps-js case-break-return
3059 (lambda () (case x
(:foo
) (:bar
1)))
3069 (test-ps-js trivial-expression-switch
3070 (foobar (case x
(1 2)))
3071 "foobar((function () {
3078 (test-ps-js trivial-expression-while
3079 (foobar (while (< 0 x
) (decf x
)))
3080 "foobar((function () {
3086 (test-ps-js funcall-block-expression-loop-lambda
3087 (foobar (loop for i from
0 to
10 do
(1+ i
)))
3088 "foobar((function () {
3089 for (var i = 0; i <= 10; i += 1) {
3095 (test-ps-js let-closures-rename
3097 (let ((x 1)) (lambda () (1+ x
)))
3098 (let ((x 2)) (lambda () (1+ x
))))
3105 return function () {
3110 (test-ps-js let-closures-rename1
3114 (lambda () (+ x y
))))
3117 (lambda () (+ x y
)))))
3126 return function () {
3131 (test-ps-js let-closures-rename2
3132 (defun make-closures ()
3134 (let ((x 1)) (lambda () (1+ x
)))
3135 (let ((x 2)) (lambda () (1+ x
)))))
3136 "function makeClosures() {
3139 return [(x = 1, function () {
3141 }), (x1 = 2, function () {
3147 (test-ps-js conditional-not-used-up
3159 (test-ps-js toplevel-local-scope
3160 (create "fn" (let ((x 5)) (lambda () x
)))
3161 "({ 'fn' : (function () {
3163 return function () {
3168 (test-ps-js toplevel-local-scope1
3169 (defvar foo
(create "fn" (let ((x 5)) (lambda () x
))))
3170 "var foo = { 'fn' : (function () {
3172 return function () {