( node: ts.ModuleDeclaration, context: SerializationContext )
| 450 | } |
| 451 | |
| 452 | const moduleMembers = ( |
| 453 | node: ts.ModuleDeclaration, |
| 454 | context: SerializationContext |
| 455 | ): ReadonlyArray<DeclarationModel> => { |
| 456 | let body = node.body |
| 457 | while (body !== undefined && ts.isModuleDeclaration(body)) { |
| 458 | body = body.body |
| 459 | } |
| 460 | if (body === undefined || !ts.isModuleBlock(body)) { |
| 461 | return [] |
| 462 | } |
| 463 | return body.statements.flatMap((statement) => { |
| 464 | if ( |
| 465 | ts.isFunctionDeclaration(statement) || ts.isInterfaceDeclaration(statement) || |
| 466 | ts.isTypeAliasDeclaration(statement) || ts.isClassDeclaration(statement) || |
| 467 | ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || |
| 468 | ts.isVariableStatement(statement) |
| 469 | ) { |
| 470 | if (ts.isVariableStatement(statement)) { |
| 471 | return statement.declarationList.declarations.map((declaration) => serializeDeclaration(declaration, context)) |
| 472 | } |
| 473 | return [serializeDeclaration(statement, context)] |
| 474 | } |
| 475 | if (ts.isExportDeclaration(statement) || ts.isImportDeclaration(statement)) { |
| 476 | return [] |
| 477 | } |
| 478 | throw new Error(`Unsupported public namespace statement: ${ts.SyntaxKind[statement.kind]}`) |
| 479 | }).sort((left, right) => `${left.kind}:${left.name}`.localeCompare(`${right.kind}:${right.name}`)) |
| 480 | } |
| 481 | |
| 482 | const serializeDeclaration = (node: ts.Declaration, context: SerializationContext): DeclarationModel => { |
| 483 | if (ts.isFunctionDeclaration(node)) { |
no test coverage detected