Skip to content
Browse files

Use compiler's API directly -- no more calls out to the FS.

  • Loading branch information...
1 parent a2cbc19 commit e9def365674963b1a67c738609017ac695ade2bf @timmc timmc committed Dec 17, 2011
Showing with 3 additions and 18 deletions.
  1. +3 −18 src/trycljs/models/compile.clj
21 src/trycljs/models/compile.clj
@@ -1,24 +1,9 @@
(ns trycljs.models.compile
- (:import ( File))
- (:require [ :as io]
- [ :as sh]
- [cljs.compiler :as comp]))
+ (:require [cljs.compiler :as comp]))
-(def compiler (io/file "resources" "private" "cljs-compiler" "bin" "cljsc"))
-(defn compile-expr [cljs]
+(defn compile-expr [cljs-expr]
"Write text to temp file, compile, and delete the input file."
- (let [tin (File/createTempFile "trycljs-" ".cljs")
- tout (File/createTempFile "trycljs-" ".js")]
- (try
- (spit tin cljs)
- ;; Because CLJS compiler will not write to existing file, we have to
- ;; delete it first. This is not secure!
- (.delete tout)
- (comp/compile-file tin tout)
- (slurp tout)
- (finally (.delete tin)
- (.delete tout)))))
+ (comp/emits (comp/analyze {} (read cljs-expr))))
BAZNEX member

Oh, much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
(defn compile-request [expr]
"Given a CLJS string, produce either a JS string or an Exception."

0 comments on commit e9def36

Please sign in to comment.
Something went wrong with that request. Please try again.