@ts-ast-parser/core
Version:
Reflects a simplified version of the TypeScript AST for generating documentation
72 lines • 2.35 kB
JavaScript
import { isBrowser } from './is-browser.js';
import ts from 'typescript';
/**
* This is used by the TypeScript Program to interact
* with the System Interface.
*/
export class CompilerHost {
constructor(system, options) {
Object.defineProperty(this, "_system", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_options", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_cwd", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._system = system;
this._options = options;
this._cwd = system.getCurrentDirectory();
}
getSourceFile(fileName, options) {
const text = this.readFile(fileName, this._options.charset);
return ts.createSourceFile(fileName, text, options, true);
}
getDefaultLibFileName(options) {
return isBrowser ? ts.getDefaultLibFileName(options) : ts.getDefaultLibFilePath(options);
}
writeFile(fileName, text, writeByteOrderMark) {
this._system.writeFile(fileName, text, writeByteOrderMark);
}
getCurrentDirectory() {
return this._cwd;
}
useCaseSensitiveFileNames() {
return this._system.useCaseSensitiveFileNames;
}
getCanonicalFileName(fileName) {
return this._system.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
}
getNewLine() {
return this._system.newLine;
}
fileExists(fileName) {
return this._system.fileExists(fileName);
}
readFile(fileName, encoding) {
return this._system.readFile(fileName, encoding) ?? '';
}
directoryExists(directoryName) {
return this._system.directoryExists(directoryName);
}
getDirectories(filePath) {
return this._system.getDirectories(filePath);
}
readDirectory(rootDir, extensions, excludes, includes, depth) {
return this._system.readDirectory(rootDir, extensions, excludes, includes, depth);
}
realpath(filePath) {
return this._system.realpath(filePath);
}
}
//# sourceMappingURL=compiler-host.js.map