Skip to content

Commit d13212d

Browse files
committed
linting
1 parent 397397d commit d13212d

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

.eslintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"rules": {
6+
"strict": 0,
7+
"curly": 0,
8+
"quotes": 0
9+
}
10+
}

lib/css-base.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Author Tobias Koppers @sokra
44
*/
55
// css base code, injected by the css-loader
6-
//
76
module.exports = function() {
87
var list = [];
98

@@ -31,7 +30,7 @@ module.exports = function() {
3130
if(typeof id === "number")
3231
alreadyImportedModules[id] = true;
3332
}
34-
for(var i = 0; i < modules.length; i++) {
33+
for(i = 0; i < modules.length; i++) {
3534
var item = modules[i];
3635
// skip already imported module
3736
// this implementation is not 100% perfect for weird media query combinations

lib/getPlaceholderIdent.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
var loaderUtils = require("loader-utils");
6+
module.exports = function getPlaceholderIdent(loaderContext, placeholderName) {
7+
var hash = require("crypto").createHash("md5");
8+
hash.update(loaderContext.options && typeof loaderContext.options.context === "string" ?
9+
loaderUtils.stringifyRequest({ context: loaderContext.options.context }, loaderContext.request) :
10+
loaderContext.request);
11+
hash.update(placeholderName);
12+
return "z" + hash.digest("hex");
13+
};

lib/loader.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var parseSource = require("./parseSource");
77
var ReplaceMany = require("./ReplaceMany");
88
var loaderUtils = require("loader-utils");
99
var SourceListMap = require("source-list-map").SourceListMap;
10-
var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
1110
var CleanCSS = require("clean-css");
11+
var getPlaceholderIdent = require("./getPlaceholderIdent");
1212

1313
module.exports = function(content, map) {
14-
this.cacheable && this.cacheable();
14+
if(this.cacheable) this.cacheable();
1515
var query = loaderUtils.parseQuery(this.query);
1616
var root = query.root;
1717
var forceMinimize = query.minimize;
@@ -49,16 +49,12 @@ module.exports = function(content, map) {
4949
});
5050
var placeholders = {};
5151
stuff.placeholders.forEach(function(placeholder) {
52+
var ident;
5253
if(!placeholders[placeholder.name]) {
53-
var hash = require("crypto").createHash("md5");
54-
hash.update(this.options && typeof this.options.context === "string" ?
55-
loaderUtils.stringifyRequest({ context: this.options.context }, this.request) :
56-
this.request);
57-
hash.update(placeholder.name);
58-
var ident = "z" + hash.digest("hex");
54+
ident = getPlaceholderIdent(this, placeholder.name);
5955
placeholders[placeholder.name] = ident;
6056
} else {
61-
var ident = placeholders[placeholder.name];
57+
ident = placeholders[placeholder.name];
6258
}
6359
replacer.replace(placeholder.start, placeholder.length, placeholder.prefix + ident);
6460
}, this);
@@ -77,6 +73,10 @@ module.exports = function(content, map) {
7773
map = JSON.stringify(map);
7874
}
7975

76+
function toEmbStr(str) {
77+
return JSON.stringify(str).replace(/^"|"$/g, "");
78+
}
79+
8080
var css = JSON.stringify(cssContent);
8181

8282
var urlRegExp = /__CSSLOADERURL_[0-9]+__/g;
@@ -89,23 +89,19 @@ module.exports = function(content, map) {
8989
var url = urlItem.url;
9090
if(!loaderUtils.isUrlRequest(url, root))
9191
return toEmbStr(urlItem.raw);
92-
var idx = url.indexOf("?#");
92+
idx = url.indexOf("?#");
9393
if(idx < 0) idx = url.indexOf("#");
9494
if(idx > 0) {
9595
// in cases like url('webfont.eot?#iefix')
96-
var request = url.substr(0, idx);
97-
return "\"+require(" + loaderUtils.stringifyRequest(this, loaderUtils.urlToRequest(request, root)) + ")+\"" + url.substr(idx);
96+
var urlRequest = url.substr(0, idx);
97+
return "\"+require(" + loaderUtils.stringifyRequest(this, loaderUtils.urlToRequest(urlRequest, root)) + ")+\"" + url.substr(idx);
9898
} else if(idx === 0) {
9999
// only hash
100100
return toEmbStr(urlItem.raw);
101101
}
102102
return "\"+require(" + loaderUtils.stringifyRequest(this, loaderUtils.urlToRequest(url, root)) + ")+\"";
103103
}.bind(this));
104104

105-
function toEmbStr(str) {
106-
return JSON.stringify(str).replace(/^"|"$/g, "");
107-
}
108-
109105
if(query.sourceMap && !minimize) {
110106
var cssRequest = loaderUtils.getRemainingRequest(this);
111107
var request = loaderUtils.getCurrentRequest(this);
@@ -137,4 +133,4 @@ module.exports = function(content, map) {
137133

138134
return "exports = module.exports = require(" + loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) + ")();\n" +
139135
result.join("\n");
140-
}
136+
};

lib/parseSource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var parser = new Parser({
5050
// placeholder
5151
"()\\{\\{([A-Za-z_0-9]+)\\}\\}": placeholderMatch,
5252
"(\\.)\\[([A-Za-z_0-9]+)\\]": placeholderMatch,
53-
"(#)\\[([A-Za-z_0-9]+)\\]": placeholderMatch,
53+
"(#)\\[([A-Za-z_0-9]+)\\]": placeholderMatch
5454
},
5555
comment: {
5656
"\\*/": "source"
@@ -64,4 +64,4 @@ module.exports = function parseSource(source) {
6464
placeholders: []
6565
};
6666
return parser.parse("source", source, context);
67-
}
67+
};

0 commit comments

Comments
 (0)