Skip to content

Commit 1c961af

Browse files
committed
fixed small issues with new loader-runner
1 parent ded70ae commit 1c961af

File tree

7 files changed

+19
-7
lines changed

7 files changed

+19
-7
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
* text=auto
2+
test/statsCases/* eol=lf
23
examples/* eol=lf
34
bin/* eol=lf

lib/ConstPlugin.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
77

88
var NullFactory = require("./NullFactory");
99

10+
function getQuery(request) {
11+
var i = request.indexOf("?");
12+
return i < 0 ? "" : request.substr(i);
13+
}
14+
1015
function ConstPlugin() {}
1116
module.exports = ConstPlugin;
1217

@@ -42,13 +47,13 @@ ConstPlugin.prototype.apply = function(compiler) {
4247
compiler.parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
4348
if(!this.state.module) return;
4449
var res = new BasicEvaluatedExpression();
45-
res.setString(this.state.module.splitQuery(this.state.module.resource)[1]);
50+
res.setString(getQuery(this.state.module.resource));
4651
res.setRange(expr.range);
4752
return res;
4853
});
4954
compiler.parser.plugin("expression __resourceQuery", function() {
5055
if(!this.state.module) return;
51-
this.state.current.addVariable("__resourceQuery", JSON.stringify(this.state.module.splitQuery(this.state.module.resource)[1]));
56+
this.state.current.addVariable("__resourceQuery", JSON.stringify(getQuery(this.state.module.resource)));
5257
return true;
5358
});
5459
};

lib/LoaderOptionsPlugin.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ LoaderOptionsPlugin.prototype.apply = function(compiler) {
1919
var options = this.options;
2020
compiler.plugin("compilation", function(compilation) {
2121
compilation.plugin("normal-module-loader", function(context, module) {
22-
if(module.resource && ModuleFilenameHelpers.matchObject(options, module.splitQuery(module.resource)[0])) {
22+
var resource = module.resource;
23+
if(!resource) return;
24+
var i = resource.indexOf("?");
25+
if(ModuleFilenameHelpers.matchObject(options, i < 0 ? resource : resource.substr(0, i))) {
2326
Object.keys(options).filter(function(key) {
2427
return ["include", "exclude", "test"].indexOf(key) < 0
2528
}).forEach(function(key) {

lib/NodeStuffPlugin.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ NodeStuffPlugin.prototype.apply = function(compiler) {
4848
compiler.parser.plugin("evaluate Identifier __filename", function(expr) {
4949
if(!this.state.module) return;
5050
var res = new BasicEvaluatedExpression();
51-
res.setString(this.state.module.splitQuery(this.state.module.resource)[0]);
51+
var resource = this.state.module.resource;
52+
var i = resource.indexOf("?");
53+
res.setString(i < 0 ? resource : resource.substr(0, i));
5254
res.setRange(expr.range);
5355
return res;
5456
});

test/cases/loaders/query/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ it("should pass query to loader over context", function() {
4040
var test = "test";
4141
var result = require("./loaders/queryloader?query!./context-query-test/" + test);
4242
result.should.be.eql({
43-
resourceQuery: null,
43+
resourceQuery: "",
4444
query: "?query",
4545
prev: "test content"
4646
});

test/cases/resolving/context/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
it("should resolve loaders relative to require", function() {
22
var index = "index", test = "test";
33
require("./loaders/queryloader?query!!!!./node_modules/subcontent/" + index + ".js").should.be.eql({
4-
resourceQuery: null,
4+
resourceQuery: "",
55
query: "?query",
66
prev: "module.exports = \"error\";"
77
});
88
require("!./loaders/queryloader?query!./node_modules/subcontent/" + test + ".jade").should.be.eql({
9-
resourceQuery: null,
9+
resourceQuery: "",
1010
query: "?query",
1111
prev: "xyz: abc"
1212
});

test/hotCases/fake-update-loader.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = function(source) {
2+
this.cacheable(false);
23
var idx = this.options.updateIndex;
34
var items = source.split(/---+\r?\n/g);
45
return items[idx] || items[items.length - 1];

0 commit comments

Comments
 (0)