Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit e9def365674963b1a67c738609017ac695ade2bf 1 parent a2cbc19
@timmc timmc authored
Showing with 3 additions and 18 deletions.
  1. +3 −18 src/trycljs/models/compile.clj
View
21 src/trycljs/models/compile.clj
@@ -1,24 +1,9 @@
(ns trycljs.models.compile
- (:import (java.io File))
- (:require [clojure.java.io :as io]
- [clojure.java.shell :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))))
@AlexBaranosky Owner

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."
Please sign in to comment.
Something went wrong with that request. Please try again.