Skip to content

Commit

Permalink
support for getter/setter syntax (recently added in parse-js)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishoo committed Dec 25, 2010
1 parent e31dc79 commit c267c10
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion build/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 22 additions & 9 deletions src/codegen.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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*)))

Expand Down
7 changes: 5 additions & 2 deletions src/walker.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit c267c10

Please sign in to comment.