Skip to content

Commit e83e9b8

Browse files
committed
test strict mode
enable strict mode if import/export is used
1 parent b98debb commit e83e9b8

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/FunctionModuleTemplatePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FunctionModuleTemplatePlugin.prototype.apply = function(moduleTemplate) {
1616
defaultArguments.push("__webpack_require__");
1717
}
1818
source.add("/***/ function(" + defaultArguments.concat(module.arguments || []).join(", ") + ") {\n\n");
19-
if(module.strict) source.add("\"use strict\";\n");
19+
if(module.strict) source.add(this.outputOptions.sourcePrefix + "\"use strict\";\n");
2020
source.add(new PrefixSource(this.outputOptions.sourcePrefix, moduleSource));
2121
source.add("\n\n/***/ }");
2222
return source;

lib/dependencies/HarmonyExportDependencyParserPlugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = AbstractPlugin.create({
1616
dep.loc = statement.loc;
1717
this.state.current.addDependency(dep);
1818
this.state.module.meta.harmonyModule = true;
19+
this.state.module.strict = true;
1920
return true;
2021
},
2122
"export import": function(statement, source) {
@@ -24,12 +25,14 @@ module.exports = AbstractPlugin.create({
2425
this.state.current.addDependency(dep);
2526
this.state.lastHarmoryImport = dep;
2627
this.state.module.meta.harmonyModule = true;
28+
this.state.module.strict = true;
2729
return true;
2830
},
2931
"export expression": function(statement, expr) {
3032
var dep = new HarmonyExportExpressionDependency(this.state.module, expr.range, statement.range);
3133
dep.loc = statement.loc;
3234
this.state.current.addDependency(dep);
35+
this.state.module.strict = true;
3336
return true;
3437
},
3538
"export declaration": function() {},

lib/dependencies/HarmonyImportDependencyParserPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = AbstractPlugin.create({
1515
dep.loc = statement.loc;
1616
this.state.current.addDependency(dep);
1717
this.state.lastHarmonyImport = dep;
18+
this.state.module.strict = true;
1819
return true;
1920
},
2021
"import specifier": function(statement, source, id, name) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function() {
2+
return typeof this;
3+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
define(["./abc"], function(abc) {
3+
// AMD is used here, because it adds stuff to the top of the code
4+
// we make sure to keep strict mode
5+
6+
var a = abc.default;
7+
8+
it("should keep strict mode", function() {
9+
var x = (function() {
10+
return this;
11+
})();
12+
(typeof x).should.be.eql("undefined");
13+
});
14+
15+
it("should import modules in strict mode", function() {
16+
a().should.be.eql("undefined");
17+
});
18+
19+
});

0 commit comments

Comments
 (0)