( node: ts.ModuleDeclaration, context: SerializationContext )
| 437 | } |
| 438 | |
| 439 | const moduleMembers = ( |
| 440 | node: ts.ModuleDeclaration, |
| 441 | context: SerializationContext |
| 442 | ): ReadonlyArray<DeclarationModel> => { |
| 443 | let body = node.body |
| 444 | while (body !== undefined && ts.isModuleDeclaration(body)) { |
| 445 | body = body.body |
| 446 | } |
| 447 | if (body === undefined || !ts.isModuleBlock(body)) { |
| 448 | return [] |
| 449 | } |
| 450 | return body.statements.flatMap((statement) => { |
| 451 | if ( |
| 452 | ts.isFunctionDeclaration(statement) || ts.isInterfaceDeclaration(statement) || |
| 453 | ts.isTypeAliasDeclaration(statement) || ts.isClassDeclaration(statement) || |
| 454 | ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || |
| 455 | ts.isVariableStatement(statement) |
| 456 | ) { |
| 457 | if (ts.isVariableStatement(statement)) { |
| 458 | return statement.declarationList.declarations.map((declaration) => serializeDeclaration(declaration, context)) |
| 459 | } |
| 460 | return [serializeDeclaration(statement, context)] |
| 461 | } |
| 462 | if (ts.isExportDeclaration(statement) || ts.isImportDeclaration(statement)) { |
| 463 | return [] |
| 464 | } |
| 465 | throw new Error(`Unsupported public namespace statement: ${ts.SyntaxKind[statement.kind]}`) |
| 466 | }).sort((left, right) => `${left.kind}:${left.name}`.localeCompare(`${right.kind}:${right.name}`)) |
| 467 | } |
| 468 | |
| 469 | const serializeDeclaration = (node: ts.Declaration, context: SerializationContext): DeclarationModel => { |
| 470 | if (ts.isFunctionDeclaration(node)) { |
no test coverage detected