Skip to content

Commit 311d95b

Browse files
committed
Fix JS defined variables marked as important
Fix #86
1 parent af71667 commit 311d95b

7 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.11.0 - 2018-10-9
2+
3+
- Fix JS-defined variables using `isImportant`, https://github.com/MadLittleMods/postcss-css-variables/pull/87
4+
5+
16
# v0.10.0 - 2018-9-25
27

38
- Cast `opts.variables` variable values to string

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ module.exports = postcss.plugin('postcss-css-variables', function(options) {
109109
// Add the variable decl to the root node
110110
var varDecl = postcss.decl({
111111
prop: variableName,
112-
value: variableValue
112+
value: variableValue,
113+
important: isImportant
113114
});
114115
variableRootRule.append(varDecl);
115116

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:root {
2+
--js-defined-important: #000;
3+
}
4+
5+
.box1 {
6+
background-color: var(--js-defined-important);
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.box1 {
2+
background-color: #0f0;
3+
}

test/fixtures/js-defined-preserve-injected.expected.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
}
55
:root {
66
}
7+
:root {
8+
}
79

810
.box1 {
911
width: 75px;

test/fixtures/js-defined-preserve.expected.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
:root {
22
--js-defined-no-prefix: #ff0000;
33
}
4+
:root {
5+
--js-defined-important: #0f0 !important;
6+
}
47
:root {
58
--js-defined2: 80px;
69
}

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ var MOCK_JS_VARIABLES = {
1818
'--js-defined2': {
1919
value: '80px'
2020
},
21+
'--js-defined-important': {
22+
value: '#0f0',
23+
isImportant: true
24+
},
2125
// Should be automatically prefixed with `--`
2226
'js-defined-no-prefix': '#ff0000'
2327
};
@@ -170,6 +174,11 @@ describe('postcss-css-variables', function() {
170174
'js-defined',
171175
{ variables: MOCK_JS_VARIABLES }
172176
);
177+
test(
178+
'should work with JS defined important variables',
179+
'js-defined-important',
180+
{ variables: MOCK_JS_VARIABLES }
181+
);
173182
test(
174183
'should preserve -- declarations and var() values with `options.variables` AND `options.preserve`',
175184
'js-defined-preserve',

0 commit comments

Comments
 (0)