If you're using the module pattern and have something like this:
(function () {
"use strict";
// this function is strict...
}());
and compile the code using the Google Closure Compiler, the "use strict";
directive will not make it into the compiled file.
So how do you prevent the Closure Compiler from removing the ES5/strict directive?
(Note that I don't want to use the other mode of enforcing ES5/strict mode, which is to simply add the "use strict"; to the first line of the compiled file. I want to use the module pattern as described here.)
Update: strict mode is now supported in the compiler.
Just use --language_in=ECMASCRIPT5_STRICT
.
References:
http://code.google.com/p/closure-compiler/issues/detail?id=69
http://code.google.com/p/closure-compiler/source/detail?r=873
http://code.google.com/p/closure-compiler/source/detail?r=1114