UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

78 lines (76 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const errors = require("./errors"); const factories_1 = require("./factories"); const compiler_1 = require("./compiler"); const ManipulationSettings_1 = require("./ManipulationSettings"); /** * Global container. * @internal */ class GlobalContainer { constructor(fileSystem, compilerOptions, createLanguageService) { this._manipulationSettings = new ManipulationSettings_1.ManipulationSettingsContainer(); this._fileSystem = fileSystem; this._compilerOptions = compilerOptions; this._compilerFactory = new factories_1.CompilerFactory(this); this._languageService = createLanguageService ? new compiler_1.LanguageService(this) : undefined; if (this._languageService != null) { this.compilerFactory.onSourceFileAdded(args => { this._languageService.addSourceFile(args.addedSourceFile); }); } } /** Gets the file system. */ get fileSystem() { return this._fileSystem; } /** Gets the compiler options. */ get compilerOptions() { return this._compilerOptions; } /** Gets the manipulation settings. */ get manipulationSettings() { return this._manipulationSettings; } /** Gets the compiler factory. */ get compilerFactory() { return this._compilerFactory; } /** Gets the language service. Throws an exception if it doesn't exist. */ get languageService() { if (this._languageService == null) { throw new errors.InvalidOperationError("A language service is required for this operation. " + "This might occur when manipulating or getting type information from a node that was not added " + `to a TsSimpleAst object and created via ${"createWrappedNode"}. ` + "Please submit a bug report if you don't believe a language service should be required for this operation."); } return this._languageService; } /** * Gets the program. */ get program() { return this.languageService.getProgram(); } /** * Gets the type checker. */ get typeChecker() { return this.program.getTypeChecker(); } /** * Gets if this object has a language service. */ hasLanguageService() { return this._languageService != null; } /** * Resets the program. */ resetProgram() { this.languageService.resetProgram(); } } exports.GlobalContainer = GlobalContainer; //# sourceMappingURL=GlobalContainer.js.map