213
213
(cond-> column
214
214
(.endsWith column " )" ) (string/replace " )" " " )))]))
215
215
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 }))))))
227
230
228
231
; ; -----------------------------------------------------------------------------
229
232
; ; Chrome Stacktrace
230
233
231
234
(defn chrome-st-el->frame
232
- [st-el opts]
235
+ [repl-env st-el opts]
233
236
(let [xs (-> st-el
234
237
(string/replace #"\s +at\s +" " " )
235
238
(string/split #"\s +" ))
238
241
[(first xs) (last xs)])
239
242
[file line column] (parse-file-line-column flc)]
240
243
(if (and file function line column)
241
- {:file (parse-file file opts)
244
+ {:file (parse-file repl-env file opts)
242
245
:function (string/replace function #"Object\. " " " )
243
246
:line line
244
247
:column column}
249
252
:column nil }))))
250
253
251
254
(comment
252
- (chrome-st-el->frame
255
+ (chrome-st-el->frame { :host " localhost " :port 9000 }
253
256
" \t at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)" {})
254
257
)
255
258
259
262
string/split-lines
260
263
(drop-while #(.startsWith % " Error" ))
261
264
(take-while #(not (.startsWith % " at eval" )))
262
- (map #(chrome-st-el->frame % opts))
265
+ (map #(chrome-st-el->frame repl-env % opts))
263
266
(remove nil?)
264
267
vec))
265
268
266
269
(comment
267
- (parse-stacktrace nil
270
+ (parse-stacktrace { :host " localhost " :port 9000 }
268
271
" Error: 1 is not ISeqable
269
272
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
270
273
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
279
282
{:ua-product :chrome }
280
283
nil )
281
284
282
- (parse-stacktrace nil
285
+ (parse-stacktrace { :host " localhost " :port 9000 }
283
286
" Error: 1 is not ISeqable
284
287
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
285
288
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
299
302
; ; Safari Stacktrace
300
303
301
304
(defn safari-st-el->frame
302
- [st-el opts]
305
+ [repl-env st-el opts]
303
306
(let [[function flc] (if (re-find #"@" st-el)
304
307
(string/split st-el #"@" )
305
308
[nil st-el])
306
309
[file line column] (parse-file-line-column flc)]
307
310
(if (and file function line column)
308
- {:file (parse-file file opts)
311
+ {:file (parse-file repl-env file opts)
309
312
:function function
310
313
:line line
311
314
:column column}
316
319
:column nil }))))
317
320
318
321
(comment
319
- (safari-st-el->frame
322
+ (safari-st-el->frame { :host " localhost " :port 9000 }
320
323
" 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" })
321
327
)
322
328
323
329
(defmethod parse-stacktrace :safari
327
333
(drop-while #(.startsWith % " Error" ))
328
334
(take-while #(not (.startsWith % " eval code" )))
329
335
(remove string/blank?)
330
- (map #(safari-st-el->frame % opts))
336
+ (map #(safari-st-el->frame repl-env % opts))
331
337
(remove nil?)
332
338
vec))
333
339
@@ -382,13 +388,13 @@ http://localhost:9000/out/goog/events/events.js:276:42"
382
388
(string/replace #"\/ " " " ))))
383
389
384
390
(defn firefox-st-el->frame
385
- [st-el opts]
391
+ [repl-env st-el opts]
386
392
(let [[function flc] (if (re-find #"@" st-el)
387
393
(string/split st-el #"@" )
388
394
[nil st-el])
389
395
[file line column] (parse-file-line-column flc)]
390
396
(if (and file function line column)
391
- {:file (parse-file file opts)
397
+ {:file (parse-file repl-env file opts)
392
398
:function (firefox-clean-function function)
393
399
:line line
394
400
:column column}
@@ -399,19 +405,19 @@ http://localhost:9000/out/goog/events/events.js:276:42"
399
405
:column nil }))))
400
406
401
407
(comment
402
- (firefox-st-el->frame
408
+ (firefox-st-el->frame { :host " localhost " :port 9000 }
403
409
" cljs$core$seq@http://localhost:9000/out/cljs/core.js:4258:8" {})
404
410
405
- (firefox-st-el->frame
411
+ (firefox-st-el->frame { :host " localhost " :port 9000 }
406
412
" cljs.core.map</cljs$core$map__2/</<@http://localhost:9000/out/cljs/core.js:16971:87" {})
407
413
408
- (firefox-st-el->frame
414
+ (firefox-st-el->frame { :host " localhost " :port 9000 }
409
415
" cljs.core.map</cljs$core$map__2/</<@http://localhost:9000/out/cljs/core.js:16971:87" {})
410
416
411
- (firefox-st-el->frame
417
+ (firefox-st-el->frame { :host " localhost " :port 9000 }
412
418
" cljs.core.pr_str</cljs$core$pr_str@http://localhost:9000/out/cljs/core.js:29138:8" {})
413
419
414
- (firefox-st-el->frame
420
+ (firefox-st-el->frame { :host " localhost " :port 9000 }
415
421
" cljs.core.pr_str</cljs$core$pr_str__delegate@http://localhost:9000/out/cljs/core.js:29129:8" {})
416
422
)
417
423
@@ -422,7 +428,7 @@ http://localhost:9000/out/goog/events/events.js:276:42"
422
428
(drop-while #(.startsWith % " Error" ))
423
429
(take-while #(= (.indexOf % " > eval" ) -1 ))
424
430
(remove string/blank?)
425
- (map #(firefox-st-el->frame % opts))
431
+ (map #(firefox-st-el->frame repl-env % opts))
426
432
(remove nil?)
427
433
vec))
428
434
@@ -502,6 +508,18 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
502
508
repl /IJavaScriptEnv
503
509
(-setup [this opts]
504
510
(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)))
505
523
repl /IReplEnvOptions
506
524
(-repl-options [this]
507
525
{:repl-requires
@@ -517,24 +535,13 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
517
535
(pr-str
518
536
{:ua-product (clojure.browser.repl/get-ua-product )
519
537
: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)}))))))
533
539
534
540
(defn repl-env*
535
541
[{:keys [output-dir] :as opts}]
536
542
(merge (BrowserEnv. )
537
- {:port 9000
543
+ {:host " localhost"
544
+ :port 9000
538
545
:working-dir (->> [" .repl" (util/clojurescript-version )]
539
546
(remove empty?) (string/join " -" ))
540
547
:serve-static true
0 commit comments