* Finds the absolute declaration file path of a type if imported.
(typeName: string)
| 224 | * Finds the absolute declaration file path of a type if imported. |
| 225 | */ |
| 226 | findTypeDeclaration(typeName: string): string | null { |
| 227 | for (const statement of this.sourceFile.statements) { |
| 228 | if (ts.isImportDeclaration(statement) && statement.importClause) { |
| 229 | const namedBindings = statement.importClause.namedBindings; |
| 230 | if (namedBindings && ts.isNamedImports(namedBindings)) { |
| 231 | const imports = namedBindings.elements.filter( |
| 232 | (element) => element.name.text === typeName, |
| 233 | ); |
| 234 | if (imports.length > 0) { |
| 235 | const moduleSpecifier = ( |
| 236 | statement.moduleSpecifier as ts.StringLiteral |
| 237 | ).text; |
| 238 | // Resolve the path relative to the directory of the current source file |
| 239 | let resolvedPath = resolve( |
| 240 | dirname(this.sourceFile.fileName), |
| 241 | moduleSpecifier, |
| 242 | ); |
| 243 | |
| 244 | if (existsSync(resolvedPath + ".ts")) { |
| 245 | return resolvedPath + ".ts"; |
| 246 | } else if (existsSync(resolvedPath + ".tsx")) { |
| 247 | return resolvedPath + ".tsx"; |
| 248 | } |
| 249 | return null; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | return null; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Get the public method definitions of a class. |
no test coverage detected