213213 (cond-> column
214214 (.endsWith column " )" ) (string/replace " )" " " )))]))
215215
216- (defn parse-file [file opts]
217- (if (re-find #"http://localhost:9000/" file)
218- (-> file
219- (string/replace #"http://localhost:9000/" " " )
220- (string/replace (Pattern/compile (str " ^" (util/output-directory opts) " /" )) " " ))
221- (if-let [asset-root (:asset-root opts)]
222- (string/replace file asset-root " " )
223- (throw
224- (ex-info (str " Could not relativize URL " file)
225- {:type :parse-stacktrace
226- :reason :relativize-url })))))
216+ (defn parse-file [{:keys [host port] :as repl-env} file {:keys [asset-path] :as opts}]
217+ (let [base-url-pattern (Pattern/compile (str " http://" host " :" port " /" ))]
218+ (if (re-find base-url-pattern file)
219+ (-> file
220+ (string/replace base-url-pattern " " )
221+ (string/replace
222+ (Pattern/compile
223+ (str " ^" (or asset-path (util/output-directory opts)) " /" )) " " ))
224+ (if-let [asset-root (:asset-root opts)]
225+ (string/replace file asset-root " " )
226+ (throw
227+ (ex-info (str " Could not relativize URL " file)
228+ {:type :parse-stacktrace
229+ :reason :relativize-url }))))))
227230
228231; ; -----------------------------------------------------------------------------
229232; ; Chrome Stacktrace
230233
231234(defn chrome-st-el->frame
232- [st-el opts]
235+ [repl-env st-el opts]
233236 (let [xs (-> st-el
234237 (string/replace #"\s +at\s +" " " )
235238 (string/split #"\s +" ))
238241 [(first xs) (last xs)])
239242 [file line column] (parse-file-line-column flc)]
240243 (if (and file function line column)
241- {:file (parse-file file opts)
244+ {:file (parse-file repl-env file opts)
242245 :function (string/replace function #"Object\. " " " )
243246 :line line
244247 :column column}
249252 :column nil }))))
250253
251254(comment
252- (chrome-st-el->frame
255+ (chrome-st-el->frame { :host " localhost " :port 9000 }
253256 " \t at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)" {})
254257 )
255258
259262 string/split-lines
260263 (drop-while #(.startsWith % " Error" ))
261264 (take-while #(not (.startsWith % " at eval" )))
262- (map #(chrome-st-el->frame % opts))
265+ (map #(chrome-st-el->frame repl-env % opts))
263266 (remove nil?)
264267 vec))
265268
266269(comment
267- (parse-stacktrace nil
270+ (parse-stacktrace { :host " localhost " :port 9000 }
268271 " Error: 1 is not ISeqable
269272 at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
270273 at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
279282 {:ua-product :chrome }
280283 nil )
281284
282- (parse-stacktrace nil
285+ (parse-stacktrace { :host " localhost " :port 9000 }
283286 " Error: 1 is not ISeqable
284287 at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
285288 at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
299302; ; Safari Stacktrace
300303
301304(defn safari-st-el->frame
302- [st-el opts]
305+ [repl-env st-el opts]
303306 (let [[function flc] (if (re-find #"@" st-el)
304307 (string/split st-el #"@" )
305308 [nil st-el])
306309 [file line column] (parse-file-line-column flc)]
307310 (if (and file function line column)
308- {:file (parse-file file opts)
311+ {:file (parse-file repl-env file opts)
309312 :function function
310313 :line line
311314 :column column}
316319 :column nil }))))
317320
318321(comment
319- (safari-st-el->frame
322+ (safari-st-el->frame { :host " localhost " :port 9000 }
320323 " cljs$core$seq@http://localhost:9000/out/cljs/core.js:4259:17" {})
324+
325+ (safari-st-el->frame {:host " localhost" :port 9000 }
326+ " cljs$core$seq@http://localhost:9000/js/cljs/core.js:4259:17" {:asset-path " js" })
321327 )
322328
323329(defmethod parse-stacktrace :safari
327333 (drop-while #(.startsWith % " Error" ))
328334 (take-while #(not (.startsWith % " eval code" )))
329335 (remove string/blank?)
330- (map #(safari-st-el->frame % opts))
336+ (map #(safari-st-el->frame repl-env % opts))
331337 (remove nil?)
332338 vec))
333339
@@ -382,13 +388,13 @@ http://localhost:9000/out/goog/events/events.js:276:42"
382388 (string/replace #"\/ " " " ))))
383389
384390(defn firefox-st-el->frame
385- [st-el opts]
391+ [repl-env st-el opts]
386392 (let [[function flc] (if (re-find #"@" st-el)
387393 (string/split st-el #"@" )
388394 [nil st-el])
389395 [file line column] (parse-file-line-column flc)]
390396 (if (and file function line column)
391- {:file (parse-file file opts)
397+ {:file (parse-file repl-env file opts)
392398 :function (firefox-clean-function function)
393399 :line line
394400 :column column}
@@ -399,19 +405,19 @@ http://localhost:9000/out/goog/events/events.js:276:42"
399405 :column nil }))))
400406
401407(comment
402- (firefox-st-el->frame
408+ (firefox-st-el->frame { :host " localhost " :port 9000 }
403409 " cljs$core$seq@http://localhost:9000/out/cljs/core.js:4258:8" {})
404410
405- (firefox-st-el->frame
411+ (firefox-st-el->frame { :host " localhost " :port 9000 }
406412 " cljs.core.map</cljs$core$map__2/</<@http://localhost:9000/out/cljs/core.js:16971:87" {})
407413
408- (firefox-st-el->frame
414+ (firefox-st-el->frame { :host " localhost " :port 9000 }
409415 " cljs.core.map</cljs$core$map__2/</<@http://localhost:9000/out/cljs/core.js:16971:87" {})
410416
411- (firefox-st-el->frame
417+ (firefox-st-el->frame { :host " localhost " :port 9000 }
412418 " cljs.core.pr_str</cljs$core$pr_str@http://localhost:9000/out/cljs/core.js:29138:8" {})
413419
414- (firefox-st-el->frame
420+ (firefox-st-el->frame { :host " localhost " :port 9000 }
415421 " cljs.core.pr_str</cljs$core$pr_str__delegate@http://localhost:9000/out/cljs/core.js:29129:8" {})
416422 )
417423
@@ -422,7 +428,7 @@ http://localhost:9000/out/goog/events/events.js:276:42"
422428 (drop-while #(.startsWith % " Error" ))
423429 (take-while #(= (.indexOf % " > eval" ) -1 ))
424430 (remove string/blank?)
425- (map #(firefox-st-el->frame % opts))
431+ (map #(firefox-st-el->frame repl-env % opts))
426432 (remove nil?)
427433 vec))
428434
@@ -502,6 +508,18 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
502508 repl /IJavaScriptEnv
503509 (-setup [this opts]
504510 (setup this opts))
511+ (-evaluate [this _ _ js]
512+ (binding [browser-state (:browser-state this)
513+ ordering (:ordering this)
514+ es (:es this)
515+ server/state (:server-state this)]
516+ (browser-eval js)))
517+ (-load [this provides url]
518+ (load-javascript this provides url))
519+ (-tear-down [this]
520+ (binding [server/state (:server-state this)]
521+ (server/stop ))
522+ (.shutdown (:es this)))
505523 repl /IReplEnvOptions
506524 (-repl-options [this]
507525 {:repl-requires
@@ -517,24 +535,13 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
517535 (pr-str
518536 {:ua-product (clojure.browser.repl/get-ua-product )
519537 :value (str ~e)
520- :stacktrace (.-stack ~e)})))))
521- (-evaluate [this _ _ js]
522- (binding [browser-state (:browser-state this)
523- ordering (:ordering this)
524- es (:es this)
525- server/state (:server-state this)]
526- (browser-eval js)))
527- (-load [this provides url]
528- (load-javascript this provides url))
529- (-tear-down [this]
530- (binding [server/state (:server-state this)]
531- (server/stop ))
532- (.shutdown (:es this))))
538+ :stacktrace (.-stack ~e)}))))))
533539
534540(defn repl-env*
535541 [{:keys [output-dir] :as opts}]
536542 (merge (BrowserEnv. )
537- {:port 9000
543+ {:host " localhost"
544+ :port 9000
538545 :working-dir (->> [" .repl" (util/clojurescript-version )]
539546 (remove empty?) (string/join " -" ))
540547 :serve-static true
0 commit comments