Fixed js-with
[clinton/parenscript.git] / src / js.lisp
index e543092..296d704 100644 (file)
   (flet ((special-append (form elt)
           (let ((len (length form)))
             (if (and (> len 0)
-                     (member (char form (1- len))
-                             '(#\; #\, #\})))
+                      (string= (char form (1- len)) elt))
                 form
                 (concatenate 'string form elt)))))
     (cond ((stringp form)
@@ -270,10 +269,11 @@ this macro."
 (defun import-macros-from-lisp (&rest names)
   "Import the named lisp macros into the js macro expansion"
   (dolist (name names)
-    (undefine-js-compiler-macro name)
-    (setf (gethash (symbol-name name) *js-macro-toplevel*)
-          (lambda (&rest args)
-            (macroexpand `(,name ,@args))))))
+    (let ((name name))
+      (undefine-js-compiler-macro name)
+      (setf (gethash (symbol-name name) *js-macro-toplevel*)
+            (lambda (&rest args)
+              (macroexpand `(,name ,@args)))))))
 
 (defun js-expand-form (expr)
   "Expand a javascript form."
@@ -335,7 +335,7 @@ prefix)."
         ,@(loop for variable in variables
                 do (setf variable (symbol-to-js variable))
                 collect `(setf (slot-value new-context ,variable) (slot-value this ,variable)))
-        (with (new-context)
+        (with new-context
               (return ,expression))))))
 
 (defvar *var-counter* 0)
@@ -1202,8 +1202,8 @@ vice-versa.")
 
 (define-js-compiler-macro with (statement &rest body)
   (make-instance 'js-with
-                :obj (js-compile-to-expression (first statement))
-                :body (js-compile-to-body (cons 'progn body) :indent "  ")))
+                 :obj (js-compile-to-expression statement)
+                 :body (js-compile-to-body (cons 'progn body) :indent "  ")))
 
 (defmethod js-to-statement-strings ((with js-with) start-pos)
   (nconc (dwim-join (list (js-to-strings (with-obj with) (+ start-pos 2)))