edge case where injecting into require.e functions #102

This commit is contained in:
Tobias Koppers 2013-10-01 10:11:25 +02:00
parent 2dd0ba9552
commit bedd59390c
1 changed files with 4 additions and 1 deletions

View File

@ -82,6 +82,7 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
var _source = this._source;
if(!_source) return new RawSource("throw new Error('No source availible');");
var source = new ReplaceSource(_source);
var topLevelBlock = this;
function doDep(dep) {
var template = dependencyTemplates.get(dep.Class);
if(!template) throw new Error("No template for dependency: " + dep.Class.name);
@ -106,7 +107,9 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
if(varNames.length == 0) return;
varStartCode += "/* WEBPACK VAR INJECTION */(function(require, " + varNames.join(", ") + ") {";
varEndCode = "}.call(exports, require, " + varExpressions.map(function(e) {return e.source()}).join(", ") + "))" + varEndCode;
// exports === this in the topLevelBlock, but exports do compress better...
varEndCode = (topLevelBlock === block ? "}.call(exports, require, " : "}.call(this, require, ") +
varExpressions.map(function(e) {return e.source()}).join(", ") + "))" + varEndCode;
varNames.length = 0;
varExpressions.length = 0;