Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/get-custom-properties-from-root.js
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 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 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);
}
10 changes: 10 additions & 0 deletions test/basic.import-is-empty.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);
}
10 changes: 10 additions & 0 deletions 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);
}
4 changes: 4 additions & 0 deletions test/basic.preserve.expect.css
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;
}
1 change: 1 addition & 0 deletions test/export-properties.css
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 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'
}
};
3 changes: 2 additions & 1 deletion test/export-properties.json
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 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'
};