Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): minor fix regexp, map-filter to reduce #2684

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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