in lib/merge.ts [589:614]
function gatherClasses(n: ts.Node, classes: Map<string, base.ClassLike>) {
if (ts.isClassExpression(n) || ts.isClassDeclaration(n) || ts.isInterfaceDeclaration(n)) {
let classDecl = <base.ClassLike>n;
let name = classDecl.name.text;
// TODO(jacobr): validate that the classes have consistent
// modifiers, etc.
if (classes.has(name)) {
let existing = classes.get(name);
(classDecl.members as ts.NodeArray<ts.ClassElement>).forEach((e: ts.ClassElement) => {
// Small hack to get around NodeArrays being readonly
Array.prototype.push.call(existing.members, e);
e.parent = existing;
});
nodeReplacements.set(classDecl, undefined);
} else {
classes.set(name, classDecl);
// Perform other class level post processing here.
}
} else if (ts.isModuleDeclaration(n) || ts.isSourceFile(n)) {
const moduleClasses: Map<string, base.ClassLike> = new Map();
ts.forEachChild(n, (child) => gatherClasses(child, moduleClasses));
ts.forEachChild(n, (child) => mergeVariablesIntoClasses(child, moduleClasses));
} else if (ts.isModuleBlock(n)) {
ts.forEachChild(n, (child) => gatherClasses(child, classes));
}
}