Skip to content

Commit

Permalink
Allow combined selectors (postcss/postcss-custom-properties#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuran authored and romainmenke committed Dec 15, 2021
1 parent 6e1f902 commit 896db28
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const rootSelectorRegExp = /^:root$/i;
const customPropertyRegExp = /^--[A-z][\w-]*$/;

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

// whether the node is an custom property
const isCustomDecl = node => node.type === 'decl' && customPropertyRegExp.test(node.prop);
Expand Down
9 changes: 9 additions & 0 deletions plugins/postcss-custom-properties/test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ html {
color: var(--color);
}

:root,
[data-theme=light] {
--theme-color: #053;
}

.ignore-line {
/* postcss-custom-properties: ignore next */
color: var(--color);
Expand Down Expand Up @@ -67,3 +72,7 @@ html {
blue
)/*rtl:red*/;
}

.test--combined-selector {
color: var(--theme-color);
}
10 changes: 10 additions & 0 deletions plugins/postcss-custom-properties/test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ html {
color: var(--color);
}

:root,
[data-theme=light] {
--theme-color: #053;
}

.ignore-line {
/* postcss-custom-properties: ignore next */
color: var(--color);
Expand Down Expand Up @@ -77,3 +82,8 @@ html {
blue
)/*rtl:red*/;
}

.test--combined-selector {
color: #053;
color: var(--theme-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ html {
color: var(--color);
}

:root,
[data-theme=light] {
--theme-color: #053;
}

.ignore-line {
/* postcss-custom-properties: ignore next */
color: var(--color);
Expand Down Expand Up @@ -77,3 +82,8 @@ html {
blue
)/*rtl:red*/;
}

.test--combined-selector {
color: #053;
color: var(--theme-color);
}
10 changes: 10 additions & 0 deletions plugins/postcss-custom-properties/test/basic.import.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ html {
color: var(--color);
}

:root,
[data-theme=light] {
--theme-color: #053;
}

.ignore-line {
/* postcss-custom-properties: ignore next */
color: var(--color);
Expand Down Expand Up @@ -78,3 +83,8 @@ html {
blue
)/*rtl:red*/;
}

.test--combined-selector {
color: #053;
color: var(--theme-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@
.test--loose-formatting {
color: rgb(255, 0, 0)/*rtl:red*/;
}

.test--combined-selector {
color: #053;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
--circular: var(--circular-2);
--circular-2: var(--circular);
--margin: 0 10px 20px 30px;
--theme-color: #053;
}
3 changes: 2 additions & 1 deletion plugins/postcss-custom-properties/test/export-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'--color': 'rgb(255, 0, 0)',
'--circular': 'var(--circular-2)',
'--circular-2': 'var(--circular)',
'--margin': '0 10px 20px 30px'
'--margin': '0 10px 20px 30px',
'--theme-color': '#053'
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"--color": "rgb(255, 0, 0)",
"--circular": "var(--circular-2)",
"--circular-2": "var(--circular)",
"--margin": "0 10px 20px 30px"
"--margin": "0 10px 20px 30px",
"--theme-color": "#053"
}
}
3 changes: 2 additions & 1 deletion plugins/postcss-custom-properties/test/export-properties.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export const customProperties = {
'--color': 'rgb(255, 0, 0)',
'--circular': 'var(--circular-2)',
'--circular-2': 'var(--circular)',
'--margin': '0 10px 20px 30px'
'--margin': '0 10px 20px 30px',
'--theme-color': '#053'
};

0 comments on commit 896db28

Please sign in to comment.