Skip to content

Commit d3a7994

Browse files
committed
expose loc for every Dependency
1 parent e38d4b7 commit d3a7994

12 files changed

Lines changed: 57 additions & 25 deletions

‎lib/ConstPlugin.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ ConstPlugin.prototype.apply = function(compiler) {
2020
var param = this.evaluateExpression(statement.test);
2121
var bool = param.asBool();
2222
if(typeof bool === "boolean") {
23-
if(statement.test.type !== "Literal")
24-
this.state.current.addDependency(new ConstDependency(bool + "", param.range));
23+
if(statement.test.type !== "Literal") {
24+
var dep = new ConstDependency(bool + "", param.range);
25+
dep.loc = statement.loc;
26+
this.state.current.addDependency(dep);
27+
}
2528
return bool;
2629
}
2730
});
2831
compiler.parser.plugin("expression ?:", function(expression) {
2932
var param = this.evaluateExpression(expression.test);
3033
var bool = param.asBool();
3134
if(typeof bool === "boolean") {
32-
if(expression.test.type !== "Literal")
33-
this.state.current.addDependency(new ConstDependency(bool + "", param.range));
35+
if(expression.test.type !== "Literal") {
36+
var dep = new ConstDependency(bool + "", param.range);
37+
dep.loc = expression.loc;
38+
this.state.current.addDependency(dep);
39+
}
3440
return bool;
3541
}
3642
});

‎lib/ContextModule.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ ContextModule.prototype.build = function(options, compilation, resolver, fs, cal
6868
if(err) return callback(err);
6969
if(dependencies) {
7070
dependencies.forEach(function(dep) {
71+
dep.loc = dep.userRequest;
7172
dep.userRequest = dep.request;
7273
dep.request = addon + dep.userRequest;
7374
});

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
185185
return param.isString();
186186
});
187187
}
188-
params.forEach(function(param){
188+
params.forEach(function(param, idx) {
189189
var dep = new ModuleHotAcceptDependency(param.string, param.range);
190190
dep.optional = true;
191+
dep.loc = Object.create(expr.loc);
192+
dep.loc.index = idx;
191193
this.state.module.addDependency(dep);
192194
}.bind(this));
193195
}
@@ -199,6 +201,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
199201
if(param.isString()) {
200202
var dep = new ModuleHotDeclineDependency(param.string, param.range);
201203
dep.optional = true;
204+
dep.loc = param.loc;
202205
this.state.module.addDependency(dep);
203206
}
204207
}

‎lib/MultiEntryPlugin.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ MultiEntryPlugin.prototype.apply = function(compiler) {
2222
compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory);
2323
});
2424
compiler.plugin("make", function(compilation, callback) {
25-
compilation.addEntry(this.context, new MultiEntryDependency(this.entries.map(function(e) {
26-
return new SingleEntryDependency(e);
27-
}), this.name), this.name, callback);
25+
compilation.addEntry(this.context, new MultiEntryDependency(this.entries.map(function(e, idx) {
26+
var dep = new SingleEntryDependency(e);
27+
dep.loc = this.name + ":" + idx;
28+
return dep;
29+
}, this), this.name), this.name, callback);
2830
}.bind(this));
29-
};
31+
};

‎lib/SingleEntryPlugin.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ SingleEntryPlugin.prototype.apply = function(compiler) {
1717
compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory);
1818
});
1919
compiler.plugin("make", function(compilation, callback) {
20-
compilation.addEntry(this.context, new SingleEntryDependency(this.entry), this.name, callback);
20+
var dep = new SingleEntryDependency(this.entry);
21+
dep.loc = this.name;
22+
compilation.addEntry(this.context, dep, this.name, callback);
2123
}.bind(this));
22-
};
24+
};

‎lib/Stats.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
8888
text += "\n @ " + e.origin.readableIdentifier(requestShortener);
8989
e.dependencies.forEach(function(dep) {
9090
if(!dep.loc) return;
91+
if(typeof dep.loc === "string") return;
9192
if(!dep.loc.start) return;
9293
if(!dep.loc.end) return;
9394
text += " " + dep.loc.start.line + ":" + dep.loc.start.column + "-" +
@@ -182,7 +183,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
182183
};
183184
var dep = reason.dependency;
184185
if(dep.templateModules) obj.templateModules = dep.templateModules.map(function(module) { return module.id; });
185-
if(dep.loc) obj.loc = dep.loc.start.line + ":" + dep.loc.start.column + "-" +
186+
if(typeof dep.loc === "object") obj.loc = dep.loc.start.line + ":" + dep.loc.start.column + "-" +
186187
(dep.loc.start.line !== dep.loc.end.line ? dep.loc.end.line + ":" : "") + dep.loc.end.column;
187188
return obj;
188189
}).sort(function(a, b) {
@@ -222,7 +223,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
222223
module: origin.module ? origin.module.identifier() : "",
223224
moduleIdentifier: origin.module ? origin.module.identifier() : "",
224225
moduleName: origin.module ? origin.module.readableIdentifier(requestShortener) : "",
225-
loc: origin.loc ? obj.loc = origin.loc.start.line + ":" + origin.loc.start.column + "-" +
226+
loc: typeof origin.loc === "object" ? obj.loc = origin.loc.start.line + ":" + origin.loc.start.column + "-" +
226227
(origin.loc.start.line !== origin.loc.end.line ? origin.loc.end.line + ":" : "") + origin.loc.end.column : "",
227228
name: origin.name,
228229
reasons: origin.reasons || []

‎lib/dependencies/AMDPlugin.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ AMDPlugin.prototype.apply = function(compiler) {
4242
compiler.parser.plugin("expression " + expr, function(expr) {
4343
var dep = new AMDRequireItemDependency(module, expr.range);
4444
dep.userRequest = expr;
45+
dep.loc = expr.loc;
4546
this.state.current.addDependency(dep);
4647
return true;
4748
});
@@ -98,6 +99,7 @@ AMDPlugin.prototype.apply = function(compiler) {
9899
compiler.parser.plugin("rename define", function(expr) {
99100
var dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
100101
dep.userRequest = "define";
102+
dep.loc = expr.loc;
101103
this.state.current.addDependency(dep);
102104
return false;
103105
});

‎lib/dependencies/AMDRequireDependenciesBlock.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function AMDRequireDependenciesBlock(expr, arrayRange, functionRange, module, lo
1515
arrayRange ? arrayRange :
1616
functionRange ? functionRange :
1717
expr.range;
18-
this.addDependency(new AMDRequireDependency(this));
18+
var dep = new AMDRequireDependency(this);
19+
dep.loc = loc;
20+
this.addDependency(dep);
1921
}
2022
module.exports = AMDRequireDependenciesBlock;
2123

‎lib/dependencies/CommonJsRequireDependencyParserPlugin.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
3434
});
3535
parser.plugin("call require", function(expr) {
3636
if(expr.arguments.length !== 1) return;
37-
var localModule;
37+
var localModule, dep;
3838
var param = this.evaluateExpression(expr.arguments[0]);
3939
if(param.isConditional()) {
4040
var isExpression = false;
4141
var prevLength = this.state.current.dependencies.length;
42-
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
42+
dep = new RequireHeaderDependency(expr.callee.range);
43+
dep.loc = expr.loc;
44+
this.state.current.addDependency(dep);
4345
param.options.forEach(function(param) {
4446
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
4547
if(result === undefined) {
@@ -53,7 +55,7 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
5355
}
5456
}
5557
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
56-
var dep = new LocalModuleDependency(localModule, expr.range);
58+
dep = new LocalModuleDependency(localModule, expr.range);
5759
dep.loc = expr.loc;
5860
this.state.current.addDependency(dep);
5961
return true;
@@ -62,7 +64,9 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
6264
if(result === undefined) {
6365
this.applyPluginsBailResult("call require:commonjs:context", expr, param);
6466
} else {
65-
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
67+
dep = new RequireHeaderDependency(expr.callee.range);
68+
dep.loc = expr.loc;
69+
this.state.current.addDependency(dep);
6670
}
6771
return true;
6872
}

‎lib/dependencies/LoaderPlugin.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LoaderPlugin.prototype.apply = function(compiler) {
1818
compilation.plugin("normal-module-loader", function(loaderContext, module) {
1919
loaderContext.loadModule = function loadModule(request, callback) {
2020
var dep = new LoaderDependency(request);
21+
dep.loc = request;
2122
compilation.addModuleDependencies(module, [[dep]], true, "lm", false, function(err) {
2223
if(err) return callback(err);
2324

@@ -31,14 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) {
3132

3233
if(dep.module.error) return callback(dep.module.error);
3334
if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source");
35+
var source, map;
3436
var moduleSource = dep.module._source;
3537
if(moduleSource.sourceAndMap) {
3638
var sourceAndMap = moduleSource.sourceAndMap();
37-
var map = sourceAndMap.map;
38-
var source = sourceAndMap.source;
39+
map = sourceAndMap.map;
40+
source = sourceAndMap.source;
3941
} else {
40-
var map = moduleSource.map();
41-
var source = moduleSource.source();
42+
map = moduleSource.map();
43+
source = moduleSource.source();
4244
}
4345
if(dep.module.fileDependencies) {
4446
dep.module.fileDependencies.forEach(function(dep) {

0 commit comments

Comments
 (0)