Permalink
Browse files

764

  • Loading branch information...
1 parent f6d743b commit 953819ff7e4250e593489445ae650856cd0ce1b7 @gtrak gtrak committed with swannodette Feb 16, 2014
Showing with 67 additions and 41 deletions.
  1. +42 −41 src/clj/cljs/repl.clj
  2. +25 −0 test/clj/cljs/repl_tests.clj
View
@@ -78,47 +78,48 @@
(evaluate-form repl-env env filename form identity))
([repl-env env filename form wrap]
(try
- (let [ast (ana/analyze env form)
- js (comp/emit-str ast)
- wrap-js
- (if (:source-map repl-env)
- (binding [comp/*source-map-data*
- (atom {:source-map (sorted-map)
- :gen-col 0
- :gen-line 0})]
- (let [js (comp/emit-str (ana/no-warn (ana/analyze env (wrap form))))
- t (System/currentTimeMillis)]
- (str js
- "\n//# sourceURL=repl-" t ".js"
- "\n//# sourceMappingURL=data:application/json;base64,"
- (DatatypeConverter/printBase64Binary
- (.getBytes
- (sm/encode
- {(str "repl-" t ".cljs")
- (:source-map @comp/*source-map-data*)}
- {:lines (+ (:gen-line @comp/*source-map-data*) 3)
- :file (str "repl-" t ".js")
- :sources-content
- [(or (:source (meta form))
- ;; handle strings / primitives without metadata
- (with-out-str (pr form)))]})
- "UTF-8")))))
- (comp/emit-str (ana/no-warn (ana/analyze env (wrap form)))))]
- (when (= (:op ast) :ns)
- (load-dependencies repl-env (into (vals (:requires ast))
- (distinct (vals (:uses ast))))))
- (when *cljs-verbose*
- (print js))
- (let [ret (-evaluate repl-env filename (:line (meta form)) wrap-js)]
- (case (:status ret)
- ;;we eat ns errors because we know goog.provide() will throw when reloaded
- ;;TODO - file bug with google, this is bs error
- ;;this is what you get when you try to 'teach new developers'
- ;;via errors (goog/base.js 104)
- :error (display-error ret form)
- :exception (display-error ret form
- #(prn "Error evaluating:" form :as js))
- :success (:value ret))))
+ (binding [ana/*cljs-file* filename]
+ (let [ast (ana/analyze env form)
+ js (comp/emit-str ast)
+ wrap-js
+ (if (:source-map repl-env)
+ (binding [comp/*source-map-data*
+ (atom {:source-map (sorted-map)
+ :gen-col 0
+ :gen-line 0})]
+ (let [js (comp/emit-str (ana/no-warn (ana/analyze env (wrap form))))
+ t (System/currentTimeMillis)]
+ (str js
+ "\n//# sourceURL=repl-" t ".js"
+ "\n//# sourceMappingURL=data:application/json;base64,"
+ (DatatypeConverter/printBase64Binary
+ (.getBytes
+ (sm/encode
+ {(str "repl-" t ".cljs")
+ (:source-map @comp/*source-map-data*)}
+ {:lines (+ (:gen-line @comp/*source-map-data*) 3)
+ :file (str "repl-" t ".js")
+ :sources-content
+ [(or (:source (meta form))
+ ;; handle strings / primitives without metadata
+ (with-out-str (pr form)))]})
+ "UTF-8")))))
+ (comp/emit-str (ana/no-warn (ana/analyze env (wrap form)))))]
+ (when (= (:op ast) :ns)
+ (load-dependencies repl-env (into (vals (:requires ast))
+ (distinct (vals (:uses ast))))))
+ (when *cljs-verbose*
+ (print js))
+ (let [ret (-evaluate repl-env filename (:line (meta form)) wrap-js)]
+ (case (:status ret)
+ ;;we eat ns errors because we know goog.provide() will throw when reloaded
+ ;;TODO - file bug with google, this is bs error
+ ;;this is what you get when you try to 'teach new developers'
+ ;;via errors (goog/base.js 104)
+ :error (display-error ret form)
+ :exception (display-error ret form
+ #(prn "Error evaluating:" form :as js))
+ :success (:value ret)))))
(catch Throwable ex
(.printStackTrace ex)
(println (str ex))))))
@@ -0,0 +1,25 @@
+(ns cljs.repl-tests
+ (:require [clojure.java.io :as io]
+ [cljs.analyzer :as ana]
+ [cljs.env :as env]
+ [cljs.repl :as repl]
+ [cljs.repl.rhino :as rhino])
+ (:use clojure.test))
+
+
+(deftest file-info
+ (let [repl-env (rhino/repl-env)
+ compiler-env (env/default-compiler-env)
+ repl-env (assoc repl-env ::env/compiler compiler-env)]
+ (env/with-compiler-env compiler-env
+ (binding [ana/*cljs-ns* 'cljs.user]
+ (repl/-setup repl-env)))
+ (let [assoc-info (get-in @compiler-env [:cljs.analyzer/namespaces 'cljs.core :defs 'assoc])
+ {:keys [file line]} assoc-info]
+
+ (is assoc-info)
+ (is (number? line))
+ (is file)
+ (and file
+ (is (io/resource file))))))
+

0 comments on commit 953819f

Please sign in to comment.