How to force google closure compiler to keep "use strict"; in the compiled js code?

ivo picture ivo · Dec 16, 2010 · Viewed 8.1k times · Source

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.)

Answer