in repo-scripts/prune-dts/prune-dts.ts [458:514]
function visit(node: ts.Node): ts.Node {
if (
ts.isInterfaceDeclaration(node) ||
ts.isClassDeclaration(node) ||
ts.isFunctionDeclaration(node) ||
ts.isVariableStatement(node) ||
ts.isTypeAliasDeclaration(node) ||
ts.isModuleDeclaration(node) ||
ts.isEnumDeclaration(node)
) {
// Remove any types that are not exported.
if (
!node.modifiers?.find(m => m.kind === ts.SyntaxKind.ExportKeyword)
) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
}
}
if (ts.isConstructorDeclaration(node)) {
// Replace internal constructors with private constructors.
return maybeHideConstructor(node);
} else if (
ts.isClassDeclaration(node) ||
ts.isInterfaceDeclaration(node)
) {
// Remove any imports that reference internal APIs, while retaining
// their public members.
return prunePrivateImports(program, host, sourceFile, node);
} else if (
ts.isPropertyDeclaration(node) ||
ts.isMethodDeclaration(node) ||
ts.isGetAccessor(node)
) {
// Remove any class and interface members that are prefixed with
// underscores.
if (hasPrivatePrefix(node.name as ts.Identifier)) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
}
} else if (ts.isTypeReferenceNode(node)) {
// For public types that refer internal types, find a public type that
// we can refer to instead.
const publicName = extractExportedSymbol(
typeChecker,
sourceFile,
node.typeName
);
return publicName
? ts.updateTypeReferenceNode(
node,
ts.createIdentifier(publicName.name),
node.typeArguments
)
: node;
}
return node;
}