Warn on invalid js forms
Description
Environment
Attachments
Activity
David Nolen February 20, 2013 at 2:35 PM
closing this one
David Nolen February 4, 2013 at 4:40 PM
Patch applied to master
Jonas Enlund February 4, 2013 at 4:25 AM
The patch revert455 removes the warnings on js/Foo.bar forms.
David Nolen February 3, 2013 at 9:12 PM
This patch creates issues around using constructors provided by libraries outside ClojureScript and GClosure. Also from Rich's original commit support js prefix, it seems like JS style access after the / was actually intended.
Jonas Enlund February 2, 2013 at 9:28 PM
I'm having second thoughts about this. Looking at the commit when the js namespace was introduced[1] you can see that, for example (goog.global.Math/exp x) was changed to (js/Math.exp x). I'm thinking maybe the js magic namespace is meant to support these kinds of calls?
Another issue I ran into was when using a js library (paper.js) and I was supposed to translate
into ClojureScript. I could not find any way to achieve this except
There is an assertion[2] in the analyzer that prohibits the following alternative:
Removing the assertion (and the call to 'resolve-existing-var') the above expression seems to work just fine.
[1] https://github.com/clojure/clojurescript/commit/954e8529b1ec814f40af77d6035f90e93a9126ea
[2] https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/analyzer.clj#L528
The ClojureScript compiler happily accepts forms like js/Math.MAX_NUMBER and (js/Math.ceil 3.14) which is not valid Clojure code. The correct way to write these expressions in ClojureScript is (.-MAX_NUMBER js/Math) and (.ceil js/Math 3.14).
The ClojureScript analyzer should at least emit a warning when these bad forms are encountered. Preferably compilation should fail but that would probably break lots of existing code.