Skip to content

Commit adbb9a6

Browse files
author
Руслан Муфтиев
committed
fixed preserve option inside at-rules
1 parent 4265ae7 commit adbb9a6

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

lib/resolve-decl.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ function resolveDecl(decl, map, /*optional*/shouldPreserve, /*optional*/logResol
9494
eachMapItemDependencyOfDecl(valueResults.variablesUsed, map, decl, function(mimicDecl, mapItem) {
9595
var ruleClone = shallowCloneNode(decl.parent);
9696
var declClone = decl.clone();
97-
// No mangle resolve
98-
declClone.value = _logResolveValueResult(resolveValue(mimicDecl, map, true)).value;
99-
10097
// Add the declaration to our new rule
10198
ruleClone.append(declClone);
10299

100+
if(shouldPreserve === true) {
101+
declClone.cloneAfter();
102+
}
103+
104+
// No mangle resolve
105+
declClone.value = _logResolveValueResult(resolveValue(mimicDecl, map, true)).value;
103106

104107
if(mapItem.isUnderAtRule) {
105108
// Create the clean atRule for which we place the declaration under
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:root {
2+
--width: 100px;
3+
}
4+
5+
@media (max-width: 1000px) {
6+
:root {
7+
--width: 200px;
8+
}
9+
}
10+
11+
.box {
12+
width: var(--width);
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:root {
2+
--width: 100px;
3+
}
4+
5+
@media (max-width: 1000px) {
6+
:root {
7+
--width: 200px;
8+
}
9+
}
10+
11+
.box {
12+
width: 100px;
13+
width: var(--width);
14+
}
15+
16+
@media (max-width: 1000px) {
17+
18+
.box {
19+
width: 200px;
20+
width: var(--width);
21+
}
22+
}

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ describe('postcss-css-variables', function() {
169169
{ preserve: true }
170170
);
171171

172+
test(
173+
'preserves variables in @media when `preserve` is `true`',
174+
'preserve-variables-in-media',
175+
{ preserve: true }
176+
);
177+
172178
test(
173179
'preserves computed value when `preserve` is `\'computed\'`',
174180
'preserve-computed',

0 commit comments

Comments
 (0)