2016-05-05 23:45:58 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
var ConstDependency = require("./dependencies/ConstDependency");
|
|
|
|
|
|
|
|
var NullFactory = require("./NullFactory");
|
|
|
|
|
|
|
|
function UseStrictPlugin() {}
|
|
|
|
module.exports = UseStrictPlugin;
|
|
|
|
|
|
|
|
UseStrictPlugin.prototype.apply = function(compiler) {
|
2016-09-14 18:04:42 +08:00
|
|
|
compiler.plugin("compilation", function(compilation, params) {
|
|
|
|
params.normalModuleFactory.plugin("parser", function(parser) {
|
|
|
|
parser.plugin("program", function(ast) {
|
2016-12-08 01:14:33 +08:00
|
|
|
var firstNode = ast.body[0];
|
|
|
|
var dep;
|
|
|
|
if(firstNode &&
|
|
|
|
firstNode.type === "ExpressionStatement" &&
|
|
|
|
firstNode.expression.type === "Literal" &&
|
|
|
|
firstNode.expression.value === "use strict") {
|
|
|
|
// Remove "use strict" expression. It will be added later by the renderer again.
|
|
|
|
// This is necessary in order to not break the strict mode when webpack prepends code.
|
|
|
|
// @see https://github.com/webpack/webpack/issues/1970
|
|
|
|
dep = new ConstDependency("", firstNode.range);
|
|
|
|
dep.loc = firstNode.loc;
|
|
|
|
this.state.current.addDependency(dep);
|
2016-09-14 18:04:42 +08:00
|
|
|
this.state.module.strict = true;
|
2016-12-08 01:14:33 +08:00
|
|
|
}
|
2016-09-14 18:04:42 +08:00
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
2016-05-05 23:45:58 +08:00
|
|
|
};
|