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
305 (block nil
(return) 1)
311 (test-ps-js single-argument-statements-2
315 (test-ps-js single-argument-expression-1
316 (delete (new (*foobar
2 3 4)))
317 "delete new Foobar(2, 3, 4);")
319 (test-ps-js single-argument-expression-2
320 (if (= (typeof blorg
) *string
)
321 (alert (+ "blorg is a string: " blorg
))
322 (alert "blorg is not a string"))
323 "if (typeof blorg === String) {
324 alert('blorg is a string: ' + blorg);
326 alert('blorg is not a string');
329 (test-ps-js conditional-statements-1
331 (if ((@ blorg is-correct
))
332 (progn (carry-on) (return-from foo i
))
333 (alert "blorg is not correct!")))
335 if (blorg.isCorrect()) {
339 return alert('blorg is not correct!');
343 (test-ps-js conditional-statements-2
344 (+ i
(if ((@ blorg add-one
)) 1 2))
345 "i + (blorg.addOne() ? 1 : 2);")
347 (test-ps-js conditional-statements-3
349 (when ((@ blorg is-correct
))
351 (return-from foo i
)))
353 if (blorg.isCorrect()) {
359 (test-ps-js conditional-statements-4
360 (unless ((@ blorg is-correct
))
361 (alert "blorg is not correct!"))
362 "if (!blorg.isCorrect()) {
363 alert('blorg is not correct!');
366 (test-ps-js variable-declaration-1
367 (defvar *a
* (array 1 2 3))
368 "var A = [ 1, 2, 3 ];")
370 (test-ps-js variable-declaration-2
371 (progn (defvar *a
* 4)
392 (test-ps-js iteration-constructs-1
393 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
395 (e (aref c d
) (aref c d
)))
396 ((or (= d
(@ c length
)) (string= e
"x")))
398 (funcall (@ document write
) (+ "a: " a
" b: " b
"<br/>")))
399 "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]) {
402 document.write('a: ' + a + ' b: ' + b + '<br/>');
405 (test-ps-js iteration-constructs-2
407 (s 0 (+ s i
(1+ i
))))
409 (funcall (@ document write
) (+ "i: " i
" s: " s
"<br/>")))
414 document.write('i: ' + i + ' s: ' + s + '<br/>');
416 var _js2 = s + i + i + 1;
422 (test-ps-js iteration-constructs-3
424 (s 0 (+ s i
(1- i
))))
426 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
427 "for (var i = 0, s = 0; i <= 10; i += 1, s = s + i + (i - 1)) {
428 document.write('i: ' + i + ' s: ' + s + '<br/>');
431 (test-ps-js iteration-constructs-4
432 (let ((arr (array "a" "b" "c" "d" "e")))
433 (dotimes (i (@ arr length
))
434 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
436 var arr = ['a', 'b', 'c', 'd', 'e'];
437 for (var i = 0; i < arr.length; i += 1) {
438 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
442 (test-ps-js iteration-constructs-5
444 (alert (+ "Summation to 10 is "
446 (incf res
(1+ i
))))))
449 return alert('Summation to 10 is ' + (function () {
450 for (var i = 0; i < 10; i += 1) {
457 (test-ps-js iteration-constructs-6
458 (let ((l (list 1 2 4 8 16 32)))
460 ((@ document write
) (+ "c: " c
"<br/>"))))
462 var l = [1, 2, 4, 8, 16, 32];
463 for (var c = null, _js_idx2 = 0; _js_idx2 < l.length; _js_idx2 += 1) {
465 document.write('c: ' + c + '<br/>');
469 (test-ps-js iteration-constructs-7
470 (let ((l '(1 2 4 8 16 32))
472 (alert (+ "Sum of " l
" is: "
476 var l = [1, 2, 4, 8, 16, 32];
478 return alert('Sum of ' + l + ' is: ' + (function () {
479 for (var c = null, _js_idx1 = 0; _js_idx1 < l.length; _js_idx1 += 1) {
487 (test-ps-js iteration-constructs-8
488 (let ((obj (create a
1 b
2 c
3)))
490 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
492 var obj = { a : 1, b : 2, c : 3 };
494 document.write(i + ': ' + obj[i] + '<br/>');
498 (test-ps-js iteration-constructs-9
499 (while ((@ film is-not-finished
))
500 ((@ this eat
) (new *popcorn
)))
501 "while (film.isNotFinished()) {
502 this.eat(new Popcorn);
505 (test-ps-js the-case-statement-1
507 ((1 "one") (alert "one"))
509 (t (alert "default clause")))
519 alert('default clause');
522 (test-ps-js the-case-statement-2
523 (switch (aref blorg i
)
524 (1 (alert "If I get here"))
525 (2 (alert "I also get here"))
526 (default (alert "I always get here")))
528 case 1: alert('If I get here');
529 case 2: alert('I also get here');
530 default: alert('I always get here');
533 (test-ps-js the-try-statement-1
536 (alert (+ "an error happened: " error
)))
538 (alert "Leaving the try form")))
542 alert('an error happened: ' + error);
544 alert('Leaving the try form');
547 (test-ps-js the-html-generator-1
548 (ps-html ((:a
:href
"foobar") "blorg"))
549 "'<A HREF=\"foobar\">blorg</A>';")
551 (test-ps-js the-html-generator-2
552 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
553 "['<A HREF=\"', generateALink(), '\">blorg</A>']['join']('');")
555 (test-ps-js the-html-generator-3
556 (funcall (getprop document
'write
)
557 (ps-html ((:a
:href
"#"
558 :onclick
(ps-inline (transport))) "link")))
559 "document.write(['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">link</A>']['join'](''));")
561 (test-ps-js the-html-generator-4
564 (setf (getprop element
'inner-h-t-m-l
)
565 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
569 var authorized = true;
570 return element.innerHTML = ['<TEXTAREA', disabled || !authorized ? [' DISABLED=\"', 'disabled', '\"']['join']('') : '', '>Edit me</TEXTAREA>']['join']('');
573 (test-ps-js plus-is-not-commutative
574 (setf x
(+ "before" x
"after"))
575 "x = 'before' + x + 'after';")
577 (test-ps-js plus-works-if-first
578 (setf x
(+ x
"middle" "after"))
579 "x = x + 'middle' + 'after';")
581 (test-ps-js method-call-op-form
582 (funcall (getprop (+ "" x
) 'to-string
))
583 "('' + x).toString();")
585 (test-ps-js method-call-op-form-args
586 (funcall (getprop (+ "" x
) 'foo
) 1 2 :baz
3)
587 "('' + x).foo(1, 2, 'baz', 3);")
589 (test-ps-js method-call-string
590 ((getprop "hi" 'to-string
))
593 (test-ps-js method-call-conditional
597 (test-ps-js method-call-variable
601 (test-ps-js method-call-array
602 ((@ (list 10 20) to-string
))
603 "[ 10, 20 ].toString();")
605 (test-ps-js method-call-lambda-call
606 (funcall (getprop (funcall (lambda (x) x
) 10) 'to-string
))
607 "(function (x) { return x; })(10).toString();")
609 (test no-whitespace-before-dot
610 (let* ((str (ps* '((@ ((lambda (x) x
) 10) to-string
))))
611 (dot-pos (position #\. str
:test
#'char
=))
612 (char-before (elt str
(1- dot-pos
)))
614 (is (char= char-before a-parenthesis
))))
616 (test-ps-js simple-getprop
617 (let ((foo (create a
1)))
618 (alert (getprop foo
'a
)))
624 (test-ps-js buggy-getprop
625 (getprop foo slot-name
)
628 (test-ps-js buggy-getprop-two
629 (getprop foo
(get-slot-name))
630 "foo[getSlotName()];")
632 (test-ps-js old-case-is-now-switch
633 ;; Switch was "case" before, but that was very non-lispish.
634 ;; For example, this code makes three messages and not one
635 ;; which may have been expected. This is because a switch
636 ;; statment must have a break statement for it to return
637 ;; after the alert. Otherwise it continues on the next
639 (switch (aref blorg i
)
642 (default (alert "default clause")))
644 case 1: alert('one');
645 case 2: alert('two');
646 default: alert('default clause');
649 (test-ps-js lisp-like-case
653 (default (alert "default clause")))
661 default: alert('default clause');
665 (test-ps-js even-lispier-case
667 ((1 2) (alert "Below three"))
669 (t (alert "Something else")))
673 alert('Below three');
678 default: alert('Something else');
681 (test-ps-js otherwise-case
684 (otherwise (alert "default clause")))
689 default: alert('default clause');
692 (test escape-sequences-in-string
693 (let ((escapes `((#\\ .
#\\)
695 (#\f .
,(code-char 12))
696 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
699 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
701 ("u001F" .
,(code-char #x001f
));; character below 32
702 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
703 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
704 (loop for
(js-escape . lisp-char
) in escapes
705 for generated
= (ps-doc* (format nil
"hello~ahi" lisp-char
))
706 for wanted
= (format nil
"'hello\\~ahi';" js-escape
)
707 do
(is (string= (normalize-js-code generated
) wanted
)))))
709 (test-ps-js getprop-setf
710 (setf (getprop x
'y
) (+ (+ a
3) 4))
713 (test-ps-js getprop-conditional1
714 (getprop (if zoo foo bar
) 'x
)
715 "(zoo ? foo : bar).x;")
717 (test-ps-js getprop-conditional2
718 (getprop (if (not zoo
) foo bar
) 'x
)
719 "(!zoo ? foo : bar).x;")
721 (test script-star-eval1
722 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x
1) '(setf y
2))))))
724 (test script-star-eval2
725 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x
1))))))
727 (test-ps-js list-with-single-nil
731 (test-ps-js quoted-nil-is-array
736 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
742 return setBaz(_js2, _js3, _js1);
745 (test-ps-js setf-macroexpands1
746 (macrolet ((bar (x y
)
748 (setf (bar foo
2) 3))
751 (test-ps-js defsetf-short
752 (progn (defsetf baz set-baz
"docstring")
753 (setf (baz 1 2 3) "foo"))
754 "setBaz(1, 2, 3, 'foo');")
756 (test-ps-js defun-setf1
757 (progn (defun (setf some-thing
) (new-val i1 i2
)
758 (setf (aref *some-thing
* i1 i2
) new-val
))
759 (setf (some-thing 1 2) "foo"))
760 "function __setf_someThing(newVal, i1, i2) {
761 return SOMETHING[i1][i2] = newVal;
763 __setf_someThing('foo', 1, 2);")
765 (test-ps-js defun-optional1
766 (defun test-opt (&optional x
)
768 "function testOpt(x) {
769 return x ? 'yes' : 'no';
772 (test-ps-js defun-optional2
773 (defun foo (x &optional y
)
775 "function foo(x, y) {
779 (test-ps-js defun-optional3
780 (defun blah (&optional
(x 0))
783 if (x === undefined) {
789 (test-ps-js arglist-optional4
790 (lambda (&optional
(x 0 supplied?
))
793 var suppliedwhat = x !== undefined;
800 (test-ps-js return-nothing
801 (defun foo () (return-from foo
))
806 (test-ps-js set-timeout
807 (set-timeout (lambda () (alert "foo")) 10)
808 "setTimeout(function () { return alert('foo'); }, 10);")
810 (test-ps-js operator-precedence
814 (test-ps-js operators-1
834 (test-ps-js setf-conditional
835 (setf foo
(if x
1 2))
838 (test-ps-js obj-literal-numbers
842 (test-ps-js obj-literal-strings
846 (test-ps-js getprop-string
850 (test-ps-js getprop-string1
851 (getprop "bar" 'length
)
854 (test-ps-js getprop-progn
855 (getprop (progn (some-fun "abc") "123") "length")
856 "(someFun('abc'), '123')['length'];")
858 (test-ps-js method-call-block
859 ((@ (progn (some-fun "abc") "123") to-string
))
860 "(someFun('abc'), '123').toString();")
862 (test-ps-js create-blank
866 (test-ps-js blank-object-literal
870 (test-ps-js array-literal1
874 (test-ps-js array-literal2
878 (test-ps-js array-literal3
882 (test-ps-js array-literal4
886 (test-ps-js array-literal5
888 "[[1, 2], ['a', 'b']];")
890 (test-ps-js defun-rest1
891 (defun foo (&rest bar
)
892 (alert (aref bar
1)))
895 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
896 bar[i1] = arguments[i1 + 0];
898 return alert(bar[1]);
901 (test-ps-js defun-rest2
902 (defun foo (baz &rest bar
) (+ baz
(aref bar
1)))
905 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
906 bar[i1] = arguments[i1 + 1];
911 (test-ps-js defun-keyword1
912 (defun zoo (foo bar
&key baz
) (+ foo bar baz
))
913 "function zoo(foo, bar) {
914 var _js2 = arguments.length;
915 for (var n1 = 2; n1 < _js2; n1 += 2) {
916 switch (arguments[n1]) {
918 baz = arguments[n1 + 1];
922 return foo + bar + baz;
925 (test-ps-js defun-keyword2
926 (defun zoo (&key baz
) (* baz baz
))
928 var _js2 = arguments.length;
929 for (var n1 = 0; n1 < _js2; n1 += 2) {
930 switch (arguments[n1]) {
932 baz = arguments[n1 + 1];
939 (test-ps-js defun-keyword3
940 (defun zoo (&key baz
(bar 4)) (* baz bar
))
942 var _js2 = arguments.length;
943 for (var n1 = 0; n1 < _js2; n1 += 2) {
944 switch (arguments[n1]) {
946 baz = arguments[n1 + 1];
949 bar = arguments[n1 + 1];
953 var bar = 'undefined' === typeof bar ? 4 : bar;
957 (test-ps-js defun-keyword4
958 (defun hello-world (&key
((:my-name-key my-name
) 1))
960 "function helloWorld() {
961 var _js2 = arguments.length;
962 for (var n1 = 0; n1 < _js2; n1 += 2) {
963 switch (arguments[n1]) {
965 myName = arguments[n1 + 1];
968 var myName = 'undefined' === typeof myName ? 1 : myName;
972 (test-ps-js arglist-keyword-supplied
973 (lambda (&key
(foo 1 supplied?
))
976 var _js2 = arguments.length;
977 for (var n1 = 0; n1 < _js2; n1 += 2) {
978 switch (arguments[n1]) {
980 foo = arguments[n1 + 1];
985 var foo = 'undefined' === typeof foo ? 1 : foo;
989 (test-ps-js keyword-funcall1
993 (test-ps-js keyword-funcall2
994 (func :baz
1 :bar foo
)
995 "func('baz', 1, 'bar', foo);")
997 (test-ps-js keyword-funcall3
999 "fun(a, b, 'baz', c);")
1009 ((= y
(* x
4)) (foo "blah") (* x y
)))
1012 } else if (y === x * 4) {
1017 (test-ps-js if-exp-without-else-return
1018 (defun foo () (return-from foo
(if x
1)))
1020 return x ? 1 : null;
1023 (test-ps-js progn-expression-single-statement
1024 (defun foo () (return-from foo
(progn (* x y
))))
1029 (test-ps-js cond-expression1
1031 (cond ((< 1 2) (bar "foo") (* 4 5))))
1039 (test-ps-js cond-expression2
1041 (cond ((< 2 1) "foo")
1046 } else if (7 === 7) {
1051 (test-ps-js cond-expression-final-t-clause
1053 (cond ((< 1 2) (bar "foo") (* 4 5))
1064 } else if (a === b) {
1066 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
1073 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
1086 (test-ps-js funcall-if-expression
1087 (funcall (getprop document
'write
)
1088 (if (= *linkornot
* 1)
1089 (ps-html ((:a
:href
"#"
1090 :onclick
(ps-inline (transport)))
1093 "document.write(LINKORNOT === 1 ? ['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">', img, '</A>']['join']('') : img);")
1095 (test-ps-js negate-number-literal
1099 (test macro-environment1
1100 (is (string= (normalize-js-code (let* ((macroname (gensym)))
1101 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
1103 (macrolet ((,macroname
(x) `(aref data
,x
)))
1104 (when (,macroname x
)
1105 (setf (,macroname x
) 123)))))))
1108 return data[x] ? (data[x] = 123) : null;
1111 (test macro-environment2
1112 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
1113 (defpsmacro macro-environment2-macro
(x)
1114 `(+ ,outer-lexical-variable
,x
))
1115 (ps* '(macro-environment2-macro 2))))
1116 (normalize-js-code "1 + 2;"))))
1118 (test-ps-js ampersand-whole-1
1119 (macrolet ((foo (&whole foo bar baz
)
1120 (declare (ignore bar baz
))
1121 (with-standard-io-syntax (format nil
"~a" foo
))))
1125 (test-ps-js keyword-consistent
1129 (test-ps-js simple-symbol-macrolet
1130 (symbol-macrolet ((x 1)) x
)
1133 (test-ps-js compound-symbol-macrolet
1134 (symbol-macrolet ((x 123)
1139 (test-ps-js define-symbol-macro
1140 (progn (define-symbol-macro tst-sym-macro
2)
1144 (test-ps-js define-symbol-macro1
1145 (progn (define-symbol-macro tst-sym-macro1
2)
1146 (foo tst-sym-macro1
))
1149 (test-ps-js expression-progn
1150 (1+ (progn (foo) (if x
1 2)))
1151 "(foo(), x ? 1 : 2) + 1;")
1153 (test-ps-js let-decl-in-expression
1155 (if x
1 (let* ((foo x
)) foo
)))
1165 (test-ps-js special-var1
1166 (progn (defvar *foo
*)
1173 FOO_TMPSTACK1 = FOO;
1177 FOO = FOO_TMPSTACK1;
1181 (test-ps-js special-var2
1182 (progn (defvar *foo
*)
1191 FOO_TMPSTACK1 = FOO;
1193 return FOO * 2 * BAZ;
1195 FOO = FOO_TMPSTACK1;
1199 (test-ps-js literal1
1203 (test-ps-js literal2
1207 (test-ps-js setf-dec1
1211 (test-ps-js setf-dec2
1215 (test-ps-js special-char-equals
1219 (test-ps-js setf-operator-priority
1221 (or (getprop cache id
)
1222 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
1224 return cache[id] || (cache[id] = document.getElementById(id));
1227 (test-ps-js aref-operator-priority
1228 (aref (if (and x
(> (length x
) 0))
1232 "(x && x.length > 0 ? x[0] : y)[z];")
1234 (test-ps-js aref-operator-priority1
1235 (aref (or (getprop x
'y
)
1240 (test-ps-js aref-operator-priority2
1244 (test-ps-js negate-operator-priority
1253 (delete (if a
(or b c
) d
))
1254 "delete (a ? b || c : d);")
1257 (not (if (or x
(not y
)) z
))
1258 "!(x || !y ? z : null);")
1265 (instanceof (or a b
) (if x y z
))
1266 "((a || b) instanceof (x ? y : z));")
1269 (or x
(if (= x
0) "zero" "empty"))
1270 "x || (x === 0 ? 'zero' : 'empty');")
1272 (test-ps-js named-op-expression
1276 (test-ps-js named-op-expression1
1280 (test-ps-js aref-array-expression
1282 "(a || b || c)[0];")
1284 (test-ps-js getprop-operator
1285 (getprop (or a b c
) 'd
)
1288 (test-ps-js getprop-parens
1289 (getprop (getprop foo
'bar
) 'baz
)
1292 (test-ps-js funcall-funcall
1296 (test-ps-js expression-funcall
1297 ((or (@ window eval
) eval
) foo nil
)
1298 "(window.eval || eval)(foo, null);")
1300 (test-ps-js expression-funcall1
1301 (((or (@ window eval
) eval
) foo nil
))
1302 "(window.eval || eval)(foo, null)();")
1304 (test-ps-js expression-funcall2
1305 (((or (@ window eval
) eval
)) foo nil
)
1306 "(window.eval || eval)()(foo, null);")
1308 (test-ps-js who-html1
1309 (who-ps-html (:span
:class
"ticker-symbol"
1310 :ticker-symbol symbol
1311 (:a
:href
"http://foo.com"
1313 (:span
:class
"ticker-symbol-popup")))
1314 "['<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"', symbol, '\"><A HREF=\"http://foo.com\">', symbol, '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>']['join']('');")
1316 (test-ps-js who-html2
1317 (who-ps-html (:p
"t0" (:span
"t1")))
1318 "'<P>t0<SPAN>t1</SPAN></P>';")
1321 ((lambda () (flet ((foo (x)
1325 var foo = function (x) {
1332 (flet ((foo (x) (1+ x
))
1336 var foo = function (x) {
1339 var bar = function (y) {
1346 (flet ((foo (x) (+ 2 x
)))
1347 (flet ((foo (x) (1+ x
))
1348 (bar (y) (+ 2 (foo y
))))
1351 var foo = function (x) {
1354 var foo1 = function (x) {
1357 var bar = function (y) {
1360 return bar(foo1(1));
1364 ((lambda () (labels ((foo (x)
1367 (+ x
(foo (1- x
))))))
1370 var foo = function (x) {
1371 return 0 === x ? 0 : x + foo(x - 1);
1377 (labels ((foo (x) (1+ (bar x
)))
1378 (bar (y) (+ 2 (foo y
))))
1381 var foo = function (x) {
1384 var bar = function (y) {
1391 (labels ((foo (x) (1+ x
))
1392 (bar (y) (+ 2 (foo y
))))
1395 var foo = function (x) {
1398 var bar = function (y) {
1404 (test-ps-js labels-lambda-list
1405 (labels ((foo (x &optional
(y 0))
1409 var foo = function (x, y) {
1410 if (y === undefined) {
1418 (test-ps-js for-loop-var-init-exp
1420 (do* ((y (if x
0 1) (1+ y
))
1425 return (function () {
1426 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
1436 (test-ps-js literal-array
1440 (test-ps-js literal-array-1
1444 (test ps-lisp-expands-in-lexical-environment
1445 (is (string= "5;" (let ((x 5)) (ps (lisp x
))))))
1447 (test ps
*-lisp-expands-in-null-lexical-environment
;; ccl only does a warning
1448 (signals unbound-variable
(let ((x 5)) (declare (ignore x
)) (ps* '(lisp x
)))))
1450 (test ps
*-lisp-expands-in-dynamic-environment
1451 (is (string= "1 + 2;" (let ((foo 2)) (declare (special foo
)) (ps* '(+ 1 (lisp (locally (declare (special foo
)) foo
))))))))
1453 (test ps-lisp-dynamic-environment
1454 (is (string= "1 + 2;" (let ((foo 2)) (declare (special foo
)) (ps (+ 1 (lisp foo
)))))))
1456 (test-ps-js nested-if-expressions1
1458 (return-from foo
(if (if x y z
) a b
)))
1467 (test-ps-js nested-if-expressions2
1469 (if x y
(if z a b
)))
1548 (test-ps-js let-exp1
1599 (test-ps-js symbol-macrolet-var
1600 (symbol-macrolet ((x y
))
1604 (test-ps-js setf-conditional1
1605 (setf x
(unless (null a
) (1+ a
)))
1606 "x = a != null ? a + 1 : null;")
1608 (test-ps-js setf-let1
1609 (setf x
(let ((a 1)) a
))
1615 (test-ps-js setf-let2
1616 (setf x
(let ((a (foo)))
1621 return a != null ? a + 1 : null;
1624 (test-ps-js symbol-macro-env1
1625 (symbol-macrolet ((bar 1))
1626 (macrolet ((bar (x y
) `(+ ,x
,y
)))
1630 (test-ps-js symbol-macrolet-fun1
1631 (symbol-macrolet ((baz +))
1635 (test-ps-js lisp2-namespaces1
1637 (setf list
(list 1 2 3)))
1640 return list = [1, 2, 3];
1643 (test-ps-js let-shadows-symbol-macrolet
1644 (symbol-macrolet ((x y
))
1654 (test-ps-js let-rename-optimization1
1662 (test-ps-js let-rename-optimization2
1671 (test-ps-js symbol-macro-array
1672 (symbol-macrolet ((x 1))
1676 (test-ps-js symbol-macro-obj
1677 (symbol-macrolet ((x y
))
1681 (test-ps-js symbol-macro-conditional1
1682 (symbol-macrolet ((x y
))
1690 (test-ps-js symbol-macro-conditional2
1691 (symbol-macrolet ((x y
))
1695 (test-ps-js flet-apply
1696 (flet ((foo () 'bar
))
1697 (apply (function foo
) nil
))
1699 var foo = function () {
1702 return foo.apply(this, null);
1705 (test-ps-js let-apply
1706 (let ((foo (lambda () 1)))
1707 (let ((foo (lambda () 2)))
1710 var foo = function () {
1713 var foo1 = function () {
1716 return foo1.apply(this, null);
1719 (test-ps-js flet-let
1720 (flet ((x (x) (1+ x
)))
1724 var x = function (x) {
1731 (test-ps-js let-flet
1733 (flet ((x (x) (1+ x
)))
1737 var x1 = function (x) {
1743 (test-ps-js labels-let
1744 (labels ((x (x) (1+ x
)))
1748 var x = function (x) {
1755 (test-ps-js let-labels
1757 (labels ((x (x) (1+ x
)))
1761 var x1 = function (x) {
1767 (test-ps-js macrolet-let-inteference
1768 (macrolet ((a (n) `(+ ,n
5)))
1770 (let ((b (a (- a
4))))
1774 var b = (a - 4) + 5;
1778 (test-ps-js let-subtract-add
1794 (test-ps-js create-reserved-word
1796 "({ 'default' : 1 });")
1798 (test-ps-js getprop-reserved-word
1799 (getprop foo
:default
)
1802 (test-ps-js getprop-reserved-word1
1803 (getprop foo
'default
)
1806 (test-ps-js eval-when-ps-side
1807 (eval-when (:execute
)
1811 (defvar *lisp-output
* nil
)
1813 (test eval-when-lisp-side
()
1814 (setf *lisp-output
* 'original-value
)
1815 (let ((js-output (normalize-js-code
1816 (ps-doc* `(eval-when (:compile-toplevel
)
1817 (setf *lisp-output
* 'it-works
))))))
1818 (is (eql 'it-works
*lisp-output
*))
1819 (is (string= "" js-output
))))
1821 (defpsmacro my-in-package
(package-name)
1822 `(eval-when (:compile-toplevel
)
1823 (setf *lisp-output
* ,package-name
)))
1825 (test eval-when-macro-expansion
()
1826 (setf *lisp-output
* 'original-value
)
1827 (let ((js-output (normalize-js-code
1829 (my-in-package :cl-user
)
1831 (declare (ignore js-output
))
1832 (is (eql :cl-user
*lisp-output
*))))
1834 (test eval-when-macrolet-expansion
()
1835 (setf *lisp-output
* 'original-value
)
1836 (let ((js-output (normalize-js-code
1837 (ps-doc* `(macrolet ((my-in-package2 (package-name)
1838 `(eval-when (:compile-toplevel
)
1839 (setf *lisp-output
* ,package-name
))))
1840 (my-in-package2 :cl-user
)
1842 (declare (ignore js-output
))
1843 (is (eql :cl-user
*lisp-output
*))))
1845 (test-ps-js getprop-keyword
1849 (test-ps-js nary-comparison1
1850 (lambda () (< 1 2 3))
1853 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
1856 (test-ps-js chain-getprop1
1857 (chain ($
"foo") (bar x z
) frob
(baz 5))
1858 "$('foo').bar(x, z).frob.baz(5);")
1860 (test-ps-js chain-getprop2
1861 (chain ($
"foo") bar baz
)
1862 "$('foo').bar.baz;")
1864 (test-ps-js chain-getprop3
1865 (chain ($
"foo") bar
(x y
) baz
)
1866 "$('foo').bar.x(y).baz;")
1868 (test-ps-js flet-expression
1869 (1+ (flet ((foo (x) (1+ x
)))
1872 var foo = function (x) {
1878 (test-ps-js flet-lambda-list
1879 (flet ((foo (x &key
(y 0))
1883 var foo = function (x) {
1884 var _js2 = arguments.length;
1885 for (var n1 = 1; n1 < _js2; n1 += 2) {
1886 switch (arguments[n1]) {
1888 y = arguments[n1 + 1];
1891 var y = 'undefined' === typeof y ? 0 : y;
1894 return foo(1, 'y', 2);
1897 (test-ps-js return-case-break-elimination
1912 (test-ps-js aplusplus
1916 (test-ps-js astarstar
1920 (test-ps-js switch-return-fallthrough
1938 (test-ps-js return-last-case
1953 (test-ps-js return-macrolet
1956 (macrolet ((x () 1))
1969 (test-ps-js mv-bind1
1970 (multiple-value-bind (a b
)
1979 prevMv2 = arguments['callee']['mv'];
1981 arguments['callee']['mv'] = true;
1983 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
1988 if ('undefined' === typeof prevMv2) {
1989 delete arguments['callee']['mv'];
1991 arguments['callee']['mv'] = prevMv2;
1996 (test-ps-js mv-bind2
1997 (multiple-value-bind (a b
)
2007 prevMv2 = arguments['callee']['mv'];
2009 arguments['callee']['mv'] = true;
2011 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
2016 if ('undefined' === typeof prevMv2) {
2017 delete arguments['callee']['mv'];
2019 arguments['callee']['mv'] = prevMv2;
2024 (test-ps-js multiple-value-bind-simple
2025 (multiple-value-bind (a b
) (blah)
2029 prevMv2 = arguments['callee']['mv'];
2031 arguments['callee']['mv'] = true;
2033 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
2037 if ('undefined' === typeof prevMv2) {
2038 delete arguments['callee']['mv'];
2040 arguments['callee']['mv'] = prevMv2;
2046 (lambda () (values))
2060 if ('undefined' !== typeof arguments['callee']['caller']['mv']) {
2061 arguments['callee']['caller']['mv'] = valrest2;
2070 var valrest2 = [y, z];
2071 if ('undefined' !== typeof arguments['callee']['caller']['mv']) {
2072 arguments['callee']['caller']['mv'] = valrest2;
2077 (test-ps-js values-return
2079 (return-from foo
(values x y
)))
2083 if ('undefined' !== typeof arguments['callee']['caller']['mv']) {
2084 arguments['callee']['caller']['mv'] = valrest2;
2089 (test-ps-js return-macrolet1
2092 (symbol-macrolet ((x 2))
2093 (loop do
(+ x x
)))))
2100 (test-ps-js return-cond
2103 (cond ((foo? x
) (loop for y in x do
(foo y
)))
2108 var _js2 = x.length;
2121 } else if (barwhat(x)) {
2128 (test-ps-js return-case
2132 (1 (loop for y in x do
(foo y
)))
2138 var _js2 = x.length;
2161 (test-ps-js return-case1
2179 (test-ps-js lambda-loop-if-return
2182 (loop for y in x do
(foo y
))
2186 var _js4 = x.length;
2204 (test-ps-js lambda-loop-if-return1
2208 (progn (loop for y in x do
(foo y
))
2213 return foo(function () {
2215 var _js4 = x.length;
2228 throw { 'ps-block-tag' : 'baz', 'ps-return-value' : null };
2234 if (err && 'baz' === err['ps-block-tag']) {
2235 return err['ps-return-value'];
2242 (test-ps-js switch-loop
2247 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
2252 (test-ps-js switch-folds-blocks
2254 (1 (loop repeat
3 do
(alert "foo"))))
2257 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
2262 (test-ps-js setf-places-before-macros
2264 (defsetf left
(el) (offset)
2265 `(setf (@ ,el style left
) ,offset
))
2266 (macrolet ((left (el)
2267 `(@ ,el offset-left
)))
2273 _js2.style.left = _js1;
2274 return x.offsetLeft;
2277 (test-ps-js for-return
2278 (lambda () (dolist (arg args
) (foo arg
)))
2280 for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
2281 arg = args[_js_idx1];
2286 (test-ps-js try-catch-return
2304 (test-ps-js defun-setf-optional
2305 (defun (setf foo
) (new-value b
&optional c
)
2306 (setf (aref b
(or c
0)) new-value
))
2307 "function __setf_foo(newValue, b, c) {
2308 return b[c || 0] = newValue;
2311 (test-ps-js defun-setf-rest
2312 (progn (defun (setf foo
) (new-value b
&rest foo
)
2313 (do-something b foo new-value
))
2314 (setf (foo x
1 2 3 4) 5))
2315 "function __setf_foo(newValue, b) {
2317 for (var i1 = 0; i1 < arguments.length - 2; i1 += 1) {
2318 foo[i1] = arguments[i1 + 2];
2320 return doSomething(b, foo, newValue);
2322 __setf_foo(5, x, 1, 2, 3, 4);")
2324 (test-ps-js return-null
2325 (defun foo () (return-from foo nil
))
2330 (test-ps-js implicit-return-null
2337 (test-ps-js implicit-return-null
2344 (test-ps-js return-conditional-nested
2345 (defun blep (ss x y
)
2349 (destructuring-bind (a b
) pair
2350 (unless (or (null a
) (null b
))
2351 (let ((val (baz a b
)))
2356 "function blep(ss, x, y) {
2362 if (!(a == null || b == null)) {
2363 var val = baz(a, b);
2366 return !blee() ? true : null;
2374 ;; this test needs to be rewritten when named blocks are implemented!!!!
2375 (test-ps-js return-when-returns-broken-return
2377 (return-from foo
(when x
1))
2380 return x ? 1 : null;
2384 (test-ps-js return-case-conditional
2388 (123 (when (bar) t
))
2393 return bar() ? true : null;
2399 (test-ps-js return-try-conditional
2407 return x ? 1 : null;
2415 (test-ps-js function-declare-special
2417 (declare (special *foo
*))
2423 FOO_TMPSTACK1 = FOO;
2427 FOO = FOO_TMPSTACK1;
2431 (test-ps-js declare-special-let
2433 (declare (special *foo
*))
2438 FOO_TMPSTACK1 = FOO;
2442 FOO = FOO_TMPSTACK1;
2446 (test-ps-js macro-null-toplevel
2448 (defmacro macro-null-toplevel
()
2450 (macro-null-toplevel))
2453 (test-ps-js define-symbol-macro-let
2455 (define-symbol-macro test-symbol-macro
1)
2456 (let ((test-symbol-macro 2))
2457 (1+ test-symbol-macro
))
2458 (1+ test-symbol-macro
))
2460 var testSymbolMacro1 = 2;
2461 return testSymbolMacro1 + 1;
2465 (test-ps-js define-symbol-macro-flet
2467 (define-symbol-macro test-symbol-macro1
1)
2468 (flet ((test-symbol-macro1 () 2))
2469 (foo test-symbol-macro1
)
2470 (test-symbol-macro1))
2471 (bar test-symbol-macro1
))
2473 var testSymbolMacro1_1 = function () {
2477 return testSymbolMacro1_1();
2481 (test compile-stream-nulls
2484 (with-input-from-string (s "
2485 (defmacro macro-null-toplevel ()
2487 (macro-null-toplevel)")
2488 (ps-compile-stream s
)))))
2490 (test compile-stream1
2493 var testSymbolMacro1_1 = function () {
2497 return testSymbolMacro1_1();
2501 (with-input-from-string (s "
2502 (define-symbol-macro test-symbol-macro1 1)
2503 (flet ((test-symbol-macro1 () 2))
2504 (foo test-symbol-macro1)
2505 (test-symbol-macro1))
2506 (bar test-symbol-macro1)")
2507 (ps::with-blank-compilation-environment
(ps-compile-stream s
))))))
2509 (test-ps-js equality-nary1
2510 (let ((x 10) (y 10) (z 10))
2517 return (_cmp1 = y, x === _cmp1 && _cmp1 === z);
2520 (test-ps-js equality1
2531 (test-ps-js getprop-quote-reserved
2532 (getprop foo
':break
)
2535 (test-ps-js defun-block-return-from
2546 (test-ps-js block-return-from
2550 (return-from scope
))
2560 (test-ps-js block-return-from0
2565 (return-from scope
))
2575 (test-ps-js block-return-from01
2580 (return-from scope
))
2594 (test-ps-js block-return-from02
2599 (return-from scope
(foobar)))
2614 (test-ps-js block-return-from1
2619 (return-from scope
))
2633 (test-ps-js block-return-from2
2639 (return-from scope
6))
2650 (test-ps-js let-funcall
2664 (test-ps-js symbol-macrolet-funcall
2665 (symbol-macrolet ((foo bar
))
2666 (funcall foo
1 2 3))
2669 (test-ps-js times-assign
2673 (test-ps-js vector-literal
2678 (+ 1 (rem 2 (+ 3 4)))
2681 (test-ps-js non-associative
2682 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
2683 "1 / (2 / 3) + (1 - (2 - 3));")
2685 (test-ps-js lambda-apply
2687 (apply (lambda (y) (bar (1+ y
))) x
))
2689 return (function (y) {
2694 (test-ps-js operator-expressions-nested-let
2695 (let ((x (let ((y 1))
2704 (test-ps-js operator-expressions-array-nested-let
2705 (list (let ((y 1)) y
) 2)
2711 (test-ps-js add-subtract-precedence
2715 (test-ps-js ps-inline-toplevel
2717 "'javascript:' + 'foo()';")
2719 (test-ps-js no-clause-progn-exp
2723 (test-ps-js no-clause-progn-return
2725 (return-from foo
(progn)))
2730 (test-ps-js empty-cond-clause
2731 (setf x
(cond ((foo))))
2732 "x = foo() ? null : null;")
2734 (test-ps-js empty-cond-clause1
2735 (setf x
(cond ((foo) 123)
2738 "x = foo() ? 123 : (bar() ? null : 456);")
2740 (test-ps-js let-no-body
2742 (return-from foo
(let ((foo bar
)))))
2748 (test-ps-js rename-lexical-dupes
2750 (list (let ((foo 12)) (* foo
2))
2751 (let ((foo 13)) (* foo
3))))
2755 return [(foo = 12, foo * 2), (foo1 = 13, foo1 * 3)];
2758 (test-ps-js defun-comment1
2760 "BARBAR is a revolutionary new foobar.
2764 * BARBAR is a revolutionary new foobar.
2771 (test-ps-js var-comment
2776 (test-ps-js case-return-break-broken-return
2779 ("bar" (if y
(return-from foo t
) nil
))
2794 (test-ps-js case-return-break1-broken-return
2797 ("bar" (if y
(return-from foo t
)))
2812 (test-ps-js setf-progn
2813 (setf foo
(progn (bar) (baz) 3))
2818 (test-ps-js var-progn
2819 (var x
(progn (foo) (bar)))
2823 (test-ps-js implicit-return-loop
2827 (loop :repeat
100 :do
(bar))
2833 for (var _js2 = 0; _js2 < 100; _js2 += 1) {
2840 ;; closures in loops need a new binding per loop iteration (idea borrowed from Scheme2JS)
2841 (test-ps-js loop-closures
2842 (dotimes (i 10) (lambda () (+ i
1)))
2843 "for (var i = 0; i < 10; i += 1) {
2851 (test-ps-js loop-closures-let
2854 (lambda () (+ i x
))))
2855 "for (var i = 0; i < 10; i += 1) {
2856 with ({ i : i, x : null }) {
2864 (test-ps-js loop-closures-flet
2865 (dotimes (i 10) (flet ((foo (x) (+ i x
))) (lambda () (foo i
))))
2866 "for (var i = 0; i < 10; i += 1) {
2867 with ({ foo : null, i : i }) {
2868 var foo = function (x) {
2877 (test-ps-js while-closures-let
2880 (lambda () (+ 1 x
))))
2882 with ({ x : null }) {
2890 (test-ps-js dotted-list-form
2893 (destructuring-bind (b . c
)
2899 var c = bar.length > 1 ? bar.slice(1) : [];
2904 (test-ps-js return-from-loop
2905 (dolist (x '(2 1 3))
2908 (chain console
(log x
)))
2910 var loopResultVar3 = null;
2911 for (var x = null, _js_arrvar2 = [2, 1, 3], _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
2912 x = _js_arrvar2[_js_idx1];
2914 loopResultVar3 = null;
2919 return loopResultVar3;
2922 (test-ps-js explicit-nil-block
2925 (block nil
(return (foo 2)) (+ 1 2))
2937 (test-ps-js dynamic-extent-function-return
2938 (defun foo () ((lambda () (return-from foo
6))))
2941 return (function () {
2942 throw { 'ps-block-tag' : 'foo', 'ps-return-value' : 6 };
2945 if (err && 'foo' === err['ps-block-tag']) {
2946 return err['ps-return-value'];
2953 (test-ps-js dynamic-extent-function-return-funcall
2954 (defun foo () ((lambda () (return-from foo
(if baz
6 5)))))
2957 return (function () {
2958 throw { 'ps-block-tag' : 'foo', 'ps-return-value' : baz ? 6 : 5 };
2961 if (err && 'foo' === err['ps-block-tag']) {
2962 return err['ps-return-value'];
2969 (test-ps-js block-dynamic-return
2970 (var foo
((lambda ()
2972 ((lambda () (return 6)))
2974 "var foo = (function () {
2977 throw { 'ps-block-tag' : 'nilBlock', 'ps-return-value' : 6 };
2981 if (err && 'nilBlock' === err['ps-block-tag']) {
2982 return err['ps-return-value'];
2989 (test-ps-js block-dynamic-return1
2990 (var foo
((lambda ()
2992 ((lambda () (return 6)))
2995 "var foo = (function () {
3002 return foobar(1, 2);
3005 (test-ps-js iteration-lambda-capture-no-need
3006 (dolist (x y
) (lambda (x) (1+ x
))) ;; there's really no need to create a 'with' scope in this case
3007 "for (var x = null, _js_idx1 = 0; _js_idx1 < y.length; _js_idx1 += 1) {
3016 (test-ps-js case-invert1
3017 (encodeURIComponent fooBar
)
3018 "encodeURIComponent(fooBar);")
3020 (test-ps-js simple-ash
3021 (+ (ash 4 1) (ash 4 -
1))
3022 "(4 << 1) + (4 >> 1);")
3024 (test-ps-js progn-nil-expression
3025 (bar (progn (foo) nil
))
3026 "bar((foo(), null));")
3028 (test-ps-js other-progn-nil-exp
3030 (or (foo) (progn (bar) nil
)))
3032 return foo() || (bar(), null);
3035 (test-ps-js lambda-nil-return
3048 (test-ps-js lambda-nil-return-implicit-nested
3060 var loopResultVar1 = null;
3061 for (var i = 0; i < 4; i += 1) {
3070 (test-ps-js lambda-nil-return-implicit-nested2
3076 (return-from foo i
)))
3082 for (var i = 0; i < 4; i += 1) {
3089 (test-ps-js throw-is-a-statement
3091 (let ((result (foo)))
3092 (unless (null result
)
3096 if (result != null) {
3101 (test-ps-js expressify1
3103 (when (some-condition)
3108 if (someCondition()) {
3115 (test-ps-js case-when-return
3118 ("a" (when (foo) (return-from blah
111)))
3133 (test-ps-js flet-return-from
3136 (return-from foo
123)))
3139 var foo = function () {
3145 (test-ps-js flet-return-from1
3147 (return-from foo
123)))
3150 var foo = function () {
3156 (test-ps-js lambda-docstring-declarations
3158 "This is a docstring"
3159 (declare (ignore x
))
3165 (test-ps-js setf-let-exp
3166 (setf foo
(let ((x (+ 1 2)))
3168 "foo = (function () {
3170 return x ? 123 : 456;
3173 (test-ps-js create-let-exp
3174 (create :abc
(let ((x (+ 1 2)))
3176 "({ 'abc' : (function () {
3178 return x ? 123 : 456;
3181 (test-ps-js eql-eql-eql-precedence
3182 (unless (equal (= 3 3) (= 3 4))
3183 (chain console
(log 1)))
3184 "if ((3 === 3) != (3 === 4)) {
3188 (test-ps-js case-cond-breaks
3194 (return-from blah nil
))
3217 (test-ps-js cond-double-t
3230 (test-ps-js let-let-funcall-lambda
3233 (funcall (lambda (x) (+ x
9)) x
)))
3237 return (function (x) {
3242 (test-ps-js let-let-lambda
3245 (lambda (x) (+ x
9))))
3249 return function (x) {
3254 (test-ps-js let-lambda
3256 (lambda (x) (+ x
9)))
3259 return function (x) {
3264 (test-ps-js symbol-macrolet-no-shadow-lambda
3265 (symbol-macrolet ((x y
))
3266 (lambda (x) (+ x x
)))
3271 (test-ps-js divide-one-arg-reciprocal
3275 (test-ps-js division-not-associative
3279 (test-ps-js divide-expressions
3283 (test-ps-js divide-expressions1
3285 "Math.floor((x - 1) / y);")
3287 (test-ps-js lexical-funargs-shadow1
3298 (test-ps-js times-rem
3302 (test-ps-js rem-divide
3306 (test-ps-js case-break-return
3307 (lambda () (case x
(:foo
) (:bar
1)))
3317 (test-ps-js trivial-expression-switch
3318 (foobar (case x
(1 2)))
3319 "foobar((function () {
3326 (test-ps-js trivial-expression-while
3327 (foobar (while (< 0 x
) (decf x
)))
3328 "foobar((function () {
3334 (test-ps-js funcall-block-expression-loop-lambda
3335 (foobar (loop for i from
0 to
10 do
(1+ i
)))
3336 "foobar((function () {
3337 for (var i = 0; i <= 10; i += 1) {
3342 (test-ps-js plus-block-expression-loop-lambda
3343 (1+ (loop for i from
0 to
10 do
(1+ i
)))
3345 for (var i = 0; i <= 10; i += 1) {
3350 (test-ps-js let-closures-rename
3352 (let ((x 1)) (lambda () (1+ x
)))
3353 (let ((x 2)) (lambda () (1+ x
))))
3360 return function () {
3365 (test-ps-js let-closures-rename1
3369 (lambda () (+ x y
))))
3372 (lambda () (+ x y
)))))
3381 return function () {
3386 (test-ps-js let-closures-rename2
3387 (defun make-closures ()
3389 (let ((x 1)) (lambda () (1+ x
)))
3390 (let ((x 2)) (lambda () (1+ x
)))))
3391 "function makeClosures() {
3394 return [(x = 1, function () {
3396 }), (x1 = 2, function () {
3402 (test-ps-js conditional-not-used-up
3414 (test-ps-js toplevel-local-scope
3415 (create "fn" (let ((x 5)) (lambda () x
)))
3416 "({ 'fn' : (function () {
3418 return function () {
3423 (test-ps-js toplevel-local-scope1
3424 (defvar foo
(create "fn" (let ((x 5)) (lambda () x
))))
3425 "var foo = { 'fn' : (function () {
3427 return function () {
3432 (test-ps-js block-let
3435 (return-from foobar x
)
3443 (test-ps-js dolist-return1
3444 (dolist (x '(5 2 3))
3447 var loopResultVar3 = null;
3448 for (var x = null, _js_arrvar2 = [5, 2, 3], _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
3449 x = _js_arrvar2[_js_idx1];
3450 loopResultVar3 = x + 1;
3453 return loopResultVar3;
3456 (test-ps-js expressionize-if-macroexpand-error
3457 (progn (defmacro xbaz
() `(blah))
3463 "function foo(xbaz) {
3473 (test-ps-js toplevel-defun-macroexpand
3474 (progn (defmacro defun-js
(name lambda-list
&body body
)
3475 `(defun ,name
,lambda-list
,@body
))
3478 (defun-js bar
() (1+ foo
))
3488 ;; (test-ps-js let-defun-toplevel
3489 ;; (progn (let ((foo 0))
3490 ;; (defun bar () foo))
3492 ;; "var bar_foo1 = 0;
3498 ;; (test-ps-js let-defvar-toplevel
3499 ;; (progn (let ((foo 0))
3500 ;; (defvar bar (1+ foo)))
3502 ;; "var bar_foo1 = 0;
3503 ;; var bar = bar_foo1 + 1;
3506 ;; (test-ps-js setf-side-effects
3509 ;; (defun side-effect()
3512 ;; (setf x (+ 2 (side-effect) x 5))))
3513 ;; "var sideEffect_x1 = 10;
3514 ;; function sideEffect() {
3515 ;; sideEffect_x1 = 4;
3518 ;; sideEffect_x1 = 2 + sideEffect() + x + 5;")