Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JS defined variables marked as important #87

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
# v0.11.0 - 2018-10-9

- Fix JS-defined variables using `isImportant`, https://github.com/MadLittleMods/postcss-css-variables/pull/87


# v0.10.0 - 2018-9-25

- Cast `opts.variables` variable values to string
Expand Down
3 changes: 2 additions & 1 deletion index.js
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
@@ -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
@@ -0,0 +1,3 @@
.box1 {
background-color: #0f0;
}
2 changes: 2 additions & 0 deletions test/fixtures/js-defined-preserve-injected.expected.css
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
@@ -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
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