Skip to content

Commit 010ce5c

Browse files
cmrnclshortfuse
authored andcommitted
Use map instead of tuple array
1 parent 7765bc3 commit 010ce5c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/Detector.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ export default class Detector {
7373
* @param {(FeatureKeys & string)[]} featureList an array of feature slugs (see caniuse-db)
7474
*/
7575
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+
}
8384
/** @type {(FeatureKeys & string)[]} */
8485
this.ignore = [];
8586
}
@@ -98,7 +99,7 @@ export default class Detector {
9899
switch (option) {
99100
case DISABLE_FEATURE_COMMENT: {
100101
if (value === '') {
101-
this.ignore = this.features.map(([featureName]) => featureName);
102+
this.ignore = [...this.features.keys()];
102103
} else {
103104
for (const feat of value.split(',')) {
104105
/** @type {any} */
@@ -135,9 +136,10 @@ export default class Detector {
135136
return;
136137
}
137138

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+
}
141143
}
142144

143145
if (child.type !== 'decl') {

0 commit comments

Comments
 (0)