Skip to content

Commit

Permalink
Fix JS defined variables marked as important
Browse files Browse the repository at this point in the history
Fix #86
  • Loading branch information
MadLittleMods committed Oct 9, 2018
1 parent af71667 commit 01e55bb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ module.exports = postcss.plugin('postcss-css-variables', function(options) {
// Add the variable decl to the root node
var varDecl = postcss.decl({
prop: variableName,
value: variableValue
value: variableValue,
important: isImportant
});
variableRootRule.append(varDecl);

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/js-defined-important.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:root {
--js-defined-important: #000;
}

.box1 {
background-color: var(--js-defined-important);
}
3 changes: 3 additions & 0 deletions test/fixtures/js-defined-important.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.box1 {
background-color: #0f0;
}
2 changes: 2 additions & 0 deletions test/fixtures/js-defined-preserve-injected.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
}
:root {
}
:root {
}

.box1 {
width: 75px;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/js-defined-preserve.expected.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
:root {
--js-defined-no-prefix: #ff0000;
}
:root {
--js-defined-important: #0f0 !important;
}
:root {
--js-defined2: 80px;
}
Expand Down
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ var MOCK_JS_VARIABLES = {
'--js-defined2': {
value: '80px'
},
'--js-defined-important': {
value: '#0f0',
isImportant: true
},
// Should be automatically prefixed with `--`
'js-defined-no-prefix': '#ff0000'
};
Expand Down Expand Up @@ -170,6 +174,11 @@ describe('postcss-css-variables', function() {
'js-defined',
{ variables: MOCK_JS_VARIABLES }
);
test(
'should work with JS defined important variables',
'js-defined-important',
{ variables: MOCK_JS_VARIABLES }
);
test(
'should preserve -- declarations and var() values with `options.variables` AND `options.preserve`',
'js-defined-preserve',
Expand Down

0 comments on commit 01e55bb

Please sign in to comment.