(fileNames: string[])
| 430 | } |
| 431 | |
| 432 | function generateDocumentation(fileNames: string[]): void { |
| 433 | const configFile = getTsCompilerOptionsJson(); |
| 434 | const host = new TypeScriptLanguageServiceHost(fileNames, configFile.options); |
| 435 | const languageService = ts.createLanguageService(host, undefined, ts.LanguageServiceMode.Semantic); |
| 436 | const program = languageService.getProgram()!; |
| 437 | const typeChecker = program!.getTypeChecker(); |
| 438 | const entries = new Map<string, TelemetryEntry>(); |
| 439 | |
| 440 | // First generate documentation for common properties and measures. |
| 441 | generateDocumentationForCommonTypes(fileNames); |
| 442 | |
| 443 | // Visit every sourceFile in the program |
| 444 | if (program) { |
| 445 | for (const sourceFile of program.getSourceFiles()) { |
| 446 | if (!sourceFile.isDeclarationFile) { |
| 447 | // Walk the tree to search for classes |
| 448 | ts.forEachChild(sourceFile, visit.bind(undefined, sourceFile)); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | /** visit nodes finding exported classes */ |
| 453 | function visit(sourceFile: ts.SourceFile, node: ts.Node) { |
| 454 | // Only consider exported nodes |
| 455 | if (!isNodeExported(node)) { |
| 456 | return; |
| 457 | } |
| 458 | if (ts.isModuleDeclaration(node)) { |
| 459 | // This is a namespace, visit its children |
| 460 | ts.forEachChild(node, visit.bind(undefined, sourceFile)); |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | if (!ts.isClassDeclaration(node) || node.name?.text !== 'IEventNamePropertyMapping') { |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | try { |
| 469 | node.members.forEach((m) => { |
| 470 | if (ts.isPropertyDeclaration(m)) { |
| 471 | const typeNode = m.type; |
| 472 | if (!typeNode || typeNode.kind !== ts.SyntaxKind.TypeReference) { |
| 473 | console.error(`Unrecognized type ${m.name.getText()}`); |
| 474 | } else if ( |
| 475 | typeNode && |
| 476 | ts.isTypeReferenceNode(typeNode) && |
| 477 | typeNode.typeArguments?.length === 1 && |
| 478 | typeNode.typeName.getText() === 'TelemetryEventInfo' |
| 479 | ) { |
| 480 | let name = m.name.getText().trim(); |
| 481 | let constantName = m.name.getText().trim().replace('[', '').replace(']', ''); |
| 482 | |
| 483 | if (m.name.kind === ts.SyntaxKind.ComputedPropertyName) { |
| 484 | const defs = languageService.getDefinitionAtPosition( |
| 485 | m.getSourceFile().fileName, |
| 486 | m.name.end - 1 |
| 487 | ); |
| 488 | if (defs && defs.length) { |
| 489 | const refSourceFile = program!.getSourceFile(defs[0].fileName); |
no test coverage detected