Permalink
Browse files

support for getter/setter syntax (recently added in parse-js)

  • Loading branch information...
1 parent e31dc79 commit c267c1097d41bf741b7385b7406bf07307a7cf75 @mishoo committed Dec 25, 2010
Showing with 29 additions and 12 deletions.
  1. +1 −0 build/build.sh
  2. +1 −1 build/main.lisp
  3. +22 −9 src/codegen.lisp
  4. +5 −2 src/walker.lisp
View
@@ -5,6 +5,7 @@ DIR=`dirname $SCRIPT`
buildapp \
--eval "(proclaim '(optimize (speed 3) (safety 0) (debug 0)))" \
+ --asdf-path ~/lisp/systems \
--asdf-tree ~/quicklisp \
--asdf-path ~/asd \
--load-system cl-uglify-js \
View
@@ -6,7 +6,7 @@
(defun uglify-stream (stream &key (beautify t) no-sequences keep-dead-code mangle-toplevel)
(ast-gen-code
(ast-squeeze
- (ast-mangle (parse-js:parse-js stream)
+ (ast-mangle (parse-js:parse-js stream :ecma-version 5)
:sequences (not no-sequences)
:dead-code (not keep-dead-code))
:toplevel mangle-toplevel)
View
@@ -180,6 +180,15 @@ characters in string S to STREAM."
(ppcre:regex-replace "\\.e" (format nil "~f" n) "e")
"."))))
+ (quote-object-prop (prop)
+ (if (or quote-keys
+ (and (stringp prop)
+ (not (is-identifier prop))))
+ (quote-string prop)
+ (if (numberp prop)
+ (make-number prop)
+ prop)))
+
(gencode (ast)
;; someone tell me how do I trick Emacs to indent this properly.
(push ast stack)
@@ -227,15 +236,19 @@ characters in string S to STREAM."
(join `("{"
,(join (with-indent 1
(mapcar (lambda (p)
- (indent (join `(,(if (or quote-keys
- (and (stringp (car p))
- (not (is-identifier (car p)))))
- (quote-string (car p))
- (if (numberp (car p))
- (make-number (car p))
- (car p)))
- ,(gencode (cdr p)))
- ": " ":"))) props))
+ (indent
+ (case (cadr p)
+ ((:get :set) (add-spaces
+ (stick
+ (add-spaces (string-downcase (string (cadr p)))
+ (quote-object-prop (car p)))
+ "("
+ (join (mapcar #'make-name (elt p 4)) ", " ",")
+ ")")
+ (format-body (elt p 5))))
+ (t (join `(,(quote-object-prop (car p))
+ ,(gencode (cdr p)))
+ ": " ":"))))) props))
#.(format nil ",~%") ",")
,(indent "}")) *codegen-newline*)))
View
@@ -40,8 +40,11 @@
(:name (name) `(:name ,name))
(:new (ctor args) `(:new ,(,walk ctor) ,(mymap #',walk args)))
(:num (n) `(:num ,n))
- (:object (props) `(:object ,(mymap (lambda (def)
- `(,(car def) ,@(,walk (cdr def)))) props)))
+ (:object (props)
+ `(:object ,(mymap (lambda (def)
+ (case (cadr def)
+ ((:set :get) `(,(car def) ,(cadr def) ,@(walk (cddr def))))
+ (t `(,(car def) ,@(,walk (cdr def)))))) props)))
(:regexp (pattern modifiers) `(:regexp ,pattern ,modifiers))
(:return (expr) `(:return ,(,walk expr)))
(:seq (one two) `(:seq ,(,walk one) ,(,walk two)))

0 comments on commit c267c10

Please sign in to comment.