Skip to content

Commit 896db28

Browse files
ryuranromainmenke
authored andcommitted
Allow combined selectors (postcss/postcss-custom-properties#199)
1 parent 6e1f902 commit 896db28

10 files changed

+52
-5
lines changed

plugins/postcss-custom-properties/src/lib/get-custom-properties-from-root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const rootSelectorRegExp = /^:root$/i;
4848
const customPropertyRegExp = /^--[A-z][\w-]*$/;
4949

5050
// whether the node is an html or :root rule
51-
const isHtmlRule = node => node.type === 'rule' && htmlSelectorRegExp.test(node.selector) && Object(node.nodes).length;
52-
const isRootRule = node => node.type === 'rule' && rootSelectorRegExp.test(node.selector) && Object(node.nodes).length;
51+
const isHtmlRule = node => node.type === 'rule' && node.selector.split(',').some(item => htmlSelectorRegExp.test(item)) && Object(node.nodes).length;
52+
const isRootRule = node => node.type === 'rule' && node.selector.split(',').some(item => rootSelectorRegExp.test(item)) && Object(node.nodes).length;
5353

5454
// whether the node is an custom property
5555
const isCustomDecl = node => node.type === 'decl' && customPropertyRegExp.test(node.prop);

plugins/postcss-custom-properties/test/basic.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ html {
1111
color: var(--color);
1212
}
1313

14+
:root,
15+
[data-theme=light] {
16+
--theme-color: #053;
17+
}
18+
1419
.ignore-line {
1520
/* postcss-custom-properties: ignore next */
1621
color: var(--color);
@@ -67,3 +72,7 @@ html {
6772
blue
6873
)/*rtl:red*/;
6974
}
75+
76+
.test--combined-selector {
77+
color: var(--theme-color);
78+
}

plugins/postcss-custom-properties/test/basic.expect.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ html {
1212
color: var(--color);
1313
}
1414

15+
:root,
16+
[data-theme=light] {
17+
--theme-color: #053;
18+
}
19+
1520
.ignore-line {
1621
/* postcss-custom-properties: ignore next */
1722
color: var(--color);
@@ -77,3 +82,8 @@ html {
7782
blue
7883
)/*rtl:red*/;
7984
}
85+
86+
.test--combined-selector {
87+
color: #053;
88+
color: var(--theme-color);
89+
}

plugins/postcss-custom-properties/test/basic.import-is-empty.expect.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ html {
1212
color: var(--color);
1313
}
1414

15+
:root,
16+
[data-theme=light] {
17+
--theme-color: #053;
18+
}
19+
1520
.ignore-line {
1621
/* postcss-custom-properties: ignore next */
1722
color: var(--color);
@@ -77,3 +82,8 @@ html {
7782
blue
7883
)/*rtl:red*/;
7984
}
85+
86+
.test--combined-selector {
87+
color: #053;
88+
color: var(--theme-color);
89+
}

plugins/postcss-custom-properties/test/basic.import.expect.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ html {
1212
color: var(--color);
1313
}
1414

15+
:root,
16+
[data-theme=light] {
17+
--theme-color: #053;
18+
}
19+
1520
.ignore-line {
1621
/* postcss-custom-properties: ignore next */
1722
color: var(--color);
@@ -78,3 +83,8 @@ html {
7883
blue
7984
)/*rtl:red*/;
8085
}
86+
87+
.test--combined-selector {
88+
color: #053;
89+
color: var(--theme-color);
90+
}

plugins/postcss-custom-properties/test/basic.preserve.expect.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@
5555
.test--loose-formatting {
5656
color: rgb(255, 0, 0)/*rtl:red*/;
5757
}
58+
59+
.test--combined-selector {
60+
color: #053;
61+
}

plugins/postcss-custom-properties/test/export-properties.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
--circular: var(--circular-2);
55
--circular-2: var(--circular);
66
--margin: 0 10px 20px 30px;
7+
--theme-color: #053;
78
}

plugins/postcss-custom-properties/test/export-properties.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
'--color': 'rgb(255, 0, 0)',
55
'--circular': 'var(--circular-2)',
66
'--circular-2': 'var(--circular)',
7-
'--margin': '0 10px 20px 30px'
7+
'--margin': '0 10px 20px 30px',
8+
'--theme-color': '#053'
89
}
910
};

plugins/postcss-custom-properties/test/export-properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"--color": "rgb(255, 0, 0)",
55
"--circular": "var(--circular-2)",
66
"--circular-2": "var(--circular)",
7-
"--margin": "0 10px 20px 30px"
7+
"--margin": "0 10px 20px 30px",
8+
"--theme-color": "#053"
89
}
910
}

plugins/postcss-custom-properties/test/export-properties.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export const customProperties = {
33
'--color': 'rgb(255, 0, 0)',
44
'--circular': 'var(--circular-2)',
55
'--circular-2': 'var(--circular)',
6-
'--margin': '0 10px 20px 30px'
6+
'--margin': '0 10px 20px 30px',
7+
'--theme-color': '#053'
78
};

0 commit comments

Comments
 (0)