JavaScript "compilers"

Danil Speransky picture Danil Speransky · Sep 3, 2012 · Viewed 9.2k times · Source

Recently I found such cool thing as Google Closure Compiler. Are there alternatives which provide opportunities to get benefits of compiled statically-typed languages?

Update

It is not about real compilers, it is about JavaScript-JavaScript translators, which provide types verification etc, optimization, and maybe compression.

Answer

Christopher Peisert picture Christopher Peisert · Sep 3, 2012

From your comment:

I am interested in type checking, interface checking, private fields checking etc, all things allows you to write safety code, not only minimizer.

JavaScript is a dynamically-typed language that does not have built-in support for classes, interfaces, or access modifiers. Closure Compiler supports various extralinguistic features such as interfaces and access modifiers by using information embedded in JSDoc comments. Several IDEs also provide static analysis using JSDoc tag information, for example, see WebStorm & PhpStorm Blog: New in 5.0: Google Closure Compiler JSDoc annotations.

In the area of JavaScript minifiers there are numerous options such as YUI Compressor, UglifyJS, dojo shrinksafe, Microsoft Ajax Minifier, and JSMIN. However, none of these tools provide the same level of support for JSDoc-based analysis as Closure Compiler.

Related stack overflow questions:

  1. Which Javascript minifier (cruncher) does the same things that the one Google uses for its JS APIs?
  2. What are some good css and js minimizers for production code?
  3. Type checker for JavaScript?
  4. Is there a good JavaScript minimizer?
  5. JavaScript and CSS minimizer
  6. JavaScript compression
  7. What is the current state of JavaScript static type checking?