(module: SourceModule)
| 733 | } |
| 734 | |
| 735 | keepRead(module: SourceModule): void { |
| 736 | for (const statement of module.program.body) { |
| 737 | if ( |
| 738 | statement.type === "ImportDeclaration" || |
| 739 | statement.type === "ExportAllDeclaration" |
| 740 | ) |
| 741 | continue |
| 742 | if (statement.type === "ExportNamedDeclaration") { |
| 743 | if ( |
| 744 | statement.declaration && |
| 745 | !isPure(statement.declaration, module.source) |
| 746 | ) |
| 747 | this.keep(module, statement) |
| 748 | continue |
| 749 | } |
| 750 | // e.g. `export default T`, kept where an import reads it |
| 751 | if (statement.type === "ExportDefaultDeclaration") { |
| 752 | const { declaration } = statement |
| 753 | if ( |
| 754 | declaration.type !== "FunctionDeclaration" && |
| 755 | !isPureExpression(declaration, module.source) |
| 756 | ) |
| 757 | this.keep(module, statement) |
| 758 | continue |
| 759 | } |
| 760 | if ( |
| 761 | statement.type === "TSImportEqualsDeclaration" && |
| 762 | statement.moduleReference.type === "TSExternalModuleReference" |
| 763 | ) |
| 764 | this.keepLoaded(statement.moduleReference.expression, module) |
| 765 | if (!isPure(statement, module.source)) this.keep(module, statement) |
| 766 | } |
| 767 | // e.g. import() or require(), reading every export |
| 768 | walk(module.program, node => { |
| 769 | const loaded = loadedSourceOf(node) |
| 770 | if (loaded) this.keepLoaded(loaded, module) |
| 771 | return true |
| 772 | }) |
| 773 | } |
| 774 | |
| 775 | keepExports(module: SourceModule): void { |
| 776 | for (const name in module.scopes.exportsByName) |
no test coverage detected