Skip to content

Commit 246ea1c

Browse files
authored
Merge pull request #7 from kisenka/error-on-empty-selector
Fix error when plugin fails with CSS node without `selector` attr
2 parents ce43863 + 13a1ccc commit 246ea1c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/helpers.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function extendStyle(htmlNode, cssNode) {
1818
export function sortCssNodesBySpecificity(nodes) {
1919
// Sort CSS nodes by specificity (ascending): div - .foo - #bar
2020
return nodes.sort((a, b) => {
21-
a = getSpecificity(a.selector);
22-
b = getSpecificity(b.selector);
21+
a = typeof a.selector == 'string' ? getSpecificity(a.selector) : 0;
22+
b = typeof b.selector == 'string' ? getSpecificity(b.selector) : 0;
2323

2424
if (a > b) {
2525
return 1;

test/plugin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ describe('Plugin', () => {
3636
expect(html).toBe(expectedHtmlWithStyle);
3737
});
3838
});
39+
40+
it('should properly process any other nodes', () => {
41+
var css = '@media {}/* comment */.test {color: red;}';
42+
var html = '<div class="test">olala</div>';
43+
var expectedHtml = '<div class="test" style="color: red">olala</div>';
44+
return initPlugin(css, html).then(html => expect(html).toBe(expectedHtml));
45+
});
3946
});
4047

4148

0 commit comments

Comments
 (0)