Skip to content

Commit f1329f6

Browse files
authored
fix(parser): minor fix regexp, map-filter to reduce (typescript-eslint#2684)
1 parent dccb6ee commit f1329f6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

packages/parser/src/parser.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,17 @@ function validateBoolean(
3636
return value;
3737
}
3838

39-
const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts/;
39+
const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts$/;
4040
function getLib(compilerOptions: CompilerOptions): Lib[] {
4141
if (compilerOptions.lib) {
42-
return compilerOptions.lib
43-
.map(lib => {
44-
const match = LIB_FILENAME_REGEX.exec(lib.toLowerCase());
45-
if (!match) {
46-
return null;
47-
}
48-
49-
return match[1] as Lib;
50-
})
51-
.filter(l => l != null) as Lib[];
42+
return compilerOptions.lib.reduce((acc, lib) => {
43+
const match = LIB_FILENAME_REGEX.exec(lib.toLowerCase());
44+
if (match) {
45+
acc.push(match[1] as Lib);
46+
}
47+
48+
return acc;
49+
}, [] as Lib[]);
5250
}
5351

5452
const target = compilerOptions.target ?? ScriptTarget.ES5;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy