Skip to content

Commit 3e22092

Browse files
committed
Plan to split comma separated rules and add new test case
1 parent b7b165b commit 3e22092

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,22 @@ const cssvariables = postcss.plugin('postcss-css-variables', function(options) {
183183

184184

185185

186+
187+
// Split comma separated selectors into separate rules
188+
// ---------------------------------------------------------
189+
// ---------------------------------------------------------
190+
191+
192+
193+
186194
// Resolve variable usage everywhere `var(--foo)`
187195
// ---------------------------------------------------------
188196
// ---------------------------------------------------------
189197
css.walkDecls(function(decl) {
190198
// Avoid any variable decls, `--foo: var(--bar);`, that may have been preserved
191199
if(!RE_VAR_PROP.test(decl.prop)) {
192200
const selectorBranches = generateSelectorBranchesFromPostcssNode(decl.parent);
201+
console.log('selectorBranches', selectorBranches);
193202

194203
const newDeclValue = decl.value.replace(new RegExp(RE_VAR_FUNC.source, 'g'), (match, variableName, fallback) => {
195204
debug('usage', variableName);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.bar {
2+
--color: red;
3+
}
4+
.baz {
5+
--color: blue;
6+
}
7+
8+
.foo {
9+
.bar, .baz {
10+
.qux {
11+
color: var(--color);
12+
}
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.foo {
2+
.bar {
3+
.qux {
4+
color: red;
5+
}
6+
}
7+
}
8+
9+
.foo {
10+
.baz {
11+
.qux {
12+
color: blue;
13+
}
14+
}
15+
}

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ describe('postcss-css-variables', function() {
113113
test('should work with variables defined in comma separated selector', 'comma-separated-variable-declaration');
114114

115115

116-
test('should work use the correct variable in comma separated selector', 'comma-separated-variable-usage');
116+
test('should use the correct variable in comma separated selector', 'comma-separated-variable-usage');
117+
test('should use the correct variable in nested comma separated selector', 'comma-separated-variable-nested-usage');
117118

118119

119120
test('should work with star selector', 'star-selector-scope');

0 commit comments

Comments
 (0)