Skip to content

Commit 7ee009e

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

4 files changed

+41
-1
lines changed

index.js

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

184184

185185

186+
187+
// Split comma separated selectors into separate rules
188+
// ---------------------------------------------------------
189+
// ---------------------------------------------------------
190+
// TODO
191+
192+
193+
194+
186195
// Resolve variable usage everywhere `var(--foo)`
187196
// ---------------------------------------------------------
188197
// ---------------------------------------------------------
189198
css.walkDecls(function(decl) {
190199
// Avoid any variable decls, `--foo: var(--bar);`, that may have been preserved
191200
if(!RE_VAR_PROP.test(decl.prop)) {
192201
const selectorBranches = generateSelectorBranchesFromPostcssNode(decl.parent);
202+
console.log('selectorBranches', selectorBranches.map((branch) => branch.selector.toString()));
193203

194204
const newDeclValue = decl.value.replace(new RegExp(RE_VAR_FUNC.source, 'g'), (match, variableName, fallback) => {
195205
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)