This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-30
Channels
- # adventofcode (11)
- # beginners (155)
- # boot (627)
- # cider (64)
- # cljs-dev (110)
- # cljsrn (36)
- # clojure (290)
- # clojure-austin (21)
- # clojure-russia (2)
- # clojure-spec (2)
- # clojure-uk (21)
- # clojurescript (81)
- # code-reviews (2)
- # core-async (33)
- # cursive (6)
- # datomic (9)
- # emacs (1)
- # hoplon (472)
- # instaparse (1)
- # lein-figwheel (4)
- # luminus (9)
- # om (2)
- # protorepl (10)
- # re-frame (10)
- # reagent (48)
- # schema (2)
- # sql (5)
- # untangled (17)
- # vim (1)
- # yada (108)
I have a problem with the ClojureScript constants table (the constants_table.js file) being emitted after JavaScript that tries to use those constants. I get a lot of errors about calling functions on undefined. Those calls are all on Clojure keywords and symbols that get defined later in the same JavaScript file via the constants_table.js file. In the list of sorted dependencies of a module I would expect the constants_table.js file before those namespaces that are using keywords or symbols from the constant table. Does anyone know if this assumption is correct?
I'm trying to update to the latest ClojureScript version and noticed this happening on advanced builds using Google Closure Modules since the Google Closure Compiler was updated CLJS-1762.
@bhauman so playing around with :foreign-libs
expansion - there’s still a problem - figure out the provided name for the lib
but the imports needs to be relative I’m pretty sure, I tried this already with Node.js and it worked just fine a long while ago
lets set the JS stuff aside for now - I’m pretty sure works, or won’t be that hard - people are already doing this with ES6 code bases
@r0man just sounds like a bug - though it also sounds very unlikely - since it would effect all production code
@dnolen yes, trying to find a minimal case. just not that easy 🙂 Trying to understand what's going on in the compiler at the moment. I think I found something suspicious, just not sure if my assumptions are correct.
Would you aggree that at his point https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L1202 the constants_table.js file should be before namespaces that make use of ClojureScript keywords or symbols? In my project that's not the case, which I think is strange.
@r0man oh right - sorry you’re talking about modules - yeah we probably need a special case here
if you’re not using modules then we have some hard-coded stuff to put it in the right place
yes, I mean modules. In my case this file is just somewhere in the middle of the sorted list. And namespaces that use keywords come before.
perhaps the easiest thing would be to look at how hard it would be to just move the constants table into the right place
a generic thing isn’t all that important here since constants table is a real special case
@dnolen Now I wonder where the constant table actually should be? I think the correct place would be for keyword constants directly after the definition of Keyword type and for symbol constants directly after the definition of the Symbol type.
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L718-L728
Do you mean with "`cljs.core` is completely static for a reason" we only get away with this because symbols and keywords are not used at the top level?
it maybe that Google Closure just needs a provide + require to work in the constants table file
but I think for google closure to pick it up correctly I would need to add a require as well in all namespaces that use it
@r0man changing code emission is preferred to mucking around with the compiler in this case
@dnolen I got it working by adding a goog.provide to the constants_table.js file and a goog.require to every ClojureScript file the compiler generates. I have 2 more questions
1. Right now I use the namespace "constant-table" , same as the file. Should I use a name under cljs.core, like cljs.core.constants?
@r0man oh, I wasn’t suggesting add it as dep to every file - just whether the single require was enough
that is that the constants file requires cljs.core
and it comes first in the module building anyway
@dnolen hmm, do you mean just a goog.provide("constants_table") and a goog.require("cljs.core") in the constants_table.js file?
another namespace that uses keywords could also just require cljs.core and google closure could sort it the other namespace and constants_table in 2 different ways
I think this is also the reason why this used to work in older versions of clojurescript.
@dnolen with regards to constants_table, a while ago I wrote a Closure Compiler pass do optimize the constants for me without any help of the CLJS compiler