Skip to content

Commit 150a017

Browse files
Add attribute selector support (#8)
* add attribute selector support * chore: fix commit email address Co-authored-by: foo <[email protected]>
1 parent 40649ca commit 150a017

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.tape.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ module.exports = {
2222
expect: '.foo { color: blue; &:hover, &:focus { color: rebeccapurple; } &:focus-within { color: red; } }',
2323
args: ['always']
2424
},
25+
{
26+
source: '.foo { color: blue; } .foo[data-bar] { color: red; }',
27+
expect: '.foo { color: blue; &[data-bar] { color: red; } }',
28+
args: ['always']
29+
},
2530
{
2631
source: '.foo { color: blue; } .foo:hover, .foo:focus { color: rebeccapurple; } .foo:focus-within { color: red; }',
2732
expect: '.foo { color: blue; &:hover, &:focus { color: rebeccapurple; } } .foo:focus-within { color: red; }',

src/lib/are-rules-potential-nesting-rule.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ export default function areRulesPotentialNestingRule(rule1, rule2, opts) {
22
const except = [].concat(Object(opts).except || []);
33
const only = [].concat(Object(opts).only || []);
44

5-
return rule1.selectors && rule2.selectors && rule2.selectors.every(
5+
const result = rule1.selectors && rule2.selectors && rule2.selectors.every(
66
rule2Selector => rule1.selectors.every(
77
rule1Selector =>
88
rule2Selector.length < rule1Selector.length &&
99
rule2Selector === rule1Selector.slice(0, rule2Selector.length) &&
10-
!/^[A-z0-9-_]/.test(rule1Selector.slice(rule2Selector.length)) &&
10+
!/^[A-Za-z0-9-_]/.test(rule1Selector.slice(rule2Selector.length)) &&
1111
(!except.length || except.some(
1212
entry => entry instanceof RegExp
1313
? !entry.test(rule1Selector.slice(rule2Selector.length))
@@ -20,4 +20,5 @@ export default function areRulesPotentialNestingRule(rule1, rule2, opts) {
2020
))
2121
)
2222
);
23+
return result
2324
}

0 commit comments

Comments
 (0)