Gets the base class for the given class declaration.
( node: ts.ClassDeclaration, typeChecker: ts.TypeChecker, )
| 105 | |
| 106 | /** Gets the base class for the given class declaration. */ |
| 107 | function getBaseClass( |
| 108 | node: ts.ClassDeclaration, |
| 109 | typeChecker: ts.TypeChecker, |
| 110 | ): ts.ClassDeclaration | null { |
| 111 | const baseTypes = getExtendsHeritageExpressions(node); |
| 112 | |
| 113 | if (baseTypes.length > 1) { |
| 114 | throw Error('Class unexpectedly extends from multiple types.'); |
| 115 | } |
| 116 | |
| 117 | const baseClass = typeChecker.getTypeAtLocation(baseTypes[0]).getSymbol(); |
| 118 | const baseClassDecl = baseClass?.valueDeclaration ?? baseClass?.declarations?.[0]; |
| 119 | |
| 120 | if (baseClassDecl !== undefined && ts.isClassDeclaration(baseClassDecl)) { |
| 121 | return baseClassDecl; |
| 122 | } |
| 123 | |
| 124 | return null; |
| 125 | } |
| 126 | |
| 127 | /** Gets the `extends` base type expressions of the specified class. */ |
| 128 | function getExtendsHeritageExpressions( |
no test coverage detected
searching dependent graphs…