1 ;;; Copyright 2005-2006 Henrik Hjelte
2 ;;; Copyright 2007-2012 Vladimir Sedach
4 ;;; SPDX-License-Identifier: BSD-3-Clause
6 ;;; Redistribution and use in source and binary forms, with or
7 ;;; without modification, are permitted provided that the following
8 ;;; conditions are met:
10 ;;; 1. Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; 2. Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials provided
16 ;;; with the distribution.
18 ;;; 3. Neither the name of the copyright holder nor the names of its
19 ;;; contributors may be used to endorse or promote products derived
20 ;;; from this software without specific prior written permission.
22 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 ;;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 ;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 ;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 ;;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
27 ;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 ;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ;;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 ;;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 ;;; POSSIBILITY OF SUCH DAMAGE.
36 (in-package #:parenscript.tests
)
37 (named-readtables:in-readtable
:parenscript
)
39 (fiveam:in-suite output-tests
)
41 (test-ps-js statements-and-expressions-1
45 (test-ps-js statements-and-expressions-2
53 (test-ps-js symbol-conversion-1
55 "bangwhathashatpercent;")
57 (test-ps-js symbol-conversion-2
61 (test-ps-js symbol-conversion-3
65 (test-ps-js symbol-conversion-4
69 (test-ps-js symbol-conversion-5
71 "encodeURIComponent;")
73 (test-ps-js symbol-conversion-6
77 (test-ps-js number-literals-1
81 (test-ps-js number-literals-2
85 (test-ps-js number-literals-3
89 (test-ps-js string-literals-1
93 (test-ps-js string-literals-2
97 (test-ps-js string-literals-3
101 (test-ps-js array-literals-1
105 (test-ps-js array-literals-2
109 (test-ps-js array-literals-3
111 (array "foobar" "bratzel bub"))
112 "[[2, 3], ['foobar', 'bratzel bub']];")
114 (test-ps-js array-literals-4
118 (test-ps-js array-literals-5
120 "new Array(1, 2, 3);")
122 (test-ps-js array-literals-6
125 (make-array "foobar" "bratzel bub"))
126 "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'));")
128 (test-ps-js array-init-1
129 (make-array 2 :initial-contents
'(10 20))
131 var arr1 = new Array(2);
132 var init2 = [10, 20];
133 for (var i4 = 0; i4 < Math.min(arr1.length, init2.length); i4 += 1) {
134 arr1[i4] = init2[i4];
139 (test-ps-js array-init-2
140 (make-array 5 :initial-element
10)
142 var arr1 = new Array(5);
144 for (var i4 = 0; i4 < arr1.length; i4 += 1) {
150 (test-ps-js object-literals-1
151 (create foo
"bar" :blorg
1)
152 "({ foo : 'bar', 'blorg' : 1 });")
154 (test-ps-js object-literals-2
157 another-object
(create :schtrunz
1))
160 anotherObject : { 'schtrunz' : 1 } });")
162 (test-ps-js object-literals-3
163 (getprop an-object
'foo
)
166 (test-ps-js object-literals-4
167 (@ an-object foo bar
)
170 (test-ps-js object-literals-5
171 (with-slots (a b c
) this
173 "this.a + this.b + this.c;")
175 (test-ps-js with-slots-single-eval
176 (lambda () (with-slots (a b
) (foo) (+ a b
)))
179 return object1.a + object1.b;
182 (test-ps-js object-literal-quoted-symbols
183 (create 'test
"bang" 'symbol-saved-my-life
"parenscript")
184 "({ 'test' : 'bang', 'symbolSavedMyLife' : 'parenscript' });")
186 (test-ps-js object-literal-property-accessors
190 (set x v
) (setf x v
))))
199 :js-target-version
"1.8.5")
201 (test-ps-js object-method-apply-1
202 (apply (@ an-object foo
) nil
)
203 "anObject.foo.apply(anObject, null);")
205 (test-ps-js object-method-apply-2
206 (apply (getprop (make-an-object) foo
'bar
) nil
)
208 var _js1 = makeAnObject()[foo];
210 return _js2.apply(_js1, null);
213 (test-ps-js object-method-apply-3
214 (apply (@ (make-an-object) foo
) (bar))
216 var _js1 = makeAnObject();
218 return _js2.apply(_js1, bar());
221 (test-ps-js regular-expression-literals-1
225 (test-ps-js regular-expression-literals-2
229 (test-ps-js literal-symbols-1
233 (test-ps-js literal-symbols-2
237 (test-ps-js literal-symbols-3
241 (test-ps-js literal-symbols-4
247 (test-ps-js literal-symbols-5
251 (test-ps-js literal-symbols-6
255 (test-ps-js variables-1
259 (test-ps-js variables-2
263 (test-ps-js variables-3
267 (test-ps-js function-calls-and-method-calls-1
271 (test-ps-js function-calls-and-method-calls-2
272 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
273 "foobar(blorg(1, 2), blabla(3, 4), [2, 3, 4]);")
275 (test-ps-js function-calls-and-method-calls-3
276 ((getprop this
'blorg
) 1 2)
279 (test-ps-js function-calls-and-method-calls-4
283 (test-ps-js function-calls-and-method-calls-5
284 ((getprop (aref foobar
1) 'blorg
) nil t
)
285 "foobar[1].blorg(null, true);")
287 (test-ps-js operator-expressions-1
291 (test-ps-js operator-expressions-2
295 (test-ps-js operator-expressions-3
296 (* 1 (+ 2 3 4) 4 (/ 6 7))
297 "1 * (2 + 3 + 4) * 4 * (6 / 7);")
299 (test-ps-js operator-expressions-4
303 (test-ps-js operator-expressions-5
307 (test-ps-js operator-expressions-6
311 (test-ps-js operator-expressions-7
315 (test-ps-js operator-expressions-8
319 (test-ps-js body-forms-1
320 (progn (blorg i
) (blafoo i
))
324 (test-ps-js body-forms-2
325 (+ i
(progn (blorg i
) (blafoo i
)))
326 "i + (blorg(i), blafoo(i));")
328 (test-ps-js function-definition-1
329 (defun a-function (a b
)
331 "function aFunction(a, b) {
335 (test-ps-js lambda-definition-2
336 (lambda (a b
) (+ a b
))
341 (test-ps-js assignment-1
345 (test-ps-js assignment-2
346 (setf a
2 b
3 c
4 x
(+ a b c
))
352 (test-ps-js assignment-3
353 (setf a
(+ a
2 3 4 a
))
354 "a = a + 2 + 3 + 4 + a;")
356 (test-ps-js assignment-4
360 (test-ps-js assignment-5
372 (test-ps-js assignment-6
376 (test-ps-js assignment-8
378 (defun (setf color
) (new-color el
)
379 (setf (getprop (getprop el
'style
) 'color
) new-color
))
380 (setf (color some-div
) (+ 23 "em")))
381 "function __setf_color(newColor, el) {
382 return el.style.color = newColor;
384 __setf_color(23 + 'em', someDiv);")
386 (test-ps-js assignment-10
388 (defsetf left
(el) (offset)
389 `(setf (getprop (getprop ,el
'style
) 'left
) ,offset
))
390 (setf (left some-div
) (+ 123 "px")))
393 var _js1 = 123 + 'px';
394 return _js2.style.left = _js1;
397 (test-ps-js assignment-12
398 (macrolet ((left (el)
399 `(getprop ,el
'offset-left
)))
401 "someDiv.offsetLeft;")
403 (test-ps-js nil-block-return-1
404 (block nil
(return) 1)
410 (test-ps-js single-argument-statements-2
414 (test-ps-js single-argument-expression-1
415 (delete (new (*foobar
2 3 4)))
416 "delete new Foobar(2, 3, 4);")
418 (test-ps-js single-argument-expression-2
419 (if (= (typeof blorg
) *string
)
420 (alert (+ "blorg is a string: " blorg
))
421 (alert "blorg is not a string"))
422 "if (typeof blorg === String) {
423 alert('blorg is a string: ' + blorg);
425 alert('blorg is not a string');
428 (test-ps-js conditional-statements-1
430 (if ((@ blorg is-correct
))
431 (progn (carry-on) (return-from foo i
))
432 (alert "blorg is not correct!")))
434 if (blorg.isCorrect()) {
438 return alert('blorg is not correct!');
442 (test-ps-js conditional-statements-2
443 (+ i
(if ((@ blorg add-one
)) 1 2))
444 "i + (blorg.addOne() ? 1 : 2);")
446 (test-ps-js conditional-statements-3
448 (when ((@ blorg is-correct
))
450 (return-from foo i
)))
452 if (blorg.isCorrect()) {
458 (test-ps-js conditional-statements-4
459 (unless ((@ blorg is-correct
))
460 (alert "blorg is not correct!"))
461 "if (!blorg.isCorrect()) {
462 alert('blorg is not correct!');
465 (test-ps-js variable-declaration-1
466 (defvar *a
* (array 1 2 3))
467 "var A = [1, 2, 3];")
469 (test-ps-js variable-declaration-2
470 (progn (defvar *a
* 4)
491 (test-ps-js iteration-constructs-1
492 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
494 (e (aref c d
) (aref c d
)))
495 ((or (= d
(@ c length
)) (string= e
"x")))
497 (funcall (@ document write
) (+ "a: " a
" b: " b
"<br/>")))
499 for (var a = null, b = null, c = ['a', 'b', 'c', 'd', 'e'], d = 0, e = c[d];
500 !(d === c.length || e === 'x'); d += 1, e = c[d]) {
503 document.write('a: ' + a + ' b: ' + b + '<br/>');
507 (test-ps-js iteration-constructs-2
509 (s 0 (+ s i
(1+ i
))))
511 (funcall (@ document write
) (+ "i: " i
" s: " s
"<br/>")))
516 document.write('i: ' + i + ' s: ' + s + '<br/>');
518 var _js2 = s + i + (i + 1);
524 (test-ps-js iteration-constructs-3
526 (s 0 (+ s i
(1- i
))))
528 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
530 for (var i = 0, s = 0; i <= 10; i += 1, s = s + i + (i - 1)) {
531 document.write('i: ' + i + ' s: ' + s + '<br/>');
535 (test-ps-js iteration-constructs-4
536 (let ((arr (array "a" "b" "c" "d" "e")))
537 (dotimes (i (@ arr length
))
538 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
540 var arr = ['a', 'b', 'c', 'd', 'e'];
541 for (var i = 0; i < arr.length; i += 1) {
542 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
546 (test-ps-js iteration-constructs-5
548 (alert (+ "Summation to 10 is "
550 (incf res
(1+ i
))))))
553 return alert('Summation to 10 is ' + (function () {
554 for (var i = 0; i < 10; i += 1) {
561 (test-ps-js iteration-constructs-6
562 (let ((l (list 1 2 4 8 16 32)))
564 ((@ document write
) (+ "c: " c
"<br/>"))))
566 var l = [1, 2, 4, 8, 16, 32];
567 for (var c = null, _js_idx2 = 0; _js_idx2 < l.length; _js_idx2 += 1) {
569 document.write('c: ' + c + '<br/>');
573 (test-ps-js iteration-constructs-7
574 (let ((l '(1 2 4 8 16 32))
576 (alert (+ "Sum of " l
" is: "
580 var l = [1, 2, 4, 8, 16, 32];
582 return alert('Sum of ' + l + ' is: ' + (function () {
583 for (var c = null, _js_idx1 = 0; _js_idx1 < l.length; _js_idx1 += 1) {
591 (test-ps-js iteration-constructs-8
592 (let ((obj (create a
1 b
2 c
3)))
594 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
596 var obj = { a : 1, b : 2, c : 3 };
598 document.write(i + ': ' + obj[i] + '<br/>');
602 (test-ps-js iteration-constructs-9
603 (while ((@ film is-not-finished
))
604 ((@ this eat
) (new *popcorn
)))
605 "while (film.isNotFinished()) {
606 this.eat(new Popcorn);
609 (test-ps-js loop-for-bindings
610 (loop :for
((a b
) (:c
:d
)) :in arr
:do
(foo a b c d
))
612 var _js2 = arr.length;
613 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
614 var _db4 = arr[_js1];
625 (test-ps-js loop-for-on
626 (loop :for
(k v
) :on plist
:by
2 :do
(foo k v
))
628 for (var _js1 = plist; _js1.length > 0; _js1 = _js1['slice'](2)) {
635 (test-ps-js loop-for-keys-of
636 (loop :for k
:of obj
:do
(foo k
))
643 (test-ps-js loop-for-key-val-pairs-of
644 (loop :for
(k v
) :of obj
:do
(foo k v
))
652 (test-ps-js loop-for-key-val-pairs-of-with-bindings
653 (loop :for
(k (a b
)) :of obj
:do
(foo k a b
))
663 (test-ps-js loop-for-just-vals-of
664 (loop :for
(nil v
) :of obj
:do
(foo k v
))
666 for (var _js1 in obj) {
672 (test-ps-js loop-map-to
673 (loop :for str
:in strs
:map str
:to
(length str
))
675 var _js2 = strs.length;
677 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
678 var str = strs[_js1];
679 map3[str] = str.length;
684 (test-ps-js loop-for-of-map-to
685 (loop :for k
:of obj
:map k
:to
(foo k
))
694 (test-ps-js loop-for-of-when
695 (loop :for k
:of obj
:when
(foo k
) :map k
:to
(bar k
))
706 (test-ps-js loop-for-in-until-when
707 (loop :for a
:in b
:until
(> a
100) :when
(< a
50) :do
(foo a
))
710 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
721 (test-ps-js loop-with-for-when
722 (loop :with c
= c1
:for d
:from c1
:below c2
723 :when
(foo c d
) :do
(setf c d
)
727 for (var d = c1; d < c2; d += 1) {
735 (test-ps-js loop-for-then-for-in-while
737 (loop :for a
= (foo) :then
(bar) :for b
:in c
:while b
:do
(foo a b c
)))
741 for (var a = foo(); true; a = bar()) {
742 var _js1 = FIRST3 ? 0 : _js1 + 1;
755 (test-ps-js loop-while-when
756 (loop :for a
= (pop stack
) :while a
:for
(b c
) = (foo a
) :when b
:do
(bar c
))
758 for (var a = pop(stack); a; a = pop(stack)) {
768 (test-ps-js loop-for-of-for-in
770 (loop :for k
:of obj
:for a
:in b
:do
(foo k a
)))
771 "function blah(obj, b) {
775 var _js1 = FIRST3 ? 0 : _js1 + 1;
785 (test-ps-js loop-for-dot
786 (loop :for
(op . args
) :in expr
:do
(foo op args
))
788 var _js2 = expr.length;
789 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
790 var _db3 = expr[_js1];
792 var args = _db3.length > 1 ? _db3.slice(1) : [];
797 (test-ps-js loop-for-rest
798 (loop :for
(op &rest args
) :in expr
:do
(foo op args
))
800 var _js2 = expr.length;
801 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
802 var _db3 = expr[_js1];
804 var args = _db3.length > 1 ? _db3.slice(1) : [];
809 (test-ps-js loop-collect
810 (setf x
(loop :for a
:in b
:collect
(foo a
)))
814 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
816 collect3.push(foo(a));
821 (test-ps-js loop-append
822 (loop :for a
:in b
:append a
)
826 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
828 append3 = append3.concat(a);
833 (test-ps-js the-case-statement-1
835 ((1 "one") (alert "one"))
837 (t (alert "default clause")))
847 alert('default clause');
850 (test-ps-js the-case-statement-2
851 (switch (aref blorg i
)
852 (1 (alert "If I get here"))
853 (2 (alert "I also get here"))
854 (default (alert "I always get here")))
856 case 1: alert('If I get here');
857 case 2: alert('I also get here');
858 default: alert('I always get here');
861 (test-ps-js the-try-statement-1
864 (alert (+ "an error happened: " error
)))
866 (alert "Leaving the try form")))
870 alert('an error happened: ' + error);
872 alert('Leaving the try form');
875 (test-ps-js the-html-generator-1
876 (ps-html ((:a
:href
"foobar") "blorg"))
877 "'<a href=\\\"foobar\\\">blorg</a>';")
879 (test-ps-js the-html-generator-2
880 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
881 "['<a href=\\\"', generateALink(), '\\\">blorg</a>'].join('');")
883 (test-ps-js the-html-generator-3
884 (funcall (getprop document
'write
)
885 (ps-html ((:a
:href
"#"
886 :onclick
(ps-inline (transport))) "link")))
887 "document.write(['<a href=\\\"#\\\" onclick=\\\"', 'javascript:' + 'transport()', '\\\">link</a>'].join(''));")
889 (test-ps-js the-html-generator-4
892 (setf (getprop element
'inner-h-t-m-l
)
893 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
897 var authorized = true;
898 return element.innerHTML = ['<textarea', disabled || !authorized ? [' disabled=\\\"', 'disabled', '\\\"'].join('') : '', '>Edit me</textarea>'].join('');
901 (test-ps-js plus-is-not-commutative
902 (setf x
(+ "before" x
"after"))
903 "x = 'before' + x + 'after';")
905 (test-ps-js plus-works-if-first
906 (setf x
(+ x
"middle" "after"))
907 "x = x + 'middle' + 'after';")
909 (test-ps-js method-call-op-form
910 (funcall (getprop (+ "" x
) 'to-string
))
911 "('' + x).toString();")
913 (test-ps-js method-call-op-form-args
914 (funcall (getprop (+ "" x
) 'foo
) 1 2 :baz
3)
915 "('' + x).foo(1, 2, 'baz', 3);")
917 (test-ps-js method-call-string
918 ((getprop "hi" 'to-string
))
921 (test-ps-js method-call-conditional
925 (test-ps-js method-call-variable
929 (test-ps-js method-call-array
930 ((@ (list 10 20) to-string
))
931 "[10, 20].toString();")
933 (test-ps-js method-call-lambda-call
934 (funcall (getprop (funcall (lambda (x) x
) 10) 'to-string
))
935 "(function (x) { return x; })(10).toString();")
937 (fiveam:test no-whitespace-before-dot
938 (let ((str (ps* '((@ ((lambda (x) x
) 10) to-string
)))))
939 (fiveam:is
(char= #\
) (elt str
(1- (position #\. str
)))))))
941 (test-ps-js simple-getprop
942 (let ((foo (create a
1)))
943 (alert (getprop foo
'a
)))
949 (test-ps-js buggy-getprop
950 (getprop foo slot-name
)
953 (test-ps-js buggy-getprop-two
954 (getprop foo
(get-slot-name))
955 "foo[getSlotName()];")
957 (test-ps-js old-case-is-now-switch
958 ;; Switch was "case" before, but that was very non-lispish.
959 ;; For example, this code makes three messages and not one
960 ;; which may have been expected. This is because a switch
961 ;; statment must have a break statement for it to return
962 ;; after the alert. Otherwise it continues on the next
964 (switch (aref blorg i
)
967 (default (alert "default clause")))
969 case 1: alert('one');
970 case 2: alert('two');
971 default: alert('default clause');
974 (test-ps-js lisp-like-case
978 (t (alert "default clause")))
986 default: alert('default clause');
990 (test-ps-js even-lispier-case
992 ((1 2) (alert "Below three"))
994 (t (alert "Something else")))
998 alert('Below three');
1003 default: alert('Something else');
1006 (test-ps-js otherwise-case
1007 (case (aref blorg i
)
1009 (otherwise (alert "default clause")))
1010 "switch (blorg[i]) {
1014 default: alert('default clause');
1017 (fiveam:test escape-sequences-in-string
1021 (#\f .
,(code-char 12))
1022 ("u000B" .
,(code-char #x000b
)) ; vertical tab
1028 ("u001F" .
,(code-char #x001f
)) ; character below 32
1029 ("u0080" .
,(code-char 128)) ; character over 127
1030 ("uABCD" .
,(code-char #xabcd
))))) ; well above ASCII
1031 (loop for
(js-escape . lisp-char
) in escapes
1032 for generated
= (ps-doc* (format nil
"hello~ahi" lisp-char
))
1033 for wanted
= (format nil
"'hello\\~ahi';" js-escape
)
1034 do
(fiveam:is
(string= generated wanted
)))))
1036 (fiveam:test escape-doublequotes
1037 (let ((*js-string-delimiter
* #\"))
1038 (fiveam:is
(string= (ps-doc* "hello\"hi") "\"hello\\\"\hi\";"))))
1040 (test-ps-js getprop-setf
1041 (setf (getprop x
'y
) (+ (+ a
3) 4))
1042 "x.y = (a + 3) + 4;")
1044 (test-ps-js getprop-conditional1
1045 (getprop (if zoo foo bar
) 'x
)
1046 "(zoo ? foo : bar).x;")
1048 (test-ps-js getprop-conditional2
1049 (getprop (if (not zoo
) foo bar
) 'x
)
1050 "(!zoo ? foo : bar).x;")
1052 (fiveam:test script-star-eval1
1054 (normalize-js-output (ps* '(setf x
1) '(setf y
2)))
1057 (fiveam:test script-star-eval2
1059 (normalize-js-output (ps* '(setf x
1)))
1062 (test-ps-js list-with-single-nil
1066 (test-ps-js quoted-nil-is-array
1070 (test-ps-js quoted-nil-is-array1
1074 (test-ps-js literal-nil
1078 (test-ps-js quoted-quoted-nil
1082 (test-ps-js quoted-quoted-nil1
1086 (test-ps-js defsetf1
1087 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
1093 return setBaz(_js2, _js3, _js1);
1096 (test-ps-js setf-macroexpands1
1097 (macrolet ((bar (x y
)
1099 (setf (bar foo
2) 3))
1102 (test-ps-js defsetf-short
1103 (progn (defsetf baz set-baz
"docstring")
1104 (setf (baz 1 2 3) "foo"))
1105 "setBaz(1, 2, 3, 'foo');")
1107 (test-ps-js defun-setf1
1108 (progn (defun (setf some-thing
) (new-val i1 i2
)
1109 (setf (aref *some-thing
* i1 i2
) new-val
))
1110 (setf (some-thing 1 2) "foo"))
1111 "function __setf_someThing(newVal, i1, i2) {
1112 return SOMETHING[i1][i2] = newVal;
1114 __setf_someThing('foo', 1, 2);")
1116 (test-ps-js defun-optional1
1117 (defun test-opt (&optional x
)
1119 "function testOpt(x) {
1120 return x ? 'yes' : 'no';
1123 (test-ps-js defun-optional2
1124 (defun foo (x &optional y
)
1126 "function foo(x, y) {
1130 (test-ps-js defun-optional3
1131 (defun blah (&optional
(x 0))
1134 if (x === undefined) {
1140 (test-ps-js arglist-optional4
1141 (lambda (&optional
(x 0 supplied?
))
1144 var suppliedwhat = x !== undefined;
1145 if (!suppliedwhat) {
1151 (test-ps-js return-nothing
1152 (defun foo () (return-from foo
))
1157 (test-ps-js return-values
1158 (defun foo () (return-from foo
(values 1 2 3)))
1160 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [2, 3] };
1164 (test-ps-js set-timeout
1165 (set-timeout (lambda () (alert "foo")) 10)
1166 "setTimeout(function () { return alert('foo'); }, 10);")
1168 (test-ps-js operator-precedence
1172 (test-ps-js operators-1
1192 (test-ps-js setf-conditional
1193 (setf foo
(if x
1 2))
1196 (test-ps-js obj-literal-numbers
1200 (test-ps-js obj-literal-strings
1204 (test-ps-js getprop-string
1208 (test-ps-js getprop-string1
1209 (getprop "bar" 'length
)
1212 (test-ps-js getprop-progn
1213 (getprop (progn (some-fun "abc") "123") "length")
1214 "(someFun('abc'), '123')['length'];")
1216 (test-ps-js getprop-multi1
1217 (getprop foo
1 "two" three
'bar
1 2)
1218 "foo[1]['two'][three].bar[1][2];")
1220 (test-ps-js method-call-block
1221 ((@ (progn (some-fun "abc") "123") to-string
))
1222 "(someFun('abc'), '123').toString();")
1224 (test-ps-js create-blank
1228 (test-ps-js blank-object-literal
1232 (test-ps-js array-literal1
1236 (test-ps-js array-literal2
1240 (test-ps-js array-literal3
1244 (test-ps-js array-literal4
1248 (test-ps-js array-literal5
1249 ([] (1 2) ("a" "b"))
1250 "[[1, 2], ['a', 'b']];")
1252 (test-ps-js defun-rest1
1253 (defun foo (&rest bar
)
1254 (alert (aref bar
1)))
1256 var bar = Array.prototype.slice.call(arguments, 0);
1257 return alert(bar[1]);
1260 (test-ps-js defun-rest2
1261 (defun foo (baz &rest bar
) (+ baz
(aref bar
1)))
1262 "function foo(baz) {
1263 var bar = Array.prototype.slice.call(arguments, 1);
1264 return baz + bar[1];
1267 (test-ps-js defun-keyword1
1268 (defun zoo (foo bar
&key baz
) (+ foo bar baz
))
1269 "function zoo(foo, bar) {
1270 var _js2 = arguments.length;
1271 for (var n1 = 2; n1 < _js2; n1 += 2) {
1272 switch (arguments[n1]) {
1274 baz = arguments[n1 + 1];
1278 return foo + bar + baz;
1281 (test-ps-js defun-keyword2
1282 (defun zoo (&key baz
) (* baz baz
))
1284 var _js2 = arguments.length;
1285 for (var n1 = 0; n1 < _js2; n1 += 2) {
1286 switch (arguments[n1]) {
1288 baz = arguments[n1 + 1];
1295 (test-ps-js defun-keyword3
1296 (defun zoo (&key baz
(bar 4)) (* baz bar
))
1298 var _js2 = arguments.length;
1299 for (var n1 = 0; n1 < _js2; n1 += 2) {
1300 switch (arguments[n1]) {
1302 baz = arguments[n1 + 1];
1305 bar = arguments[n1 + 1];
1309 var bar = 'undefined' === typeof bar ? 4 : bar;
1313 (test-ps-js defun-keyword4
1314 (defun hello-world (&key
((:my-name-key my-name
) 1))
1316 "function helloWorld() {
1317 var _js2 = arguments.length;
1318 for (var n1 = 0; n1 < _js2; n1 += 2) {
1319 switch (arguments[n1]) {
1321 myName = arguments[n1 + 1];
1324 var myName = 'undefined' === typeof myName ? 1 : myName;
1328 (test-ps-js arglist-keyword-supplied
1329 (lambda (&key
(foo 1 supplied?
))
1332 var _js2 = arguments.length;
1333 for (var n1 = 0; n1 < _js2; n1 += 2) {
1334 switch (arguments[n1]) {
1336 foo = arguments[n1 + 1];
1337 suppliedwhat = true;
1341 var foo = 'undefined' === typeof foo ? 1 : foo;
1345 (test-ps-js keyword-funcall1
1349 (test-ps-js keyword-funcall2
1350 (func :baz
1 :bar foo
)
1351 "func('baz', 1, 'bar', foo);")
1353 (test-ps-js keyword-funcall3
1355 "fun(a, b, 'baz', c);")
1365 ((= y
(* x
4)) (foo "blah") (* x y
)))
1368 } else if (y === x * 4) {
1373 (test-ps-js if-exp-without-else-return
1374 (defun foo () (return-from foo
(if x
1)))
1376 return x ? 1 : null;
1379 (test-ps-js progn-expression-single-statement
1380 (defun foo () (return-from foo
(progn (* x y
))))
1385 (test-ps-js cond-expression1
1387 (cond ((< 1 2) (bar "foo") (* 4 5))))
1395 (test-ps-js cond-expression2
1397 (cond ((< 2 1) "foo")
1402 } else if (7 === 7) {
1407 (test-ps-js cond-expression-final-t-clause
1409 (cond ((< 1 2) (bar "foo") (* 4 5))
1420 } else if (a === b) {
1422 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
1429 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
1442 (test-ps-js funcall-if-expression
1443 (funcall (getprop document
'write
)
1444 (if (= *linkornot
* 1)
1445 (ps-html ((:a
:href
"#"
1446 :onclick
(ps-inline (transport)))
1449 "document.write(LINKORNOT === 1 ? ['<a href=\\\"#\\\" onclick=\\\"', 'javascript:' + 'transport()', '\\\">', img, '</a>'].join('') : img);")
1451 (test-ps-js negate-number-literal
1455 (fiveam:test macro-environment1
1458 (normalize-js-output
1459 (let* ((macroname (gensym)))
1460 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
1462 (macrolet ((,macroname
(x) `(aref data
,x
)))
1463 (when (,macroname x
)
1464 (setf (,macroname x
) 123)))))))
1465 (normalize-js-output
1467 return data[x] ? (data[x] = 123) : null;
1470 (fiveam:test macro-environment2
1473 (let ((outer-lexical-variable 1))
1474 (defpsmacro macro-environment2-macro
(x)
1475 `(+ ,outer-lexical-variable
,x
))
1476 (ps* '(macro-environment2-macro 2)))
1479 (test-ps-js ampersand-whole-1
1480 (macrolet ((foo (&whole foo bar baz
)
1481 (declare (ignore bar baz
))
1482 (with-standard-io-syntax
1483 (let ((*print-case
* :downcase
))
1484 (format nil
"~a" foo
)))))
1488 (test-ps-js ampersand-whole-2
1489 (macrolet ((foo (&whole foo bar baz
)
1494 (test-ps-js keyword-consistent
1498 (test-ps-js simple-symbol-macrolet
1499 (symbol-macrolet ((x 1)) x
)
1502 (test-ps-js compound-symbol-macrolet
1503 (symbol-macrolet ((x 123)
1508 (test-ps-js define-symbol-macro
1509 (progn (define-symbol-macro tst-sym-macro
2)
1513 (test-ps-js define-symbol-macro1
1514 (progn (define-symbol-macro tst-sym-macro1
2)
1515 (foo tst-sym-macro1
))
1518 (test-ps-js define-symbol-macro2
1519 (progn (define-symbol-macro tst-sym-macro2
3)
1520 (list tst-sym-macro2
))
1523 (test-ps-js define-symbol-macro3
1524 (progn (define-symbol-macro tst-sym-macro3
4)
1525 (setq foo
(create tst-sym-macro3 tst-sym-macro3
)))
1526 "foo = { tstSymMacro3 : 4 };")
1528 (test-ps-js define-symbol-macro4
1529 (progn (define-symbol-macro tst-sym-macro4
5)
1530 (setq foo
(if (baz) tst-sym-macro4 bar
)))
1531 "foo = baz() ? 5 : bar;")
1533 (test-ps-js expression-progn
1534 (1+ (progn (foo) (if x
1 2)))
1535 "(foo(), x ? 1 : 2) + 1;")
1537 (test-ps-js let-decl-in-expression
1539 (if x
1 (let* ((foo x
)) foo
)))
1549 (test-ps-js special-var1
1550 (progn (defvar *foo
*)
1557 FOO_TMPSTACK1 = FOO;
1561 FOO = FOO_TMPSTACK1;
1565 (test-ps-js special-var2
1566 (progn (defvar *foo
*)
1575 FOO_TMPSTACK1 = FOO;
1577 return FOO * 2 * BAZ;
1579 FOO = FOO_TMPSTACK1;
1583 (test-ps-js literal1
1587 (test-ps-js literal2
1591 (test-ps-js setf-dec1
1595 (test-ps-js setf-dec2
1599 (test-ps-js special-char-equals
1603 (test-ps-js setf-operator-priority
1605 (or (getprop cache id
)
1606 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
1608 return cache[id] || (cache[id] = document.getElementById(id));
1611 (test-ps-js aref-operator-priority
1612 (aref (if (and x
(> (length x
) 0))
1616 "(x && x.length > 0 ? x[0] : y)[z];")
1618 (test-ps-js aref-operator-priority1
1619 (aref (or (getprop x
'y
)
1624 (test-ps-js aref-operator-priority2
1628 (test-ps-js negate-operator-priority
1637 (delete (if a
(or b c
) d
))
1638 "delete (a ? b || c : d);")
1641 (not (if (or x
(not y
)) z
))
1642 "!(x || !y ? z : null);")
1649 (instanceof (or a b
) (if x y z
))
1650 "((a || b) instanceof (x ? y : z));")
1653 (or x
(if (= x
0) "zero" "empty"))
1654 "x || (x === 0 ? 'zero' : 'empty');")
1656 (test-ps-js named-op-expression
1660 (test-ps-js named-op-expression1
1664 (test-ps-js aref-array-expression
1666 "(a || b || c)[0];")
1668 (test-ps-js getprop-operator
1669 (getprop (or a b c
) 'd
)
1672 (test-ps-js getprop-parens
1673 (getprop (getprop foo
'bar
) 'baz
)
1676 (test-ps-js funcall-funcall
1680 (test-ps-js expression-funcall
1681 ((or (@ window eval
) eval
) foo nil
)
1682 "(window.eval || eval)(foo, null);")
1684 (test-ps-js expression-funcall1
1685 (((or (@ window eval
) eval
) foo nil
))
1686 "(window.eval || eval)(foo, null)();")
1688 (test-ps-js expression-funcall2
1689 (((or (@ window eval
) eval
)) foo nil
)
1690 "(window.eval || eval)()(foo, null);")
1692 (test-ps-js who-html1
1693 (who-ps-html (:span
:class
"ticker-symbol"
1694 :ticker-symbol symbol
1695 (:a
:href
"http://foo.com"
1697 (:span
:class
"ticker-symbol-popup")))
1698 "['<span class=\\\"ticker-symbol\\\" ticker-symbol=\\\"', symbol, '\\\"><a href=\\\"http://foo.com\\\">', symbol, '</a><span class=\\\"ticker-symbol-popup\\\"></span></span>'].join('');")
1700 (test-ps-js who-html2
1701 (who-ps-html (:p
"t0" (:span
"t1")))
1702 "'<p>t0<span>t1</span></p>';")
1705 ((lambda () (flet ((foo (x)
1709 var foo = function (x) {
1716 (flet ((foo (x) (1+ x
))
1720 var foo = function (x) {
1723 var bar = function (y) {
1730 (flet ((foo (x) (+ 2 x
)))
1731 (flet ((foo (x) (1+ x
))
1732 (bar (y) (+ 2 (foo y
))))
1735 var foo = function (x) {
1738 var foo1 = function (x) {
1741 var bar = function (y) {
1744 return bar(foo1(1));
1748 ((lambda () (labels ((foo (x)
1751 (+ x
(foo (1- x
))))))
1754 var foo = function (x) {
1755 return 0 === x ? 0 : x + foo(x - 1);
1761 (labels ((foo (x) (1+ (bar x
)))
1762 (bar (y) (+ 2 (foo y
))))
1765 var foo = function (x) {
1768 var bar = function (y) {
1775 (labels ((foo (x) (1+ x
))
1776 (bar (y) (+ 2 (foo y
))))
1779 var foo = function (x) {
1782 var bar = function (y) {
1788 (test-ps-js labels-lambda-list
1789 (labels ((foo (x &optional
(y 0))
1793 var foo = function (x, y) {
1794 if (y === undefined) {
1802 (test-ps-js for-loop-var-init-exp
1804 (do* ((y (if x
0 1) (1+ y
))
1809 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
1818 (test-ps-js literal-array
1822 (test-ps-js literal-array-1
1826 (test-ps-js literal-array-literal
1830 (test-ps-js literal-array-literal1
1834 (fiveam:test ps-lisp-expands-in-lexical-environment
1835 (fiveam:is
(string= (let ((x 5)) (ps (lisp x
)))
1838 (fiveam:test ps-lisp-expands-in-lexical-environment1
1839 (fiveam:is
(string= (let ((x 5)) (ps (+ 1 (lisp x
))))
1842 (fiveam:test ps-lisp-expands-in-lexical-environment2
1843 (fiveam:is
(string= (let ((x 2)) (ps (+ 1 (lisp x
) 3)))
1846 (fiveam:test ps
*-lisp-expands-in-null-lexical-environment
1847 (fiveam:signals unbound-variable
1849 (declare (ignore x
))
1852 (fiveam:test ps
*-lisp-expands-in-dynamic-environment
1855 (declare (special foo
))
1856 (ps* '(+ 1 (lisp (locally (declare (special foo
))
1860 (fiveam:test ps-lisp-dynamic-environment
1863 (declare (special foo
))
1864 (ps (+ 1 (lisp foo
))))
1867 (test-ps-js nested-if-expressions1
1869 (return-from foo
(if (if x y z
) a b
)))
1878 (test-ps-js nested-if-expressions2
1880 (if x y
(if z a b
)))
1889 (test-ps-js nested-if-expressions3
1890 (foo (if (if x y z
) a b
)
1891 (if x y
(if z a b
)))
1892 "foo((x ? y : z) ? a : b, x ? y : (z ? a : b));")
1964 (test-ps-js let-exp1
2015 (test-ps-js symbol-macrolet-var
2016 (symbol-macrolet ((x y
))
2020 (test-ps-js setf-conditional1
2021 (setf x
(unless (null a
) (1+ a
)))
2022 "x = a != null ? a + 1 : null;")
2024 (test-ps-js setf-let1
2025 (setf x
(let ((a 1)) a
))
2031 (test-ps-js setf-let2
2032 (setf x
(let ((a (foo)))
2037 return a != null ? a + 1 : null;
2040 (test-ps-js symbol-macro-env1
2041 (symbol-macrolet ((bar 1))
2042 (macrolet ((bar (x y
) `(+ ,x
,y
)))
2046 (test-ps-js symbol-macrolet-fun1
2047 (symbol-macrolet ((baz +))
2051 (test-ps-js lisp2-namespaces1
2053 (setf list
(list 1 2 3)))
2056 return list = [1, 2, 3];
2059 (test-ps-js let-shadows-symbol-macrolet
2060 (symbol-macrolet ((x y
))
2070 (test-ps-js let-rename-optimization1
2078 (test-ps-js let-rename-optimization2
2087 (test-ps-js symbol-macro-array
2088 (symbol-macrolet ((x 1))
2092 (test-ps-js symbol-macro-obj
2093 (symbol-macrolet ((x (+ 1 2)))
2097 (test-ps-js symbol-macro-obj1
2098 (symbol-macrolet ((x (+ 1 2)))
2102 (test-ps-js symbol-macro-getprop1
2103 (symbol-macrolet ((x (+ 1 2)))
2107 (test-ps-js symbol-macro-getprop1
2108 (symbol-macrolet ((x (+ 1 2)))
2112 (test-ps-js let-let-create
2122 (test-ps-js symbol-macro-conditional1
2123 (symbol-macrolet ((x y
))
2131 (test-ps-js symbol-macro-conditional2
2132 (symbol-macrolet ((x y
))
2136 (test-ps-js preserve-this
2138 (let ((y (block nil
(bar this
))))
2141 var y = (function () {
2147 (test-ps-js flet-apply
2148 (flet ((foo () 'bar
))
2149 (apply (function foo
) nil
))
2151 var foo = function () {
2154 return foo.apply(this, null);
2157 (test-ps-js let-apply
2158 (let ((foo (lambda () 1)))
2159 (let ((foo (lambda () 2)))
2162 var foo = function () {
2165 var foo1 = function () {
2168 return foo1.apply(this, null);
2171 (test-ps-js flet-let
2172 (flet ((x (x) (1+ x
)))
2176 var x = function (x) {
2183 (test-ps-js let-flet
2185 (flet ((x (x) (1+ x
)))
2189 var x1 = function (x) {
2195 (test-ps-js labels-let
2196 (labels ((x (x) (1+ x
)))
2200 var x = function (x) {
2207 (test-ps-js let-labels
2209 (labels ((x (x) (1+ x
)))
2213 var x1 = function (x) {
2219 (test-ps-js macrolet-let-inteference
2220 (macrolet ((a (n) `(+ ,n
5)))
2222 (let ((b (a (- a
4))))
2226 var b = (a - 4) + 5;
2230 (test-ps-js let-subtract-add
2246 (test-ps-js create-reserved-word
2248 "({ 'default' : 1 });")
2250 (test-ps-js getprop-reserved-word
2251 (getprop foo
:default
)
2254 (test-ps-js getprop-reserved-word1
2255 (getprop foo
'default
)
2258 (test-ps-js eval-when-ps-side
2259 (eval-when (:execute
)
2263 (defvar *lisp-output
* nil
)
2265 (fiveam:test eval-when-lisp-side
()
2266 (setf *lisp-output
* 'original-value
)
2268 (normalize-js-output
2269 (ps-doc* `(eval-when (:compile-toplevel
)
2270 (setf *lisp-output
* 'it-works
))))))
2271 (fiveam:is
(eql 'it-works
*lisp-output
*))
2272 (fiveam:is
(string= "" js-output
))))
2274 (defpsmacro my-in-package
(package-name)
2275 `(eval-when (:compile-toplevel
)
2276 (setf *lisp-output
* ,package-name
)))
2278 (fiveam:test eval-when-macro-expansion
()
2279 (setf *lisp-output
* 'original-value
)
2281 (normalize-js-output
2283 (my-in-package :cl-user
)
2285 (declare (ignore js-output
))
2286 (fiveam:is
(eql :cl-user
*lisp-output
*))))
2288 (fiveam:test eval-when-macrolet-expansion
()
2289 (setf *lisp-output
* 'original-value
)
2291 (normalize-js-output
2293 `(macrolet ((my-in-package2 (package-name)
2294 `(eval-when (:compile-toplevel
)
2295 (setf *lisp-output
* ,package-name
))))
2296 (my-in-package2 :cl-user
)
2298 (declare (ignore js-output
))
2299 (fiveam:is
(eql :cl-user
*lisp-output
*))))
2301 (test-ps-js getprop-keyword
2305 (test-ps-js nary-comparison1
2306 (lambda () (< 1 2 3))
2309 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
2312 (test-ps-js chain-getprop1
2313 (chain ($
"foo") (bar x z
) frob
(baz 5))
2314 "$('foo').bar(x, z).frob.baz(5);")
2316 (test-ps-js chain-getprop2
2317 (chain ($
"foo") bar baz
)
2318 "$('foo').bar.baz;")
2320 (test-ps-js chain-getprop3
2321 (chain ($
"foo") bar
(x y
) baz
)
2322 "$('foo').bar.x(y).baz;")
2324 (test-ps-js flet-expression
2325 (1+ (flet ((foo (x) (1+ x
)))
2328 var foo = function (x) {
2334 (test-ps-js flet-lambda-list
2335 (flet ((foo (x &key
(y 0))
2339 var foo = function (x) {
2340 var _js2 = arguments.length;
2341 for (var n1 = 1; n1 < _js2; n1 += 2) {
2342 switch (arguments[n1]) {
2344 y = arguments[n1 + 1];
2347 var y = 'undefined' === typeof y ? 0 : y;
2350 return foo(1, 'y', 2);
2353 (test-ps-js return-case-break-elimination
2367 (test-ps-js aplusplus
2371 (test-ps-js astarstar
2375 (test-ps-js switch-return-fallthrough
2392 (test-ps-js return-last-case
2406 (test-ps-js return-macrolet
2408 (macrolet ((x () 1))
2421 (test-ps-js mv-bind1
2422 (multiple-value-bind (a b
)
2430 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2433 var _db2 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2438 __PS_MV_REG = prevMv1;
2442 (test-ps-js mv-bind2
2443 (multiple-value-bind (a b
)
2452 var prevMv2 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2455 var _db4 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2460 __PS_MV_REG = prevMv2;
2464 (test-ps-js multiple-value-bind-simple
2465 (multiple-value-bind (a b
) (blah)
2468 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2471 var _db2 = blah === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2475 __PS_MV_REG = prevMv1;
2480 (lambda () (values))
2491 (lambda () (values x y
))
2493 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2498 (lambda () (values x y z
))
2500 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y, z] };
2504 (test-ps-js values-return
2506 (return-from foo
(values (* x x
) y
)))
2507 "function foo(x, y) {
2509 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2513 (test-ps-js return-macrolet1
2515 (symbol-macrolet ((x 2))
2523 (test-ps-js return-cond
2526 (cond ((foo? x
) (loop for y in x do
(foo y
)))
2531 var _js2 = x.length;
2532 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2536 } else if (barwhat(x)) {
2543 (test-ps-js return-case
2547 (1 (loop for y in x do
(foo y
)))
2553 var _js2 = x.length;
2554 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2566 (test-ps-js return-case1
2584 (test-ps-js lambda-loop-if-return
2587 (loop for y in x do
(foo y
))
2591 var _js4 = x.length;
2592 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2601 (test-ps-js lambda-loop-if-return1
2605 (progn (loop for y in x do
(foo y
))
2610 return foo(function () {
2612 var _js4 = x.length;
2613 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2617 throw { '__ps_block_tag' : 'baz',
2618 '__ps_value1' : null };
2623 } catch (_ps_err5) {
2624 if (_ps_err5 && 'baz' === _ps_err5['__ps_block_tag']) {
2625 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err5['__ps_values'] };
2626 return _ps_err5['__ps_value1'];
2633 (test-ps-js switch-loop
2636 (1 (dolist (a b
)))))
2640 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
2647 (test-ps-js switch-folds-blocks
2650 (1 (loop repeat
3 do
(alert "foo")))
2655 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
2664 (test-ps-js setf-places-before-macros
2666 (defsetf left
(el) (offset)
2667 `(setf (@ ,el style left
) ,offset
))
2668 (macrolet ((left (el)
2669 `(@ ,el offset-left
)))
2675 _js2.style.left = _js1;
2676 return x.offsetLeft;
2679 (test-ps-js for-return
2680 (lambda () (dolist (arg args
) (foo arg
)))
2682 for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
2683 arg = args[_js_idx1];
2688 (test-ps-js try-catch-return
2706 (let ((x (ps:try
(+ 1 2)
2710 var x = (function () {
2720 (test-ps-js try-finally-return-from
2723 (ps:try
(when (blah) 4)
2728 return blah() ? 4 : null;
2732 return dontCallMe();
2735 (test-ps-js defun-setf-optional
2736 (defun (setf foo
) (new-value b
&optional c
)
2737 (setf (aref b
(or c
0)) new-value
))
2738 "function __setf_foo(newValue, b, c) {
2739 return b[c || 0] = newValue;
2742 (test-ps-js defun-setf-rest
2743 (progn (defun (setf foo
) (new-value b
&rest foo
)
2744 (do-something b foo new-value
))
2745 (setf (foo x
1 2 3 4) 5))
2746 "function __setf_foo(newValue, b) {
2747 var foo = Array.prototype.slice.call(arguments, 2);
2748 return doSomething(b, foo, newValue);
2750 __setf_foo(5, x, 1, 2, 3, 4);")
2752 (test-ps-js return-null
2753 (defun foo () (return-from foo nil
))
2758 (test-ps-js implicit-return-null
2765 (test-ps-js implicit-return-null
2772 (test-ps-js return-conditional-nested
2773 (defun blep (ss x y
)
2777 (destructuring-bind (a b
) pair
2778 (unless (or (null a
) (null b
))
2779 (let ((val (baz a b
)))
2784 "function blep(ss, x, y) {
2790 if (!(a == null || b == null)) {
2791 var val = baz(a, b);
2794 return !blee() ? true : null;
2802 (test-ps-js return-when-returns-broken-return
2804 (return-from foo
(when x
1))
2807 return x ? 1 : null;
2811 (test-ps-js return-case-conditional
2815 (123 (when (bar) t
))
2820 return bar() ? true : null;
2826 (test-ps-js return-try-conditional
2834 return x ? 1 : null;
2842 (test-ps-js function-declare-special
2844 (declare (special *foo
*))
2850 FOO_TMPSTACK1 = FOO;
2854 FOO = FOO_TMPSTACK1;
2858 (test-ps-js declare-special-let
2860 (declare (special *foo
*))
2865 FOO_TMPSTACK1 = FOO;
2869 FOO = FOO_TMPSTACK1;
2873 (test-ps-js declare-special-let-scope
2876 (declare (special *foo
*))
2883 FOO_TMPSTACK1 = FOO;
2887 FOO = FOO_TMPSTACK1;
2893 (test-ps-js declare-special-let
*
2894 (let* ((*foo
* 123) (*bar
* (+ *foo
* *bar
*)))
2895 (declare (special *foo
* *bar
*))
2900 FOO_TMPSTACK1 = FOO;
2904 BAR_TMPSTACK2 = BAR;
2908 BAR = BAR_TMPSTACK2;
2911 FOO = FOO_TMPSTACK1;
2915 (test-ps-js defun-multiple-declarations-around-docstring
2917 (declare (ignorable x y
))
2918 (declare (integer x
) (float y
))
2919 "Fooes X while barring Y."
2920 (declare (special *foo
*) (special *bar
*))
2921 (let ((*bar
* (bar y
)))
2923 "/** Fooes X while barring Y. */
2924 function foo(x, y) {
2927 BAR_TMPSTACK1 = BAR;
2931 BAR = BAR_TMPSTACK1;
2935 (test-ps-js macro-null-toplevel
2937 (defmacro macro-null-toplevel
()
2939 (macro-null-toplevel))
2942 (test-ps-js define-symbol-macro-let
2944 (define-symbol-macro test-symbol-macro
1)
2945 (let ((test-symbol-macro 2))
2946 (1+ test-symbol-macro
))
2947 (1+ test-symbol-macro
))
2949 var testSymbolMacro1 = 2;
2950 return testSymbolMacro1 + 1;
2954 (test-ps-js define-symbol-macro-flet
2956 (define-symbol-macro test-symbol-macro1
1)
2957 (flet ((test-symbol-macro1 () 2))
2958 (foo test-symbol-macro1
)
2959 (test-symbol-macro1))
2960 (bar test-symbol-macro1
))
2962 var testSymbolMacro1_1 = function () {
2966 return testSymbolMacro1_1();
2970 (fiveam:test compile-stream-nulls
2973 (with-input-from-string (s "
2974 (defmacro macro-null-toplevel ()
2976 (macro-null-toplevel)")
2977 (ps-compile-stream s
))
2980 (fiveam:test compile-stream1
2983 (with-input-from-string (s "
2984 (define-symbol-macro test-symbol-macro1 1)
2985 (flet ((test-symbol-macro1 () 2))
2986 (foo test-symbol-macro1)
2987 (test-symbol-macro1))
2988 (bar test-symbol-macro1)")
2989 (ps::with-blank-compilation-environment
2990 (ps-compile-stream s
)))
2992 var testSymbolMacro1_1 = function () {
2996 return testSymbolMacro1_1();
3001 (test-ps-js equality-nary1
3002 (let ((x 10) (y 10) (z 10))
3009 return (_cmp1 = y, x === _cmp1 && _cmp1 === z);
3012 (test-ps-js equality1
3023 (test-ps-js getprop-quote-reserved
3024 (getprop foo
':break
)
3027 (test-ps-js defun-block-return-from
3038 (test-ps-js block-return-from
3042 (return-from scope
))
3052 (test-ps-js block-return-from0
3057 (return-from scope
))
3067 (test-ps-js block-return-from01
3072 (return-from scope
))
3086 (test-ps-js block-return-from02
3091 (return-from scope
(foobar)))
3106 (test-ps-js block-return-from1
3111 (return-from scope
))
3125 (test-ps-js block-return-from2
3131 (return-from scope
6))
3142 (test-ps-js let-funcall
3156 (test-ps-js symbol-macrolet-funcall
3157 (symbol-macrolet ((foo bar
))
3158 (funcall foo
1 2 3))
3161 (test-ps-js times-assign
3165 (test-ps-js vector-literal
3169 (test-ps-js vector-literal1
3171 "[1, 2, ['a', 'b'], 3];")
3174 (+ 1 (rem 2 (+ 3 4)))
3177 (test-ps-js non-associative
3178 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
3179 "1 / (2 / 3) + (1 - (2 - 3));")
3181 (test-ps-js lambda-apply
3183 (apply (lambda (y) (bar (1+ y
))) x
))
3185 return (function (y) {
3190 (test-ps-js operator-expressions-nested-let
3191 (let ((x (let ((y 1))
3200 (test-ps-js operator-expressions-array-nested-let
3201 (list (let ((y 1)) y
) 2)
3207 (test-ps-js add-subtract-precedence
3211 (test-ps-js ps-inline-toplevel
3213 "'javascript:' + 'foo()';")
3215 (test-ps-js no-clause-progn-exp
3219 (test-ps-js no-clause-progn-return
3221 (return-from foo
(progn)))
3226 (test-ps-js empty-cond-clause
3227 (setf x
(cond ((foo))))
3228 "x = (function () { var testResult1 = foo(); return testResult1 ? testResult1 : null; })();")
3230 (test-ps-js empty-cond-clause1
3231 (setf x
(cond ((foo) 123)
3236 var testResult1 = bar();
3240 if (true) { return 456; };
3244 (test-ps-js let-no-body
3246 (return-from foo
(let ((foo bar
)))))
3252 (test-ps-js rename-lexical-dupes
3254 (list (let ((foo 12)) (* foo
2))
3255 (let ((foo 13)) (* foo
3))))
3259 return [(foo = 12, foo * 2), (foo1 = 13, foo1 * 3)];
3262 (test-ps-js defun-comment1
3264 "BARBAR is a revolutionary new foobar.
3268 * BARBAR is a revolutionary new foobar.
3275 (test-ps-js var-comment
3280 (test-ps-js case-return-break-broken-return
3283 ("bar" (if y
(return-from foo t
) nil
))
3298 (test-ps-js case-return-break1-broken-return
3301 ("bar" (if y
(return-from foo t
)))
3316 (test-ps-js setf-progn
3317 (setf foo
(progn (bar) (baz) 3))
3322 (test-ps-js var-progn
3323 (var x
(progn (foo) (bar)))
3327 (test-ps-js implicit-return-loop
3331 (loop :repeat
100 :do
(bar))
3337 for (var _js2 = 0; _js2 < 100; _js2 += 1) {
3344 (test-ps-js loop-closures
3345 (dotimes (i 10) (lambda () (+ i
1)))
3347 for (var i = 0; i < 10; i += 1) {
3354 (test-ps-js loop-closures-let
3357 (lambda () (+ i x
))))
3359 for (var i = 0; i < 10; i += 1) {
3360 with ({ x : null }) {
3369 (test-ps-js loop-closures-flet
3371 (flet ((foo (x) (+ i x
)))
3372 (lambda () (foo i
))))
3374 for (var i = 0; i < 10; i += 1) {
3375 with ({ foo : null }) {
3376 var foo = function (x) {
3386 (test-ps-js while-closures-let
3389 (lambda () (+ 1 abc
))))
3391 with ({ abc : null }) {
3399 (test-ps-js dotted-list-form
3402 (destructuring-bind (b . c
)
3408 var c = bar.length > 1 ? bar.slice(1) : [];
3413 (test-ps-js explicit-nil-block
3416 (block nil
(return (foo 2)) (+ 1 2))
3428 (test-ps-js dynamic-extent-function-return
3431 (return-from foo
6))))
3434 return (function () {
3435 throw { '__ps_block_tag' : 'foo', '__ps_value1' : 6 };
3437 } catch (_ps_err1) {
3438 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3439 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3440 return _ps_err1['__ps_value1'];
3447 (test-ps-js dynamic-extent-function-return-nothing
3450 (return-from foo
))))
3453 return (function () {
3454 throw { '__ps_block_tag' : 'foo', '__ps_value1' : null };
3456 } catch (_ps_err1) {
3457 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3458 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3459 return _ps_err1['__ps_value1'];
3466 (test-ps-js dynamic-extent-function-return-values
3469 (return-from foo
(values 1 2 3)))))
3473 return (function () {
3474 throw { '__ps_block_tag' : 'foo',
3476 '__ps_values' : [2, 3] };
3478 } catch (_ps_err1) {
3479 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3480 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3481 return _ps_err1['__ps_value1'];
3488 (test-ps-js dynamic-extent-function-return-funcall
3491 (return-from foo
(if baz
6 5)))))
3494 return (function () {
3495 throw { '__ps_block_tag' : 'foo', '__ps_value1' : baz ? 6 : 5 };
3497 } catch (_ps_err1) {
3498 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3499 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3500 return _ps_err1['__ps_value1'];
3507 (test-ps-js block-dynamic-return
3508 (var foo
((lambda ()
3510 ((lambda () (return 6)))
3512 "var foo = (function () {
3515 throw { '__ps_block_tag' : 'nilBlock', '__ps_value1' : 6 };
3518 } catch (_ps_err1) {
3519 if (_ps_err1 && 'nilBlock' === _ps_err1['__ps_block_tag']) {
3520 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3521 return _ps_err1['__ps_value1'];
3528 (test-ps-js block-dynamic-return1
3529 (var foo
((lambda ()
3531 ((lambda () (return 6)))
3534 "var foo = (function () {
3541 return foobar(1, 2);
3544 (test-ps-js iteration-lambda-capture-no-need
3546 (lambda (x) (1+ x
)))
3548 for (var x = null, _js_idx1 = 0; _js_idx1 < y.length; _js_idx1 += 1) {
3556 (test-ps-js case-invert1
3557 (encodeURIComponent fooBar
)
3558 "encodeURIComponent(fooBar);")
3560 (test-ps-js simple-ash
3561 (+ (ash 4 1) (ash 4 -
1))
3562 "(4 << 1) + (4 >> 1);")
3564 (test-ps-js progn-nil-expression
3565 (bar (progn (foo) nil
))
3566 "bar((foo(), null));")
3568 (test-ps-js other-progn-nil-exp
3570 (or (foo) (progn (bar) nil
)))
3572 return foo() || (bar(), null);
3575 (test-ps-js lambda-nil-return
3588 (test-ps-js lambda-nil-return-implicit-nested2
3594 (return-from foo i
)))
3600 for (var i = 0; i < 4; i += 1) {
3607 (test-ps-js throw-is-a-statement
3609 (let ((result (foo)))
3610 (unless (null result
)
3614 if (result != null) {
3619 (test-ps-js expressify1
3621 (when (some-condition)
3626 if (someCondition()) {
3633 (test-ps-js case-when-return
3636 ("a" (when (foo) (return-from blah
111)))
3651 (test-ps-js flet-return-from
3654 (return-from foo
123)))
3657 var foo = function () {
3663 (test-ps-js flet-return-from1
3665 (return-from foo
123)))
3668 var foo = function () {
3674 (test-ps-js lambda-docstring-declarations
3676 "This is a docstring"
3677 (declare (ignore x
))
3683 (test-ps-js setf-let-exp
3684 (setf foo
(let ((x (+ 1 2)))
3686 "foo = (function () {
3688 return x ? 123 : 456;
3691 (test-ps-js create-let-exp
3692 (create :abc
(let ((x (+ 1 2)))
3694 "({ 'abc' : (function () {
3696 return x ? 123 : 456;
3699 (test-ps-js eql-eql-eql-precedence
3700 (unless (equal (= 3 3) (= 3 4))
3701 (chain console
(log 1)))
3702 "if ((3 === 3) != (3 === 4)) {
3706 (test-ps-js case-cond-breaks
3712 (return-from blah nil
))
3735 (test-ps-js cond-double-t
3748 (test-ps-js let-let-funcall-lambda
3751 (funcall (lambda (x) (+ x
9)) x
)))
3755 return (function (x) {
3760 (test-ps-js let-let-lambda
3763 (lambda (x) (+ x
9))))
3767 return function (x) {
3772 (test-ps-js let-lambda
3774 (lambda (x) (+ x
9)))
3777 return function (x) {
3782 (test-ps-js symbol-macrolet-no-shadow-lambda
3783 (symbol-macrolet ((x y
))
3784 (lambda (x) (+ x x
)))
3789 (test-ps-js divide-one-arg-reciprocal
3793 (test-ps-js division-not-associative
3797 (test-ps-js divide-expressions
3801 (test-ps-js divide-expressions1
3803 "Math.floor((x - 1) / y);")
3805 (test-ps-js lexical-funargs-shadow1
3816 (test-ps-js times-rem
3820 (test-ps-js rem-divide
3824 (test-ps-js case-break-return
3825 (lambda () (case x
(:foo
) (:bar
1)))
3835 (test-ps-js trivial-expression-switch
3836 (foobar (case x
(1 2)))
3837 "foobar((function () {
3844 (test-ps-js trivial-expression-while
3845 (foobar (while (< 0 x
) (decf x
)))
3846 "foobar((function () {
3852 (test-ps-js funcall-block-expression-loop-lambda
3853 (foobar (loop for i from
0 to
10 do
(1+ i
)))
3854 "foobar((function () {
3855 for (var i = 0; i <= 10; i += 1) {
3860 (test-ps-js plus-block-expression-loop-lambda
3861 (1+ (loop for i from
0 to
10 do
(1+ i
)))
3863 for (var i = 0; i <= 10; i += 1) {
3868 (test-ps-js let-closures-rename
3870 (let ((x 1)) (lambda () (1+ x
)))
3871 (let ((x 2)) (lambda () (1+ x
))))
3878 return function () {
3883 (test-ps-js let-closures-rename1
3887 (lambda () (+ x y
))))
3890 (lambda () (+ x y
)))))
3899 return function () {
3904 (test-ps-js let-closures-rename2
3905 (defun make-closures ()
3907 (let ((x 1)) (lambda () (1+ x
)))
3908 (let ((x 2)) (lambda () (1+ x
)))))
3909 "function makeClosures() {
3912 return [(x = 1, function () {
3914 }), (x1 = 2, function () {
3920 (test-ps-js conditional-not-used-up
3932 (test-ps-js toplevel-local-scope
3933 (create "fn" (let ((x 5)) (lambda () x
)))
3934 "({ 'fn' : (function () {
3936 return function () {
3941 (test-ps-js toplevel-local-scope1
3942 (defvar foo
(create "fn" (let ((x 5)) (lambda () x
))))
3943 "var foo = { 'fn' : (function () {
3945 return function () {
3950 (test-ps-js block-let
3953 (return-from foobar x
)
3961 (test-ps-js expressionize-if-macroexpand-error
3962 (progn (defmacro xbaz
() `(blah))
3968 "function foo(xbaz) {
3978 (test-ps-js toplevel-defun-macroexpand
3979 (progn (defmacro defun-js
(name lambda-list
&body body
)
3980 `(defun ,name
,lambda-list
,@body
))
3983 (defun-js bar
() (1+ foo
))
3991 (test-ps-js js-ir-package-unique-symbols
3992 (loop :for i
:from
0 :below
5 :do
3993 (let ((block (elt blocks i
)))
3997 for (var i = 0; i < 5; i += 1) {
3998 var block = blocks[i];
4006 (test-ps-js broken-quote-expansion1
4011 return p.x < 0 ? p.y : p.x;
4014 (test-ps-js broken-quote-expansion2
4016 (define-symbol-macro foo123
(ps:@ a foo123
))
4017 (lambda () (when (> foo123
1) 2)))
4019 return a.foo123 > 1 ? 2 : null;
4022 (test-ps-js unused-named-block-not-printed1
4029 (test-ps-js unused-named-block-not-printed2
4037 (test-ps-js unused-named-block-not-printed3
4045 (test-ps-js unused-named-block-not-printed4
4054 (test-ps-js trig-no-bind1
4056 "(Math.exp(3.14) + Math.exp(-3.14)) / 2;")
4058 (test-ps-js trig-bind1
4061 var x1 = blah(3.14);
4062 return 2 * Math.log(Math.sqrt((x1 + 1) / 2) + Math.sqrt((x1 - 1) / 2));
4065 (test-ps-js double-negation
4066 (or (not foo
) (not (not foo
)) (not (not (not foo
))))
4067 "!foo || foo || !foo;")
4069 (test-ps-js empty-let
4077 (test-ps-js empty-let
*
4085 (test-ps-js defun-no-body-declare
4086 (defun foo () (declare (ignore x
)))
4091 (test-ps-js defun-no-body-let-decare
4092 (defun foo () (let () (declare (ignore x
))))
4097 (test-ps-js empty-defun-docstring-declare
4100 (declare (ignore x
)))
4106 (test-ps-js defun-docstring-string
4115 (test-ps-js return-object
4117 (ps:create
:abc
(let ((x (ps:getprop obj
"blah")))
4119 "function foo(obj) {
4121 return { 'abc' : (x = obj['blah'], x ? 123 : 456) };
4126 ;; (test-ps-js let-defun-toplevel
4127 ;; (progn (let ((foo 0))
4128 ;; (defun bar () foo))
4130 ;; "var bar_foo1 = 0;
4136 ;; (test-ps-js let-defvar-toplevel
4137 ;; (progn (let ((foo 0))
4138 ;; (defvar bar (1+ foo)))
4140 ;; "var bar_foo1 = 0;
4141 ;; var bar = bar_foo1 + 1;
4144 ;; (test-ps-js setf-side-effects
4147 ;; (defun side-effect()
4150 ;; (setf x (+ 2 (side-effect) x 5))))
4151 ;; "var sideEffect_x1 = 10;
4152 ;; function sideEffect() {
4153 ;; sideEffect_x1 = 4;
4156 ;; sideEffect_x1 = 2 + sideEffect() + x + 5;")