Skip to content

Commit ce642ec

Browse files
committed
reverted module.e to module.exports
because it causes issues with modules that define exports on the module object
1 parent 3540d5a commit ce642ec

File tree

22 files changed

+52
-71
lines changed

22 files changed

+52
-71
lines changed

buildin/module.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ module.exports = function(module) {
44
module.paths = [];
55
// module.parent = undefined by default
66
module.children = [];
7-
Object.defineProperty(module, "exports", {
8-
enumerable: true,
9-
configurable: false,
10-
get: function() { return module.e; },
11-
set: function(v) { return module.e = v; }
12-
});
137
Object.defineProperty(module, "loaded", {
148
enumerable: true,
159
configurable: false,

lib/ContextModule.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ContextModule.prototype.source = function() {
117117
"\treturn Object.keys(map);\n",
118118
"};\n",
119119
"webpackContext.resolve = webpackContextResolve;\n",
120-
"module.e = webpackContext;\n",
120+
"module.exports = webpackContext;\n",
121121
"webpackContext.id = " + this.id + ";\n"
122122
];
123123
} else if(this.blocks && this.blocks.length > 0) {
@@ -160,7 +160,7 @@ ContextModule.prototype.source = function() {
160160
"webpackAsyncContext.keys = function webpackAsyncContextKeys() {\n",
161161
"\treturn Object.keys(map);\n",
162162
"};\n",
163-
"module.e = webpackAsyncContext;\n",
163+
"module.exports = webpackAsyncContext;\n",
164164
"webpackAsyncContext.id = " + this.id + ";\n"
165165
];
166166
} else {
@@ -170,7 +170,7 @@ ContextModule.prototype.source = function() {
170170
"}\n",
171171
"webpackEmptyContext.keys = function() { return []; };\n",
172172
"webpackEmptyContext.resolve = webpackEmptyContext;\n",
173-
"module.e = webpackEmptyContext;\n",
173+
"module.exports = webpackEmptyContext;\n",
174174
"webpackEmptyContext.id = " + this.id + ";\n"
175175
];
176176
}

lib/DelegatedModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DelegatedModule.prototype.source = function() {
4747
if(!sourceModule) {
4848
str = WebpackMissingModule.moduleCode(this.sourceRequest);
4949
} else {
50-
str = "module.e = (__webpack_require__(" + sourceModule.id + "))";
50+
str = "module.exports = (__webpack_require__(" + sourceModule.id + "))";
5151
switch(this.type) {
5252
case "require":
5353
str += "(" + JSON.stringify(this.request) + ");";

lib/DllModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DllModule.prototype.build = function build(options, compilation, resolver, fs, c
3737
};
3838

3939
DllModule.prototype.source = function() {
40-
return new RawSource("module.e = __webpack_require__;");
40+
return new RawSource("module.exports = __webpack_require__;");
4141
};
4242

4343
DllModule.prototype.needRebuild = function needRebuild() {

lib/ExternalModule.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ ExternalModule.prototype.source = function() {
4545
case "window":
4646
case "global":
4747
if(Array.isArray(request)) {
48-
str = "(function() { module.e = " + this.type + request.map(function(r) {
48+
str = "(function() { module.exports = " + this.type + request.map(function(r) {
4949
return "[" + JSON.stringify(r) + "]";
5050
}).join("") + "; }());";
5151
} else
52-
str = "(function() { module.e = " + this.type + "[" + JSON.stringify(request) + "]; }());";
52+
str = "(function() { module.exports = " + this.type + "[" + JSON.stringify(request) + "]; }());";
5353
break;
5454
case "commonjs":
5555
case "commonjs2":
5656
if(Array.isArray(request)) {
57-
str = "module.e = require(" + JSON.stringify(request[0]) + ")" + request.slice(1).map(function(r) {
57+
str = "module.exports = require(" + JSON.stringify(request[0]) + ")" + request.slice(1).map(function(r) {
5858
return "[" + JSON.stringify(r) + "]";
5959
}).join("") + ";";
6060
} else
61-
str = "module.e = require(" + JSON.stringify(request) + ");";
61+
str = "module.exports = require(" + JSON.stringify(request) + ");";
6262
break;
6363
case "amd":
6464
case "umd":
@@ -67,14 +67,14 @@ ExternalModule.prototype.source = function() {
6767
if(this.optional) {
6868
str += "if(typeof __WEBPACK_EXTERNAL_MODULE_" + this.id + "__ === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n";
6969
}
70-
str += "module.e = __WEBPACK_EXTERNAL_MODULE_" + this.id + "__;";
70+
str += "module.exports = __WEBPACK_EXTERNAL_MODULE_" + this.id + "__;";
7171
break;
7272
default:
7373
str = "";
7474
if(this.optional) {
7575
str += "if(typeof " + request + " === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n";
7676
}
77-
str += "module.e = " + request + ";";
77+
str += "module.exports = " + request + ";";
7878
break;
7979
}
8080
if(this.useSourceMap) {

lib/MainTemplate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,28 @@ function MainTemplate(outputOptions) {
5050
source,
5151
"// Check if module is in cache",
5252
"if(installedModules[moduleId])",
53-
this.indent("return installedModules[moduleId].e;"),
53+
this.indent("return installedModules[moduleId].exports;"),
5454
"",
5555
"// Create a new module (and put it into the cache)",
5656
"var module = installedModules[moduleId] = {",
5757
this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
5858
"};",
5959
"",
6060
"// Execute the module function",
61-
"modules[moduleId].call(module.e, module, module.e, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
61+
"modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
6262
"",
6363
"// Flag the module as loaded",
6464
"module.l = true;",
6565
"",
6666
"// Return the exports of the module",
67-
"return module.e;"
67+
"return module.exports;"
6868
]);
6969
});
7070
this.plugin("module-obj", function( /*source, chunk, hash, varModuleId*/ ) {
7171
return this.asString([
72-
"e: {},",
7372
"i: moduleId,",
74-
"l: false"
73+
"l: false,",
74+
"exports: {}"
7575
]);
7676
});
7777
this.plugin("require-extensions", function(source, chunk) {

lib/MultiModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MultiModule.prototype.source = function(dependencyTemplates, outputOptions) {
4040
this.dependencies.forEach(function(dep, idx) {
4141
if(dep.module) {
4242
if(idx === this.dependencies.length - 1)
43-
str.push("module.e = ");
43+
str.push("module.exports = ");
4444
str.push("__webpack_require__(");
4545
if(outputOptions.pathinfo)
4646
str.push("/*! " + dep.request + " */");

lib/NodeStuffPlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ NodeStuffPlugin.prototype.apply = function(compiler) {
9494
this.state.current.addDependency(dep);
9595
return true;
9696
});
97+
compiler.parser.plugin("expression module.exports", ignore);
9798
compiler.parser.plugin("evaluate Identifier module.hot", function(expr) {
9899
return new BasicEvaluatedExpression().setBoolean(false).setRange(expr.range);
99100
});
100-
compiler.parser.plugin("expression module", function(expr) {
101+
compiler.parser.plugin("expression module", function() {
101102
var moduleJsPath = path.join(__dirname, "..", "buildin", "module.js");
102103
if(this.state.module.context) {
103104
moduleJsPath = path.relative(this.state.module.context, moduleJsPath);

lib/dependencies/AMDDefineDependency.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ AMDDefineDependency.Template.prototype.apply = function(dep, source) {
4646
}
4747
var branch = (localModuleVar ? "l" : "") + (dep.arrayRange ? "a" : "") + (dep.objectRange ? "o" : "") + (dep.functionRange ? "f" : "");
4848
var defs = {
49-
f: ["var __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.e = __WEBPACK_AMD_DEFINE_RESULT__))"],
50-
o: ["", "!(module.e = #)"],
51-
of: ["var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.e = __WEBPACK_AMD_DEFINE_RESULT__))"],
52-
af: ["var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.e = __WEBPACK_AMD_DEFINE_RESULT__))"],
53-
ao: ["", "!(#, module.e = #)"],
54-
aof: ["var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_FACTORY__ = (#), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.e = __WEBPACK_AMD_DEFINE_RESULT__))"],
49+
f: ["var __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))"],
50+
o: ["", "!(module.exports = #)"],
51+
of: ["var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))"],
52+
af: ["var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))"],
53+
ao: ["", "!(#, module.exports = #)"],
54+
aof: ["var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;", "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_FACTORY__ = (#), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))"],
5555
lf: ["var XXX;", "!(XXX = #.call(exports, __webpack_require__, exports, module))"],
5656
lo: ["var XXX;", "!(XXX = #)"],
5757
lof: ["var __WEBPACK_AMD_DEFINE_FACTORY__, XXX;", "!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), XXX = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__))"],

lib/dependencies/CommonJsPlugin.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ CommonJsPlugin.prototype.apply = function(compiler) {
8686
compiler.parser.plugin("evaluate typeof exports", function(expr) {
8787
return new BasicEvaluatedExpression().setString("object").setRange(expr.range);
8888
});
89-
compiler.parser.plugin("expression module.exports", function(expr) {
90-
var dep = new ConstDependency("module.e", expr.range);
91-
dep.loc = expr.loc;
92-
this.state.current.addDependency(dep);
93-
return true;
94-
});
9589
compiler.parser.apply(
9690
new CommonJsRequireDependencyParserPlugin(this.options),
9791
new RequireResolveDependencyParserPlugin(this.options)

0 commit comments

Comments
 (0)