ClojureScript

Exception when compiler output is redirected

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    windows 7
  • Patch:
    Code

Description

To reproduce on windows 7:
> cljsc ./file.cljs '{:optimizations :advanced :source-map "file.map.js"}' > file.js

results in the following stack trace:

Exception in thread "main" java.lang.IllegalArgumentException: No implementation
of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: c
lojure.lang.Keyword
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:541)
at clojure.java.io$fn_8496$G8491_8501.invoke(io.clj:35)
at clojure.java.io$file.invoke(io.clj:413)
at cljs.closure$add_source_map_link.invoke(closure.clj:940)
at cljs.closure$build.invoke(closure.clj:986)
at cljs.closure$build.invoke(closure.clj:945)
at user$eval2565.invoke(cljsc.clj:21)
at clojure.lang.Compiler.eval(Compiler.java:6619)
at clojure.lang.Compiler.load(Compiler.java:7064)
at clojure.lang.Compiler.loadFile(Compiler.java:7020)
at clojure.main$load_script.invoke(main.clj:294)
at clojure.main$script_opt.invoke(main.clj:356)
at clojure.main$main.doInvoke(main.clj:440)
at clojure.lang.RestFn.invoke(RestFn.java:436)
at clojure.lang.Var.invoke(Var.java:423)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)

Source map file is generated but no file.js is generated.

Expected: When no output-to is specified then resulting js file has a sourceMappingURL that corresponding to where source map file is placed.

Problem:
add-source-map-link function in closure.clj is called with output-to :print when no output-to is specified. The code then tries to open a the file :print.

Fix:
In this case point sourceMappingURL to where resulting mapping file is placed:

cljsc ./file.cljs '{:optimizations :advanced :source-map "../file.map.js"}' > file.js

should result in
//@ sourceMappingURL=../file.map.js

Attached patch fixes this. It also changes //@ to //# (new format).

Weakness in solution: Only works for redirect to current dir. If the redirect is not to current directory ( [...] > ./out/file.js) then sourceMappingURL is not correct - but the compiler does not throw an exception.

I have only tested on windows.

Activity

Hide
Sean Grove added a comment -

Tested on osx, repro'd the issue. After applying the patch, issue is resolved. All tests still pass locally with patch applied. Haven't tried out the patch with an actual project though, just a single file.

Show
Sean Grove added a comment - Tested on osx, repro'd the issue. After applying the patch, issue is resolved. All tests still pass locally with patch applied. Haven't tried out the patch with an actual project though, just a single file.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: