@@ -5,14 +5,15 @@ const selectorParser = require('postcss-selector-parser');
5
5
const nameGenerators = require ( './name-generators' ) ;
6
6
7
7
class MinifyClassnames {
8
- constructor ( { genNameClass, genNameId, filter, customAttributes = [ ] } = { } ) {
8
+ constructor ( { genNameClass, genNameId, filter, customAttributes = [ ] , removeUnfound = true } = { } ) {
9
9
this . filter = filter || / ^ .j s - / ;
10
10
// TODO: Pass a seed for emojinamestring, make this better
11
11
this . genNameClass = this . getNameGenerator ( genNameClass , 7 ) ;
12
12
this . genNameId = this . getNameGenerator ( genNameId , 5 ) ;
13
13
this . classMap = { } ;
14
14
this . idMap = { } ;
15
15
this . customAttributes = customAttributes ;
16
+ this . removeUnfound = removeUnfound ;
16
17
}
17
18
18
19
getNameGenerator ( value , seed ) {
@@ -75,7 +76,7 @@ class MinifyClassnames {
75
76
return value ;
76
77
}
77
78
78
- return this . classMap [ value ] || '' ;
79
+ return this . classMap [ value ] || ( this . removeUnfound ? '' : value ) ;
79
80
} )
80
81
. filter ( Boolean )
81
82
. join ( ' ' )
@@ -93,7 +94,7 @@ class MinifyClassnames {
93
94
return value ;
94
95
}
95
96
96
- return this . classMap [ value ] || '' ;
97
+ return this . classMap [ value ] || ( this . removeUnfound ? '' : value ) ;
97
98
} )
98
99
. filter ( Boolean )
99
100
. join ( ' ' )
@@ -109,11 +110,11 @@ class MinifyClassnames {
109
110
return value ;
110
111
}
111
112
112
- if ( ! this . idMap [ value ] ) {
113
+ if ( ! this . idMap [ value ] && this . removeUnfound ) {
113
114
this . idMap [ value ] = this . genNameId . next ( ) . value ;
114
115
}
115
116
116
- return this . idMap [ value ] ;
117
+ return this . idMap [ value ] || ( this . removeUnfound ? '' : value ) ;
117
118
} )
118
119
. join ( ' ' ) ;
119
120
}
0 commit comments