Fork me on GitHub
#dirac
<
2016-02-01
>
frank14:02:51

is there something that can be done about this warning?

devtools/sanity_hints.js:111: WARNING - dangerous use of this in static method devtools.sanity_hints.type_error_to_string
var self = this;
           ^

Feb 01, 2016 10:36:24 PM com.google.javascript.jscomp.LoggerErrorManager printSummary

frank14:02:15

our CI tests grep for warnings in the cljsbuild log so I can't get my build to pass šŸ˜ž

darwin14:02:32

patch welcome, or disable sanity-hints feature in cljs-devtools

darwin14:02:11

oh, wait maybe disabling it wonā€™t help, this is compile-time warning I guess

frank14:02:01

I wonder what the compiler's issue is with that

frank14:02:13

does it have warnings whenever you use the this-as macro?

darwin14:02:11

I think that warning is a relatively recent thing in google closure compiler, this-as could have been written/designed before

darwin14:02:38

now I understand the issue

darwin14:02:07

actually my code in cljs-devtools is using this-as in prototype method, but it is not obvious to closure compiler

frank14:02:52

it thinks it's a static method

darwin14:02:56

so this warning shows up only when compiling under :advanced mode?

darwin14:02:01

Iā€™m not seeing it normally

frank14:02:10

maybe if type-error-to-string was an anonymous function, it could get the compiler to successfully detect it as a prototype method?

darwin14:02:27

ok, Iā€™m going to try it

frank14:02:52

yes, this is with :advanced optimizations

darwin14:02:15

i think you could just remove cljs-devtools from advanced build

darwin14:02:23

it doesnā€™t work under advanced anyways

frank15:02:03

I tried only including devtools as a dependency for my :devtools lein profile, but the code doesn't compile when I'm not using that profile

frank15:02:27

I'm requiring it with a macro as you suggested a few days earlier

frank15:02:45

(defmacro require-devtools! []
  (when (:devtools env)
    '(js/goog.require "frontend.devtools")))

frank15:02:09

I think because this source file is still in my source path

frank15:02:16

I may need to move it out

darwin15:02:24

good, and also remove frontend/devtools folder from cljs-buildā€™s source-paths

frank15:02:44

thanks for helping me sort out my lein dependencies too simple_smile

frank15:02:53

source paths and whatnot

darwin15:02:03

youā€™re welcome simple_smile

frank15:02:17

is there a way to set a common source path for all lein cljsbuild profiles?

frank15:02:41

I have

:profiles {:devtools {:repl-options {:port 8230
                                       :nrepl-middleware [dirac.nrepl.middleware/dirac-repl]
                                       :init (do
                                               (require 'dirac.agent)
                                               (dirac.agent/boot!))}
                        :env {:devtools true}
                        :cljsbuild {:builds {:dev {:source-paths ["devtools"]}
                                             :whitespace {:source-paths ["devtools"]}
                                             :test {:source-paths ["devtools"]}
                                             :production {:source-paths ["devtools"]}}}
                        
                        :dependencies [[binaryage/devtools "0.5.2"]]}}

frank15:02:55

as you can see i'm specifying :source-paths several times šŸ˜ž

darwin15:02:00

you can use ~(<code>) to eval arbitrary <code> within leiningen project.clj

darwin15:02:40

but that might be tricky, if some other tool reads project.clj directly

darwin15:02:52

e.g. Cursive or maybe your own tasks

darwin15:02:38

that being said, Iā€™m not aware of any lein-cljsbuild feature which would allow you to compose builds somehow

frank15:02:19

I guess I'll do something like ~(zipmap [:dev :whitespace :test :production] (repeat {:source-paths ["devtools"]})

darwin15:02:45

yes, you can define it as a separate lein profile and compose lein profiles instead

darwin15:02:31

but in this case I would just (def shared-source-paths [ā€¦]) and then use :source-paths ~(concat shared-source-paths [ā€¦])

darwin15:02:20

more readable IMO than zipmap

frank15:02:35

I've moved the source file into a different source path but the compiler still seems to be looking for the file šŸ˜ž

frank15:02:40

it just says it can't find it

darwin15:02:15

lein clean? sometimes the caches are causing weird issue

darwin15:02:18

lein clean? sometimes the caches are causing weird issues

frank15:02:47

dumb error on my part -_-

danielcompton20:02:40

I got a bit confused by the devtools sample because it includes devtools in the main dependencies. Am I reading it wrong, or is that project going to include devtools in advanced compilation? https://github.com/binaryage/cljs-devtools-sample/blob/master/project.clj#L7

darwin23:02:16

@danielcompton: hmm, adding something into dependencies does not mean it will be included by cljsbuild

darwin23:02:26

for cljs compilation :source-paths of cljsbuild :build configs is the important piece, and cljs-devtools-sample didnā€™t have any :advanced build until today

darwin23:02:51

and I added it today just to test compilation warnings under :advanced mode, not really use cljs-devtools under :advanced mode

danielcompton23:02:42

What weā€™ve done is made dev-src/init.cljs, and src/init.clj. The dev-src one adds cljs-devtools, the src one doesn't

darwin23:02:07

yes, that is what Iā€™m doing in most of my projects too

danielcompton23:02:10

When we build for dev we add dev-src to the classpath, in prod we use the src one which is a no-op

darwin23:02:50

classpath is not that important, important it what you put into :source-paths of cljsbuild

darwin23:02:59

btw. alternative solution is to require devtools dynamically, by calling js/goog.require (depending on some condition)

darwin23:02:08

weā€™ve discussed it here with frank, it is pretty flexible to use environ library and include cljs-devtools dynamically based on environmental variable

darwin23:02:23

with lein-environ you can define that variable in project.clj

danielcompton23:02:23

yeah sorry, classpath was the wrong term to suse

danielcompton23:02:31

So something like (if js/goog.DEBUG (js/goog.require devtools.core))

darwin23:02:36

yes, but you require your dev-src namespace which does its work to require devtools and calls install!

darwin23:02:05

wait, you want to use macro to generate that js/goog.require snippet only under debug mode

darwin23:02:26

if you generate that require under :advanced, that namespace would not be elided

darwin23:02:50

Iā€™m not sure now js/goog.DEBUG may be special and closure compiler can elide it

darwin23:02:11

let me find an example project with that environ variable setup

darwin23:02:34

I require weasel dynamically here^

darwin23:02:26

when it evals to false, I believe closure compiler elides whole code branch

darwin23:02:41

but what frank did above, he has a macro which generates the code (js/goog.require ā€œsomethingā€) or nothing, this is the safest way I think

darwin23:02:20

when it is not generated, there is not goog.require for something anywhere in the code, so something will be marked as a dead code and eliminated

danielcompton23:02:16

awesome, thanks!