Skip to content

Commit

Permalink
fix(parser): minor fix regexp, map-filter to reduce (#2684)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Oct 18, 2020
1 parent dccb6ee commit f1329f6
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/parser/src/parser.ts
Expand Up @@ -36,19 +36,17 @@ function validateBoolean(
return value;
}

const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts/;
const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts$/;
function getLib(compilerOptions: CompilerOptions): Lib[] {
if (compilerOptions.lib) {
return compilerOptions.lib
.map(lib => {
const match = LIB_FILENAME_REGEX.exec(lib.toLowerCase());
if (!match) {
return null;
}

return match[1] as Lib;
})
.filter(l => l != null) as Lib[];
return compilerOptions.lib.reduce((acc, lib) => {
const match = LIB_FILENAME_REGEX.exec(lib.toLowerCase());
if (match) {
acc.push(match[1] as Lib);
}

return acc;
}, [] as Lib[]);
}

const target = compilerOptions.target ?? ScriptTarget.ES5;
Expand Down

0 comments on commit f1329f6

Please sign in to comment.