Skip to content

Commit

Permalink
Adds the quote special form, allows inserting raw javascript strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
arohner committed Nov 9, 2010
1 parent 798ccaa commit d038f59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject scriptjure "0.1.19"
(defproject scriptjure "0.1.20"
:description "a clojure DSL for generating javascript"
:url "http://github.com/arohner/scriptjure"
:dependencies [[org.clojure/clojure "1.2.0"]
Expand Down
5 changes: 4 additions & 1 deletion src/com/reasonr/scriptjure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
(defmethod emit :default [expr]
(str expr))

(def special-forms (set ['var '. '.. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do 'aget 'while 'doseq 'str 'inc! 'dec! 'dec 'inc 'defined? 'and 'or '?]))
(def special-forms (set ['var '. '.. 'if 'funcall 'fn 'quote 'set! 'return 'delete 'new 'do 'aget 'while 'doseq 'str 'inc! 'dec! 'dec 'inc 'defined? 'and 'or '?]))

(def prefix-unary-operators (set ['!]))

Expand Down Expand Up @@ -199,6 +199,9 @@
(defmethod emit-special 'or [type [_ & more]]
(apply str (interpose "||" (map emit more))))

(defmethod emit-special 'quote [type [_ & more]]
(apply str more))

(defn emit-do [exprs]
(str/join "" (map (comp statement emit) exprs)))

Expand Down
4 changes: 4 additions & 0 deletions test/test_scriptjure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
(is (= (strip-whitespace (js (doseq [i [1 2 3] j [4 5]] (foo i j))))
"for (i in [1, 2, 3]) { for (j in [4, 5]) { foo(i, j); } }")))

(deftest test-quote
(is (= (strip-whitespace (js (do (+ 1 1) (quote "alert()"))))
"(1 + 1); alert();")))

(deftest test-combine-forms
(let [stuff (js* (do
(var x 3)
Expand Down

0 comments on commit d038f59

Please sign in to comment.