in lib/main.ts [368:414]
private translate(sourceFile: ts.SourceFile): string {
this.currentFile = sourceFile;
this.outputs = [];
this.outputStack = [];
this.imports = new Map();
for (let i = 0; i < NUM_OUTPUT_CONTEXTS; ++i) {
this.outputs.push(new Output());
}
this.lastCommentIdx = -1;
this.pushContext(OutputContext.Default);
this.visit(sourceFile);
this.popContext();
if (this.outputStack.length > 0) {
this.reportError(
sourceFile,
'Internal error managing output contexts. ' +
'Inconsistent push and pop context calls.');
}
this.pushContext(OutputContext.Import);
this.imports.forEach((summary, name) => {
this.emit(`import ${JSON.stringify(name)}`);
if (!summary.showAll) {
let shownNames = Array.from(summary.shown);
if (shownNames.length > 0) {
this.emit(`show ${shownNames.join(', ')}`);
}
}
if (summary.asPrefix) {
this.emit(`as ${summary.asPrefix}`);
}
this.emit(';\n');
});
this.popContext();
let result = '';
for (let output of this.outputs) {
result += output.getResult();
}
if (this.options.skipFormatting) {
return result;
}
return this.formatCode(result, sourceFile);
}