From f1329f6c4e3d1de21b1dc59c30ce16503c346eee Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Sun, 18 Oct 2020 22:23:33 +0300 Subject: [PATCH] fix(parser): minor fix regexp, map-filter to reduce (#2684) --- packages/parser/src/parser.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 54dbd399724..c1422dc261b 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -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;