Skip to content

Commit 94af250

Browse files
committed
Merge branch 'lemieux-fix-url-in-value'
2 parents 1298d2b + a0ec195 commit 94af250

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

lib/processCss.js

+30-22
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,39 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
7777
exports[exportName] = replaceImportsInString(exports[exportName]);
7878
});
7979

80+
function processNode(item) {
81+
switch (item.type) {
82+
case "value":
83+
item.nodes.forEach(processNode);
84+
break;
85+
case "nested-item":
86+
item.nodes.forEach(processNode);
87+
break;
88+
case "item":
89+
var importIndex = imports["$" + item.name];
90+
if (typeof importIndex === "number") {
91+
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
92+
}
93+
break;
94+
case "url":
95+
if (!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
96+
item.stringType = "";
97+
delete item.innerSpacingBefore;
98+
delete item.innerSpacingAfter;
99+
var url = item.url;
100+
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
101+
urlItems.push({
102+
url: url
103+
});
104+
}
105+
break;
106+
}
107+
}
108+
80109
css.walkDecls(function(decl) {
81110
var values = Tokenizer.parseValues(decl.value);
82111
values.nodes.forEach(function(value) {
83-
value.nodes.forEach(function(item) {
84-
switch(item.type) {
85-
case "item":
86-
var importIndex = imports["$" + item.name];
87-
if(typeof importIndex === "number") {
88-
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
89-
}
90-
break;
91-
case "url":
92-
if(!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
93-
item.stringType = "";
94-
delete item.innerSpacingBefore;
95-
delete item.innerSpacingAfter;
96-
var url = item.url;
97-
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
98-
urlItems.push({
99-
url: url
100-
});
101-
}
102-
break;
103-
}
104-
});
112+
value.nodes.forEach(processNode);
105113
});
106114
decl.value = Tokenizer.stringifyValues(values);
107115
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lodash.camelcase": "^3.0.1",
1212
"postcss": "^5.0.6",
1313
"postcss-modules-extract-imports": "^1.0.0",
14-
"postcss-modules-local-by-default": "^1.0.0",
14+
"postcss-modules-local-by-default": "^1.0.1",
1515
"postcss-modules-scope": "^1.0.0",
1616
"postcss-modules-values": "^1.1.0",
1717
"source-list-map": "^0.1.4"

test/urlTest.js

+3
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ describe("url", function() {
5050
test("keyframe background img", "@keyframes anim { background: green url('img.png') xyz }", [
5151
[1, "@keyframes anim { background: green url({./img.png}) xyz }", ""]
5252
]);
53+
test("-webkit-image-set", ".a { background-image: -webkit-image-set(url('url1x.png') 1x, url('url2x.png') 2x) }", [
54+
[1, ".a { background-image: -webkit-image-set(url({./url1x.png}) 1x, url({./url2x.png}) 2x) }", ""]
55+
]);
5356
});

0 commit comments

Comments
 (0)