refactor(compiler-cli): move map creation to avoid unnecessary work (#38959)

If the `symbol` for the given `node` does not exist then there is no
point in creating the `map`.

PR Close #38959
This commit is contained in:
Pete Bacon Darwin 2020-09-29 20:44:43 +01:00 committed by atscott
parent 87274e3eec
commit ed81588c79
1 changed files with 2 additions and 1 deletions

View File

@ -105,7 +105,6 @@ export class TypeScriptReflectionHost implements ReflectionHost {
if (!ts.isSourceFile(node)) { if (!ts.isSourceFile(node)) {
throw new Error(`getExportsOfModule() called on non-SourceFile in TS code`); throw new Error(`getExportsOfModule() called on non-SourceFile in TS code`);
} }
const map = new Map<string, Declaration>();
// Reflect the module to a Symbol, and use getExportsOfModule() to get a list of exported // Reflect the module to a Symbol, and use getExportsOfModule() to get a list of exported
// Symbols. // Symbols.
@ -113,6 +112,8 @@ export class TypeScriptReflectionHost implements ReflectionHost {
if (symbol === undefined) { if (symbol === undefined) {
return null; return null;
} }
const map = new Map<string, Declaration>();
this.checker.getExportsOfModule(symbol).forEach(exportSymbol => { this.checker.getExportsOfModule(symbol).forEach(exportSymbol => {
// Map each exported Symbol to a Declaration and add it to the map. // Map each exported Symbol to a Declaration and add it to the map.
const decl = this.getDeclarationOfSymbol(exportSymbol, null); const decl = this.getDeclarationOfSymbol(exportSymbol, null);