refactor(compiler-cli): simplify and clarify `TypeScriptReflectionHost.isClass()` (#36989)

The comment in this function confused me, so I updated it to clarify that
`isClass()` is not true for un-named classes.

Also, I took the opportunity to use a helper method to simplify the function
itself.

PR Close #36989
This commit is contained in:
Pete Bacon Darwin 2020-05-12 08:19:59 +01:00 committed by Kara Erickson
parent 491da99abe
commit 0066a1ae70
1 changed files with 4 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import * as ts from 'typescript';
import {ClassDeclaration, ClassMember, ClassMemberKind, CtorParameter, Declaration, Decorator, FunctionDefinition, Import, isDecoratorIdentifier, ReflectionHost} from './host';
import {typeToValue} from './type_to_value';
import {isNamedClassDeclaration} from './util';
/**
* reflector.ts implements static reflection of declarations using the TypeScript `ts.TypeChecker`.
@ -121,9 +122,9 @@ export class TypeScriptReflectionHost implements ReflectionHost {
}
isClass(node: ts.Node): node is ClassDeclaration {
// In TypeScript code, classes are ts.ClassDeclarations.
// (`name` can be undefined in unnamed default exports: `default export class { ... }`)
return ts.isClassDeclaration(node) && (node.name !== undefined) && ts.isIdentifier(node.name);
// For our purposes, classes are "named" ts.ClassDeclarations;
// (`node.name` can be undefined in unnamed default exports: `default export class { ... }`).
return isNamedClassDeclaration(node);
}
hasBaseClass(clazz: ClassDeclaration): boolean {