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 #xB
)) ; vertical tab
1028 ("u001F" .
,(code-char #x1F
)) ; character below 32
1029 ("u0080" .
,(code-char 128)) ; character over 127
1030 ("u00A0" .
,(code-char 160)) ; non-breaking space
1031 ("u00AD" .
,(code-char 173)) ; soft hyphen
1032 ("u200B" .
,(code-char #x200B
)) ; zero-width space
1033 ("u200C" .
,(code-char #x200C
)) ; zero-width non-joiner
1035 (loop for
(js-escape . lisp-char
) in escapes
1036 for generated
= (ps-doc* (format nil
"hello~ahi" lisp-char
))
1037 for wanted
= (format nil
"'hello\\~ahi';" js-escape
)
1038 do
(fiveam:is
(string= generated wanted
)))))
1040 (fiveam:test escape-doublequotes
1041 (let ((*js-string-delimiter
* #\"))
1042 (fiveam:is
(string= (ps-doc* "hello\"hi") "\"hello\\\"\hi\";"))))
1044 (test-ps-js getprop-setf
1045 (setf (getprop x
'y
) (+ (+ a
3) 4))
1046 "x.y = (a + 3) + 4;")
1048 (test-ps-js getprop-conditional1
1049 (getprop (if zoo foo bar
) 'x
)
1050 "(zoo ? foo : bar).x;")
1052 (test-ps-js getprop-conditional2
1053 (getprop (if (not zoo
) foo bar
) 'x
)
1054 "(!zoo ? foo : bar).x;")
1056 (fiveam:test script-star-eval1
1058 (normalize-js-output (ps* '(setf x
1) '(setf y
2)))
1061 (fiveam:test script-star-eval2
1063 (normalize-js-output (ps* '(setf x
1)))
1066 (test-ps-js list-with-single-nil
1070 (test-ps-js quoted-nil-is-array
1074 (test-ps-js quoted-nil-is-array1
1078 (test-ps-js literal-nil
1082 (test-ps-js quoted-quoted-nil
1086 (test-ps-js quoted-quoted-nil1
1090 (test-ps-js defsetf1
1091 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
1097 return setBaz(_js2, _js3, _js1);
1100 (test-ps-js setf-macroexpands1
1101 (macrolet ((bar (x y
)
1103 (setf (bar foo
2) 3))
1106 (test-ps-js defsetf-short
1107 (progn (defsetf baz set-baz
"docstring")
1108 (setf (baz 1 2 3) "foo"))
1109 "setBaz(1, 2, 3, 'foo');")
1111 (test-ps-js defun-setf1
1112 (progn (defun (setf some-thing
) (new-val i1 i2
)
1113 (setf (aref *some-thing
* i1 i2
) new-val
))
1114 (setf (some-thing 1 2) "foo"))
1115 "function __setf_someThing(newVal, i1, i2) {
1116 return SOMETHING[i1][i2] = newVal;
1118 __setf_someThing('foo', 1, 2);")
1120 (test-ps-js defun-optional1
1121 (defun test-opt (&optional x
)
1123 "function testOpt(x) {
1124 return x ? 'yes' : 'no';
1127 (test-ps-js defun-optional2
1128 (defun foo (x &optional y
)
1130 "function foo(x, y) {
1134 (test-ps-js defun-optional3
1135 (defun blah (&optional
(x 0))
1138 if (x === undefined) {
1144 (test-ps-js arglist-optional4
1145 (lambda (&optional
(x 0 supplied?
))
1148 var suppliedwhat = x !== undefined;
1149 if (!suppliedwhat) {
1155 (test-ps-js return-nothing
1156 (defun foo () (return-from foo
))
1161 (test-ps-js return-values
1162 (defun foo () (return-from foo
(values 1 2 3)))
1164 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [2, 3] };
1168 (test-ps-js set-timeout
1169 (set-timeout (lambda () (alert "foo")) 10)
1170 "setTimeout(function () { return alert('foo'); }, 10);")
1172 (test-ps-js operator-precedence
1176 (test-ps-js operators-1
1196 (test-ps-js setf-conditional
1197 (setf foo
(if x
1 2))
1200 (test-ps-js obj-literal-numbers
1204 (test-ps-js obj-literal-strings
1208 (test-ps-js getprop-string
1212 (test-ps-js getprop-string1
1213 (getprop "bar" 'length
)
1216 (test-ps-js getprop-progn
1217 (getprop (progn (some-fun "abc") "123") "length")
1218 "(someFun('abc'), '123')['length'];")
1220 (test-ps-js getprop-multi1
1221 (getprop foo
1 "two" three
'bar
1 2)
1222 "foo[1]['two'][three].bar[1][2];")
1224 (test-ps-js method-call-block
1225 ((@ (progn (some-fun "abc") "123") to-string
))
1226 "(someFun('abc'), '123').toString();")
1228 (test-ps-js create-blank
1232 (test-ps-js blank-object-literal
1236 (test-ps-js array-literal1
1240 (test-ps-js array-literal2
1244 (test-ps-js array-literal3
1248 (test-ps-js array-literal4
1252 (test-ps-js array-literal5
1253 ([] (1 2) ("a" "b"))
1254 "[[1, 2], ['a', 'b']];")
1256 (test-ps-js defun-rest1
1257 (defun foo (&rest bar
)
1258 (alert (aref bar
1)))
1260 var bar = Array.prototype.slice.call(arguments, 0);
1261 return alert(bar[1]);
1264 (test-ps-js defun-rest2
1265 (defun foo (baz &rest bar
) (+ baz
(aref bar
1)))
1266 "function foo(baz) {
1267 var bar = Array.prototype.slice.call(arguments, 1);
1268 return baz + bar[1];
1271 (test-ps-js defun-keyword1
1272 (defun zoo (foo bar
&key baz
) (+ foo bar baz
))
1273 "function zoo(foo, bar) {
1274 var _js2 = arguments.length;
1275 for (var n1 = 2; n1 < _js2; n1 += 2) {
1276 switch (arguments[n1]) {
1278 baz = arguments[n1 + 1];
1282 return foo + bar + baz;
1285 (test-ps-js defun-keyword2
1286 (defun zoo (&key baz
) (* baz baz
))
1288 var _js2 = arguments.length;
1289 for (var n1 = 0; n1 < _js2; n1 += 2) {
1290 switch (arguments[n1]) {
1292 baz = arguments[n1 + 1];
1299 (test-ps-js defun-keyword3
1300 (defun zoo (&key baz
(bar 4)) (* baz bar
))
1302 var _js2 = arguments.length;
1303 for (var n1 = 0; n1 < _js2; n1 += 2) {
1304 switch (arguments[n1]) {
1306 baz = arguments[n1 + 1];
1309 bar = arguments[n1 + 1];
1313 var bar = 'undefined' === typeof bar ? 4 : bar;
1317 (test-ps-js defun-keyword4
1318 (defun hello-world (&key
((:my-name-key my-name
) 1))
1320 "function helloWorld() {
1321 var _js2 = arguments.length;
1322 for (var n1 = 0; n1 < _js2; n1 += 2) {
1323 switch (arguments[n1]) {
1325 myName = arguments[n1 + 1];
1328 var myName = 'undefined' === typeof myName ? 1 : myName;
1332 (test-ps-js arglist-keyword-supplied
1333 (lambda (&key
(foo 1 supplied?
))
1336 var _js2 = arguments.length;
1337 for (var n1 = 0; n1 < _js2; n1 += 2) {
1338 switch (arguments[n1]) {
1340 foo = arguments[n1 + 1];
1341 suppliedwhat = true;
1345 var foo = 'undefined' === typeof foo ? 1 : foo;
1349 (test-ps-js keyword-funcall1
1353 (test-ps-js keyword-funcall2
1354 (func :baz
1 :bar foo
)
1355 "func('baz', 1, 'bar', foo);")
1357 (test-ps-js keyword-funcall3
1359 "fun(a, b, 'baz', c);")
1369 ((= y
(* x
4)) (foo "blah") (* x y
)))
1372 } else if (y === x * 4) {
1377 (test-ps-js if-exp-without-else-return
1378 (defun foo () (return-from foo
(if x
1)))
1380 return x ? 1 : null;
1383 (test-ps-js progn-expression-single-statement
1384 (defun foo () (return-from foo
(progn (* x y
))))
1389 (test-ps-js cond-expression1
1391 (cond ((< 1 2) (bar "foo") (* 4 5))))
1399 (test-ps-js cond-expression2
1401 (cond ((< 2 1) "foo")
1406 } else if (7 === 7) {
1411 (test-ps-js cond-expression-final-t-clause
1413 (cond ((< 1 2) (bar "foo") (* 4 5))
1424 } else if (a === b) {
1426 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
1433 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
1446 (test-ps-js funcall-if-expression
1447 (funcall (getprop document
'write
)
1448 (if (= *linkornot
* 1)
1449 (ps-html ((:a
:href
"#"
1450 :onclick
(ps-inline (transport)))
1453 "document.write(LINKORNOT === 1 ? ['<a href=\\\"#\\\" onclick=\\\"', 'javascript:' + 'transport()', '\\\">', img, '</a>'].join('') : img);")
1455 (test-ps-js negate-number-literal
1459 (fiveam:test macro-environment1
1462 (normalize-js-output
1463 (let* ((macroname (gensym)))
1464 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
1466 (macrolet ((,macroname
(x) `(aref data
,x
)))
1467 (when (,macroname x
)
1468 (setf (,macroname x
) 123)))))))
1469 (normalize-js-output
1471 return data[x] ? (data[x] = 123) : null;
1474 (fiveam:test macro-environment2
1477 (let ((outer-lexical-variable 1))
1478 (defpsmacro macro-environment2-macro
(x)
1479 `(+ ,outer-lexical-variable
,x
))
1480 (ps* '(macro-environment2-macro 2)))
1483 (test-ps-js ampersand-whole-1
1484 (macrolet ((foo (&whole foo bar baz
)
1485 (declare (ignore bar baz
))
1486 (with-standard-io-syntax
1487 (let ((*print-case
* :downcase
))
1488 (format nil
"~a" foo
)))))
1492 (test-ps-js ampersand-whole-2
1493 (macrolet ((foo (&whole foo bar baz
)
1498 (test-ps-js keyword-consistent
1502 (test-ps-js simple-symbol-macrolet
1503 (symbol-macrolet ((x 1)) x
)
1506 (test-ps-js compound-symbol-macrolet
1507 (symbol-macrolet ((x 123)
1512 (test-ps-js define-symbol-macro
1513 (progn (define-symbol-macro tst-sym-macro
2)
1517 (test-ps-js define-symbol-macro1
1518 (progn (define-symbol-macro tst-sym-macro1
2)
1519 (foo tst-sym-macro1
))
1522 (test-ps-js define-symbol-macro2
1523 (progn (define-symbol-macro tst-sym-macro2
3)
1524 (list tst-sym-macro2
))
1527 (test-ps-js define-symbol-macro3
1528 (progn (define-symbol-macro tst-sym-macro3
4)
1529 (setq foo
(create tst-sym-macro3 tst-sym-macro3
)))
1530 "foo = { tstSymMacro3 : 4 };")
1532 (test-ps-js define-symbol-macro4
1533 (progn (define-symbol-macro tst-sym-macro4
5)
1534 (setq foo
(if (baz) tst-sym-macro4 bar
)))
1535 "foo = baz() ? 5 : bar;")
1537 (test-ps-js expression-progn
1538 (1+ (progn (foo) (if x
1 2)))
1539 "(foo(), x ? 1 : 2) + 1;")
1541 (test-ps-js let-decl-in-expression
1543 (if x
1 (let* ((foo x
)) foo
)))
1553 (test-ps-js special-var1
1554 (progn (defvar *foo
*)
1561 FOO_TMPSTACK1 = FOO;
1565 FOO = FOO_TMPSTACK1;
1569 (test-ps-js special-var2
1570 (progn (defvar *foo
*)
1579 FOO_TMPSTACK1 = FOO;
1581 return FOO * 2 * BAZ;
1583 FOO = FOO_TMPSTACK1;
1587 (test-ps-js literal1
1591 (test-ps-js literal2
1595 (test-ps-js setf-dec1
1599 (test-ps-js setf-dec2
1603 (test-ps-js special-char-equals
1607 (test-ps-js setf-operator-priority
1609 (or (getprop cache id
)
1610 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
1612 return cache[id] || (cache[id] = document.getElementById(id));
1615 (test-ps-js aref-operator-priority
1616 (aref (if (and x
(> (length x
) 0))
1620 "(x && x.length > 0 ? x[0] : y)[z];")
1622 (test-ps-js aref-operator-priority1
1623 (aref (or (getprop x
'y
)
1628 (test-ps-js aref-operator-priority2
1632 (test-ps-js negate-operator-priority
1641 (delete (if a
(or b c
) d
))
1642 "delete (a ? b || c : d);")
1645 (not (if (or x
(not y
)) z
))
1646 "!(x || !y ? z : null);")
1653 (instanceof (or a b
) (if x y z
))
1654 "((a || b) instanceof (x ? y : z));")
1657 (or x
(if (= x
0) "zero" "empty"))
1658 "x || (x === 0 ? 'zero' : 'empty');")
1660 (test-ps-js named-op-expression
1664 (test-ps-js named-op-expression1
1668 (test-ps-js aref-array-expression
1670 "(a || b || c)[0];")
1672 (test-ps-js getprop-operator
1673 (getprop (or a b c
) 'd
)
1676 (test-ps-js getprop-parens
1677 (getprop (getprop foo
'bar
) 'baz
)
1680 (test-ps-js funcall-funcall
1684 (test-ps-js expression-funcall
1685 ((or (@ window eval
) eval
) foo nil
)
1686 "(window.eval || eval)(foo, null);")
1688 (test-ps-js expression-funcall1
1689 (((or (@ window eval
) eval
) foo nil
))
1690 "(window.eval || eval)(foo, null)();")
1692 (test-ps-js expression-funcall2
1693 (((or (@ window eval
) eval
)) foo nil
)
1694 "(window.eval || eval)()(foo, null);")
1696 (test-ps-js who-html1
1697 (who-ps-html (:span
:class
"ticker-symbol"
1698 :ticker-symbol symbol
1699 (:a
:href
"http://foo.com"
1701 (:span
:class
"ticker-symbol-popup")))
1702 "['<span class=\\\"ticker-symbol\\\" ticker-symbol=\\\"', symbol, '\\\"><a href=\\\"http://foo.com\\\">', symbol, '</a><span class=\\\"ticker-symbol-popup\\\"></span></span>'].join('');")
1704 (test-ps-js who-html2
1705 (who-ps-html (:p
"t0" (:span
"t1")))
1706 "'<p>t0<span>t1</span></p>';")
1709 ((lambda () (flet ((foo (x)
1713 var foo = function (x) {
1720 (flet ((foo (x) (1+ x
))
1724 var foo = function (x) {
1727 var bar = function (y) {
1734 (flet ((foo (x) (+ 2 x
)))
1735 (flet ((foo (x) (1+ x
))
1736 (bar (y) (+ 2 (foo y
))))
1739 var foo = function (x) {
1742 var foo1 = function (x) {
1745 var bar = function (y) {
1748 return bar(foo1(1));
1752 ((lambda () (labels ((foo (x)
1755 (+ x
(foo (1- x
))))))
1758 var foo = function (x) {
1759 return 0 === x ? 0 : x + foo(x - 1);
1765 (labels ((foo (x) (1+ (bar x
)))
1766 (bar (y) (+ 2 (foo y
))))
1769 var foo = function (x) {
1772 var bar = function (y) {
1779 (labels ((foo (x) (1+ x
))
1780 (bar (y) (+ 2 (foo y
))))
1783 var foo = function (x) {
1786 var bar = function (y) {
1792 (test-ps-js labels-lambda-list
1793 (labels ((foo (x &optional
(y 0))
1797 var foo = function (x, y) {
1798 if (y === undefined) {
1806 (test-ps-js for-loop-var-init-exp
1808 (do* ((y (if x
0 1) (1+ y
))
1813 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
1822 (test-ps-js literal-array
1826 (test-ps-js literal-array-1
1830 (test-ps-js literal-array-literal
1834 (test-ps-js literal-array-literal1
1838 (fiveam:test ps-lisp-expands-in-lexical-environment
1839 (fiveam:is
(string= (let ((x 5)) (ps (lisp x
)))
1842 (fiveam:test ps-lisp-expands-in-lexical-environment1
1843 (fiveam:is
(string= (let ((x 5)) (ps (+ 1 (lisp x
))))
1846 (fiveam:test ps-lisp-expands-in-lexical-environment2
1847 (fiveam:is
(string= (let ((x 2)) (ps (+ 1 (lisp x
) 3)))
1850 (fiveam:test ps
*-lisp-expands-in-null-lexical-environment
1851 (fiveam:signals unbound-variable
1853 (declare (ignore x
))
1856 (fiveam:test ps
*-lisp-expands-in-dynamic-environment
1859 (declare (special foo
))
1860 (ps* '(+ 1 (lisp (locally (declare (special foo
))
1864 (fiveam:test ps-lisp-dynamic-environment
1867 (declare (special foo
))
1868 (ps (+ 1 (lisp foo
))))
1871 (test-ps-js nested-if-expressions1
1873 (return-from foo
(if (if x y z
) a b
)))
1882 (test-ps-js nested-if-expressions2
1884 (if x y
(if z a b
)))
1893 (test-ps-js nested-if-expressions3
1894 (foo (if (if x y z
) a b
)
1895 (if x y
(if z a b
)))
1896 "foo((x ? y : z) ? a : b, x ? y : (z ? a : b));")
1968 (test-ps-js let-exp1
2019 (test-ps-js symbol-macrolet-var
2020 (symbol-macrolet ((x y
))
2024 (test-ps-js setf-conditional1
2025 (setf x
(unless (null a
) (1+ a
)))
2026 "x = a != null ? a + 1 : null;")
2028 (test-ps-js setf-let1
2029 (setf x
(let ((a 1)) a
))
2035 (test-ps-js setf-let2
2036 (setf x
(let ((a (foo)))
2041 return a != null ? a + 1 : null;
2044 (test-ps-js symbol-macro-env1
2045 (symbol-macrolet ((bar 1))
2046 (macrolet ((bar (x y
) `(+ ,x
,y
)))
2050 (test-ps-js symbol-macrolet-fun1
2051 (symbol-macrolet ((baz +))
2055 (test-ps-js lisp2-namespaces1
2057 (setf list
(list 1 2 3)))
2060 return list = [1, 2, 3];
2063 (test-ps-js let-shadows-symbol-macrolet
2064 (symbol-macrolet ((x y
))
2074 (test-ps-js let-rename-optimization1
2082 (test-ps-js let-rename-optimization2
2091 (test-ps-js symbol-macro-array
2092 (symbol-macrolet ((x 1))
2096 (test-ps-js symbol-macro-obj
2097 (symbol-macrolet ((x (+ 1 2)))
2101 (test-ps-js symbol-macro-obj1
2102 (symbol-macrolet ((x (+ 1 2)))
2106 (test-ps-js symbol-macro-getprop1
2107 (symbol-macrolet ((x (+ 1 2)))
2111 (test-ps-js symbol-macro-getprop1
2112 (symbol-macrolet ((x (+ 1 2)))
2116 (test-ps-js let-let-create
2126 (test-ps-js symbol-macro-conditional1
2127 (symbol-macrolet ((x y
))
2135 (test-ps-js symbol-macro-conditional2
2136 (symbol-macrolet ((x y
))
2140 (test-ps-js preserve-this
2142 (let ((y (block nil
(bar this
))))
2145 var y = (function () {
2151 (test-ps-js flet-apply
2152 (flet ((foo () 'bar
))
2153 (apply (function foo
) nil
))
2155 var foo = function () {
2158 return foo.apply(this, null);
2161 (test-ps-js let-apply
2162 (let ((foo (lambda () 1)))
2163 (let ((foo (lambda () 2)))
2166 var foo = function () {
2169 var foo1 = function () {
2172 return foo1.apply(this, null);
2175 (test-ps-js flet-let
2176 (flet ((x (x) (1+ x
)))
2180 var x = function (x) {
2187 (test-ps-js let-flet
2189 (flet ((x (x) (1+ x
)))
2193 var x1 = function (x) {
2199 (test-ps-js labels-let
2200 (labels ((x (x) (1+ x
)))
2204 var x = function (x) {
2211 (test-ps-js let-labels
2213 (labels ((x (x) (1+ x
)))
2217 var x1 = function (x) {
2223 (test-ps-js macrolet-let-inteference
2224 (macrolet ((a (n) `(+ ,n
5)))
2226 (let ((b (a (- a
4))))
2230 var b = (a - 4) + 5;
2234 (test-ps-js let-subtract-add
2250 (test-ps-js create-reserved-word
2252 "({ 'default' : 1 });")
2254 (test-ps-js getprop-reserved-word
2255 (getprop foo
:default
)
2258 (test-ps-js getprop-reserved-word1
2259 (getprop foo
'default
)
2262 (test-ps-js eval-when-ps-side
2263 (eval-when (:execute
)
2267 (defvar *lisp-output
* nil
)
2269 (fiveam:test eval-when-lisp-side
()
2270 (setf *lisp-output
* 'original-value
)
2272 (normalize-js-output
2273 (ps-doc* `(eval-when (:compile-toplevel
)
2274 (setf *lisp-output
* 'it-works
))))))
2275 (fiveam:is
(eql 'it-works
*lisp-output
*))
2276 (fiveam:is
(string= "" js-output
))))
2278 (defpsmacro my-in-package
(package-name)
2279 `(eval-when (:compile-toplevel
)
2280 (setf *lisp-output
* ,package-name
)))
2282 (fiveam:test eval-when-macro-expansion
()
2283 (setf *lisp-output
* 'original-value
)
2285 (normalize-js-output
2287 (my-in-package :cl-user
)
2289 (declare (ignore js-output
))
2290 (fiveam:is
(eql :cl-user
*lisp-output
*))))
2292 (fiveam:test eval-when-macrolet-expansion
()
2293 (setf *lisp-output
* 'original-value
)
2295 (normalize-js-output
2297 `(macrolet ((my-in-package2 (package-name)
2298 `(eval-when (:compile-toplevel
)
2299 (setf *lisp-output
* ,package-name
))))
2300 (my-in-package2 :cl-user
)
2302 (declare (ignore js-output
))
2303 (fiveam:is
(eql :cl-user
*lisp-output
*))))
2305 (test-ps-js getprop-keyword
2309 (test-ps-js nary-comparison1
2310 (lambda () (< 1 2 3))
2313 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
2316 (test-ps-js chain-getprop1
2317 (chain ($
"foo") (bar x z
) frob
(baz 5))
2318 "$('foo').bar(x, z).frob.baz(5);")
2320 (test-ps-js chain-getprop2
2321 (chain ($
"foo") bar baz
)
2322 "$('foo').bar.baz;")
2324 (test-ps-js chain-getprop3
2325 (chain ($
"foo") bar
(x y
) baz
)
2326 "$('foo').bar.x(y).baz;")
2328 (test-ps-js flet-expression
2329 (1+ (flet ((foo (x) (1+ x
)))
2332 var foo = function (x) {
2338 (test-ps-js flet-lambda-list
2339 (flet ((foo (x &key
(y 0))
2343 var foo = function (x) {
2344 var _js2 = arguments.length;
2345 for (var n1 = 1; n1 < _js2; n1 += 2) {
2346 switch (arguments[n1]) {
2348 y = arguments[n1 + 1];
2351 var y = 'undefined' === typeof y ? 0 : y;
2354 return foo(1, 'y', 2);
2357 (test-ps-js return-case-break-elimination
2371 (test-ps-js aplusplus
2375 (test-ps-js astarstar
2379 (test-ps-js switch-return-fallthrough
2396 (test-ps-js return-last-case
2410 (test-ps-js return-macrolet
2412 (macrolet ((x () 1))
2425 (test-ps-js mv-bind1
2426 (multiple-value-bind (a b
)
2434 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2437 var _db2 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2442 __PS_MV_REG = prevMv1;
2446 (test-ps-js mv-bind2
2447 (multiple-value-bind (a b
)
2456 var prevMv2 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2459 var _db4 = doesnt === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2464 __PS_MV_REG = prevMv2;
2468 (test-ps-js multiple-value-bind-simple
2469 (multiple-value-bind (a b
) (blah)
2472 var prevMv1 = 'undefined' === typeof __PS_MV_REG ? (__PS_MV_REG = undefined) : __PS_MV_REG;
2475 var _db2 = blah === __PS_MV_REG['tag'] ? __PS_MV_REG['values'] : [];
2479 __PS_MV_REG = prevMv1;
2484 (lambda () (values))
2495 (lambda () (values x y
))
2497 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2502 (lambda () (values x y z
))
2504 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y, z] };
2508 (test-ps-js values-return
2510 (return-from foo
(values (* x x
) y
)))
2511 "function foo(x, y) {
2513 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : [y] };
2517 (test-ps-js return-macrolet1
2519 (symbol-macrolet ((x 2))
2527 (test-ps-js return-cond
2530 (cond ((foo? x
) (loop for y in x do
(foo y
)))
2535 var _js2 = x.length;
2536 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2540 } else if (barwhat(x)) {
2547 (test-ps-js return-case
2551 (1 (loop for y in x do
(foo y
)))
2557 var _js2 = x.length;
2558 for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
2570 (test-ps-js return-case1
2588 (test-ps-js lambda-loop-if-return
2591 (loop for y in x do
(foo y
))
2595 var _js4 = x.length;
2596 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2605 (test-ps-js lambda-loop-if-return1
2609 (progn (loop for y in x do
(foo y
))
2614 return foo(function () {
2616 var _js4 = x.length;
2617 for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
2621 throw { '__ps_block_tag' : 'baz',
2622 '__ps_value1' : null };
2627 } catch (_ps_err5) {
2628 if (_ps_err5 && 'baz' === _ps_err5['__ps_block_tag']) {
2629 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err5['__ps_values'] };
2630 return _ps_err5['__ps_value1'];
2637 (test-ps-js switch-loop
2640 (1 (dolist (a b
)))))
2644 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
2651 (test-ps-js switch-folds-blocks
2654 (1 (loop repeat
3 do
(alert "foo")))
2659 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
2668 (test-ps-js setf-places-before-macros
2670 (defsetf left
(el) (offset)
2671 `(setf (@ ,el style left
) ,offset
))
2672 (macrolet ((left (el)
2673 `(@ ,el offset-left
)))
2679 _js2.style.left = _js1;
2680 return x.offsetLeft;
2683 (test-ps-js for-return
2684 (lambda () (dolist (arg args
) (foo arg
)))
2686 for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
2687 arg = args[_js_idx1];
2692 (test-ps-js try-catch-return
2710 (let ((x (ps:try
(+ 1 2)
2714 var x = (function () {
2724 (test-ps-js try-finally-return-from
2727 (ps:try
(when (blah) 4)
2732 return blah() ? 4 : null;
2736 return dontCallMe();
2739 (test-ps-js defun-setf-optional
2740 (defun (setf foo
) (new-value b
&optional c
)
2741 (setf (aref b
(or c
0)) new-value
))
2742 "function __setf_foo(newValue, b, c) {
2743 return b[c || 0] = newValue;
2746 (test-ps-js defun-setf-rest
2747 (progn (defun (setf foo
) (new-value b
&rest foo
)
2748 (do-something b foo new-value
))
2749 (setf (foo x
1 2 3 4) 5))
2750 "function __setf_foo(newValue, b) {
2751 var foo = Array.prototype.slice.call(arguments, 2);
2752 return doSomething(b, foo, newValue);
2754 __setf_foo(5, x, 1, 2, 3, 4);")
2756 (test-ps-js return-null
2757 (defun foo () (return-from foo nil
))
2762 (test-ps-js implicit-return-null
2769 (test-ps-js implicit-return-null
2776 (test-ps-js return-conditional-nested
2777 (defun blep (ss x y
)
2781 (destructuring-bind (a b
) pair
2782 (unless (or (null a
) (null b
))
2783 (let ((val (baz a b
)))
2788 "function blep(ss, x, y) {
2794 if (!(a == null || b == null)) {
2795 var val = baz(a, b);
2798 return !blee() ? true : null;
2806 (test-ps-js return-when-returns-broken-return
2808 (return-from foo
(when x
1))
2811 return x ? 1 : null;
2815 (test-ps-js return-case-conditional
2819 (123 (when (bar) t
))
2824 return bar() ? true : null;
2830 (test-ps-js return-try-conditional
2838 return x ? 1 : null;
2846 (test-ps-js function-declare-special
2848 (declare (special *foo
*))
2854 FOO_TMPSTACK1 = FOO;
2858 FOO = FOO_TMPSTACK1;
2862 (test-ps-js declare-special-let
2864 (declare (special *foo
*))
2869 FOO_TMPSTACK1 = FOO;
2873 FOO = FOO_TMPSTACK1;
2877 (test-ps-js declare-special-let-scope
2880 (declare (special *foo
*))
2887 FOO_TMPSTACK1 = FOO;
2891 FOO = FOO_TMPSTACK1;
2897 (test-ps-js declare-special-let
*
2898 (let* ((*foo
* 123) (*bar
* (+ *foo
* *bar
*)))
2899 (declare (special *foo
* *bar
*))
2904 FOO_TMPSTACK1 = FOO;
2908 BAR_TMPSTACK2 = BAR;
2912 BAR = BAR_TMPSTACK2;
2915 FOO = FOO_TMPSTACK1;
2919 (test-ps-js defun-multiple-declarations-around-docstring
2921 (declare (ignorable x y
))
2922 (declare (integer x
) (float y
))
2923 "Fooes X while barring Y."
2924 (declare (special *foo
*) (special *bar
*))
2925 (let ((*bar
* (bar y
)))
2927 "/** Fooes X while barring Y. */
2928 function foo(x, y) {
2931 BAR_TMPSTACK1 = BAR;
2935 BAR = BAR_TMPSTACK1;
2939 (test-ps-js macro-null-toplevel
2941 (defmacro macro-null-toplevel
()
2943 (macro-null-toplevel))
2946 (test-ps-js define-symbol-macro-let
2948 (define-symbol-macro test-symbol-macro
1)
2949 (let ((test-symbol-macro 2))
2950 (1+ test-symbol-macro
))
2951 (1+ test-symbol-macro
))
2953 var testSymbolMacro1 = 2;
2954 return testSymbolMacro1 + 1;
2958 (test-ps-js define-symbol-macro-flet
2960 (define-symbol-macro test-symbol-macro1
1)
2961 (flet ((test-symbol-macro1 () 2))
2962 (foo test-symbol-macro1
)
2963 (test-symbol-macro1))
2964 (bar test-symbol-macro1
))
2966 var testSymbolMacro1_1 = function () {
2970 return testSymbolMacro1_1();
2974 (fiveam:test compile-stream-nulls
2977 (with-input-from-string (s "
2978 (defmacro macro-null-toplevel ()
2980 (macro-null-toplevel)")
2981 (ps-compile-stream s
))
2984 (fiveam:test compile-stream1
2987 (with-input-from-string (s "
2988 (define-symbol-macro test-symbol-macro1 1)
2989 (flet ((test-symbol-macro1 () 2))
2990 (foo test-symbol-macro1)
2991 (test-symbol-macro1))
2992 (bar test-symbol-macro1)")
2993 (ps::with-blank-compilation-environment
2994 (ps-compile-stream s
)))
2996 var testSymbolMacro1_1 = function () {
3000 return testSymbolMacro1_1();
3005 (test-ps-js equality-nary1
3006 (let ((x 10) (y 10) (z 10))
3013 return (_cmp1 = y, x === _cmp1 && _cmp1 === z);
3016 (test-ps-js equality1
3027 (test-ps-js getprop-quote-reserved
3028 (getprop foo
':break
)
3031 (test-ps-js defun-block-return-from
3042 (test-ps-js block-return-from
3046 (return-from scope
))
3056 (test-ps-js block-return-from0
3061 (return-from scope
))
3071 (test-ps-js block-return-from01
3076 (return-from scope
))
3090 (test-ps-js block-return-from02
3095 (return-from scope
(foobar)))
3110 (test-ps-js block-return-from1
3115 (return-from scope
))
3129 (test-ps-js block-return-from2
3135 (return-from scope
6))
3146 (test-ps-js let-funcall
3160 (test-ps-js symbol-macrolet-funcall
3161 (symbol-macrolet ((foo bar
))
3162 (funcall foo
1 2 3))
3165 (test-ps-js times-assign
3169 (test-ps-js vector-literal
3173 (test-ps-js vector-literal1
3175 "[1, 2, ['a', 'b'], 3];")
3178 (+ 1 (rem 2 (+ 3 4)))
3181 (test-ps-js non-associative
3182 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
3183 "1 / (2 / 3) + (1 - (2 - 3));")
3185 (test-ps-js lambda-apply
3187 (apply (lambda (y) (bar (1+ y
))) x
))
3189 return (function (y) {
3194 (test-ps-js operator-expressions-nested-let
3195 (let ((x (let ((y 1))
3204 (test-ps-js operator-expressions-array-nested-let
3205 (list (let ((y 1)) y
) 2)
3211 (test-ps-js add-subtract-precedence
3215 (test-ps-js ps-inline-toplevel
3217 "'javascript:' + 'foo()';")
3219 (test-ps-js no-clause-progn-exp
3223 (test-ps-js no-clause-progn-return
3225 (return-from foo
(progn)))
3230 (test-ps-js empty-cond-clause
3231 (setf x
(cond ((foo))))
3232 "x = (function () { var testResult1 = foo(); return testResult1 ? testResult1 : null; })();")
3234 (test-ps-js empty-cond-clause1
3235 (setf x
(cond ((foo) 123)
3240 var testResult1 = bar();
3244 if (true) { return 456; };
3248 (test-ps-js let-no-body
3250 (return-from foo
(let ((foo bar
)))))
3256 (test-ps-js rename-lexical-dupes
3258 (list (let ((foo 12)) (* foo
2))
3259 (let ((foo 13)) (* foo
3))))
3263 return [(foo = 12, foo * 2), (foo1 = 13, foo1 * 3)];
3266 (test-ps-js defun-comment1
3268 "BARBAR is a revolutionary new foobar.
3272 * BARBAR is a revolutionary new foobar.
3279 (test-ps-js var-comment
3284 (test-ps-js case-return-break-broken-return
3287 ("bar" (if y
(return-from foo t
) nil
))
3302 (test-ps-js case-return-break1-broken-return
3305 ("bar" (if y
(return-from foo t
)))
3320 (test-ps-js setf-progn
3321 (setf foo
(progn (bar) (baz) 3))
3326 (test-ps-js var-progn
3327 (var x
(progn (foo) (bar)))
3331 (test-ps-js implicit-return-loop
3335 (loop :repeat
100 :do
(bar))
3341 for (var _js2 = 0; _js2 < 100; _js2 += 1) {
3348 (test-ps-js loop-closures
3349 (dotimes (i 10) (lambda () (+ i
1)))
3351 for (var i = 0; i < 10; i += 1) {
3358 (test-ps-js loop-closures-let
3361 (lambda () (+ i x
))))
3363 for (var i = 0; i < 10; i += 1) {
3364 with ({ x : null }) {
3373 (test-ps-js loop-closures-flet
3375 (flet ((foo (x) (+ i x
)))
3376 (lambda () (foo i
))))
3378 for (var i = 0; i < 10; i += 1) {
3379 with ({ foo : null }) {
3380 var foo = function (x) {
3390 (test-ps-js while-closures-let
3393 (lambda () (+ 1 abc
))))
3395 with ({ abc : null }) {
3403 (test-ps-js dotted-list-form
3406 (destructuring-bind (b . c
)
3412 var c = bar.length > 1 ? bar.slice(1) : [];
3417 (test-ps-js explicit-nil-block
3420 (block nil
(return (foo 2)) (+ 1 2))
3432 (test-ps-js dynamic-extent-function-return
3435 (return-from foo
6))))
3438 return (function () {
3439 throw { '__ps_block_tag' : 'foo', '__ps_value1' : 6 };
3441 } catch (_ps_err1) {
3442 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3443 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3444 return _ps_err1['__ps_value1'];
3451 (test-ps-js dynamic-extent-function-return-nothing
3454 (return-from foo
))))
3457 return (function () {
3458 throw { '__ps_block_tag' : 'foo', '__ps_value1' : null };
3460 } catch (_ps_err1) {
3461 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3462 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3463 return _ps_err1['__ps_value1'];
3470 (test-ps-js dynamic-extent-function-return-values
3473 (return-from foo
(values 1 2 3)))))
3477 return (function () {
3478 throw { '__ps_block_tag' : 'foo',
3480 '__ps_values' : [2, 3] };
3482 } catch (_ps_err1) {
3483 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3484 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3485 return _ps_err1['__ps_value1'];
3492 (test-ps-js dynamic-extent-function-return-funcall
3495 (return-from foo
(if baz
6 5)))))
3498 return (function () {
3499 throw { '__ps_block_tag' : 'foo', '__ps_value1' : baz ? 6 : 5 };
3501 } catch (_ps_err1) {
3502 if (_ps_err1 && 'foo' === _ps_err1['__ps_block_tag']) {
3503 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3504 return _ps_err1['__ps_value1'];
3511 (test-ps-js block-dynamic-return
3512 (var foo
((lambda ()
3514 ((lambda () (return 6)))
3516 "var foo = (function () {
3519 throw { '__ps_block_tag' : 'nilBlock', '__ps_value1' : 6 };
3522 } catch (_ps_err1) {
3523 if (_ps_err1 && 'nilBlock' === _ps_err1['__ps_block_tag']) {
3524 __PS_MV_REG = { 'tag' : arguments.callee, 'values' : _ps_err1['__ps_values'] };
3525 return _ps_err1['__ps_value1'];
3532 (test-ps-js block-dynamic-return1
3533 (var foo
((lambda ()
3535 ((lambda () (return 6)))
3538 "var foo = (function () {
3545 return foobar(1, 2);
3548 (test-ps-js iteration-lambda-capture-no-need
3550 (lambda (x) (1+ x
)))
3552 for (var x = null, _js_idx1 = 0; _js_idx1 < y.length; _js_idx1 += 1) {
3560 (test-ps-js case-invert1
3561 (encodeURIComponent fooBar
)
3562 "encodeURIComponent(fooBar);")
3564 (test-ps-js simple-ash
3565 (+ (ash 4 1) (ash 4 -
1))
3566 "(4 << 1) + (4 >> 1);")
3568 (test-ps-js progn-nil-expression
3569 (bar (progn (foo) nil
))
3570 "bar((foo(), null));")
3572 (test-ps-js other-progn-nil-exp
3574 (or (foo) (progn (bar) nil
)))
3576 return foo() || (bar(), null);
3579 (test-ps-js lambda-nil-return
3592 (test-ps-js lambda-nil-return-implicit-nested2
3598 (return-from foo i
)))
3604 for (var i = 0; i < 4; i += 1) {
3611 (test-ps-js throw-is-a-statement
3613 (let ((result (foo)))
3614 (unless (null result
)
3618 if (result != null) {
3623 (test-ps-js expressify1
3625 (when (some-condition)
3630 if (someCondition()) {
3637 (test-ps-js case-when-return
3640 ("a" (when (foo) (return-from blah
111)))
3655 (test-ps-js flet-return-from
3658 (return-from foo
123)))
3661 var foo = function () {
3667 (test-ps-js flet-return-from1
3669 (return-from foo
123)))
3672 var foo = function () {
3678 (test-ps-js lambda-docstring-declarations
3680 "This is a docstring"
3681 (declare (ignore x
))
3687 (test-ps-js setf-let-exp
3688 (setf foo
(let ((x (+ 1 2)))
3690 "foo = (function () {
3692 return x ? 123 : 456;
3695 (test-ps-js create-let-exp
3696 (create :abc
(let ((x (+ 1 2)))
3698 "({ 'abc' : (function () {
3700 return x ? 123 : 456;
3703 (test-ps-js eql-eql-eql-precedence
3704 (unless (equal (= 3 3) (= 3 4))
3705 (chain console
(log 1)))
3706 "if ((3 === 3) != (3 === 4)) {
3710 (test-ps-js case-cond-breaks
3716 (return-from blah nil
))
3739 (test-ps-js cond-double-t
3752 (test-ps-js let-let-funcall-lambda
3755 (funcall (lambda (x) (+ x
9)) x
)))
3759 return (function (x) {
3764 (test-ps-js let-let-lambda
3767 (lambda (x) (+ x
9))))
3771 return function (x) {
3776 (test-ps-js let-lambda
3778 (lambda (x) (+ x
9)))
3781 return function (x) {
3786 (test-ps-js symbol-macrolet-no-shadow-lambda
3787 (symbol-macrolet ((x y
))
3788 (lambda (x) (+ x x
)))
3793 (test-ps-js divide-one-arg-reciprocal
3797 (test-ps-js division-not-associative
3801 (test-ps-js divide-expressions
3805 (test-ps-js divide-expressions1
3807 "Math.floor((x - 1) / y);")
3809 (test-ps-js lexical-funargs-shadow1
3820 (test-ps-js times-rem
3824 (test-ps-js rem-divide
3828 (test-ps-js case-break-return
3829 (lambda () (case x
(:foo
) (:bar
1)))
3839 (test-ps-js trivial-expression-switch
3840 (foobar (case x
(1 2)))
3841 "foobar((function () {
3848 (test-ps-js trivial-expression-while
3849 (foobar (while (< 0 x
) (decf x
)))
3850 "foobar((function () {
3856 (test-ps-js funcall-block-expression-loop-lambda
3857 (foobar (loop for i from
0 to
10 do
(1+ i
)))
3858 "foobar((function () {
3859 for (var i = 0; i <= 10; i += 1) {
3864 (test-ps-js plus-block-expression-loop-lambda
3865 (1+ (loop for i from
0 to
10 do
(1+ i
)))
3867 for (var i = 0; i <= 10; i += 1) {
3872 (test-ps-js let-closures-rename
3874 (let ((x 1)) (lambda () (1+ x
)))
3875 (let ((x 2)) (lambda () (1+ x
))))
3882 return function () {
3887 (test-ps-js let-closures-rename1
3891 (lambda () (+ x y
))))
3894 (lambda () (+ x y
)))))
3903 return function () {
3908 (test-ps-js let-closures-rename2
3909 (defun make-closures ()
3911 (let ((x 1)) (lambda () (1+ x
)))
3912 (let ((x 2)) (lambda () (1+ x
)))))
3913 "function makeClosures() {
3916 return [(x = 1, function () {
3918 }), (x1 = 2, function () {
3924 (test-ps-js conditional-not-used-up
3936 (test-ps-js toplevel-local-scope
3937 (create "fn" (let ((x 5)) (lambda () x
)))
3938 "({ 'fn' : (function () {
3940 return function () {
3945 (test-ps-js toplevel-local-scope1
3946 (defvar foo
(create "fn" (let ((x 5)) (lambda () x
))))
3947 "var foo = { 'fn' : (function () {
3949 return function () {
3954 (test-ps-js block-let
3957 (return-from foobar x
)
3965 (test-ps-js expressionize-if-macroexpand-error
3966 (progn (defmacro xbaz
() `(blah))
3972 "function foo(xbaz) {
3982 (test-ps-js toplevel-defun-macroexpand
3983 (progn (defmacro defun-js
(name lambda-list
&body body
)
3984 `(defun ,name
,lambda-list
,@body
))
3987 (defun-js bar
() (1+ foo
))
3995 (test-ps-js js-ir-package-unique-symbols
3996 (loop :for i
:from
0 :below
5 :do
3997 (let ((block (elt blocks i
)))
4001 for (var i = 0; i < 5; i += 1) {
4002 var block = blocks[i];
4010 (test-ps-js broken-quote-expansion1
4015 return p.x < 0 ? p.y : p.x;
4018 (test-ps-js broken-quote-expansion2
4020 (define-symbol-macro foo123
(ps:@ a foo123
))
4021 (lambda () (when (> foo123
1) 2)))
4023 return a.foo123 > 1 ? 2 : null;
4026 (test-ps-js unused-named-block-not-printed1
4033 (test-ps-js unused-named-block-not-printed2
4041 (test-ps-js unused-named-block-not-printed3
4049 (test-ps-js unused-named-block-not-printed4
4058 (test-ps-js trig-no-bind1
4060 "(Math.exp(3.14) + Math.exp(-3.14)) / 2;")
4062 (test-ps-js trig-bind1
4065 var x1 = blah(3.14);
4066 return 2 * Math.log(Math.sqrt((x1 + 1) / 2) + Math.sqrt((x1 - 1) / 2));
4069 (test-ps-js double-negation
4070 (or (not foo
) (not (not foo
)) (not (not (not foo
))))
4071 "!foo || foo || !foo;")
4073 (test-ps-js empty-let
4081 (test-ps-js empty-let
*
4089 (test-ps-js defun-no-body-declare
4090 (defun foo () (declare (ignore x
)))
4095 (test-ps-js defun-no-body-let-decare
4096 (defun foo () (let () (declare (ignore x
))))
4101 (test-ps-js empty-defun-docstring-declare
4104 (declare (ignore x
)))
4110 (test-ps-js defun-docstring-string
4119 (test-ps-js return-object
4121 (ps:create
:abc
(let ((x (ps:getprop obj
"blah")))
4123 "function foo(obj) {
4125 return { 'abc' : (x = obj['blah'], x ? 123 : 456) };
4128 (test-ps-js unicode-strings
4134 ;; (test-ps-js let-defun-toplevel
4135 ;; (progn (let ((foo 0))
4136 ;; (defun bar () foo))
4138 ;; "var bar_foo1 = 0;
4144 ;; (test-ps-js let-defvar-toplevel
4145 ;; (progn (let ((foo 0))
4146 ;; (defvar bar (1+ foo)))
4148 ;; "var bar_foo1 = 0;
4149 ;; var bar = bar_foo1 + 1;
4152 ;; (test-ps-js setf-side-effects
4155 ;; (defun side-effect()
4158 ;; (setf x (+ 2 (side-effect) x 5))))
4159 ;; "var sideEffect_x1 = 10;
4160 ;; function sideEffect() {
4161 ;; sideEffect_x1 = 4;
4164 ;; sideEffect_x1 = 2 + sideEffect() + x + 5;")