ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
119 lines (118 loc) • 4.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var errors = require("./errors");
var factories_1 = require("./factories");
var compiler_1 = require("./compiler");
var ManipulationSettings_1 = require("./ManipulationSettings");
/**
* Global container.
* @internal
*/
var GlobalContainer = /** @class */ (function () {
function GlobalContainer(fileSystem, compilerOptions, opts) {
this._manipulationSettings = new ManipulationSettings_1.ManipulationSettingsContainer();
this._fileSystem = fileSystem;
this._compilerOptions = compilerOptions;
this._compilerFactory = new factories_1.CompilerFactory(this);
this._languageService = opts.createLanguageService ? new compiler_1.LanguageService(this) : undefined;
if (opts.typeChecker != null) {
errors.throwIfTrue(opts.createLanguageService, "Cannot specify a type checker and create a language service.");
this._customTypeChecker = new compiler_1.TypeChecker(this);
this._customTypeChecker.reset(function () { return opts.typeChecker; });
}
}
Object.defineProperty(GlobalContainer.prototype, "fileSystem", {
/** Gets the file system. */
get: function () {
return this._fileSystem;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "compilerOptions", {
/** Gets the compiler options. */
get: function () {
return this._compilerOptions;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "manipulationSettings", {
/** Gets the manipulation settings. */
get: function () {
return this._manipulationSettings;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "compilerFactory", {
/** Gets the compiler factory. */
get: function () {
return this._compilerFactory;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "languageService", {
/** Gets the language service. Throws an exception if it doesn't exist. */
get: function () {
if (this._languageService == null)
throw this.getToolRequiredError("language service");
return this._languageService;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "program", {
/**
* Gets the program.
*/
get: function () {
if (this._languageService == null)
throw this.getToolRequiredError("program");
return this.languageService.getProgram();
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalContainer.prototype, "typeChecker", {
/**
* Gets the type checker.
*/
get: function () {
if (this._customTypeChecker != null)
return this._customTypeChecker;
if (this._languageService == null)
throw this.getToolRequiredError("type checker");
return this.program.getTypeChecker();
},
enumerable: true,
configurable: true
});
/**
* Gets if this object has a language service.
*/
GlobalContainer.prototype.hasLanguageService = function () {
return this._languageService != null;
};
/**
* Gets the encoding.
*/
GlobalContainer.prototype.getEncoding = function () {
return this.compilerOptions.charset || "utf-8";
};
/**
* Resets the program.
*/
GlobalContainer.prototype.resetProgram = function () {
this.languageService.resetProgram();
};
GlobalContainer.prototype.getToolRequiredError = function (name) {
return new errors.InvalidOperationError("A " + name + " 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 " + name + " should be required for this operation."));
};
return GlobalContainer;
}());
exports.GlobalContainer = GlobalContainer;