Deprecated DO-SET-TIMEOUT.
[parenscript.git] / t / ps-tests.lisp
blobff2277f2e7b262bd6bc58364d3c874caaec66004
1 (in-package "PARENSCRIPT-TEST")
3 (in-suite ps-tests)
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
14 (progn
15 (let ((x 10))
16 (defun side-effect()
17 (setf x 4)
19 (setf x (+ 2 (side-effect) x 5))))
20 "var x = 10;
21 function sideEffect() {
22 x = 4;
23 return 3;
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))
37 "'hi'.toString();")
39 (test-ps-js method-call-conditional
40 ((if a x y) 1)
41 "(a ? x : y)(1);")
43 (test-ps-js method-call-variable
44 ((@ x to-string))
45 "x.toString();")
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)))
59 (a-parenthesis #\)))
60 (is (char= char-before a-parenthesis))))
62 (test-ps-js simple-getprop
63 (let ((foo (create a 1)))
64 (alert (getprop foo 'a)))
65 "var foo = { a : 1 };
66 alert(foo.a);")
68 (test-ps-js buggy-getprop
69 (getprop foo slot-name)
70 "foo[slotName];")
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
82 ;; clause.
83 (switch (aref blorg i)
84 (1 (alert "one"))
85 (2 (alert "two"))
86 (default (alert "default clause")))
87 "switch (blorg[i]) {
88 case 1: alert('one');
89 case 2: alert('two');
90 default: alert('default clause');
91 };")
93 (test-ps-js lisp-like-case
94 (case (aref blorg i)
95 (1 (alert "one"))
96 (2 (alert "two"))
97 (default (alert "default clause")))
98 "switch (blorg[i]) {
99 case 1:
100 alert('one');
101 break;
102 case 2:
103 alert('two');
104 break;
105 default: alert('default clause');
106 };")
109 (test-ps-js even-lispier-case
110 (case (aref blorg i)
111 ((1 2) (alert "Below three"))
112 (3 (alert "Three"))
113 (t (alert "Something else")))
114 "switch (blorg[i]) {
115 case 1:
116 case 2:
117 alert('Below three');
118 break;
119 case 3:
120 alert('Three');
121 break;
122 default: alert('Something else');
123 };")
125 (test-ps-js otherwise-case
126 (case (aref blorg i)
127 (1 (alert "one"))
128 (otherwise (alert "default clause")))
129 "switch (blorg[i]) {
130 case 1:
131 alert('one');
132 break;
133 default: alert('default clause');
134 };")
136 (test escape-sequences-in-string
137 (let ((escapes `((#\\ . #\\)
138 (#\b . #\Backspace)
139 (#\f . ,(code-char 12))
140 ("u000B" . ,(code-char #x000b));;Vertical tab, too uncommon to bother with
141 (#\n . #\Newline)
142 (#\r . #\Return)
143 (#\' . #\');;Double quote need not be quoted because parenscript strings are single quoted
144 (#\t . #\Tab)
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))
155 "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
172 (array nil)
173 "[null];")
175 (test-ps-js quoted-nil-is-array
176 'nil
177 "[];")
179 (test-ps-js defsetf1
180 (progn (defsetf baz (x y) (newval) `(set-baz ,x ,y ,newval))
181 (setf (baz 1 2) 3))
182 "var _js2 = 1;
183 var _js3 = 2;
184 var _js1 = 3;
185 setBaz(_js2, _js3, _js1);")
187 (test-ps-js setf-macroexpands1
188 (macrolet ((bar (x y)
189 `(aref ,x ,y 1)))
190 (setf (bar foo 2) 3))
191 "foo[2][1] = 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)
209 (if x "yes" "no"))
210 "function testOpt(x) {
211 if (x === undefined) {
212 x = null;
214 if (x) {
215 return 'yes';
216 } else {
217 return 'no';
219 };")
221 (test-ps-js defun-optional2
222 (defun foo (x &optional y)
223 (+ x y))
224 "function foo(x, y) {
225 if (y === undefined) {
226 y = null;
228 return x + y;
229 };")
231 (test-ps-js defun-optional3
232 (defun blah (&optional (x 0))
234 "function blah(x) {
235 if (x === undefined) {
236 x = 0;
238 return x;
239 };")
241 (test-ps-js return-nothing
242 (return)
243 "return null;")
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
250 (* 3 (+ 4 5) 6)
251 "3 * (4 + 5) * 6;")
253 (test-ps-js operators-1
254 (in prop obj)
255 "prop in obj;")
257 (test-ps-js incf1
258 (incf foo bar)
259 "foo += bar;")
261 (test-ps-js decf1
262 (decf foo bar)
263 "foo -= bar;")
265 (test-ps-js incf2
266 (incf x 5)
267 "x += 5;")
269 (test-ps-js decf2
270 (decf y 10)
271 "y -= 10;")
273 (test-ps-js setf-conditional
274 (setf foo (if x 1 2))
275 "foo = x ? 1 : 2;")
277 (test-ps-js obj-literal-numbers
278 (create 1 "foo")
279 "{ 1 : 'foo' };")
281 (test-ps-js obj-literal-strings
282 (create "foo" 2)
283 "{ 'foo' : 2 };")
285 (test-ps-js getprop-string
286 (getprop foo "bar")
287 "foo['bar'];")
289 (test-ps-js getprop-string1
290 (getprop "bar" 'length)
291 "'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
302 (create)
303 "{ };")
305 (test-ps-js blank-object-literal
307 "{ };")
309 (test-ps-js array-literal1
311 "[];")
313 (test-ps-js array-literal2
314 ([])
315 "[];")
317 (test-ps-js array-literal3
318 ([] 1 2 3)
319 "[1, 2, 3];")
321 (test-ps-js array-literal4
322 ([] 1 (2 3))
323 "[1, [2, 3]];")
325 (test-ps-js array-literal5
326 ([] (1 2) ("a" "b"))
327 "[[1, 2], ['a', 'b']];")
329 (test-ps-js defun-rest1
330 (defun foo (&rest bar)
331 (alert (aref bar 1)))
332 "function foo() {
333 var bar = [];
334 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
335 bar[i1] = arguments[i1 + 0];
337 return alert(bar[1]);
338 };")
340 (test-ps-js defun-rest2
341 (defun foo (baz &rest bar) (return (+ baz (aref bar 1))))
342 "function foo(baz) {
343 var bar = [];
344 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
345 bar[i1] = arguments[i1 + 1];
347 return baz + bar[1];
348 };")
350 (test-ps-js defun-keyword1
351 (defun zoo (foo bar &key baz) (return (+ foo bar baz)))
352 "function zoo(foo, bar) {
353 var baz;
354 var _js2 = arguments.length;
355 for (var n1 = 2; n1 < _js2; n1 += 2) {
356 switch (arguments[n1]) {
357 case 'baz':
358 baz = arguments[n1 + 1];
361 if (baz === undefined) {
362 baz = null;
364 return foo + bar + baz;
365 };")
367 (test-ps-js defun-keyword2
368 (defun zoo (&key baz) (return (* baz baz)))
369 "function zoo() {
370 var baz;
371 var _js2 = arguments.length;
372 for (var n1 = 0; n1 < _js2; n1 += 2) {
373 switch (arguments[n1]) {
374 case 'baz':
375 baz = arguments[n1 + 1];
378 if (baz === undefined) {
379 baz = null;
381 return baz * baz;
382 };")
384 (test-ps-js defun-keyword3
385 (defun zoo (&key baz (bar 4)) (return (* baz bar)))
386 "function zoo() {
387 var baz;
388 var bar;
389 var _js2 = arguments.length;
390 for (var n1 = 0; n1 < _js2; n1 += 2) {
391 switch (arguments[n1]) {
392 case 'baz':
393 baz = arguments[n1 + 1];
394 break;
395 case 'bar':
396 bar = arguments[n1 + 1];
399 if (baz === undefined) {
400 baz = null;
402 if (bar === undefined) {
403 bar = 4;
405 return baz * bar;
406 };")
408 (test-ps-js defun-keyword4
409 (defun hello-world (&key ((:my-name-key my-name) 1))
410 my-name)
411 "function helloWorld() {
412 var myName;
413 var _js2 = arguments.length;
414 for (var n1 = 0; n1 < _js2; n1 += 2) {
415 switch (arguments[n1]) {
416 case 'my-name-key':
417 myName = arguments[n1 + 1];
420 if (myName === undefined) {
421 myName = 1;
423 return myName;
424 };")
426 (test-ps-js keyword-funcall1
427 (func :baz 1)
428 "func('baz', 1);")
430 (test-ps-js keyword-funcall2
431 (func :baz 1 :bar foo)
432 "func('baz', 1, 'bar', foo);")
434 (test-ps-js keyword-funcall3
435 (fun a b :baz c)
436 "fun(a, b, 'baz', c);")
438 (test-ps-js cond1
439 (cond ((= x 1) 1))
440 "if (x === 1) {
442 };")
444 (test-ps-js cond2
445 (cond ((= x 1) 2)
446 ((= y (* x 4)) (foo "blah") (* x y)))
447 "if (x === 1) {
449 } else if (y === x * 4) {
450 foo('blah');
451 x * y;
452 };")
454 (test-ps-js if-exp-without-else-return
455 (return (if x 1))
456 "if (x) {
457 return 1;
458 } else {
459 return null;
460 };")
462 (test-ps-js progn-expression-single-statement
463 (return (progn (* x y)))
464 "return x * y;")
466 (test-ps-js cond-expression1
467 (defun foo ()
468 (cond ((< 1 2) (bar "foo") (* 4 5))))
469 "function foo() {
470 if (1 < 2) {
471 bar('foo');
472 return 4 * 5;
474 };")
476 (test-ps-js cond-expression2
477 (defun foo ()
478 (cond ((< 2 1) "foo")
479 ((= 7 7) "bar")))
480 "function foo() {
481 if (2 < 1) {
482 return 'foo';
483 } else if (7 === 7) {
484 return 'bar';
486 };")
488 (test-ps-js cond-expression-final-t-clause
489 (defun foo ()
490 (cond ((< 1 2) (bar "foo") (* 4 5))
491 ((= a b) (+ c d))
492 ((< 1 2 3 4 5) x)
493 (t "foo")))
494 "function foo() {
495 var _cmp3;
496 var _cmp2;
497 var _cmp1;
498 if (1 < 2) {
499 bar('foo');
500 return 4 * 5;
501 } else if (a === b) {
502 return c + d;
503 } else if (_cmp1 = 2, _cmp2 = 3, _cmp3 = 4, 1 < _cmp1 && _cmp1 < _cmp2 && _cmp2 < _cmp3 && _cmp3 < 5) {
504 return x;
505 } else {
506 return 'foo';
508 };")
510 (test-ps-js cond-expression-middle-t-clause ;; should this signal a warning?
511 (defun foo ()
512 (cond ((< 2 1) 5)
513 (t "foo")
514 ((< 1 2) "bar")))
515 "function foo() {
516 if (2 < 1) {
517 return 5;
518 } else {
519 return 'foo';
521 };")
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)))
528 img))
529 img))
530 "document.write(LINKORNOT === 1 ? ['<A HREF=\"#\" ONCLICK=\"', 'javascript:' + 'transport()', '\">', img, '</A>']['join']('') : img);")
532 (test-ps-js negate-number-literal
533 (- 1)
534 "-1;")
536 (test macro-environment1
537 (is (string= (normalize-js-code (let* ((macroname (gensym)))
538 (ps* `(defmacro ,macroname (x) `(+ ,x 123))
539 `(defun test1 ()
540 (macrolet ((,macroname (x) `(aref data ,x)))
541 (when (,macroname x)
542 (setf (,macroname x) 123)))))))
543 (normalize-js-code
544 "function test1() {
545 if (data[x]) {
546 return data[x] = 123;
548 };"))))
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)))
561 (foo 1 2))
562 "'(FOO 1 2)';")
564 (test-ps-js keyword-consistent
566 "'x';")
568 (test-ps-js simple-symbol-macrolet
569 (symbol-macrolet ((x 1)) x)
570 "1;")
572 (test-ps-js compound-symbol-macrolet
573 (symbol-macrolet ((x 123)
574 (y (* 2 x)))
576 "2 * 123;")
578 (test-ps-js define-symbol-macro
579 (progn (define-symbol-macro tst-sym-macro 2)
580 tst-sym-macro)
581 "2;")
583 (test-ps-js define-symbol-macro1
584 (progn (define-symbol-macro tst-sym-macro1 2)
585 (foo tst-sym-macro1))
586 "foo(2);")
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
593 (defun f (x)
594 (if x 1 (let* ((foo x))
595 foo)))
596 "function f(x) {
597 if (x) {
598 return 1;
599 } else {
600 var foo = x;
601 return foo;
603 };")
605 (test-ps-js special-var1
606 (progn (defvar *foo*)
607 (let* ((*foo* 2))
608 (* *foo* 2)))
609 "var FOO;
610 var FOO_TMPSTACK1;
611 try {
612 FOO_TMPSTACK1 = FOO;
613 FOO = 2;
614 FOO * 2;
615 } finally {
616 FOO = FOO_TMPSTACK1;
617 };")
619 (test-ps-js special-var2
620 (progn (defvar *foo*)
621 (let* ((*baz* 3)
622 (*foo* 2))
623 (* *foo* 2 *baz*)))
624 "var FOO;
625 var BAZ = 3;
626 var FOO_TMPSTACK1;
627 try {
628 FOO_TMPSTACK1 = FOO;
629 FOO = 2;
630 FOO * 2 * BAZ;
631 } finally {
632 FOO = FOO_TMPSTACK1;
633 };")
635 (test-ps-js literal1
636 (setf x undefined)
637 "x = undefined;")
639 (test-ps-js literal2
640 (aref this x)
641 "this[x];")
643 (test-ps-js setf-dec1
644 (setf x (- 1 x 2))
645 "x = 1 - x - 2;")
647 (test-ps-js setf-dec2
648 (setf x (- x 1 2))
649 "x = x - 1 - 2;")
651 (test-ps-js special-char-equals
652 blah=
653 "blahequals;")
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))
662 (aref x 0)
665 "(x && x.length > 0 ? x[0] : y)[z];")
667 (test-ps-js aref-operator-priority1
668 (aref (or (getprop x 'y)
669 (getprop a 'b))
671 "(x.y || a.b)[z];")
673 (test-ps-js aref-operator-priority2
674 (aref (if a b c) 0)
675 "(a ? b : c)[0];")
677 (test-ps-js negate-operator-priority
678 (- (if x y z))
679 "-(x ? y : z);")
681 (test-ps-js op-p1
682 (new (or a b))
683 "new (a || b);")
685 (test-ps-js op-p2
686 (delete (if a (or b c) d))
687 "delete (a ? b || c : d);")
689 (test-ps-js op-p3
690 (not (if (or x (not y)) z))
691 "!(x || !y ? z : null);")
693 (test-ps-js op-p4
694 (- (- (* 1 2) 3))
695 "-(1 * 2 - 3);")
697 (test-ps-js op-p5
698 (instanceof (or a b) (if x y z))
699 "((a || b) instanceof (x ? y : z));")
701 (test-ps-js op-p7
702 (or x (if (= x 0) "zero" "empty"))
703 "x || (x === 0 ? 'zero' : 'empty');")
705 (test-ps-js named-op-expression
706 (throw (if a b c))
707 "throw a ? b : c;")
709 (test-ps-js named-op-expression1
710 (typeof (or x y))
711 "typeof (x || y);")
713 (test-ps-js aref-array-expression
714 (aref (or a b c) 0)
715 "(a || b || c)[0];")
717 (test-ps-js getprop-operator
718 (getprop (or a b c) 'd)
719 "(a || b || c).d;")
721 (test-ps-js getprop-parens
722 (getprop (getprop foo 'bar) 'baz)
723 "foo.bar.baz;")
725 (test-ps-js funcall-funcall
726 ((foo))
727 "foo()();")
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"
745 symbol)
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']('');")
749 (test-ps-js flet1
750 ((lambda () (flet ((foo (x)
751 (1+ x)))
752 (return (foo 1)))))
753 "(function () {
754 var foo = function (x) {
755 return x + 1;
757 return foo(1);
758 })();")
760 (test-ps-js flet2
761 (flet ((foo (x) (return (1+ x)))
762 (bar (y) (return (+ 2 y))))
763 (bar (foo 1)))
764 "var foo = function (x) {
765 return x + 1;
767 var bar = function (y) {
768 return 2 + y;
770 bar(foo(1));")
772 (test-ps-js flet3
773 (flet ((foo (x) (+ 2 x)))
774 (flet ((foo (x) (1+ x))
775 (bar (y) (+ 2 (foo y))))
776 (bar (foo 1))))
777 "var foo = function (x) {
778 return 2 + x;
780 var foo1 = function (x) {
781 return x + 1;
783 var bar = function (y) {
784 return 2 + foo(y);
786 bar(foo1(1));")
788 (test-ps-js labels1
789 ((lambda () (labels ((foo (x)
790 (if (= 0 x)
792 (+ x (foo (1- x))))))
793 (foo 3))))
794 "(function () {
795 var foo = function (x) {
796 if (0 === x) {
797 return 0;
798 } else {
799 return x + foo(x - 1);
802 return foo(3);
803 })();")
805 (test-ps-js labels2
806 (labels ((foo (x) (return (1+ (bar x))))
807 (bar (y) (return (+ 2 (foo y)))))
808 (bar (foo 1)))
809 "var foo = function (x) {
810 return bar(x) + 1;
812 var bar = function (y) {
813 return 2 + foo(y);
815 bar(foo(1));")
817 (test-ps-js labels3
818 (labels ((foo (x) (return (1+ x)))
819 (bar (y) (return (+ 2 (foo y)))))
820 (bar (foo 1)))
821 "var foo = function (x) {
822 return x + 1;
824 var bar = function (y) {
825 return 2 + foo(y);
827 bar(foo(1));")
829 (test-ps-js for-loop-var-init-exp
830 ((lambda (x)
831 (return (do* ((y (if x 0 1) (1+ y))
832 (z 0 (1+ z)))
833 ((= y 3) z))))
834 true)
835 "(function (x) {
836 return (function () {
837 for (var y = x ? 0 : 1, z = 0; y !== 3; y += 1, z += 1) {
839 return z;
840 })();
841 })(true);")
843 (test-ps-js math-pi
845 "Math.PI;")
847 (test-ps-js literal-array
848 '(1 2 3)
849 "[1, 2, 3];")
851 (test-ps-js literal-array-1
852 '(1 foo 3)
853 "[1, 'foo', 3];")
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) {
870 var baz;
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))
880 "if (x ? y : z) {
881 return a;
882 } else {
883 return b;
884 };")
886 (test-ps-js nested-if-expressions2
887 (return (if x y (if z a b)))
888 "if (x) {
889 return y;
890 } else {
891 if (z) {
892 return a;
893 } else {
894 return b;
896 };")
898 (test-ps-js let1
899 (let (x)
900 (+ x x))
901 "var x = null;
902 x + x;")
904 (test-ps-js let2
905 (let ((x 1))
906 (+ x x))
907 "var x = 1;
908 x + x;")
910 (test-ps-js let-x-x
911 (let ((x (1+ x)))
912 (+ x x))
913 "var x1 = x + 1;
914 x1 + x1;")
916 (test-ps-js let3
917 (let ((x 1)
918 (y 2))
919 (+ x x))
920 "var x = 1;
921 var y = 2;
922 x + x;")
924 (test-ps-js let4
925 (let ((x 1)
926 (y (1+ x)))
927 (+ x y))
928 "var x1 = 1;
929 var y = x + 1;
930 x1 + y;")
932 (test-ps-js let5
933 (let ((x 1))
934 (+ x 1)
935 (let ((x (+ x 5)))
936 (+ x 1))
937 (+ x 1))
938 "var x = 1;
939 x + 1;
940 var x1 = x + 5;
941 x1 + 1;
942 x + 1;")
944 (test-ps-js let6
945 (let ((x 2))
946 (let ((x 1)
947 (y (1+ x)))
948 (+ x y)))
949 "var x = 2;
950 var x1 = 1;
951 var y = x + 1;
952 x1 + y;")
954 (test-ps-js let-exp1
955 (lambda ()
956 (let (x)
957 (+ x x)))
958 "function () {
959 var x = null;
960 return x + x;
961 };")
963 (test-ps-js let*1
964 (let* ((x 1))
965 (+ x x))
966 "var x = 1;
967 x + x;")
969 (test-ps-js let*2
970 (let* ((x 1)
971 (y (+ x 2)))
972 (+ x y))
973 "var x = 1;
974 var y = x + 2;
975 x + y;")
977 (test-ps-js let*3
978 (let ((x 3))
979 (let* ((x 1)
980 (y (+ x 2)))
981 (+ x y)))
982 "var x = 3;
983 var x1 = 1;
984 var y = x1 + 2;
985 x1 + y;")
987 (test-ps-js let*4
988 (let ((x 3))
989 (let* ((y (+ x 2))
990 (x 1))
991 (+ x y)))
992 "var x = 3;
993 var y = x + 2;
994 var x1 = 1;
995 x1 + y;")
997 (test-ps-js symbol-macrolet-var
998 (symbol-macrolet ((x y))
999 (var x))
1000 "var 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))
1008 "x = (a = 1, a);")
1010 (test-ps-js setf-let2
1011 (setf x (let ((a (foo)))
1012 (unless (null a)
1013 (1+ a))))
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)))
1019 (bar bar bar)))
1020 "1 + 1;")
1022 (test-ps-js symbol-macrolet-fun1
1023 (symbol-macrolet ((baz +))
1024 (baz 1 2))
1025 "baz(1, 2);")
1027 (test-ps-js lisp2-namespaces1
1028 (let ((list nil))
1029 (setf list (list 1 2 3)))
1030 "var list = null;
1031 list = [1, 2, 3];")
1033 (test-ps-js let-shadows-symbol-macrolet
1034 (symbol-macrolet ((x y))
1035 (let ((x 1))
1036 (+ x x))
1037 (+ x x))
1038 "var x1 = 1;
1039 x1 + x1;
1040 y + y;")
1042 (test-ps-js let-rename-optimization1
1043 (let ((x 1))
1044 (+ x x))
1045 "var x = 1;
1046 x + x;")
1048 (test-ps-js let-rename-optimization2
1049 (lambda (x)
1050 (let ((x (+ 1 x)))
1051 (return x)))
1052 "function (x) {
1053 var x1 = 1 + x;
1054 return x1;
1055 };")
1057 (test-ps-js symbol-macro-array
1058 (symbol-macrolet ((x 1))
1059 (list x))
1060 "[1];")
1062 (test-ps-js symbol-macro-obj
1063 (symbol-macrolet ((x y))
1064 (create x 1))
1065 "{ x : 1 };")
1067 (test-ps-js symbol-macro-conditional1
1068 (symbol-macrolet ((x y))
1069 (if x x x))
1070 "if (y) {
1072 } else {
1074 };")
1076 (test-ps-js symbol-macro-conditional2
1077 (symbol-macrolet ((x y))
1078 (return (if x x x)))
1079 "if (y) {
1080 return y;
1081 } else {
1082 return y;
1083 };")
1085 (test-ps-js flet-apply
1086 (flet ((foo () 'bar))
1087 (apply (function foo) nil))
1088 "var foo = function () {
1089 return 'bar';
1091 foo.apply(this, null);")
1093 (test-ps-js let-apply
1094 (let ((foo (lambda () (return 1))))
1095 (let ((foo (lambda () (return 2))))
1096 (apply foo nil)))
1097 "var foo = function () {
1098 return 1;
1100 var foo1 = function () {
1101 return 2;
1103 foo1.apply(this, null);")
1105 (test-ps-js flet-let
1106 (flet ((x (x) (return (1+ x))))
1107 (let ((x 2))
1108 (x x)))
1109 "var x = function (x) {
1110 return x + 1;
1112 var x1 = 2;
1113 x(x1);")
1115 (test-ps-js let-flet
1116 (let ((x 2))
1117 (flet ((x (x) (return (1+ x))))
1118 (x x)))
1119 "var x = 2;
1120 var x1 = function (x) {
1121 return x + 1;
1123 x1(x);")
1125 (test-ps-js labels-let
1126 (labels ((x (x) (return (1+ x))))
1127 (let ((x 2))
1128 (x x)))
1129 "var x = function (x) {
1130 return x + 1;
1132 var x1 = 2;
1133 x(x1);")
1135 (test-ps-js let-labels
1136 (let ((x 2))
1137 (labels ((x (x) (return (1+ x))))
1138 (x x)))
1139 "var x = 2;
1140 var x1 = function (x) {
1141 return x + 1;
1143 x1(x);")
1145 (test-ps-js macrolet-let-inteference
1146 (macrolet ((a (n) `(+ ,n 5)))
1147 (let ((a (a 1)))
1148 (let ((b (a (- a 4))))
1149 (+ a b))))
1150 "var a = 1 + 5;
1151 var b = a - 4 + 5;
1152 a + b;")
1154 (test-ps-js let-subtract-add
1155 (let ((x 1))
1156 (let ((x 2))
1157 (- x x)
1158 (- x)
1159 (decf x)
1160 (incf x)))
1161 "var x = 1;
1162 var x1 = 2;
1163 x1 - x1;
1164 -x1;
1165 --x1;
1166 ++x1;")
1168 (test-ps-js create-reserved-word
1169 (create :default 1)
1170 "{ 'default' : 1 };")
1172 (test-ps-js getprop-reserved-word
1173 (getprop foo :default)
1174 "foo['default'];")
1176 (test-ps-js getprop-reserved-word1
1177 (getprop foo 'default)
1178 "foo['default'];")
1180 (test-ps-js eval-when-ps-side
1181 (eval-when (:execute)
1183 "5;")
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
1202 (ps-doc* `(progn
1203 (my-in-package :cl-user)
1204 3)))))
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)
1215 3)))))
1216 (declare (ignore js-output))
1217 (is (eql :cl-user *lisp-output*))))
1219 (test-ps-js getprop-keyword
1220 (getprop foo :bar)
1221 "foo['bar'];")
1223 (test-ps-js nary-comparison1
1224 (lambda () (return (< 1 2 3)))
1225 "function () {
1226 var _cmp1;
1227 return (_cmp1 = 2, 1 < _cmp1 && _cmp1 < 3);
1228 };")
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)))
1244 (foo 1)))
1245 "(foo = function (x) {
1246 return x + 1;
1247 }, foo(1)) + 1;")
1249 (test-ps-js return-case-break-elimination
1250 (return (case 1
1251 (0 1)
1252 (otherwise 2)))
1253 "switch (1) {
1254 case 0:
1255 return 1;
1256 default:
1257 return 2;
1258 };")
1260 (test-ps-js aplusplus
1262 "aplusplus;")
1264 (test-ps-js astarstar
1266 "astarstar;")
1268 (test-ps-js switch-return-fallthrough
1269 (return
1270 (switch x
1271 (1 (foo) break)
1272 (2 (bar))
1273 (default 4)))
1274 "switch (x) {
1275 case 1:
1276 return foo();
1277 case 2:
1278 bar();
1279 default:
1280 return 4;
1281 };")
1283 (test-ps-js return-last-case
1284 (return
1285 (case x
1286 (a 'eh)
1287 (b 'bee)))
1288 "switch (x) {
1289 case a:
1290 return 'eh';
1291 case b:
1292 return 'bee';
1293 };")
1295 (test-ps-js return-macrolet
1296 (return
1297 (macrolet ((x () 1))
1298 (case (x)
1299 (a 'eh)
1300 (b 'bee))))
1301 "switch (1) {
1302 case a:
1303 return 'eh';
1304 case b:
1305 return 'bee';
1306 };")
1308 (test-ps-js mv-bind1
1309 (multiple-value-bind (a b)
1310 (progn
1311 (returns-mv)
1312 (doesnt))
1313 (alert a)
1314 (alert b))
1315 "returnsMv();
1316 var prevmv2 = arguments['callee']['mv'];
1317 try {
1318 arguments['callee']['mv'] = true;
1319 var a = doesnt();
1320 var mv1 = typeof arguments['callee']['mv'] === 'object' ? arguments['callee']['mv'] : new Array(1);
1321 var b = mv1[0];
1322 alert(a);
1323 alert(b);
1324 } finally {
1325 if (undefined === prevmv2) {
1326 delete arguments['callee']['mv'];
1327 } else {
1328 arguments['callee']['mv'] = prevmv2;
1330 };")
1332 (test-ps-js values0
1333 (lambda () (values))
1334 "function () {
1335 return null;
1336 };")
1338 (test-ps-js values1
1339 (values x)
1340 "x;")
1342 (test-ps-js values2
1343 (values x y)
1344 "var val1_1 = x;
1345 var valrest2 = [y];
1346 if (undefined !== arguments['callee']['caller']['mv']) {
1347 arguments['callee']['caller']['mv'] = valrest2;
1349 val1_1;")
1351 (test-ps-js values3
1352 (values x y z)
1353 "var val1_1 = x;
1354 var valrest2 = [y, z];
1355 if (undefined !== arguments['callee']['caller']['mv']) {
1356 arguments['callee']['caller']['mv'] = valrest2;
1358 val1_1;")
1360 (test-ps-js values-return
1361 (return (values x y))
1362 "var val1_1 = x;
1363 var valrest2 = [y];
1364 if (undefined !== arguments['callee']['caller']['mv']) {
1365 arguments['callee']['caller']['mv'] = valrest2;
1367 return val1_1;")
1369 (test-ps-js return-macrolet
1370 (return
1371 (symbol-macrolet ((x 2))
1372 (loop do (+ x x))))
1373 "for (; true; ) {
1374 2 + 2;
1376 return null;")
1378 (test-ps-js return-cond
1379 (return
1380 (cond ((foo? x) (loop for y in x do (foo y)))
1381 ((bar? x) x)
1382 (t 3)))
1383 "if (foowhat(x)) {
1384 var _js2 = x.length;
1385 var _js1 = 0;
1386 if (_js1 < _js2) {
1387 var y = x[_js1];
1388 while (true) {
1389 foo(y);
1390 _js1 += 1;
1391 if (_js1 >= _js2) {
1392 break;
1394 y = x[_js1];
1397 return null;
1398 } else if (barwhat(x)) {
1399 return x;
1400 } else {
1401 return 3;
1402 };")
1404 (test-ps-js switch-loop
1405 (case x
1406 (1 (dolist (a b))))
1407 "switch (x) {
1408 case 1:
1409 for (var a = null, _js_idx1 = 0; _js_idx1 < b.length; _js_idx1 += 1) {
1410 a = b[_js_idx1];
1412 };")
1414 (test-ps-js switch-folds-blocks
1415 (case x
1416 (1 (loop repeat 3 do (alert "foo"))))
1417 "switch (x) {
1418 case 1:
1419 for (var _js1 = 0; _js1 < 3; _js1 += 1) {
1420 alert('foo');
1422 };")
1424 (test-ps-js setf-places-before-macros
1425 (progn
1426 (defsetf left (el) (offset)
1427 `(setf (@ ,el style left) ,offset))
1428 (macrolet ((left (el)
1429 `(@ ,el offset-left)))
1430 (setf (left x) 10)
1431 (left x)))
1432 "var _js2 = x;
1433 var _js1 = 10;
1434 _js2.style.left = _js1;
1435 x.offsetLeft;")
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];
1441 foo(arg);
1442 };")
1444 (test-ps-js try-catch-return
1445 (return (try (foo)
1446 (:catch (e)
1447 (bar))
1448 (:finally
1449 (cleanup))))
1450 "try {
1451 return foo();
1452 } catch (e) {
1453 return bar();
1454 } finally {
1455 cleanup();
1456 };")
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) {
1463 c = null;
1465 return b[c || 0] = newValue;
1466 };")
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) {
1473 var foo = [];
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
1482 (return nil)
1483 "return null;")
1485 (test-ps-js implicit-return-null
1486 (lambda ()
1488 "function () {
1489 return null;
1490 };")
1492 (test-ps-js implicit-return-null
1493 (lambda ()
1494 nil)
1495 "function () {
1496 return null;
1497 };")
1499 (test-ps-js return-conditional-nested
1500 (defun blep (ss x y)
1501 (when foo?
1502 (let ((pair (bar)))
1503 (unless (null pair)
1504 (destructuring-bind (a b) pair
1505 (unless (or (null a) (null b))
1506 (let ((val (baz a b)))
1507 (unless (null val)
1508 (when (blah val)
1509 (unless (blee)
1510 t))))))))))
1511 "function blep(ss, x, y) {
1512 if (foowhat) {
1513 var pair = bar();
1514 if (pair != null) {
1515 var a = pair[0];
1516 var b = pair[1];
1517 if (!(a == null || b == null)) {
1518 var val = baz(a, b);
1519 if (val != null) {
1520 if (blah(val)) {
1521 if (!blee()) {
1522 return true;
1529 };")
1531 (test-ps-js return-when-returns
1532 (lambda ()
1533 (return (when x 1))
1534 (+ 2 3))
1535 "function () {
1536 if (x) {
1537 return 1;
1538 } else {
1539 return null;
1541 return 2 + 3;
1542 };")
1544 (test-ps-js return-case-conditional
1545 (return
1546 (case foo
1547 (123 (when (bar) t))
1548 (345 (blah))))
1549 "switch (foo) {
1550 case 123:
1551 if (bar()) {
1552 return true;
1553 } else {
1554 return null;
1556 case 345:
1557 return blah();
1558 };")
1560 (test-ps-js return-try-conditional
1561 (return
1562 (try (when x 1)
1563 (:catch (x) 2)
1564 (:finally (bar))))
1565 "try {
1566 if (x) {
1567 return 1;
1568 } else {
1569 return null;
1571 } catch (x) {
1572 return 2;
1573 } finally {
1574 bar();
1575 };")
1577 (test-ps-js function-declare-special
1578 (lambda ()
1579 (declare (special *foo*))
1580 (let ((*foo* 1))
1581 (1+ *foo*)))
1582 "function () {
1583 var FOO_TMPSTACK1;
1584 try {
1585 FOO_TMPSTACK1 = FOO;
1586 FOO = 1;
1587 return FOO + 1;
1588 } finally {
1589 FOO = FOO_TMPSTACK1;
1591 };")
1593 (test-ps-js declare-special-let
1594 (let ((*foo* 123))
1595 (declare (special *foo*))
1596 (blah))
1597 "var FOO_TMPSTACK1;
1598 try {
1599 FOO_TMPSTACK1 = FOO;
1600 FOO = 123;
1601 blah();
1602 } finally {
1603 FOO = FOO_TMPSTACK1;
1604 };")
1606 (test-ps-js macro-null-toplevel
1607 (progn
1608 (defmacro macro-null-toplevel ()
1609 nil)
1610 (macro-null-toplevel))
1613 (test-ps-js define-symbol-macro-let
1614 (progn
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;
1621 1 + 1;")
1623 (test-ps-js define-symbol-macro-flet
1624 (progn
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 () {
1631 return 2;
1633 foo(1);
1634 testSymbolMacro1_1();
1635 bar(1);")
1637 (test compile-stream-nulls
1638 (is (string=
1640 (with-input-from-string (s "
1641 (defmacro macro-null-toplevel ()
1642 nil)
1643 (macro-null-toplevel)")
1644 (ps-compile-stream s)))))
1646 (test-ps-js equality-nary1
1647 (let ((x 10) (y 10) (z 10))
1648 (= x y z))
1649 "var x = 10;
1650 var y = 10;
1651 var z = 10;
1652 var _cmp1 = y;
1653 x === _cmp1 && _cmp1 === z;")
1655 (test-ps-js equality1
1656 (progn
1657 (equal a b)
1658 (eql a b)
1659 (eq a b)
1660 (= a b))
1661 "a == b;
1662 a === b;
1663 a === b;
1664 a === b;")
1666 (test-ps-js getprop-quote-reserved
1667 (getprop foo ':break)
1668 "foo['break'];")
1670 (test-ps-js label1
1671 (label scope
1672 (foo)
1673 (when (bar)
1674 (break scope))
1675 (blee))
1676 "scope: {
1677 foo();
1678 if (bar()) {
1679 break scope;
1681 blee();
1682 };")
1684 (test-ps-js let-funcall
1685 (let ((x foo))
1686 (funcall x)
1687 (let ((x bar))
1688 (funcall x))
1689 (funcall x))
1690 "var x = foo;
1691 x();
1692 var x1 = bar;
1693 x1();
1694 x();")
1696 (test-ps-js symbol-macrolet-funcall
1697 (symbol-macrolet ((foo bar))
1698 (funcall foo 1 2 3))
1699 "bar(1, 2, 3);")
1701 (test-ps-js times-assign
1702 (setf x (* x 1000))
1703 "x *= 1000;")
1705 (test-ps-js vector-literal
1706 #(1 2 3)
1707 "[1, 2, 3];")
1709 (test-ps-js rem1
1710 (+ 1 (rem 2 (+ 3 4)))
1711 "1 + 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
1718 (lambda (x)
1719 (apply (lambda (y) (bar (1+ y))) x))
1720 "function (x) {
1721 return (function (y) {
1722 return bar(y + 1);
1723 }).apply(this, x);
1724 };")
1726 (test-ps-js operator-expressions-nested-let
1727 (let ((x (let ((y 1))
1728 y)))
1730 "var x = (y = 1, y); x;")
1732 (test-ps-js operator-expressions-array-nested-let
1733 (list (let ((y 1)) y) 2)
1734 "[(y = 1, y), 2];")
1736 (test-ps-js add-subtract-precedence
1737 (- x (+ y z))
1738 "x - (y + z);")
1740 (test-ps-js ps-inline-toplevel
1741 (ps-inline (foo))
1742 "'javascript:' + 'foo()';")
1744 (test-ps-js no-clause-progn-exp
1745 (setf x (progn))
1746 "x = null;")
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)
1754 ((bar))
1755 (t 456)))
1756 "x = foo() ? 123 : (bar() ? null : 456);")
1758 (test-ps-js let-no-body
1759 (return (let ((foo bar))))
1760 "var foo = bar;
1761 return null;")