Skip to content

Commit f7b0da3

Browse files
committed
change to array some
1 parent dff48e5 commit f7b0da3

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@ module.exports = postcss.plugin('postcss-pxtorem', function (options) {
2323
css.eachDecl(function (decl, i) {
2424
if (propWhiteList.indexOf(decl.prop) === -1) return;
2525

26-
var selector = decl.parent.selector;
27-
var match = false;
28-
for (var j=0; j<selectorBlackList.length; j++) {
29-
match = selector.match(selectorBlackList[j]);
30-
if (match) {
31-
break;
32-
}
33-
}
34-
if (match) {
35-
return;
36-
}
26+
if (blacklistedSelector(selectorBlackList, decl.parent.selector)) return;
3727

3828
var rule = decl.parent;
3929
var value = decl.value;
@@ -76,3 +66,9 @@ function remExists(decls, prop, value) {
7666
return (decl.prop === prop && decl.value === value);
7767
});
7868
}
69+
70+
function blacklistedSelector(blacklist, selector) {
71+
return blacklist.some(function (regex) {
72+
return selector.match(regex);
73+
});
74+
}

spec/pxtorem-spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ var css = '.rule { font-size: 15px }';
1212

1313
describe('pxtorem', function () {
1414

15-
it('should ignore selectors in the selector black list', function () {
16-
var rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }';
17-
var expected = '.rule { font-size: 0.9375rem } .rule2 { font-size: 15px }';
18-
var options = {
19-
selector_black_list: ['.rule2']
20-
};
21-
var processed = postcss(pxtorem(options)).process(rules).css;
22-
23-
expect(processed).toBe(expected);
24-
});
25-
2615
it('should replace the px unit with rem', function () {
2716
var processed = postcss(pxtorem()).process(css).css;
2817
var expected = '.rule { font-size: 0.9375rem }';
@@ -60,6 +49,17 @@ describe('pxtorem', function () {
6049
expect(processed).toBe(expected);
6150
});
6251

52+
it('should ignore selectors in the selector black list', function () {
53+
var rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }';
54+
var expected = '.rule { font-size: 0.9375rem } .rule2 { font-size: 15px }';
55+
var options = {
56+
selector_black_list: ['.rule2']
57+
};
58+
var processed = postcss(pxtorem(options)).process(rules).css;
59+
60+
expect(processed).toBe(expected);
61+
});
62+
6363
it('should leave fallback pixel unit with root em value', function () {
6464
var options = {
6565
replace: false

0 commit comments

Comments
 (0)