1
1
import valuesParser from 'postcss-value-parser' ;
2
- import { isBlockIgnored } from './is-ignored' ;
2
+ import { isBlockIgnored , isDeclarationIgnored } from './is-ignored' ;
3
3
4
4
// return custom selectors from the css root, conditionally removing them
5
5
export default function getCustomPropertiesFromRoot ( root , opts ) : Map < string , valuesParser . ParsedValue > {
6
6
// initialize custom selectors
7
- const customPropertiesFromHtmlElement : Map < string , valuesParser . ParsedValue > = new Map ( ) ;
8
- const customPropertiesFromRootPseudo : Map < string , valuesParser . ParsedValue > = new Map ( ) ;
9
- const out : Map < string , valuesParser . ParsedValue > = new Map ( ) ;
7
+ const customPropertiesFromHtmlElement : Map < string , string > = new Map ( ) ;
8
+ const customPropertiesFromRootPseudo : Map < string , string > = new Map ( ) ;
10
9
11
10
// for each html or :root rule
12
11
root . nodes . slice ( ) . forEach ( rule => {
12
+ if ( isBlockIgnored ( rule ) ) {
13
+ return ;
14
+ }
15
+
13
16
const customPropertiesObject = isHtmlRule ( rule )
14
17
? customPropertiesFromHtmlElement
15
18
: isRootRule ( rule )
@@ -19,11 +22,11 @@ export default function getCustomPropertiesFromRoot(root, opts): Map<string, val
19
22
// for each custom property
20
23
if ( customPropertiesObject ) {
21
24
rule . nodes . slice ( ) . forEach ( decl => {
22
- if ( decl . variable && ! isBlockIgnored ( decl ) ) {
25
+ if ( decl . variable && ! isDeclarationIgnored ( decl ) ) {
23
26
const { prop } = decl ;
24
27
25
28
// write the parsed value to the custom property
26
- customPropertiesObject . set ( prop , valuesParser ( decl . value ) ) ;
29
+ customPropertiesObject . set ( prop , decl . value ) ;
27
30
28
31
// conditionally remove the custom property declaration
29
32
if ( ! opts . preserve ) {
@@ -33,18 +36,19 @@ export default function getCustomPropertiesFromRoot(root, opts): Map<string, val
33
36
} ) ;
34
37
35
38
// conditionally remove the empty html or :root rule
36
- if ( ! opts . preserve && isEmptyParent ( rule ) && ! isBlockIgnored ( rule ) ) {
39
+ if ( ! opts . preserve && isEmptyParent ( rule ) ) {
37
40
rule . remove ( ) ;
38
41
}
39
42
}
40
43
} ) ;
41
44
45
+ const out : Map < string , valuesParser . ParsedValue > = new Map ( ) ;
42
46
for ( const [ name , value ] of customPropertiesFromHtmlElement . entries ( ) ) {
43
- out . set ( name , value ) ;
47
+ out . set ( name , valuesParser ( value ) ) ;
44
48
}
45
49
46
50
for ( const [ name , value ] of customPropertiesFromRootPseudo . entries ( ) ) {
47
- out . set ( name , value ) ;
51
+ out . set ( name , valuesParser ( value ) ) ;
48
52
}
49
53
50
54
// return all custom properties, preferring :root properties over html properties
0 commit comments