ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
51 lines (49 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const TypeChecker_1 = require("./TypeChecker");
const results_1 = require("./results");
/**
* Wrapper around Program.
*/
class Program {
/** @internal */
constructor(global, rootNames, host) {
this.global = global;
this.typeChecker = new TypeChecker_1.TypeChecker(this.global);
this.reset(rootNames, host);
}
/**
* Gets the underlying compiler program.
*/
get compilerObject() {
return this._compilerObject;
}
/**
* Resets the program.
* @internal
*/
reset(rootNames, host) {
this._compilerObject = ts.createProgram(rootNames, this.global.compilerOptions, host, this._compilerObject);
this.typeChecker.reset(this._compilerObject.getTypeChecker());
}
/**
* Get the program's type checker.
*/
getTypeChecker() {
return this.typeChecker;
}
/**
* Emits the TypeScript files to the specified target.
*/
emit(options = {}) {
const targetSourceFile = options != null && options.targetSourceFile != null ? options.targetSourceFile.compilerNode : undefined;
const cancellationToken = undefined; // todo: expose this
const emitOnlyDtsFiles = options != null && options.emitOnlyDtsFiles != null ? options.emitOnlyDtsFiles : undefined;
const customTransformers = undefined; // todo: expose this
const emitResult = this.compilerObject.emit(targetSourceFile, undefined, cancellationToken, emitOnlyDtsFiles, customTransformers);
return new results_1.EmitResult(this.global, emitResult);
}
}
exports.Program = Program;
//# sourceMappingURL=Program.js.map