1 (in-package "PARENSCRIPT-TEST")
5 (test-ps-js plus-is-not-commutative
6 (setf x
(+ "before" x
"after"))
7 "x = 'before' + x + 'after';")
9 (test-ps-js plus-works-if-first
10 (setf x
(+ x
"middle" "after"))
11 "x = x + 'middle' + 'after';")
13 (test-ps-js setf-side-effects
19 (setf x
(+ 2 (side-effect) x
5))))
21 function sideEffect() {
25 x = 2 + sideEffect() + x + 5;")
27 (test-ps-js method-call-op-form
28 (funcall (getprop (+ "" x
) 'to-string
))
29 "('' + x).toString();")
31 (test-ps-js method-call-op-form-args
32 (funcall (getprop (+ "" x
) 'foo
) 1 2 :baz
3)
33 "('' + x).foo(1, 2, 'baz', 3);")
35 (test-ps-js method-call-string
36 ((getprop "hi" 'to-string
))
39 (test-ps-js method-call-conditional
43 (test-ps-js method-call-variable
47 (test-ps-js method-call-array
48 ((@ (list 10 20) to-string
))
49 "[ 10, 20 ].toString();")
51 (test-ps-js method-call-lambda-call
52 (funcall (getprop (funcall (lambda (x) (return x
)) 10) 'to-string
))
53 "(function (x) { return x; })(10).toString();")
55 (test no-whitespace-before-dot
56 (let* ((str (ps* '((@ ((lambda (x) (return x
)) 10) to-string
))))
57 (dot-pos (position #\. str
:test
#'char
=))
58 (char-before (elt str
(1- dot-pos
)))
60 (is (char= char-before a-parenthesis
))))
62 (test-ps-js simple-getprop
63 (let ((foo (create a
1)))
64 (alert (getprop foo
'a
)))
68 (test-ps-js buggy-getprop
69 (getprop foo slot-name
)
72 (test-ps-js buggy-getprop-two
73 (getprop foo
(get-slot-name))
74 "foo[getSlotName()];")
76 (test-ps-js old-case-is-now-switch
77 ;; Switch was "case" before, but that was very non-lispish.
78 ;; For example, this code makes three messages and not one
79 ;; which may have been expected. This is because a switch
80 ;; statment must have a break statement for it to return
81 ;; after the alert. Otherwise it continues on the next
83 (switch (aref blorg i
)
86 (default (alert "default clause")))
90 default: alert('default clause');
93 (test-ps-js lisp-like-case
97 (default (alert "default clause")))
105 default: alert('default clause');
109 (test-ps-js even-lispier-case
111 ((1 2) (alert "Below three"))
113 (t (alert "Something else")))
117 alert('Below three');
122 default: alert('Something else');
125 (test-ps-js otherwise-case
128 (otherwise (alert "default clause")))
133 default: alert('default clause');
136 (test escape-sequences-in-string
137 (let ((escapes `((#\\ .
#\\)
139 (#\f .
,(code-char 12))
140 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
143 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
145 ("u001F" .
,(code-char #x001f
));; character below 32
146 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
147 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
148 (loop for
(js-escape . lisp-char
) in escapes
149 for generated
= (ps-doc* `(let ((x ,(format nil
"hello~ahi" lisp-char
)))))
150 for wanted
= (format nil
"var x = 'hello\\~ahi';" js-escape
)
151 do
(is (string= (normalize-js-code generated
) wanted
)))))
153 (test-ps-js getprop-setf
154 (setf (getprop x
'y
) (+ (+ a
3) 4))
157 (test-ps-js getprop-conditional1
158 (getprop (if zoo foo bar
) 'x
)
159 "(zoo ? foo : bar).x;")
161 (test-ps-js getprop-conditional2
162 (getprop (if (not zoo
) foo bar
) 'x
)
163 "(!zoo ? foo : bar).x;")
165 (test script-star-eval1
166 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x
1) '(setf y
2))))))
168 (test script-star-eval2
169 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x
1))))))
171 (test-ps-js list-with-single-nil
175 (test-ps-js quoted-nil-is-array
180 (progn (defsetf baz
(x y
) (newval) `(set-baz ,x
,y
,newval
))
185 setBaz(_js2, _js3, _js1);")
187 (test-ps-js setf-macroexpands1
188 (macrolet ((bar (x y
)
190 (setf (bar foo
2) 3))
193 (test-ps-js defsetf-short
194 (progn (defsetf baz set-baz
"docstring")
195 (setf (baz 1 2 3) "foo"))
196 "setBaz(1, 2, 3, 'foo');")
198 (test-ps-js defun-setf1
199 (progn (defun (setf some-thing
) (new-val i1 i2
)
200 (setf (aref *some-thing
* i1 i2
) new-val
))
201 (setf (some-thing 1 2) "foo"))
202 "function __setf_someThing(newVal, i1, i2) {
203 return SOMETHING[i1][i2] = newVal;
205 __setf_someThing('foo', 1, 2);")
207 (test-ps-js defun-optional1
208 (defun test-opt (&optional x
)
210 "function testOpt(x) {
211 if (x === undefined) {
221 (test-ps-js defun-optional2
222 (defun foo (x &optional y
)
224 "function foo(x, y) {
225 if (y === undefined) {
231 (test-ps-js defun-optional3
232 (defun blah (&optional
(x 0))
235 if (x === undefined) {
241 (test-ps-js return-nothing
245 (test-ps-js set-timeout
246 (set-timeout (lambda () (alert "foo")) 10)
247 "setTimeout(function () { return alert('foo'); }, 10);")
249 (test-ps-js operator-precedence
253 (test-ps-js operators-1
273 (test-ps-js setf-conditional
274 (setf foo
(if x
1 2))
277 (test-ps-js obj-literal-numbers
281 (test-ps-js obj-literal-strings
285 (test-ps-js getprop-string
289 (test-ps-js getprop-string1
290 (getprop "bar" 'length
)
293 (test-ps-js getprop-progn
294 (getprop (progn (some-fun "abc") "123") "length")
295 "(someFun('abc'), '123')['length'];")
297 (test-ps-js method-call-block
298 ((@ (progn (some-fun "abc") "123") to-string
))
299 "(someFun('abc'), '123').toString();")
301 (test-ps-js create-blank
305 (test-ps-js blank-object-literal
309 (test-ps-js array-literal1
313 (test-ps-js array-literal2
317 (test-ps-js array-literal3
321 (test-ps-js array-literal4
325 (test-ps-js array-literal5
327 "[[1, 2], ['a', 'b']];")
329 (test-ps-js defun-rest1
330 (defun foo (&rest bar
)
331 (alert (aref bar
1)))
334 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
335 bar[i1] = arguments[i1 + 0];
337 return alert(bar[1]);
340 (test-ps-js defun-rest2
341 (defun foo (baz &rest bar
) (return (+ baz
(aref bar
1))))
344 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
345 bar[i1] = arguments[i1 + 1];
350 (test-ps-js defun-keyword1
351 (defun zoo (foo bar
&key baz
) (return (+ foo bar baz
)))
352 "function zoo(foo, bar) {
354 var _js2 = arguments.length;
355 for (var n1 = 2; n1 < _js2; n1 += 2) {
356 switch (arguments[n1]) {
358 baz = arguments[n1 + 1];
361 if (baz === undefined) {
364 return foo + bar + baz;
367 (test-ps-js defun-keyword2
368 (defun zoo (&key baz
) (return (* baz baz
)))
371 var _js2 = arguments.length;
372 for (var n1 = 0; n1 < _js2; n1 += 2) {
373 switch (arguments[n1]) {
375 baz = arguments[n1 + 1];
378 if (baz === undefined) {
384 (test-ps-js defun-keyword3
385 (defun zoo (&key baz
(bar 4)) (return (* baz bar
)))
389 var _js2 = arguments.length;
390 for (var n1 = 0; n1 < _js2; n1 += 2) {
391 switch (arguments[n1]) {
393 baz = arguments[n1 + 1];
396 bar = arguments[n1 + 1];
399 if (baz === undefined) {
402 if (bar === undefined) {
408 (test-ps-js defun-keyword4
409 (defun hello-world (&key
((:my-name-key my-name
) 1))
411 "function helloWorld() {
413 var _js2 = arguments.length;
414 for (var n1 = 0; n1 < _js2; n1 += 2) {
415 switch (arguments[n1]) {
417 myName = arguments[n1 + 1];
420 if (myName === undefined) {
426 (test-ps-js keyword-funcall1
430 (test-ps-js keyword-funcall2
431 (func :baz
1 :bar foo
)
432 "func('baz', 1, 'bar', foo);")
434 (test-ps-js keyword-funcall3
436 "fun(a, b, 'baz', c);")
446 ((= y
(* x
4)) (foo "blah") (* x y
)))
449 } else if (y === x * 4) {
454 (test-ps-js if-exp-without-else-return
462 (test-ps-js progn-expression-single-statement
463 (return (progn (* x y
)))
466 (test-ps-js cond-expression1
468 (cond ((< 1 2) (bar "foo") (* 4 5))))
476 (test-ps-js cond-expression2
478 (cond ((< 2 1) "foo")
483 } else if (7 === 7) {
488 (test-ps-js cond-expression-final-t-clause
490 (cond ((< 1 2) (bar "foo") (* 4 5))
501 } else if (a === b) {
503 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
510 (test-ps-js cond-expression-middle-t-clause
;; should this signal a warning?
523 (test-ps-js funcall-if-expression
524 (funcall (getprop document
'write
)
525 (if (= *linkornot
* 1)
526 (ps-html ((:a
:href
"#"
527 :onclick
(ps-inline (transport)))
530 "document.write(LINKORNOT === 1 ? ['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">', img, '</A>']['join']('') : img);")
532 (test-ps-js negate-number-literal
536 (test macro-environment1
537 (is (string= (normalize-js-code (let* ((macroname (gensym)))
538 (ps* `(defmacro ,macroname
(x) `(+ ,x
123))
540 (macrolet ((,macroname
(x) `(aref data
,x
)))
542 (setf (,macroname x
) 123)))))))
546 return data[x] = 123;
550 (test macro-environment2
551 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
552 (defpsmacro macro-environment2-macro
(x)
553 `(+ ,outer-lexical-variable
,x
))
554 (ps* '(macro-environment2-macro 2))))
555 (normalize-js-code "1 + 2;"))))
557 (test-ps-js ampersand-whole-1
558 (macrolet ((foo (&whole foo bar baz
)
559 (declare (ignore bar baz
))
560 (format nil
"~a" foo
)))
564 (test-ps-js keyword-consistent
568 (test-ps-js simple-symbol-macrolet
569 (symbol-macrolet ((x 1)) x
)
572 (test-ps-js compound-symbol-macrolet
573 (symbol-macrolet ((x 123)
578 (test-ps-js define-symbol-macro
579 (progn (define-symbol-macro tst-sym-macro
2)
583 (test-ps-js define-symbol-macro1
584 (progn (define-symbol-macro tst-sym-macro1
2)
585 (foo tst-sym-macro1
))
588 (test-ps-js expression-progn
589 (1+ (progn (foo) (if x
1 2)))
590 "(foo(), x ? 1 : 2) + 1;")
592 (test-ps-js let-decl-in-expression
594 (if x
1 (let* ((foo x
))
605 (test-ps-js special-var1
606 (progn (defvar *foo
*)
619 (test-ps-js special-var2
620 (progn (defvar *foo
*)
643 (test-ps-js setf-dec1
647 (test-ps-js setf-dec2
651 (test-ps-js special-char-equals
655 (test-ps-js setf-operator-priority
656 (return (or (getprop cache id
)
657 (setf (getprop cache id
) ((@ document get-element-by-id
) id
))))
658 "return cache[id] || (cache[id] = document.getElementById(id));")
660 (test-ps-js aref-operator-priority
661 (aref (if (and x
(> (length x
) 0))
665 "(x && x.length > 0 ? x[0] : y)[z];")
667 (test-ps-js aref-operator-priority1
668 (aref (or (getprop x
'y
)
673 (test-ps-js aref-operator-priority2
677 (test-ps-js negate-operator-priority
686 (delete (if a
(or b c
) d
))
687 "delete (a ? b || c : d);")
690 (not (if (or x
(not y
)) z
))
691 "!(x || !y ? z : null);")
698 (instanceof (or a b
) (if x y z
))
699 "((a || b) instanceof (x ? y : z));")
702 (or x
(if (= x
0) "zero" "empty"))
703 "x || (x === 0 ? 'zero' : 'empty');")
705 (test-ps-js named-op-expression
709 (test-ps-js named-op-expression1
713 (test-ps-js aref-array-expression
717 (test-ps-js getprop-operator
718 (getprop (or a b c
) 'd
)
721 (test-ps-js getprop-parens
722 (getprop (getprop foo
'bar
) 'baz
)
725 (test-ps-js funcall-funcall
729 (test-ps-js expression-funcall
730 ((or (@ window eval
) eval
) foo nil
)
731 "(window.eval || eval)(foo, null);")
733 (test-ps-js expression-funcall1
734 (((or (@ window eval
) eval
) foo nil
))
735 "(window.eval || eval)(foo, null)();")
737 (test-ps-js expression-funcall2
738 (((or (@ window eval
) eval
)) foo nil
)
739 "(window.eval || eval)()(foo, null);")
741 (test-ps-js who-html1
742 (who-ps-html (:span
:class
"ticker-symbol"
743 :ticker-symbol symbol
744 (:a
:href
"http://foo.com"
746 (:span
:class
"ticker-symbol-popup")))
747 "['<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"', symbol, '\"><A HREF=\"http://foo.com\">', symbol, '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>']['join']('');")
750 ((lambda () (flet ((foo (x)
754 var foo = function (x) {
761 (flet ((foo (x) (return (1+ x
)))
762 (bar (y) (return (+ 2 y
))))
764 "var foo = function (x) {
767 var bar = function (y) {
773 (flet ((foo (x) (+ 2 x
)))
774 (flet ((foo (x) (1+ x
))
775 (bar (y) (+ 2 (foo y
))))
777 "var foo = function (x) {
780 var foo1 = function (x) {
783 var bar = function (y) {
789 ((lambda () (labels ((foo (x)
792 (+ x
(foo (1- x
))))))
795 var foo = function (x) {
799 return x + foo(x - 1);
806 (labels ((foo (x) (return (1+ (bar x
))))
807 (bar (y) (return (+ 2 (foo y
)))))
809 "var foo = function (x) {
812 var bar = function (y) {
818 (labels ((foo (x) (return (1+ x
)))
819 (bar (y) (return (+ 2 (foo y
)))))
821 "var foo = function (x) {
824 var bar = function (y) {
829 (test-ps-js for-loop-var-init-exp
831 (return (do* ((y (if x
0 1) (1+ y
))
836 return (function () {
837 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
847 (test-ps-js literal-array
851 (test-ps-js literal-array-1
855 (test ps-lisp-expands-in-lexical-environment
856 (is (string= "5;" (let ((x 5)) (ps (lisp x
))))))
858 (test ps
*-lisp-expands-in-null-lexical-environment
859 (signals error
(let ((x 5)) (declare (ignore x
)) (ps* '(lisp x
)))))
861 (test ps
*-lisp-expands-in-dynamic-environment
862 (is (string= "1 + 2;" (let ((*print-level
* 2)) (ps* '(+ 1 (lisp *print-level
*)))))))
864 (test ps-lisp-dynamic-environment
865 (is (string= "1 + 2;" (let ((*print-level
* 2)) (ps (+ 1 (lisp *print-level
*)))))))
867 (test-ps-js ps-js-target-version-keyword-test1
868 (defun foo (x y
&key bar baz
))
869 "function foo(x, y) {
871 var x1 = Array.prototype.indexOf.call(arguments, 'bar', 2);
872 var bar = -1 === x1 ? null : arguments[x1 + 1];
873 var x2 = Array.prototype.indexOf.call(arguments, 'baz', 2);
874 return baz = -1 === x2 ? null : arguments[x2 + 1];
876 :js-target-version
1.6)
878 (test-ps-js nested-if-expressions1
879 (return (if (if x y z
) a b
))
886 (test-ps-js nested-if-expressions2
887 (return (if x y
(if z a b
)))
997 (test-ps-js symbol-macrolet-var
998 (symbol-macrolet ((x y
))
1002 (test-ps-js setf-conditional1
1003 (setf x
(unless (null a
) (1+ a
)))
1004 "x = a != null ? a + 1 : null;")
1006 (test-ps-js setf-let1
1007 (setf x
(let ((a 1)) a
))
1010 (test-ps-js setf-let2
1011 (setf x
(let ((a (foo)))
1014 "x = (a = foo(), a != null ? a + 1 : null);")
1016 (test-ps-js symbol-macro-env1
1017 (symbol-macrolet ((bar 1))
1018 (macrolet ((bar (x y
) `(+ ,x
,y
)))
1022 (test-ps-js symbol-macrolet-fun1
1023 (symbol-macrolet ((baz +))
1027 (test-ps-js lisp2-namespaces1
1029 (setf list
(list 1 2 3)))
1033 (test-ps-js let-shadows-symbol-macrolet
1034 (symbol-macrolet ((x y
))
1042 (test-ps-js let-rename-optimization1
1048 (test-ps-js let-rename-optimization2
1057 (test-ps-js symbol-macro-array
1058 (symbol-macrolet ((x 1))
1062 (test-ps-js symbol-macro-obj
1063 (symbol-macrolet ((x y
))
1067 (test-ps-js symbol-macro-conditional1
1068 (symbol-macrolet ((x y
))
1076 (test-ps-js symbol-macro-conditional2
1077 (symbol-macrolet ((x y
))
1078 (return (if x x x
)))
1085 (test-ps-js flet-apply
1086 (flet ((foo () 'bar
))
1087 (apply (function foo
) nil
))
1088 "var foo = function () {
1091 foo.apply(this, null);")
1093 (test-ps-js let-apply
1094 (let ((foo (lambda () (return 1))))
1095 (let ((foo (lambda () (return 2))))
1097 "var foo = function () {
1100 var foo1 = function () {
1103 foo1.apply(this, null);")
1105 (test-ps-js flet-let
1106 (flet ((x (x) (return (1+ x
))))
1109 "var x = function (x) {
1115 (test-ps-js let-flet
1117 (flet ((x (x) (return (1+ x
))))
1120 var x1 = function (x) {
1125 (test-ps-js labels-let
1126 (labels ((x (x) (return (1+ x
))))
1129 "var x = function (x) {
1135 (test-ps-js let-labels
1137 (labels ((x (x) (return (1+ x
))))
1140 var x1 = function (x) {
1145 (test-ps-js macrolet-let-inteference
1146 (macrolet ((a (n) `(+ ,n
5)))
1148 (let ((b (a (- a
4))))
1154 (test-ps-js let-subtract-add
1168 (test-ps-js create-reserved-word
1170 "{ 'default' : 1 };")
1172 (test-ps-js getprop-reserved-word
1173 (getprop foo
:default
)
1176 (test-ps-js getprop-reserved-word1
1177 (getprop foo
'default
)
1180 (test-ps-js eval-when-ps-side
1181 (eval-when (:execute
)
1185 (defvar *lisp-output
* nil
)
1187 (test eval-when-lisp-side
()
1188 (setf *lisp-output
* 'original-value
)
1189 (let ((js-output (normalize-js-code
1190 (ps-doc* `(eval-when (:compile-toplevel
)
1191 (setf *lisp-output
* 'it-works
))))))
1192 (is (eql 'it-works
*lisp-output
*))
1193 (is (string= "" js-output
))))
1195 (defpsmacro my-in-package
(package-name)
1196 `(eval-when (:compile-toplevel
)
1197 (setf *lisp-output
* ,package-name
)))
1199 (test eval-when-macro-expansion
()
1200 (setf *lisp-output
* 'original-value
)
1201 (let ((js-output (normalize-js-code
1203 (my-in-package :cl-user
)
1205 (declare (ignore js-output
))
1206 (is (eql :cl-user
*lisp-output
*))))
1208 (test eval-when-macrolet-expansion
()
1209 (setf *lisp-output
* 'original-value
)
1210 (let ((js-output (normalize-js-code
1211 (ps-doc* `(macrolet ((my-in-package2 (package-name)
1212 `(eval-when (:compile-toplevel
)
1213 (setf *lisp-output
* ,package-name
))))
1214 (my-in-package2 :cl-user
)
1216 (declare (ignore js-output
))
1217 (is (eql :cl-user
*lisp-output
*))))
1219 (test-ps-js getprop-keyword
1223 (test-ps-js nary-comparison1
1224 (lambda () (return (< 1 2 3)))
1227 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
1230 (test-ps-js chain-getprop1
1231 (chain ($
"foo") (bar x z
) frob
(baz 5))
1232 "$('foo').bar(x, z).frob.baz(5);")
1234 (test-ps-js chain-getprop2
1235 (chain ($
"foo") bar baz
)
1236 "$('foo').bar.baz;")
1238 (test-ps-js chain-getprop3
1239 (chain ($
"foo") bar
(x y
) baz
)
1240 "$('foo').bar.x(y).baz;")
1242 (test-ps-js flet-expression
1243 (1+ (flet ((foo (x) (1+ x
)))
1245 "(foo = function (x) {
1249 (test-ps-js return-case-break-elimination
1260 (test-ps-js aplusplus
1264 (test-ps-js astarstar
1268 (test-ps-js switch-return-fallthrough
1283 (test-ps-js return-last-case
1295 (test-ps-js return-macrolet
1297 (macrolet ((x () 1))
1308 (test-ps-js mv-bind1
1309 (multiple-value-bind (a b
)
1316 var prevmv2 = arguments['callee']['mv'];
1318 arguments['callee']['mv'] = true;
1320 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
1325 if (undefined === prevmv2) {
1326 delete arguments['callee']['mv'];
1328 arguments['callee']['mv'] = prevmv2;
1333 (lambda () (values))
1346 if (undefined !== arguments['callee']['caller']['mv']) {
1347 arguments['callee']['caller']['mv'] = valrest2;
1354 var valrest2 = [y, z];
1355 if (undefined !== arguments['callee']['caller']['mv']) {
1356 arguments['callee']['caller']['mv'] = valrest2;
1360 (test-ps-js values-return
1361 (return (values x y
))
1364 if (undefined !== arguments['callee']['caller']['mv']) {
1365 arguments['callee']['caller']['mv'] = valrest2;
1369 (test-ps-js return-macrolet
1371 (symbol-macrolet ((x 2))
1378 (test-ps-js return-cond
1380 (cond ((foo? x
) (loop for y in x do
(foo y
)))
1384 var _js2 = x.length;
1398 } else if (barwhat(x)) {
1404 (test-ps-js switch-loop
1409 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
1414 (test-ps-js switch-folds-blocks
1416 (1 (loop repeat
3 do
(alert "foo"))))
1419 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
1424 (test-ps-js setf-places-before-macros
1426 (defsetf left
(el) (offset)
1427 `(setf (@ ,el style left
) ,offset
))
1428 (macrolet ((left (el)
1429 `(@ ,el offset-left
)))
1434 _js2.style.left = _js1;
1437 (test-ps-js for-return
1438 (return (dolist (arg args
) (foo arg
)))
1439 "for (var arg = null, _js_idx1 = 0; _js_idx1 < args.length; _js_idx1 += 1) {
1440 arg = args[_js_idx1];
1444 (test-ps-js try-catch-return
1458 (test-ps-js defun-setf-optional
1459 (defun (setf foo
) (new-value b
&optional c
)
1460 (setf (aref b
(or c
0)) new-value
))
1461 "function __setf_foo(newValue, b, c) {
1462 if (c === undefined) {
1465 return b[c || 0] = newValue;
1468 (test-ps-js defun-setf-rest
1469 (progn (defun (setf foo
) (new-value b
&rest foo
)
1470 (do-something b foo new-value
))
1471 (setf (foo x
1 2 3 4) 5))
1472 "function __setf_foo(newValue, b) {
1474 for (var i1 = 0; i1 < arguments.length - 2; i1 += 1) {
1475 foo[i1] = arguments[i1 + 2];
1477 return doSomething(b, foo, newValue);
1479 __setf_foo(5, x, 1, 2, 3, 4);")
1481 (test-ps-js return-null
1485 (test-ps-js implicit-return-null
1492 (test-ps-js implicit-return-null
1499 (test-ps-js return-conditional-nested
1500 (defun blep (ss x y
)
1504 (destructuring-bind (a b
) pair
1505 (unless (or (null a
) (null b
))
1506 (let ((val (baz a b
)))
1511 "function blep(ss, x, y) {
1517 if (!(a == null || b == null)) {
1518 var val = baz(a, b);
1531 (test-ps-js return-when-returns
1544 (test-ps-js return-case-conditional
1547 (123 (when (bar) t
))
1560 (test-ps-js return-try-conditional
1577 (test-ps-js function-declare-special
1579 (declare (special *foo
*))
1585 FOO_TMPSTACK1 = FOO;
1589 FOO = FOO_TMPSTACK1;
1593 (test-ps-js declare-special-let
1595 (declare (special *foo
*))
1599 FOO_TMPSTACK1 = FOO;
1603 FOO = FOO_TMPSTACK1;
1606 (test-ps-js macro-null-toplevel
1608 (defmacro macro-null-toplevel
()
1610 (macro-null-toplevel))
1613 (test-ps-js define-symbol-macro-let
1615 (define-symbol-macro test-symbol-macro
1)
1616 (let ((test-symbol-macro 2))
1617 (1+ test-symbol-macro
))
1618 (1+ test-symbol-macro
))
1619 "var testSymbolMacro1 = 2;
1620 testSymbolMacro1 + 1;
1623 (test-ps-js define-symbol-macro-flet
1625 (define-symbol-macro test-symbol-macro1
1)
1626 (flet ((test-symbol-macro1 () 2))
1627 (foo test-symbol-macro1
)
1628 (test-symbol-macro1))
1629 (bar test-symbol-macro1
))
1630 "var testSymbolMacro1_1 = function () {
1634 testSymbolMacro1_1();
1637 (test compile-stream-nulls
1640 (with-input-from-string (s "
1641 (defmacro macro-null-toplevel ()
1643 (macro-null-toplevel)")
1644 (ps-compile-stream s
)))))
1646 (test-ps-js equality-nary1
1647 (let ((x 10) (y 10) (z 10))
1653 x === _cmp1 && _cmp1 === z;")
1655 (test-ps-js equality1
1666 (test-ps-js getprop-quote-reserved
1667 (getprop foo
':break
)
1684 (test-ps-js let-funcall
1696 (test-ps-js symbol-macrolet-funcall
1697 (symbol-macrolet ((foo bar
))
1698 (funcall foo
1 2 3))
1701 (test-ps-js times-assign
1705 (test-ps-js vector-literal
1710 (+ 1 (rem 2 (+ 3 4)))
1713 (test-ps-js non-associative
1714 (+ (/ 1 (/ 2 3)) (- 1 (- 2 3)))
1715 "1 / (2 / 3) + 1 - (2 - 3);")
1717 (test-ps-js lambda-apply
1719 (apply (lambda (y) (bar (1+ y
))) x
))
1721 return (function (y) {
1726 (test-ps-js operator-expressions-nested-let
1727 (let ((x (let ((y 1))
1730 "var x = (y = 1, y); x;")
1732 (test-ps-js operator-expressions-array-nested-let
1733 (list (let ((y 1)) y
) 2)
1736 (test-ps-js add-subtract-precedence
1740 (test-ps-js ps-inline-toplevel
1742 "'javascript:' + 'foo()';")
1744 (test-ps-js no-clause-progn-exp
1748 (test-ps-js empty-cond-clause
1749 (setf x
(cond ((foo))))
1750 "x = foo() ? null : null;")
1752 (test-ps-js empty-cond-clause1
1753 (setf x
(cond ((foo) 123)
1756 "x = foo() ? 123 : (bar() ? null : 456);")
1758 (test-ps-js let-no-body
1759 (return (let ((foo bar
))))