@@ -73,13 +73,14 @@ export default class Detector {
73
73
* @param {(FeatureKeys & string)[] } featureList an array of feature slugs (see caniuse-db)
74
74
*/
75
75
constructor ( featureList ) {
76
- /** @type {[FeatureKeys, RuleCheck][] } */
77
- this . features = featureList
78
- . filter ( ( featureName ) => FEATURES [ featureName ] != null )
79
- . map ( ( featureName ) => {
80
- const feature = FEATURES [ featureName ] ;
81
- return [ featureName , normaliseFeature ( feature ) ] ;
82
- } ) ;
76
+ /** @type {Map<FeatureKeys, RuleCheck> } */
77
+ this . features = new Map ( ) ;
78
+ for ( const featureName of featureList ) {
79
+ const feature = FEATURES [ featureName ] ;
80
+ if ( feature != null ) {
81
+ this . features . set ( featureName , normaliseFeature ( feature ) ) ;
82
+ }
83
+ }
83
84
/** @type {(FeatureKeys & string)[] } */
84
85
this . ignore = [ ] ;
85
86
}
@@ -98,7 +99,7 @@ export default class Detector {
98
99
switch ( option ) {
99
100
case DISABLE_FEATURE_COMMENT : {
100
101
if ( value === '' ) {
101
- this . ignore = this . features . map ( ( [ featureName ] ) => featureName ) ;
102
+ this . ignore = [ ... this . features . keys ( ) ] ;
102
103
} else {
103
104
for ( const feat of value . split ( ',' ) ) {
104
105
/** @type {any } */
@@ -135,9 +136,10 @@ export default class Detector {
135
136
return ;
136
137
}
137
138
138
- const detectedFeatures = this . features . filter ( ( [ , ruleCheck ] ) => ruleCheck ( child ) ) ;
139
- for ( const [ featureName ] of detectedFeatures ) {
140
- callback ( { usage : child , feature : featureName , ignore : this . ignore } ) ;
139
+ for ( const [ feature , ruleCheck ] of this . features ) {
140
+ if ( ruleCheck ( child ) ) {
141
+ callback ( { usage : child , feature, ignore : this . ignore } ) ;
142
+ }
141
143
}
142
144
143
145
if ( child . type !== 'decl' ) {
0 commit comments