1 ;; SPDX-License-Identifier: BSD-3-Clause
4 (named-readtables:in-readtable
:parenscript
)
6 (in-suite output-tests
)
8 (test-ps-js statements-and-expressions-1
12 (test-ps-js statements-and-expressions-2
20 (test-ps-js symbol-conversion-1
22 "bangwhathashatpercent;")
24 (test-ps-js symbol-conversion-2
28 (test-ps-js symbol-conversion-3
32 (test-ps-js symbol-conversion-4
36 (test-ps-js symbol-conversion-5
38 "encodeURIComponent;")
40 (test-ps-js symbol-conversion-6
44 (test-ps-js number-literals-1
48 (test-ps-js number-literals-2
52 (test-ps-js number-literals-3
56 (test-ps-js string-literals-1
60 (test-ps-js string-literals-2
64 (test-ps-js string-literals-3
68 (test-ps-js array-literals-1
72 (test-ps-js array-literals-2
76 (test-ps-js array-literals-3
78 (array "foobar" "bratzel bub"))
79 "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ];")
81 (test-ps-js array-literals-4
85 (test-ps-js array-literals-5
87 "new Array(1, 2, 3);")
89 (test-ps-js array-literals-6
92 (make-array "foobar" "bratzel bub"))
93 "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'));")
95 (test-ps-js array-init-1
96 (make-array 2 :initial-contents
'(10 20))
98 var arr1 = new Array(2);
100 for (var i4 = 0; i4 < Math.min(arr1.length, init2.length); i4 += 1) {
101 arr1[i4] = init2[i4];
106 (test-ps-js array-init-2
107 (make-array 5 :initial-element
10)
109 var arr1 = new Array(5);
111 for (var i4 = 0; i4 < arr1.length; i4 += 1) {
117 (test-ps-js object-literals-1
118 (create foo
"bar" :blorg
1)
119 "({ foo : 'bar', 'blorg' : 1 });")
121 (test-ps-js object-literals-2
124 another-object
(create :schtrunz
1))
127 anotherObject : { 'schtrunz' : 1 } });")
129 (test-ps-js object-literals-3
130 (getprop an-object
'foo
)
133 (test-ps-js object-literals-4
134 (@ an-object foo bar
)
137 (test-ps-js object-literals-5
138 (with-slots (a b c
) this
140 "this.a + this.b + this.c;")
142 (test-ps-js with-slots-single-eval
143 (lambda () (with-slots (a b
) (foo) (+ a b
)))
146 return object1.a + object1.b;
149 (test-ps-js object-literal-quoted-symbols
150 (create 'test
"bang" 'symbol-saved-my-life
"parenscript")
151 "({ 'test' : 'bang', 'symbolSavedMyLife' : 'parenscript' });")
153 (test-ps-js object-literal-property-accessors
157 (set x v
) (setf x v
))))
166 :js-target-version
"1.8.5")
168 (test-ps-js object-method-apply-1
169 (apply (@ an-object foo
) nil
)
170 "anObject.foo.apply(anObject, null);")
172 (test-ps-js object-method-apply-2
173 (apply (getprop (make-an-object) foo
'bar
) nil
)
175 var _js1 = makeAnObject()[foo];
177 return _js2.apply(_js1, null);
180 (test-ps-js object-method-apply-3
181 (apply (@ (make-an-object) foo
) (bar))
183 var _js1 = makeAnObject();
185 return _js2.apply(_js1, bar());
188 (test-ps-js regular-expression-literals-1
192 (test-ps-js regular-expression-literals-2
196 (test-ps-js literal-symbols-1
200 (test-ps-js literal-symbols-2
204 (test-ps-js literal-symbols-3
208 (test-ps-js literal-symbols-4
214 (test-ps-js literal-symbols-5
218 (test-ps-js literal-symbols-6
222 (test-ps-js variables-1
226 (test-ps-js variables-2
230 (test-ps-js variables-3
234 (test-ps-js function-calls-and-method-calls-1
238 (test-ps-js function-calls-and-method-calls-2
239 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
240 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ]);")
242 (test-ps-js function-calls-and-method-calls-3
243 ((getprop this
'blorg
) 1 2)
246 (test-ps-js function-calls-and-method-calls-4
250 (test-ps-js function-calls-and-method-calls-5
251 ((getprop (aref foobar
1) 'blorg
) nil t
)
252 "foobar[1].blorg(null, true);")
254 (test-ps-js operator-expressions-1
258 (test-ps-js operator-expressions-2
262 (test-ps-js operator-expressions-3
263 (* 1 (+ 2 3 4) 4 (/ 6 7))
264 "1 * (2 + 3 + 4) * 4 * (6 / 7);")
266 (test-ps-js operator-expressions-4
270 (test-ps-js operator-expressions-5
274 (test-ps-js operator-expressions-6
278 (test-ps-js operator-expressions-7
282 (test-ps-js operator-expressions-8
286 (test-ps-js body-forms-1
287 (progn (blorg i
) (blafoo i
))
291 (test-ps-js body-forms-2
292 (+ i
(progn (blorg i
) (blafoo i
)))
293 "i + (blorg(i), blafoo(i));")
295 (test-ps-js function-definition-1
296 (defun a-function (a b
)
298 "function aFunction(a, b) {
302 (test-ps-js lambda-definition-2
303 (lambda (a b
) (+ a b
))
308 (test-ps-js assignment-1
312 (test-ps-js assignment-2
313 (setf a
2 b
3 c
4 x
(+ a b c
))
319 (test-ps-js assignment-3
320 (setf a
(+ a
2 3 4 a
))
321 "a = a + 2 + 3 + 4 + a;")
323 (test-ps-js assignment-4
327 (test-ps-js assignment-5
339 (test-ps-js assignment-6
343 (test-ps-js assignment-8
345 (defun (setf color
) (new-color el
)
346 (setf (getprop (getprop el
'style
) 'color
) new-color
))
347 (setf (color some-div
) (+ 23 "em")))
348 "function __setf_color(newColor, el) {
349 return el.style.color = newColor;
351 __setf_color(23 + 'em', someDiv);")
353 (test-ps-js assignment-10
355 (defsetf left
(el) (offset)
356 `(setf (getprop (getprop ,el
'style
) 'left
) ,offset
))
357 (setf (left some-div
) (+ 123 "px")))
360 var _js1 = 123 + 'px';
361 return _js2.style.left = _js1;
364 (test-ps-js assignment-12
365 (macrolet ((left (el)
366 `(getprop ,el
'offset-left
)))
368 "someDiv.offsetLeft;")
370 (test-ps-js nil-block-return-1
371 (block nil
(return) 1)
377 (test-ps-js single-argument-statements-2
381 (test-ps-js single-argument-expression-1
382 (delete (new (*foobar
2 3 4)))
383 "delete new Foobar(2, 3, 4);")
385 (test-ps-js single-argument-expression-2
386 (if (= (typeof blorg
) *string
)
387 (alert (+ "blorg is a string: " blorg
))
388 (alert "blorg is not a string"))
389 "if (typeof blorg === String) {
390 alert('blorg is a string: ' + blorg);
392 alert('blorg is not a string');
395 (test-ps-js conditional-statements-1
397 (if ((@ blorg is-correct
))
398 (progn (carry-on) (return-from foo i
))
399 (alert "blorg is not correct!")))
401 if (blorg.isCorrect()) {
405 return alert('blorg is not correct!');
409 (test-ps-js conditional-statements-2
410 (+ i
(if ((@ blorg add-one
)) 1 2))
411 "i + (blorg.addOne() ? 1 : 2);")
413 (test-ps-js conditional-statements-3
415 (when ((@ blorg is-correct
))
417 (return-from foo i
)))
419 if (blorg.isCorrect()) {
425 (test-ps-js conditional-statements-4
426 (unless ((@ blorg is-correct
))
427 (alert "blorg is not correct!"))
428 "if (!blorg.isCorrect()) {
429 alert('blorg is not correct!');
432 (test-ps-js variable-declaration-1
433 (defvar *a
* (array 1 2 3))
434 "var A = [ 1, 2, 3 ];")
436 (test-ps-js variable-declaration-2
437 (progn (defvar *a
* 4)
458 (test-ps-js iteration-constructs-1
459 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
461 (e (aref c d
) (aref c d
)))
462 ((or (= d
(@ c length
)) (string= e
"x")))
464 (funcall (@ document write
) (+ "a: " a
" b: " b
"<br/>")))
466 for (var a = null, b = null, c = ['a', 'b', 'c', 'd', 'e'], d = 0, e = c[d];
467 !(d === c.length || e === 'x'); d += 1, e = c[d]) {
470 document.write('a: ' + a + ' b: ' + b + '<br/>');
474 (test-ps-js iteration-constructs-2
476 (s 0 (+ s i
(1+ i
))))
478 (funcall (@ document write
) (+ "i: " i
" s: " s
"<br/>")))
483 document.write('i: ' + i + ' s: ' + s + '<br/>');
485 var _js2 = s + i + (i + 1);
491 (test-ps-js iteration-constructs-3
493 (s 0 (+ s i
(1- i
))))
495 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
497 for (var i = 0, s = 0; i <= 10; i += 1, s = s + i + (i - 1)) {
498 document.write('i: ' + i + ' s: ' + s + '<br/>');
502 (test-ps-js iteration-constructs-4
503 (let ((arr (array "a" "b" "c" "d" "e")))
504 (dotimes (i (@ arr length
))
505 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
507 var arr = ['a', 'b', 'c', 'd', 'e'];
508 for (var i = 0; i < arr.length; i += 1) {
509 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
513 (test-ps-js iteration-constructs-5
515 (alert (+ "Summation to 10 is "
517 (incf res
(1+ i
))))))
520 return alert('Summation to 10 is ' + (function () {
521 for (var i = 0; i < 10; i += 1) {
528 (test-ps-js iteration-constructs-6
529 (let ((l (list 1 2 4 8 16 32)))
531 ((@ document write
) (+ "c: " c
"<br/>"))))
533 var l = [1, 2, 4, 8, 16, 32];
534 for (var c = null, _js_idx2 = 0; _js_idx2 < l.length; _js_idx2 += 1) {
536 document.write('c: ' + c + '<br/>');
540 (test-ps-js iteration-constructs-7
541 (let ((l '(1 2 4 8 16 32))
543 (alert (+ "Sum of " l
" is: "
547 var l = [1, 2, 4, 8, 16, 32];
549 return alert('Sum of ' + l + ' is: ' + (function () {
550 for (var c = null, _js_idx1 = 0; _js_idx1 < l.length; _js_idx1 += 1) {
558 (test-ps-js iteration-constructs-8
559 (let ((obj (create a
1 b
2 c
3)))
561 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
563 var obj = { a : 1, b : 2, c : 3 };
565 document.write(i + ': ' + obj[i] + '<br/>');
569 (test-ps-js iteration-constructs-9
570 (while ((@ film is-not-finished
))
571 ((@ this eat
) (new *popcorn
)))
572 "while (film.isNotFinished()) {
573 this.eat(new Popcorn);
576 (test-ps-js loop-for-bindings
577 (loop :for
((a b
) (:c
:d
)) :in arr
:do
(foo a b c d
))
579 var _js2 = arr.length;
580 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
581 var _db4 = arr[_js1];
592 (test-ps-js loop-for-on
593 (loop :for
(k v
) :on plist
:by
2 :do
(foo k v
))
595 for (var _js1 = plist; _js1.length > 0; _js1 = _js1['slice'](2)) {
602 (test-ps-js loop-for-keys-of
603 (loop :for k
:of obj
:do
(foo k
))
610 (test-ps-js loop-for-key-val-pairs-of
611 (loop :for
(k v
) :of obj
:do
(foo k v
))
619 (test-ps-js loop-for-key-val-pairs-of-with-bindings
620 (loop :for
(k (a b
)) :of obj
:do
(foo k a b
))
630 (test-ps-js loop-for-just-vals-of
631 (loop :for
(nil v
) :of obj
:do
(foo k v
))
633 for (var _js1 in obj) {
639 (test-ps-js loop-map-to
640 (loop :for str
:in strs
:map str
:to
(length str
))
642 var _js2 = strs.length;
644 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
645 var str = strs[_js1];
646 map3[str] = str.length;
651 (test-ps-js loop-for-of-map-to
652 (loop :for k
:of obj
:map k
:to
(foo k
))
661 (test-ps-js loop-for-of-when
662 (loop :for k
:of obj
:when
(foo k
) :map k
:to
(bar k
))
673 (test-ps-js loop-for-in-until-when
674 (loop :for a
:in b
:until
(> a
100) :when
(< a
50) :do
(foo a
))
677 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
688 (test-ps-js loop-with-for-when
689 (loop :with c
= c1
:for d
:from c1
:below c2
690 :when
(foo c d
) :do
(setf c d
)
694 for (var d = c1; d < c2; d += 1) {
702 (test-ps-js loop-for-then-for-in-while
704 (loop :for a
= (foo) :then
(bar) :for b
:in c
:while b
:do
(foo a b c
)))
708 for (var a = foo(); true; a = bar()) {
709 var _js1 = FIRST3 ? 0 : _js1 + 1;
722 (test-ps-js loop-while-when
723 (loop :for a
= (pop stack
) :while a
:for
(b c
) = (foo a
) :when b
:do
(bar c
))
725 for (var a = pop(stack); a; a = pop(stack)) {
735 (test-ps-js loop-for-of-for-in
737 (loop :for k
:of obj
:for a
:in b
:do
(foo k a
)))
738 "function blah(obj, b) {
742 var _js1 = FIRST3 ? 0 : _js1 + 1;
752 (test-ps-js loop-for-dot
753 (loop :for
(op . args
) :in expr
:do
(foo op args
))
755 var _js2 = expr.length;
756 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
757 var _db3 = expr[_js1];
759 var args = _db3.length > 1 ? _db3.slice(1) : [];
764 (test-ps-js loop-for-rest
765 (loop :for
(op &rest args
) :in expr
:do
(foo op args
))
767 var _js2 = expr.length;
768 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
769 var _db3 = expr[_js1];
771 var args = _db3.length > 1 ? _db3.slice(1) : [];
776 (test-ps-js loop-collect
777 (setf x
(loop :for a
:in b
:collect
(foo a
)))
781 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
783 collect3.push(foo(a));
788 (test-ps-js loop-append
789 (loop :for a
:in b
:append a
)
793 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
795 append3 = append3.concat(a);
800 (test-ps-js the-case-statement-1
802 ((1 "one") (alert "one"))
804 (t (alert "default clause")))
814 alert('default clause');
817 (test-ps-js the-case-statement-2
818 (switch (aref blorg i
)
819 (1 (alert "If I get here"))
820 (2 (alert "I also get here"))
821 (default (alert "I always get here")))
823 case 1: alert('If I get here');
824 case 2: alert('I also get here');
825 default: alert('I always get here');
828 (test-ps-js the-try-statement-1
831 (alert (+ "an error happened: " error
)))
833 (alert "Leaving the try form")))
837 alert('an error happened: ' + error);
839 alert('Leaving the try form');
842 (test-ps-js the-html-generator-1
843 (ps-html ((:a
:href
"foobar") "blorg"))
844 "'<A HREF=\"foobar\">blorg</A>';")
846 (test-ps-js the-html-generator-2
847 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
848 "['<A HREF=\"', generateALink(), '\">blorg</A>'].join('');")
850 (test-ps-js the-html-generator-3
851 (funcall (getprop document
'write
)
852 (ps-html ((:a
:href
"#"
853 :onclick
(ps-inline (transport))) "link")))
854 "document.write(['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">link</A>'].join(''));")
856 (test-ps-js the-html-generator-4
859 (setf (getprop element
'inner-h-t-m-l
)
860 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
864 var authorized = true;
865 return element.innerHTML = ['<TEXTAREA', disabled || !authorized ? [' DISABLED=\"', 'disabled', '\"'].join('') : '', '>Edit me</TEXTAREA>'].join('');
868 (test-ps-js plus-is-not-commutative
869 (setf x
(+ "before" x
"after"))
870 "x = 'before' + x + 'after';")
872 (test-ps-js plus-works-if-first
873 (setf x
(+ x
"middle" "after"))
874 "x = x + 'middle' + 'after';")
876 (test-ps-js method-call-op-form
877 (funcall (getprop (+ "" x
) 'to-string
))
878 "('' + x).toString();")
880 (test-ps-js method-call-op-form-args
881 (funcall (getprop (+ "" x
) 'foo
) 1 2 :baz
3)
882 "('' + x).foo(1, 2, 'baz', 3);")
884 (test-ps-js method-call-string
885 ((getprop "hi" 'to-string
))
888 (test-ps-js method-call-conditional
892 (test-ps-js method-call-variable
896 (test-ps-js method-call-array
897 ((@ (list 10 20) to-string
))
898 "[ 10, 20 ].toString();")
900 (test-ps-js method-call-lambda-call
901 (funcall (getprop (funcall (lambda (x) x
) 10) 'to-string
))
902 "(function (x) { return x; })(10).toString();")
904 (test no-whitespace-before-dot
905 (let* ((str (ps* '((@ ((lambda (x) x
) 10) to-string
))))
906 (dot-pos (position #\. str
:test
#'char
=))
907 (char-before (elt str
(1- dot-pos
)))
909 (is (char= char-before a-parenthesis
))))
911 (test-ps-js simple-getprop
912 (let ((foo (create a
1)))
913 (alert (getprop foo
'a
)))
919 (test-ps-js buggy-getprop
920 (getprop foo slot-name
)
923 (test-ps-js buggy-getprop-two
924 (getprop foo
(get-slot-name))
925 "foo[getSlotName()];")
927 (test-ps-js old-case-is-now-switch
928 ;; Switch was "case" before, but that was very non-lispish.
929 ;; For example, this code makes three messages and not one
930 ;; which may have been expected. This is because a switch
931 ;; statment must have a break statement for it to return
932 ;; after the alert. Otherwise it continues on the next
934 (switch (aref blorg i
)
937 (default (alert "default clause")))
939 case 1: alert('one');
940 case 2: alert('two');
941 default: alert('default clause');
944 (test-ps-js lisp-like-case
948 (t (alert "default clause")))
956 default: alert('default clause');
960 (test-ps-js even-lispier-case
962 ((1 2) (alert "Below three"))
964 (t (alert "Something else")))
968 alert('Below three');
973 default: alert('Something else');
976 (test-ps-js otherwise-case
979 (otherwise (alert "default clause")))
984 default: alert('default clause');
987 (test escape-sequences-in-string
988 (let ((escapes `((#\\ .
#\\)
990 (#\f .
,(code-char 12))
991 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
994 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
996 ("u001F" .
,(code-char #x001f
));; character below 32
997 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
998 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
999 (loop for
(js-escape . lisp-char
) in escapes
1000 for generated
= (ps-doc* (format nil
"hello~ahi" lisp-char
))
1001 for wanted
= (format nil
"'hello\\~ahi';" js-escape
)
1002 do
(is (string= (normalize-js-code generated
) wanted
)))))
1004 (test-ps-js getprop-setf
1005 (setf (getprop x
'y
) (+ (+ a
3) 4))
1006 "x.y = (a + 3) + 4;")
1008 (test-ps-js getprop-conditional1
1009 (getprop (if zoo foo bar
) 'x
)
1010 "(zoo ? foo : bar).x;")
1012 (test-ps-js getprop-conditional2
1013 (getprop (if (not zoo
) foo bar
) 'x
)
1014 "(!zoo ? foo : bar).x;")
1016 (test script-star-eval1
1017 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x
1) '(setf y
2))))))
1019 (test script-star-eval2
1020 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x
1))))))
1022 (test-ps-js list-with-single-nil
1026 (test-ps-js quoted-nil-is-array
1030 (test-ps-js quoted-nil-is-array1
1034 (test-ps-js literal-nil
1038 (test-ps-js quoted-quoted-nil
1042 (test-ps-js quoted-quoted-nil1
1046 (test-ps-js defsetf1
1047 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
1053 return setBaz(_js2, _js3, _js1);
1056 (test-ps-js setf-macroexpands1
1057 (macrolet ((bar (x y
)
1059 (setf (bar foo
2) 3))
1062 (test-ps-js defsetf-short
1063 (progn (defsetf baz set-baz
"docstring")
1064 (setf (baz 1 2 3) "foo"))
1065 "setBaz(1, 2, 3, 'foo');")
1067 (test-ps-js defun-setf1
1068 (progn (defun (setf some-thing
) (new-val i1 i2
)
1069 (setf (aref *some-thing
* i1 i2
) new-val
))
1070 (setf (some-thing 1 2) "foo"))
1071 "function __setf_someThing(newVal, i1, i2) {
1072 return SOMETHING[i1][i2] = newVal;
1074 __setf_someThing('foo', 1, 2);")
1076 (test-ps-js defun-optional1
1077 (defun test-opt (&optional x
)
1079 "function testOpt(x) {
1080 return x ? 'yes' : 'no';
1083 (test-ps-js defun-optional2
1084 (defun foo (x &optional y
)
1086 "function foo(x, y) {
1090 (test-ps-js defun-optional3
1091 (defun blah (&optional
(x 0))
1094 if (x === undefined) {
1100 (test-ps-js arglist-optional4
1101 (lambda (&optional
(x 0 supplied?
))
1104 var suppliedwhat = x !== undefined;
1105 if (!suppliedwhat) {
1111 (test-ps-js return-nothing
1112 (defun foo () (return-from foo
))
1117 (test-ps-js return-values
1118 (defun foo () (return-from foo
(values 1 2 3)))
1120 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [2, 3] };
1124 (test-ps-js set-timeout
1125 (set-timeout (lambda () (alert "foo")) 10)
1126 "setTimeout(function () { return alert('foo'); }, 10);")
1128 (test-ps-js operator-precedence
1132 (test-ps-js operators-1
1152 (test-ps-js setf-conditional
1153 (setf foo
(if x
1 2))
1156 (test-ps-js obj-literal-numbers
1160 (test-ps-js obj-literal-strings
1164 (test-ps-js getprop-string
1168 (test-ps-js getprop-string1
1169 (getprop "bar" 'length
)
1172 (test-ps-js getprop-progn
1173 (getprop (progn (some-fun "abc") "123") "length")
1174 "(someFun('abc'), '123')['length'];")
1176 (test-ps-js method-call-block
1177 ((@ (progn (some-fun "abc") "123") to-string
))
1178 "(someFun('abc'), '123').toString();")
1180 (test-ps-js create-blank
1184 (test-ps-js blank-object-literal
1188 (test-ps-js array-literal1
1192 (test-ps-js array-literal2
1196 (test-ps-js array-literal3
1200 (test-ps-js array-literal4
1204 (test-ps-js array-literal5
1205 ([] (1 2) ("a" "b"))
1206 "[[1, 2], ['a', 'b']];")
1208 (test-ps-js defun-rest1
1209 (defun foo (&rest bar
)
1210 (alert (aref bar
1)))
1212 var bar = Array.prototype.slice.call(arguments, 0);
1213 return alert(bar[1]);
1216 (test-ps-js defun-rest2
1217 (defun foo (baz &rest bar
) (+ baz
(aref bar
1)))
1218 "function foo(baz) {
1219 var bar = Array.prototype.slice.call(arguments, 1);
1220 return baz + bar[1];
1223 (test-ps-js defun-keyword1
1224 (defun zoo (foo bar
&key baz
) (+ foo bar baz
))
1225 "function zoo(foo, bar) {
1226 var _js2 = arguments.length;
1227 for (var n1 = 2; n1 < _js2; n1 += 2) {
1228 switch (arguments[n1]) {
1230 baz = arguments[n1 + 1];
1234 return foo + bar + baz;
1237 (test-ps-js defun-keyword2
1238 (defun zoo (&key baz
) (* baz baz
))
1240 var _js2 = arguments.length;
1241 for (var n1 = 0; n1 < _js2; n1 += 2) {
1242 switch (arguments[n1]) {
1244 baz = arguments[n1 + 1];
1251 (test-ps-js defun-keyword3
1252 (defun zoo (&key baz
(bar 4)) (* baz bar
))
1254 var _js2 = arguments.length;
1255 for (var n1 = 0; n1 < _js2; n1 += 2) {
1256 switch (arguments[n1]) {
1258 baz = arguments[n1 + 1];
1261 bar = arguments[n1 + 1];
1265 var bar = 'undefined' === typeof bar ? 4 : bar;
1269 (test-ps-js defun-keyword4
1270 (defun hello-world (&key
((:my-name-key my-name
) 1))
1272 "function helloWorld() {
1273 var _js2 = arguments.length;
1274 for (var n1 = 0; n1 < _js2; n1 += 2) {
1275 switch (arguments[n1]) {
1277 myName = arguments[n1 + 1];
1280 var myName = 'undefined' === typeof myName ? 1 : myName;
1284 (test-ps-js arglist-keyword-supplied
1285 (lambda (&key
(foo 1 supplied?
))
1288 var _js2 = arguments.length;
1289 for (var n1 = 0; n1 < _js2; n1 += 2) {
1290 switch (arguments[n1]) {
1292 foo = arguments[n1 + 1];
1293 suppliedwhat = true;
1297 var foo = 'undefined' === typeof foo ? 1 : foo;
1301 (test-ps-js keyword-funcall1
1305 (test-ps-js keyword-funcall2
1306 (func :baz
1 :bar foo
)
1307 "func('baz', 1, 'bar', foo);")
1309 (test-ps-js keyword-funcall3
1311 "fun(a, b, 'baz', c);")
1321 ((= y
(* x
4)) (foo "blah") (* x y
)))
1324 } else if (y === x * 4) {
1329 (test-ps-js if-exp-without-else-return
1330 (defun foo () (return-from foo
(if x
1)))
1332 return x ? 1 : null;
1335 (test-ps-js progn-expression-single-statement
1336 (defun foo () (return-from foo
(progn (* x y
))))
1341 (test-ps-js cond-expression1
1343 (cond ((< 1 2) (bar "foo") (* 4 5))))
1351 (test-ps-js cond-expression2
1353 (cond ((< 2 1) "foo")
1358 } else if (7 === 7) {
1363 (test-ps-js cond-expression-final-t-clause
1365 (cond ((< 1 2) (bar "foo") (* 4 5))
1376 } else if (a === b) {
1378 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
1385 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
1398 (test-ps-js funcall-if-expression
1399 (funcall (getprop document
'write
)
1400 (if (= *linkornot
* 1)
1401 (ps-html ((:a
:href
"#"
1402 :onclick
(ps-inline (transport)))
1405 "document.write(LINKORNOT === 1 ? ['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">', img, '</A>'].join('') : img);")
1407 (test-ps-js negate-number-literal
1411 (test macro-environment1
1412 (is (string= (normalize-js-code (let* ((macroname (gensym)))
1413 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
1415 (macrolet ((,macroname
(x) `(aref data
,x
)))
1416 (when (,macroname x
)
1417 (setf (,macroname x
) 123)))))))
1420 return data[x] ? (data[x] = 123) : null;
1423 (test macro-environment2
1424 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
1425 (defpsmacro macro-environment2-macro
(x)
1426 `(+ ,outer-lexical-variable
,x
))
1427 (ps* '(macro-environment2-macro 2))))
1428 (normalize-js-code "1 + 2;"))))
1430 (test-ps-js ampersand-whole-1
1431 (macrolet ((foo (&whole foo bar baz
)
1432 (declare (ignore bar baz
))
1433 (with-standard-io-syntax (format nil
"~a" foo
))))
1437 (test-ps-js keyword-consistent
1441 (test-ps-js simple-symbol-macrolet
1442 (symbol-macrolet ((x 1)) x
)
1445 (test-ps-js compound-symbol-macrolet
1446 (symbol-macrolet ((x 123)
1451 (test-ps-js define-symbol-macro
1452 (progn (define-symbol-macro tst-sym-macro
2)
1456 (test-ps-js define-symbol-macro1
1457 (progn (define-symbol-macro tst-sym-macro1
2)
1458 (foo tst-sym-macro1
))
1461 (test-ps-js expression-progn
1462 (1+ (progn (foo) (if x
1 2)))
1463 "(foo(), x ? 1 : 2) + 1;")
1465 (test-ps-js let-decl-in-expression
1467 (if x
1 (let* ((foo x
)) foo
)))
1477 (test-ps-js special-var1
1478 (progn (defvar *foo
*)
1485 FOO_TMPSTACK1 = FOO;
1489 FOO = FOO_TMPSTACK1;
1493 (test-ps-js special-var2
1494 (progn (defvar *foo
*)
1503 FOO_TMPSTACK1 = FOO;
1505 return FOO * 2 * BAZ;
1507 FOO = FOO_TMPSTACK1;
1511 (test-ps-js literal1
1515 (test-ps-js literal2
1519 (test-ps-js setf-dec1
1523 (test-ps-js setf-dec2
1527 (test-ps-js special-char-equals
1531 (test-ps-js setf-operator-priority
1533 (or (getprop cache id
)
1534 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
1536 return cache[id] || (cache[id] = document.getElementById(id));
1539 (test-ps-js aref-operator-priority
1540 (aref (if (and x
(> (length x
) 0))
1544 "(x && x.length > 0 ? x[0] : y)[z];")
1546 (test-ps-js aref-operator-priority1
1547 (aref (or (getprop x
'y
)
1552 (test-ps-js aref-operator-priority2
1556 (test-ps-js negate-operator-priority
1565 (delete (if a
(or b c
) d
))
1566 "delete (a ? b || c : d);")
1569 (not (if (or x
(not y
)) z
))
1570 "!(x || !y ? z : null);")
1577 (instanceof (or a b
) (if x y z
))
1578 "((a || b) instanceof (x ? y : z));")
1581 (or x
(if (= x
0) "zero" "empty"))
1582 "x || (x === 0 ? 'zero' : 'empty');")
1584 (test-ps-js named-op-expression
1588 (test-ps-js named-op-expression1
1592 (test-ps-js aref-array-expression
1594 "(a || b || c)[0];")
1596 (test-ps-js getprop-operator
1597 (getprop (or a b c
) 'd
)
1600 (test-ps-js getprop-parens
1601 (getprop (getprop foo
'bar
) 'baz
)
1604 (test-ps-js funcall-funcall
1608 (test-ps-js expression-funcall
1609 ((or (@ window eval
) eval
) foo nil
)
1610 "(window.eval || eval)(foo, null);")
1612 (test-ps-js expression-funcall1
1613 (((or (@ window eval
) eval
) foo nil
))
1614 "(window.eval || eval)(foo, null)();")
1616 (test-ps-js expression-funcall2
1617 (((or (@ window eval
) eval
)) foo nil
)
1618 "(window.eval || eval)()(foo, null);")
1620 (test-ps-js who-html1
1621 (who-ps-html (:span
:class
"ticker-symbol"
1622 :ticker-symbol symbol
1623 (:a
:href
"http://foo.com"
1625 (:span
:class
"ticker-symbol-popup")))
1626 "['<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"', symbol, '\"><A HREF=\"http://foo.com\">', symbol, '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>'].join('');")
1628 (test-ps-js who-html2
1629 (who-ps-html (:p
"t0" (:span
"t1")))
1630 "'<P>t0<SPAN>t1</SPAN></P>';")
1633 ((lambda () (flet ((foo (x)
1637 var foo = function (x) {
1644 (flet ((foo (x) (1+ x
))
1648 var foo = function (x) {
1651 var bar = function (y) {
1658 (flet ((foo (x) (+ 2 x
)))
1659 (flet ((foo (x) (1+ x
))
1660 (bar (y) (+ 2 (foo y
))))
1663 var foo = function (x) {
1666 var foo1 = function (x) {
1669 var bar = function (y) {
1672 return bar(foo1(1));
1676 ((lambda () (labels ((foo (x)
1679 (+ x
(foo (1- x
))))))
1682 var foo = function (x) {
1683 return 0 === x ? 0 : x + foo(x - 1);
1689 (labels ((foo (x) (1+ (bar x
)))
1690 (bar (y) (+ 2 (foo y
))))
1693 var foo = function (x) {
1696 var bar = function (y) {
1703 (labels ((foo (x) (1+ x
))
1704 (bar (y) (+ 2 (foo y
))))
1707 var foo = function (x) {
1710 var bar = function (y) {
1716 (test-ps-js labels-lambda-list
1717 (labels ((foo (x &optional
(y 0))
1721 var foo = function (x, y) {
1722 if (y === undefined) {
1730 (test-ps-js for-loop-var-init-exp
1732 (do* ((y (if x
0 1) (1+ y
))
1737 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
1746 (test-ps-js literal-array
1750 (test-ps-js literal-array-1
1754 (test-ps-js literal-array-literal
1758 (test-ps-js literal-array-literal1
1762 (test ps-lisp-expands-in-lexical-environment
1763 (is (string= "5;" (let ((x 5))
1766 (test ps-lisp-expands-in-lexical-environment1
1767 (is (string= "1 + 5;" (let ((x 5))
1768 (ps (+ 1 (lisp x
)))))))
1770 (test ps-lisp-expands-in-lexical-environment2
1771 (is (string= "1 + 2 + 3;" (let ((x 2))
1772 (ps (+ 1 (lisp x
) 3))))))
1774 (test ps
*-lisp-expands-in-null-lexical-environment
1775 (signals unbound-variable
(let ((x 5))
1776 (declare (ignore x
))
1779 (test ps
*-lisp-expands-in-dynamic-environment
1780 (is (string= "1 + 2;"
1782 (declare (special foo
))
1783 (ps* '(+ 1 (lisp (locally (declare (special foo
)) foo
))))))))
1785 (test ps-lisp-dynamic-environment
1786 (is (string= "1 + 2;"
1788 (declare (special foo
))
1789 (ps (+ 1 (lisp foo
)))))))
1791 (test-ps-js nested-if-expressions1
1793 (return-from foo
(if (if x y z
) a b
)))
1802 (test-ps-js nested-if-expressions2
1804 (if x y
(if z a b
)))
1883 (test-ps-js let-exp1
1934 (test-ps-js symbol-macrolet-var
1935 (symbol-macrolet ((x y
))
1939 (test-ps-js setf-conditional1
1940 (setf x
(unless (null a
) (1+ a
)))
1941 "x = a != null ? a + 1 : null;")
1943 (test-ps-js setf-let1
1944 (setf x
(let ((a 1)) a
))
1950 (test-ps-js setf-let2
1951 (setf x
(let ((a (foo)))
1956 return a != null ? a + 1 : null;
1959 (test-ps-js symbol-macro-env1
1960 (symbol-macrolet ((bar 1))
1961 (macrolet ((bar (x y
) `(+ ,x
,y
)))
1965 (test-ps-js symbol-macrolet-fun1
1966 (symbol-macrolet ((baz +))
1970 (test-ps-js lisp2-namespaces1
1972 (setf list
(list 1 2 3)))
1975 return list = [1, 2, 3];
1978 (test-ps-js let-shadows-symbol-macrolet
1979 (symbol-macrolet ((x y
))
1989 (test-ps-js let-rename-optimization1
1997 (test-ps-js let-rename-optimization2
2006 (test-ps-js symbol-macro-array
2007 (symbol-macrolet ((x 1))
2011 (test-ps-js symbol-macro-obj
2012 (symbol-macrolet ((x y
))
2016 (test-ps-js symbol-macro-conditional1
2017 (symbol-macrolet ((x y
))
2025 (test-ps-js symbol-macro-conditional2
2026 (symbol-macrolet ((x y
))
2030 (test-ps-js preserve-this
2032 (let ((y (block nil
(bar this
))))
2035 var y = (function () {
2041 (test-ps-js flet-apply
2042 (flet ((foo () 'bar
))
2043 (apply (function foo
) nil
))
2045 var foo = function () {
2048 return foo.apply(this, null);
2051 (test-ps-js let-apply
2052 (let ((foo (lambda () 1)))
2053 (let ((foo (lambda () 2)))
2056 var foo = function () {
2059 var foo1 = function () {
2062 return foo1.apply(this, null);
2065 (test-ps-js flet-let
2066 (flet ((x (x) (1+ x
)))
2070 var x = function (x) {
2077 (test-ps-js let-flet
2079 (flet ((x (x) (1+ x
)))
2083 var x1 = function (x) {
2089 (test-ps-js labels-let
2090 (labels ((x (x) (1+ x
)))
2094 var x = function (x) {
2101 (test-ps-js let-labels
2103 (labels ((x (x) (1+ x
)))
2107 var x1 = function (x) {
2113 (test-ps-js macrolet-let-inteference
2114 (macrolet ((a (n) `(+ ,n
5)))
2116 (let ((b (a (- a
4))))
2120 var b = (a - 4) + 5;
2124 (test-ps-js let-subtract-add
2140 (test-ps-js create-reserved-word
2142 "({ 'default' : 1 });")
2144 (test-ps-js getprop-reserved-word
2145 (getprop foo
:default
)
2148 (test-ps-js getprop-reserved-word1
2149 (getprop foo
'default
)
2152 (test-ps-js eval-when-ps-side
2153 (eval-when (:execute
)
2157 (defvar *lisp-output
* nil
)
2159 (test eval-when-lisp-side
()
2160 (setf *lisp-output
* 'original-value
)
2161 (let ((js-output (normalize-js-code
2162 (ps-doc* `(eval-when (:compile-toplevel
)
2163 (setf *lisp-output
* 'it-works
))))))
2164 (is (eql 'it-works
*lisp-output
*))
2165 (is (string= "" js-output
))))
2167 (defpsmacro my-in-package
(package-name)
2168 `(eval-when (:compile-toplevel
)
2169 (setf *lisp-output
* ,package-name
)))
2171 (test eval-when-macro-expansion
()
2172 (setf *lisp-output
* 'original-value
)
2173 (let ((js-output (normalize-js-code
2175 (my-in-package :cl-user
)
2177 (declare (ignore js-output
))
2178 (is (eql :cl-user
*lisp-output
*))))
2180 (test eval-when-macrolet-expansion
()
2181 (setf *lisp-output
* 'original-value
)
2182 (let ((js-output (normalize-js-code
2183 (ps-doc* `(macrolet ((my-in-package2 (package-name)
2184 `(eval-when (:compile-toplevel
)
2185 (setf *lisp-output
* ,package-name
))))
2186 (my-in-package2 :cl-user
)
2188 (declare (ignore js-output
))
2189 (is (eql :cl-user
*lisp-output
*))))
2191 (test-ps-js getprop-keyword
2195 (test-ps-js nary-comparison1
2196 (lambda () (< 1 2 3))
2199 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
2202 (test-ps-js chain-getprop1
2203 (chain ($
"foo") (bar x z
) frob
(baz 5))
2204 "$('foo').bar(x, z).frob.baz(5);")
2206 (test-ps-js chain-getprop2
2207 (chain ($
"foo") bar baz
)
2208 "$('foo').bar.baz;")
2210 (test-ps-js chain-getprop3
2211 (chain ($
"foo") bar
(x y
) baz
)
2212 "$('foo').bar.x(y).baz;")
2214 (test-ps-js flet-expression
2215 (1+ (flet ((foo (x) (1+ x
)))
2218 var foo = function (x) {
2224 (test-ps-js flet-lambda-list
2225 (flet ((foo (x &key
(y 0))
2229 var foo = function (x) {
2230 var _js2 = arguments.length;
2231 for (var n1 = 1; n1 < _js2; n1 += 2) {
2232 switch (arguments[n1]) {
2234 y = arguments[n1 + 1];
2237 var y = 'undefined' === typeof y ? 0 : y;
2240 return foo(1, 'y', 2);
2243 (test-ps-js return-case-break-elimination
2258 (test-ps-js aplusplus
2262 (test-ps-js astarstar
2266 (test-ps-js switch-return-fallthrough
2284 (test-ps-js return-last-case
2299 (test-ps-js return-macrolet
2302 (macrolet ((x () 1))
2315 (test-ps-js mv-bind1
2316 (multiple-value-bind (a b
)
2324 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2327 var _db2 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2332 __PS_MV_REG = prevMv1;
2336 (test-ps-js mv-bind2
2337 (multiple-value-bind (a b
)
2346 var prevMv2 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2349 var _db4 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2354 __PS_MV_REG = prevMv2;
2358 (test-ps-js multiple-value-bind-simple
2359 (multiple-value-bind (a b
) (blah)
2362 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2365 var _db2 = blah === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2369 __PS_MV_REG = prevMv1;
2374 (lambda () (values))
2385 (lambda () (values x y
))
2387 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2392 (lambda () (values x y z
))
2394 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y, z] };
2398 (test-ps-js values-return
2400 (return-from foo
(values (* x x
) y
)))
2401 "function foo(x, y) {
2403 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2407 (test-ps-js return-macrolet1
2410 (symbol-macrolet ((x 2))
2411 (loop do
(+ x x
)))))
2418 (test-ps-js return-cond
2421 (cond ((foo? x
) (loop for y in x do
(foo y
)))
2426 var _js2 = x.length;
2427 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2431 } else if (barwhat(x)) {
2438 (test-ps-js return-case
2442 (1 (loop for y in x do
(foo y
)))
2448 var _js2 = x.length;
2449 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2461 (test-ps-js return-case1
2479 (test-ps-js lambda-loop-if-return
2482 (loop for y in x do
(foo y
))
2486 var _js4 = x.length;
2487 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2496 (test-ps-js lambda-loop-if-return1
2500 (progn (loop for y in x do
(foo y
))
2505 return foo(function () {
2507 var _js4 = x.length;
2508 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2512 throw { '__ps_block_tag' : 'baz',
2513 '__ps_value1' : null };
2518 } catch (_ps_err5) {
2519 if (_ps_err5 && 'baz' === _ps_err5['__ps_block_tag']) {
2520 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err5['__ps_values'] };
2521 return _ps_err5['__ps_value1'];
2528 (test-ps-js switch-loop
2531 (1 (dolist (a b
)))))
2535 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
2542 (test-ps-js switch-folds-blocks
2545 (1 (loop repeat
3 do
(alert "foo")))
2550 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
2559 (test-ps-js setf-places-before-macros
2561 (defsetf left
(el) (offset)
2562 `(setf (@ ,el style left
) ,offset
))
2563 (macrolet ((left (el)
2564 `(@ ,el offset-left
)))
2570 _js2.style.left = _js1;
2571 return x.offsetLeft;
2574 (test-ps-js for-return
2575 (lambda () (dolist (arg args
) (foo arg
)))
2577 for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
2578 arg = args[_js_idx1];
2583 (test-ps-js try-catch-return
2601 (test-ps-js defun-setf-optional
2602 (defun (setf foo
) (new-value b
&optional c
)
2603 (setf (aref b
(or c
0)) new-value
))
2604 "function __setf_foo(newValue, b, c) {
2605 return b[c || 0] = newValue;
2608 (test-ps-js defun-setf-rest
2609 (progn (defun (setf foo
) (new-value b
&rest foo
)
2610 (do-something b foo new-value
))
2611 (setf (foo x
1 2 3 4) 5))
2612 "function __setf_foo(newValue, b) {
2613 var foo = Array.prototype.slice.call(arguments, 2);
2614 return doSomething(b, foo, newValue);
2616 __setf_foo(5, x, 1, 2, 3, 4);")
2618 (test-ps-js return-null
2619 (defun foo () (return-from foo nil
))
2624 (test-ps-js implicit-return-null
2631 (test-ps-js implicit-return-null
2638 (test-ps-js return-conditional-nested
2639 (defun blep (ss x y
)
2643 (destructuring-bind (a b
) pair
2644 (unless (or (null a
) (null b
))
2645 (let ((val (baz a b
)))
2650 "function blep(ss, x, y) {
2656 if (!(a == null || b == null)) {
2657 var val = baz(a, b);
2660 return !blee() ? true : null;
2668 ;; this test needs to be rewritten when named blocks are implemented!!!!
2669 (test-ps-js return-when-returns-broken-return
2671 (return-from foo
(when x
1))
2674 return x ? 1 : null;
2678 (test-ps-js return-case-conditional
2682 (123 (when (bar) t
))
2687 return bar() ? true : null;
2693 (test-ps-js return-try-conditional
2701 return x ? 1 : null;
2709 (test-ps-js function-declare-special
2711 (declare (special *foo
*))
2717 FOO_TMPSTACK1 = FOO;
2721 FOO = FOO_TMPSTACK1;
2725 (test-ps-js declare-special-let
2727 (declare (special *foo
*))
2732 FOO_TMPSTACK1 = FOO;
2736 FOO = FOO_TMPSTACK1;
2740 (test-ps-js declare-special-let
*
2741 (let* ((*foo
* 123) (*bar
* (+ *foo
* *bar
*)))
2742 (declare (special *foo
* *bar
*))
2747 FOO_TMPSTACK1 = FOO;
2751 BAR_TMPSTACK2 = BAR;
2755 BAR = BAR_TMPSTACK2;
2758 FOO = FOO_TMPSTACK1;
2762 (test-ps-js defun-multiple-declarations-around-docstring
2764 (declare (ignorable x y
))
2765 (declare (integer x
) (float y
))
2766 "Fooes X while barring Y."
2767 (declare (special *foo
*) (special *bar
*))
2768 (let ((*bar
* (bar y
)))
2770 "/** Fooes X while barring Y. */
2771 function foo(x, y) {
2774 BAR_TMPSTACK1 = BAR;
2778 BAR = BAR_TMPSTACK1;
2782 (test-ps-js macro-null-toplevel
2784 (defmacro macro-null-toplevel
()
2786 (macro-null-toplevel))
2789 (test-ps-js define-symbol-macro-let
2791 (define-symbol-macro test-symbol-macro
1)
2792 (let ((test-symbol-macro 2))
2793 (1+ test-symbol-macro
))
2794 (1+ test-symbol-macro
))
2796 var testSymbolMacro1 = 2;
2797 return testSymbolMacro1 + 1;
2801 (test-ps-js define-symbol-macro-flet
2803 (define-symbol-macro test-symbol-macro1
1)
2804 (flet ((test-symbol-macro1 () 2))
2805 (foo test-symbol-macro1
)
2806 (test-symbol-macro1))
2807 (bar test-symbol-macro1
))
2809 var testSymbolMacro1_1 = function () {
2813 return testSymbolMacro1_1();
2817 (test compile-stream-nulls
2820 (with-input-from-string (s "
2821 (defmacro macro-null-toplevel ()
2823 (macro-null-toplevel)")
2824 (ps-compile-stream s
)))))
2826 (test compile-stream1
2829 var testSymbolMacro1_1 = function () {
2833 return testSymbolMacro1_1();
2837 (with-input-from-string (s "
2838 (define-symbol-macro test-symbol-macro1 1)
2839 (flet ((test-symbol-macro1 () 2))
2840 (foo test-symbol-macro1)
2841 (test-symbol-macro1))
2842 (bar test-symbol-macro1)")
2843 (ps::with-blank-compilation-environment
(ps-compile-stream s
))))))
2845 (test-ps-js equality-nary1
2846 (let ((x 10) (y 10) (z 10))
2853 return (_cmp1 = y, x === _cmp1 && _cmp1 === z);
2856 (test-ps-js equality1
2867 (test-ps-js getprop-quote-reserved
2868 (getprop foo
':break
)
2871 (test-ps-js defun-block-return-from
2882 (test-ps-js block-return-from
2886 (return-from scope
))
2896 (test-ps-js block-return-from0
2901 (return-from scope
))
2911 (test-ps-js block-return-from01
2916 (return-from scope
))
2930 (test-ps-js block-return-from02
2935 (return-from scope
(foobar)))
2950 (test-ps-js block-return-from1
2955 (return-from scope
))
2969 (test-ps-js block-return-from2
2975 (return-from scope
6))
2986 (test-ps-js let-funcall
3000 (test-ps-js symbol-macrolet-funcall
3001 (symbol-macrolet ((foo bar
))
3002 (funcall foo
1 2 3))
3005 (test-ps-js times-assign
3009 (test-ps-js vector-literal
3014 (+ 1 (rem 2 (+ 3 4)))
3017 (test-ps-js non-associative
3018 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
3019 "1 / (2 / 3) + (1 - (2 - 3));")
3021 (test-ps-js lambda-apply
3023 (apply (lambda (y) (bar (1+ y
))) x
))
3025 return (function (y) {
3030 (test-ps-js operator-expressions-nested-let
3031 (let ((x (let ((y 1))
3040 (test-ps-js operator-expressions-array-nested-let
3041 (list (let ((y 1)) y
) 2)
3047 (test-ps-js add-subtract-precedence
3051 (test-ps-js ps-inline-toplevel
3053 "'javascript:' + 'foo()';")
3055 (test-ps-js no-clause-progn-exp
3059 (test-ps-js no-clause-progn-return
3061 (return-from foo
(progn)))
3066 (test-ps-js empty-cond-clause
3067 (setf x
(cond ((foo))))
3068 "x = (function () { var testResult1 = foo(); return testResult1 ? testResult1 : null; })();")
3070 (test-ps-js empty-cond-clause1
3071 (setf x
(cond ((foo) 123)
3076 var testResult1 = bar();
3080 if (true) { return 456; };
3084 (test-ps-js let-no-body
3086 (return-from foo
(let ((foo bar
)))))
3092 (test-ps-js rename-lexical-dupes
3094 (list (let ((foo 12)) (* foo
2))
3095 (let ((foo 13)) (* foo
3))))
3099 return [(foo = 12, foo * 2), (foo1 = 13, foo1 * 3)];
3102 (test-ps-js defun-comment1
3104 "BARBAR is a revolutionary new foobar.
3108 * BARBAR is a revolutionary new foobar.
3115 (test-ps-js var-comment
3120 (test-ps-js case-return-break-broken-return
3123 ("bar" (if y
(return-from foo t
) nil
))
3138 (test-ps-js case-return-break1-broken-return
3141 ("bar" (if y
(return-from foo t
)))
3156 (test-ps-js setf-progn
3157 (setf foo
(progn (bar) (baz) 3))
3162 (test-ps-js var-progn
3163 (var x
(progn (foo) (bar)))
3167 (test-ps-js implicit-return-loop
3171 (loop :repeat
100 :do
(bar))
3177 for (var _js2 = 0; _js2 < 100; _js2 += 1) {
3184 ;; closures in loops need a new binding per loop iteration (idea borrowed from Scheme2JS)
3185 (test-ps-js loop-closures
3186 (dotimes (i 10) (lambda () (+ i
1)))
3188 for (var i = 0; i < 10; i += 1) {
3197 (test-ps-js loop-closures-let
3200 (lambda () (+ i x
))))
3202 for (var i = 0; i < 10; i += 1) {
3203 with ({ i : i, x : null }) {
3212 (test-ps-js loop-closures-flet
3213 (dotimes (i 10) (flet ((foo (x) (+ i x
))) (lambda () (foo i
))))
3215 for (var i = 0; i < 10; i += 1) {
3216 with ({ foo : null, i : i }) {
3217 var foo = function (x) {
3227 (test-ps-js while-closures-let
3230 (lambda () (+ 1 x
))))
3232 with ({ x : null }) {
3240 (test-ps-js dotted-list-form
3243 (destructuring-bind (b . c
)
3249 var c = bar.length > 1 ? bar.slice(1) : [];
3254 (test-ps-js explicit-nil-block
3257 (block nil
(return (foo 2)) (+ 1 2))
3269 (test-ps-js dynamic-extent-function-return
3272 (return-from foo
6))))
3275 return (function () {
3276 throw { '__ps_block_tag' : 'foo', '__ps_value1' : 6 };
3278 } catch (_ps_err1) {
3279 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3280 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3281 return _ps_err1['__ps_value1'];
3288 (test-ps-js dynamic-extent-function-return-nothing
3291 (return-from foo
))))
3294 return (function () {
3295 throw { '__ps_block_tag' : 'foo', '__ps_value1' : null };
3297 } catch (_ps_err1) {
3298 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3299 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3300 return _ps_err1['__ps_value1'];
3307 (test-ps-js dynamic-extent-function-return-values
3310 (return-from foo
(values 1 2 3)))))
3314 return (function () {
3315 throw { '__ps_block_tag' : 'foo',
3317 '__ps_values' : [2, 3] };
3319 } catch (_ps_err1) {
3320 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3321 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3322 return _ps_err1['__ps_value1'];
3329 (test-ps-js dynamic-extent-function-return-funcall
3332 (return-from foo
(if baz
6 5)))))
3335 return (function () {
3336 throw { '__ps_block_tag' : 'foo', '__ps_value1' : baz ? 6 : 5 };
3338 } catch (_ps_err1) {
3339 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3340 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3341 return _ps_err1['__ps_value1'];
3348 (test-ps-js block-dynamic-return
3349 (var foo
((lambda ()
3351 ((lambda () (return 6)))
3353 "var foo = (function () {
3356 throw { '__ps_block_tag' : 'nilBlock', '__ps_value1' : 6 };
3359 } catch (_ps_err1) {
3360 if (_ps_err1 && 'nilBlock' === _ps_err1['__ps_block_tag']) {
3361 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3362 return _ps_err1['__ps_value1'];
3369 (test-ps-js block-dynamic-return1
3370 (var foo
((lambda ()
3372 ((lambda () (return 6)))
3375 "var foo = (function () {
3382 return foobar(1, 2);
3385 (test-ps-js iteration-lambda-capture-no-need
3386 (dolist (x y
) (lambda (x) (1+ x
))) ;; there's really no need to create a 'with' scope in this case
3388 for (var x = null, _js_idx1 = 0; _js_idx1 < y.length; _js_idx1 += 1) {
3398 (test-ps-js case-invert1
3399 (encodeURIComponent fooBar
)
3400 "encodeURIComponent(fooBar);")
3402 (test-ps-js simple-ash
3403 (+ (ash 4 1) (ash 4 -
1))
3404 "(4 << 1) + (4 >> 1);")
3406 (test-ps-js progn-nil-expression
3407 (bar (progn (foo) nil
))
3408 "bar((foo(), null));")
3410 (test-ps-js other-progn-nil-exp
3412 (or (foo) (progn (bar) nil
)))
3414 return foo() || (bar(), null);
3417 (test-ps-js lambda-nil-return
3430 (test-ps-js lambda-nil-return-implicit-nested2
3436 (return-from foo i
)))
3442 for (var i = 0; i < 4; i += 1) {
3449 (test-ps-js throw-is-a-statement
3451 (let ((result (foo)))
3452 (unless (null result
)
3456 if (result != null) {
3461 (test-ps-js expressify1
3463 (when (some-condition)
3468 if (someCondition()) {
3475 (test-ps-js case-when-return
3478 ("a" (when (foo) (return-from blah
111)))
3493 (test-ps-js flet-return-from
3496 (return-from foo
123)))
3499 var foo = function () {
3505 (test-ps-js flet-return-from1
3507 (return-from foo
123)))
3510 var foo = function () {
3516 (test-ps-js lambda-docstring-declarations
3518 "This is a docstring"
3519 (declare (ignore x
))
3525 (test-ps-js setf-let-exp
3526 (setf foo
(let ((x (+ 1 2)))
3528 "foo = (function () {
3530 return x ? 123 : 456;
3533 (test-ps-js create-let-exp
3534 (create :abc
(let ((x (+ 1 2)))
3536 "({ 'abc' : (function () {
3538 return x ? 123 : 456;
3541 (test-ps-js eql-eql-eql-precedence
3542 (unless (equal (= 3 3) (= 3 4))
3543 (chain console
(log 1)))
3544 "if ((3 === 3) != (3 === 4)) {
3548 (test-ps-js case-cond-breaks
3554 (return-from blah nil
))
3577 (test-ps-js cond-double-t
3590 (test-ps-js let-let-funcall-lambda
3593 (funcall (lambda (x) (+ x
9)) x
)))
3597 return (function (x) {
3602 (test-ps-js let-let-lambda
3605 (lambda (x) (+ x
9))))
3609 return function (x) {
3614 (test-ps-js let-lambda
3616 (lambda (x) (+ x
9)))
3619 return function (x) {
3624 (test-ps-js symbol-macrolet-no-shadow-lambda
3625 (symbol-macrolet ((x y
))
3626 (lambda (x) (+ x x
)))
3631 (test-ps-js divide-one-arg-reciprocal
3635 (test-ps-js division-not-associative
3639 (test-ps-js divide-expressions
3643 (test-ps-js divide-expressions1
3645 "Math.floor((x - 1) / y);")
3647 (test-ps-js lexical-funargs-shadow1
3658 (test-ps-js times-rem
3662 (test-ps-js rem-divide
3666 (test-ps-js case-break-return
3667 (lambda () (case x
(:foo
) (:bar
1)))
3677 (test-ps-js trivial-expression-switch
3678 (foobar (case x
(1 2)))
3679 "foobar((function () {
3686 (test-ps-js trivial-expression-while
3687 (foobar (while (< 0 x
) (decf x
)))
3688 "foobar((function () {
3694 (test-ps-js funcall-block-expression-loop-lambda
3695 (foobar (loop for i from
0 to
10 do
(1+ i
)))
3696 "foobar((function () {
3697 for (var i = 0; i <= 10; i += 1) {
3702 (test-ps-js plus-block-expression-loop-lambda
3703 (1+ (loop for i from
0 to
10 do
(1+ i
)))
3705 for (var i = 0; i <= 10; i += 1) {
3710 (test-ps-js let-closures-rename
3712 (let ((x 1)) (lambda () (1+ x
)))
3713 (let ((x 2)) (lambda () (1+ x
))))
3720 return function () {
3725 (test-ps-js let-closures-rename1
3729 (lambda () (+ x y
))))
3732 (lambda () (+ x y
)))))
3741 return function () {
3746 (test-ps-js let-closures-rename2
3747 (defun make-closures ()
3749 (let ((x 1)) (lambda () (1+ x
)))
3750 (let ((x 2)) (lambda () (1+ x
)))))
3751 "function makeClosures() {
3754 return [(x = 1, function () {
3756 }), (x1 = 2, function () {
3762 (test-ps-js conditional-not-used-up
3774 (test-ps-js toplevel-local-scope
3775 (create "fn" (let ((x 5)) (lambda () x
)))
3776 "({ 'fn' : (function () {
3778 return function () {
3783 (test-ps-js toplevel-local-scope1
3784 (defvar foo
(create "fn" (let ((x 5)) (lambda () x
))))
3785 "var foo = { 'fn' : (function () {
3787 return function () {
3792 (test-ps-js block-let
3795 (return-from foobar x
)
3803 (test-ps-js expressionize-if-macroexpand-error
3804 (progn (defmacro xbaz
() `(blah))
3810 "function foo(xbaz) {
3820 (test-ps-js toplevel-defun-macroexpand
3821 (progn (defmacro defun-js
(name lambda-list
&body body
)
3822 `(defun ,name
,lambda-list
,@body
))
3825 (defun-js bar
() (1+ foo
))
3833 (test-ps-js js-ir-package-unique-symbols
3834 (loop :for i
:from
0 :below
5 :do
3835 (let ((block (elt blocks i
)))
3839 for (var i = 0; i < 5; i += 1) {
3840 var block = blocks[i];
3848 (test-ps-js broken-quote-expansion1
3853 return p.x < 0 ? p.y : p.x;
3856 (test-ps-js broken-quote-expansion2
3858 (define-symbol-macro foo123
(ps:@ a foo123
))
3859 (lambda () (when (> foo123
1) 2)))
3861 return a.foo123 > 1 ? 2 : null;
3864 (test-ps-js unused-named-block-not-printed1
3871 (test-ps-js unused-named-block-not-printed2
3879 (test-ps-js unused-named-block-not-printed3
3887 (test-ps-js unused-named-block-not-printed4
3896 (test-ps-js trig-no-bind1
3898 "(Math.exp(3.14) + Math.exp(-3.14)) / 2;")
3900 (test-ps-js trig-bind1
3903 var x1 = blah(3.14);
3904 return 2 * Math.log(Math.sqrt((x1 + 1) / 2) + Math.sqrt((x1 - 1) / 2));
3909 ;; (test-ps-js let-defun-toplevel
3910 ;; (progn (let ((foo 0))
3911 ;; (defun bar () foo))
3913 ;; "var bar_foo1 = 0;
3919 ;; (test-ps-js let-defvar-toplevel
3920 ;; (progn (let ((foo 0))
3921 ;; (defvar bar (1+ foo)))
3923 ;; "var bar_foo1 = 0;
3924 ;; var bar = bar_foo1 + 1;
3927 ;; (test-ps-js setf-side-effects
3930 ;; (defun side-effect()
3933 ;; (setf x (+ 2 (side-effect) x 5))))
3934 ;; "var sideEffect_x1 = 10;
3935 ;; function sideEffect() {
3936 ;; sideEffect_x1 = 4;
3939 ;; sideEffect_x1 = 2 + sideEffect() + x + 5;")