Skip to content

Commit ac7d566

Browse files
authored
Merge pull request #1 from Dashlane/fix-error-with-comments
Fix TypeError Exception when stylesheet uses CSS comments
2 parents ddef54e + 567c5b3 commit ac7d566

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"homepage": "https://github.com/Dashlane/css-variables-loader#readme",
2020
"devDependencies": {
21-
"ava": "^0.13.0"
21+
"ava": "^0.16.0"
2222
},
2323
"dependencies": {
2424
"css": "^2.2.1"

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function(source) {
55
css.parse(source).stylesheet.rules
66
.filter(rule => rule.selectors.some(sel => sel === ':root'))
77
.forEach(rule => rule.declarations
8-
.filter(decl => decl.property.indexOf('--') === 0)
8+
.filter(decl => decl.type === 'declaration' && decl.property.indexOf('--') === 0)
99
.forEach(decl => result[decl.property] = decl.value));
1010
return 'module.exports = ' + JSON.stringify(result);
1111
};

test/simple.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var check = function(name, css, result){
88
test(name, function(t){
99
var module = { exports: {} };
1010
eval(loader(css));
11-
t.same(module.exports, result);
11+
t.deepEqual(module.exports, result);
1212
});
1313
};
1414

@@ -30,3 +30,6 @@ check('should only import from :root',
3030
check('should import from :root among multiple selectors',
3131
':hover, :root { --theme: red }',
3232
{ '--theme': 'red' })
33+
check('should not break when there is a comment',
34+
':root { --theme: red; /* important info */ --accent: blue }',
35+
{ '--accent': 'blue', '--theme': 'red' })

0 commit comments

Comments
 (0)