Skip to content

Commit 4025f2f

Browse files
committed
Merge pull request #16 from css-modules/decls-in-atrule
localized decls in atrules
2 parents cc7f5bc + f73ce72 commit 4025f2f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
211211
} else if(!globalMode) {
212212
atrule.params = ":local(" + atrule.params + ")";
213213
}
214+
} else if(atrule.nodes) {
215+
atrule.nodes.forEach(function(decl) {
216+
if(decl.type === "decl") {
217+
localizeDecl(decl, {
218+
options: options,
219+
global: globalMode
220+
});
221+
}
222+
});
214223
}
215224
});
216225
css.eachRule(function(rule) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"url": "https://github.com/css-modules/postcss-modules-local-by-default.git"
1616
},
1717
"dependencies": {
18-
"css-selector-tokenizer": "^0.4.0",
18+
"css-selector-tokenizer": "^0.5.1",
1919
"postcss": "^4.1.5"
2020
},
2121
"devDependencies": {

test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ var tests = [
357357
should: 'rewrite url in local block',
358358
input: '.a { background: url(./image.png); }\n' +
359359
':global .b { background: url(image.png); }\n' +
360-
'.c { background: url("./image.png"); }',
360+
'.c { background: url("./image.png"); }\n' +
361+
'@font-face { src: url("./font.woff"); }\n' +
362+
'@-webkit-font-face { src: url("./font.woff"); }',
361363
options: {
362364
rewriteUrl: function(global, url) {
363365
var mode = global ? 'global' : 'local';
@@ -366,7 +368,14 @@ var tests = [
366368
},
367369
expected: ':local(.a) { background: url((local\\)./image.png\\\"local\\\"); }\n' +
368370
'.b { background: url((global\\)image.png\\\"global\\\"); }\n' +
369-
':local(.c) { background: url(\"(local)./image.png\\\"local\\\"\"); }'
371+
':local(.c) { background: url(\"(local)./image.png\\\"local\\\"\"); }\n' +
372+
'@font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }\n' +
373+
'@-webkit-font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }'
374+
},
375+
{
376+
should: 'not crash on atrule without nodes',
377+
input: '@charset "utf-8";',
378+
expected: '@charset "utf-8";'
370379
}
371380

372381
];

0 commit comments

Comments
 (0)