cljsjs

mikebelanger 2016-11-27T15:29:21.001265Z

Hey has anyone tried the auto externs generator lately? I get a failed response for a certain file and I'm unsure why: http://www.dotnetwise.com/Code/Externs/index.html

mikebelanger 2016-11-27T15:30:45.001266Z

I'm trying to generate externs for this file: https://raw.githubusercontent.com/Tonejs/Tone.js/master/build/Tone.js

mikebelanger 2016-11-27T15:30:49.001267Z

I feel like I'm missing something

mikebelanger 2016-11-27T17:35:32.001269Z

I'm wary of manually creating the externs simply due to the work (Tonejs is ~ 20k lines) and find out its not even compatible, but referencing this closed PR https://github.com/google/closure-compiler/pull/1048 (by a core cljs contributor) it looks like AMD modules are at the very least, Google Closure compatible. Might just be the auto-externs generator doesn't cover all usage cases, and I'll have to just manually do these externs 😞

juhoteperi 2016-11-27T17:38:45.001271Z

@mikebelanger Did you try this generator: http://michaelmclellan.me/javascript-externs-generator/?

juhoteperi 2016-11-27T17:40:09.001272Z

And even if you need to create externs manually, you don't need to go through the code, it is easier to just go through API docs: https://tonejs.github.io/docs/#Split

mikebelanger 2016-11-27T17:40:10.001273Z

@juhoteperi yes, I had to use the <http://raw.github.com|raw.github.com> -> <http://rawgit.com|rawgit.com> trick with that, and it just repeatedly hanged (using FF)

mikebelanger 2016-11-27T17:41:02.001274Z

@juhoteperi you mean just list off each module in the API?

juhoteperi 2016-11-27T17:41:08.001275Z

Pretty much yeah

juhoteperi 2016-11-27T17:41:16.001276Z

Each class & their methods

juhoteperi 2016-11-27T17:42:13.001277Z

There is also some change that Closure module processing world work in this case.

mikebelanger 2016-11-27T17:42:28.001278Z

Tone.js has a lot of type annotations, do you think those would be useful to Closure compiler?

juhoteperi 2016-11-27T17:42:43.001279Z

No

juhoteperi 2016-11-27T17:43:24.001280Z

Not at least if you are using the lib as foreign-lib, with the concatenated file

mikebelanger 2016-11-27T17:44:31.001281Z

Sorry, I don't know what you mean by concatenated file, like the minified file?

juhoteperi 2016-11-27T17:44:35.001282Z

Yes

juhoteperi 2016-11-27T17:45:21.001283Z

concatenated file = all source in one file, minified = all source in one file + minified

mikebelanger 2016-11-27T17:48:36.001284Z

@juhoteperi Ah I see, thanks. I might just use the Tone.js source (un-minified, but concatenated), and delete everything in the blocks, and save it as an extern. There's a lot of prototypes, objects, etc.

juhoteperi 2016-11-27T17:49:27.001285Z

That is one way.

juhoteperi 2016-11-27T17:50:01.001286Z

But just keep in mind that only the public API matters, the functions you could call from Cljs

juhoteperi 2016-11-27T17:50:23.001287Z

There are lots of internal functions that don't need to be present in the extern

mikebelanger 2016-11-27T17:54:00.001289Z

@juhoteperi true, oh I see what you mean -- because if I cross-reference the API to figure out which functions are public vs. which aren't, I'm probably going to spend as much time doing that as just listing them off in a new file anyways.

juhoteperi 2016-11-27T17:55:56.001290Z

Btw. they have TypeScript annotations which also lists the public API: https://github.com/Tonejs/TypeScript/blob/master/Tone.d.ts

mikebelanger 2016-11-27T18:01:11.001292Z

@juhoteperi oh cool, good find! Translating that doesn't look like it would take nearly as long

mikebelanger 2016-11-27T18:23:37.001294Z

@juhoteperi well thanks a lot for your help, its going to make my life much easier

mikebelanger 2016-11-27T20:38:34.001295Z

Ok, I'm just writing them up, and seeing there's lots of methods inside of other prototype functions. Seeing that using this in externs is strongly discouraged, would the best bet be writing the full method name (ie Tone.Foo.prototype.bar = function() {})?

mikebelanger 2016-11-27T20:42:57.001296Z

At least, it appears Google Closure doesn't like this due to its context-dependent reference http://stackoverflow.com/questions/13109358/javascript-this-keyword-and-closure-compiler-warnings

juhoteperi 2016-11-27T20:47:37.001298Z

Full name is fine

mikebelanger 2016-11-27T23:47:02.001299Z

alright thanks