From 0066a1ae706a2d4d9335ea43b3a339f72f1bdb98 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 12 May 2020 08:19:59 +0100 Subject: [PATCH] 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 --- .../compiler-cli/src/ngtsc/reflection/src/typescript.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts b/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts index 07bf421ef7..e25a444938 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts @@ -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 {