Skip to content

Commit 000b757

Browse files
committed
refactor(es6): Update UseStrictPlugin to es6 class
1 parent 1160ec8 commit 000b757

3 files changed

Lines changed: 27 additions & 28 deletions

File tree

lib/UseStrictPlugin.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var ConstDependency = require("./dependencies/ConstDependency");
5+
const ConstDependency = require("./dependencies/ConstDependency");
6+
const NullFactory = require("./NullFactory");
67

7-
var NullFactory = require("./NullFactory");
8+
class UseStrictPlugin {
9+
apply(compiler) {
10+
compiler.plugin("compilation", (compilation, params) => {
11+
params.normalModuleFactory.plugin("parser", (parser) => {
12+
let parserInstance = parser;
13+
parser.plugin("program", (ast) => {
14+
let firstNode = ast.body[0];
15+
let dep;
16+
if(firstNode &&
17+
firstNode.type === "ExpressionStatement" &&
18+
firstNode.expression.type === "Literal" &&
19+
firstNode.expression.value === "use strict") {
20+
// Remove "use strict" expression. It will be added later by the renderer again.
21+
// This is necessary in order to not break the strict mode when webpack prepends code.
22+
// @see https://github.com/webpack/webpack/issues/1970
23+
dep = new ConstDependency("", firstNode.range);
24+
dep.loc = firstNode.loc;
25+
parserInstance.state.current.addDependency(dep);
26+
parserInstance.state.module.strict = true;
27+
}
28+
});
29+
})
30+
})
31+
}
32+
}
833

9-
function UseStrictPlugin() {}
1034
module.exports = UseStrictPlugin;
11-
12-
UseStrictPlugin.prototype.apply = function(compiler) {
13-
compiler.plugin("compilation", function(compilation, params) {
14-
params.normalModuleFactory.plugin("parser", function(parser) {
15-
parser.plugin("program", function(ast) {
16-
var firstNode = ast.body[0];
17-
var dep;
18-
if(firstNode &&
19-
firstNode.type === "ExpressionStatement" &&
20-
firstNode.expression.type === "Literal" &&
21-
firstNode.expression.value === "use strict") {
22-
// Remove "use strict" expression. It will be added later by the renderer again.
23-
// This is necessary in order to not break the strict mode when webpack prepends code.
24-
// @see https://github.com/webpack/webpack/issues/1970
25-
dep = new ConstDependency("", firstNode.range);
26-
dep.loc = firstNode.loc;
27-
this.state.current.addDependency(dep);
28-
this.state.module.strict = true;
29-
}
30-
});
31-
})
32-
})
33-
};

test/fixtures/temp-1000/file.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/temp-1000/file2.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)