Live data from Hacker News

Closure Compiler in JavaScript

developers.googleblog.com

41–50 of 115 posts

Re: Closure Compiler in JavaScript

#42
post #27
post #19

Earlier quoted context omitted.

The advanced compilation mode does some pretty powerful dead code removal and minification [1]. I guess that is available from plugins in Babel as well but Google has been using it for Gmail, Google.com etc, so it's quite battle tested. [1]: https://developers.google.com/closure/compiler/docs/api-tuto...

In my experience Babel minified better than Closure Compiler with less maintenance of the externs on my part.

Only possible in simplified mode. I highly doubt Babel comes close with full optimizations turned on in a nontrivial codebase.

Re: Closure Compiler in JavaScript

#43
post #40

Earlier quoted context omitted.

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Wait, how is that a thing? I'm a pure JS developer (for now) but I don't understand how something framed on desktop OSs could compile to JS, a browser language. Does it compile to Node maybe? Which version of JS? EDIT: I'm googling now to learn more but I'm not asking to challenge anybody, I'm asking because probably you guys know more than me and I wanna know how this works.

^F JVM on this page: https://github.com/jashkenas/coffeescript/wiki/list-of-langu...

Re: Closure Compiler in JavaScript

#44
post #40

Earlier quoted context omitted.

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Wait, how is that a thing? I'm a pure JS developer (for now) but I don't understand how something framed on desktop OSs could compile to JS, a browser language. Does it compile to Node maybe? Which version of JS? EDIT: I'm googling now to learn more but I'm not asking to challenge anybody, I'm asking because probably you guys know more than me and I wanna know how this works.

> but I don't understand how something framed on desktop OSs could compile to JS, a browser language

GWT compiles Java to JS. If the Closure Compiler is mostly Java code, you only need to implement a few native code things (like replace file loading with just giving it source code as strings) in JS to do a cross compile to javascript.

Re: Closure Compiler in JavaScript

#46
post #27
post #19

Earlier quoted context omitted.

The advanced compilation mode does some pretty powerful dead code removal and minification [1]. I guess that is available from plugins in Babel as well but Google has been using it for Gmail, Google.com etc, so it's quite battle tested. [1]: https://developers.google.com/closure/compiler/docs/api-tuto...

In my experience Babel minified better than Closure Compiler with less maintenance of the externs on my part.

With what plugins? Babel without any plugins or with the common ES2015 plugins doesn't do any minification.

Re: Closure Compiler in JavaScript

#47
post #40

Earlier quoted context omitted.

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Wait, how is that a thing? I'm a pure JS developer (for now) but I don't understand how something framed on desktop OSs could compile to JS, a browser language. Does it compile to Node maybe? Which version of JS? EDIT: I'm googling now to learn more but I'm not asking to challenge anybody, I'm asking because probably you guys know more than me and I wanna know how this works.

There's no intrinsic property of “desktop” languages preventing them targeting “browser” languages. Any Turing-complete language can be compiled to and from any other.

And you don't even need to go down to that level of abstraction for Java-to-JavaScript, the two share many commonalities. Java classes can become JavaScript objects, Java methods can become JavaScript functions, Java exceptions can become JavaScript exceptions, and so on.

There's some things you can't directly translate (64-bit integer math, for instance), but these can be emulated.

As for “desktop” OS facilities, the browser may not be able to provide all of these, but whatever you need can be substituted (file access can be replaced with e.g. localStorage) or worked around.

Re: Closure Compiler in JavaScript

#49
post #40

Earlier quoted context omitted.

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Wait, how is that a thing? I'm a pure JS developer (for now) but I don't understand how something framed on desktop OSs could compile to JS, a browser language. Does it compile to Node maybe? Which version of JS? EDIT: I'm googling now to learn more but I'm not asking to challenge anybody, I'm asking because probably you guys know more than me and I wanna know how this works.

Node is JS. And JS isn't a browser language. And similar things like Scala.js [1] have been quite popular for quite a while.

https://www.scala-js.org/

Post reply on HN