Skip to content

Commit ac8355f

Browse files
authored
Don't throw on trailing commas in SelectorList (#180)
Refs #157 (thnx @xqin) Technically a traling comma in a SelectorList is a syntax error that the CSS engine does not know how to handle (reduced testcase: https://codepen.io/bartveneman/pen/NWWYJOE). But this analyzer tries to give insight in your CSS complexity, not in the validity of it. There are better tools for that. So for that, it'll look the other way and continue analyzing. Co-authored-by: @xqin
1 parent db0105e commit ac8355f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/parser/selectors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ module.exports = tree => {
1717
}
1818

1919
const getSelectorsFromRule = rule => {
20-
return rule.selector.split(',').map(s => s.trim())
20+
return rule.selector
21+
.split(',')
22+
.map(s => s.trim())
23+
.filter(Boolean)
2124
}
2225

2326
module.exports.getSelectorsFromRule = getSelectorsFromRule

test/parser/selectors.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ test('"selectors" in @keyframes are not passed as actual selectors', async t =>
3232

3333
t.deepEqual(actual, expected)
3434
})
35+
36+
test('it ignores trailing commas in selectorLists', async t => {
37+
const fixture = `
38+
html,
39+
body, {
40+
color: red;
41+
}
42+
`
43+
44+
const {selectors: actual} = await parser(fixture)
45+
const expected = ['html', 'body']
46+
47+
t.deepEqual(actual, expected)
48+
})

0 commit comments

Comments
 (0)