(js-expr value)
(js-format "){")
(dolist (case cases)
- (destructuring-bind (x &body body) case
- (if (eq x 'default)
- (js-format "default: ")
- (progn
- (unless (or (stringp x) (numberp x))
- (error "Non-constant switch case `~S'." (car cases)))
- (js-format "case ")
- (js-expr x)
- (js-format ":")))
- (mapc #'js-stmt body)))
+ (cond
+ ((and (consp case) (eq (car case) 'case))
+ (js-format "case ")
+ (let ((value (cadr case)))
+ (unless (or (stringp value) (integerp value))
+ (error "Non-constant switch case `~S'." value))
+ (js-expr value))
+ (js-format ":"))
+ ((eq case 'default)
+ (js-format "default:"))
+ (t
+ (js-stmt case))))
(js-format "}")))
(for
(destructuring-bind ((start condition step) &body body) (cdr form)
,@(with-collect
(dotimes (idx n-optional-arguments)
(let ((arg (nth idx optional-arguments)))
- (collect `(,(+ idx n-required-arguments)
- (= ,(make-symbol (translate-variable (car arg)))
- ,(ls-compile (cadr arg)))
- ,(when (third arg)
- `(= ,(make-symbol (translate-variable (third arg)))
- ,(ls-compile nil)))))))
- (collect `(default (break))))))))
+ (collect `(case ,(+ idx n-required-arguments)))
+ (collect `(= ,(make-symbol (translate-variable (car arg)))
+ ,(ls-compile (cadr arg))))
+ (collect (when (third arg)
+ `(= ,(make-symbol (translate-variable (third arg)))
+ ,(ls-compile nil))))))
+ (collect 'default)
+ (collect '(break)))))))
(defun compile-lambda-rest (ll)
(let ((n-required-arguments (length (ll-required-arguments ll)))