MCPcopy Index your code
hub / github.com/nodejs/node / createCompilerHostFromProgramHost

Function createCompilerHostFromProgramHost

test/fixtures/snapshot/typescript.js:123116–123172  ·  view source on GitHub ↗
(host, getCompilerOptions, directoryStructureHost)

Source from the content-addressed store, hash-verified

123114 }
123115 ts.createWatchFactory = createWatchFactory;
123116 function createCompilerHostFromProgramHost(host, getCompilerOptions, directoryStructureHost) {
123117 if (directoryStructureHost === void 0) { directoryStructureHost = host; }
123118 var useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
123119 var hostGetNewLine = ts.memoize(function () { return host.getNewLine(); });
123120 return {
123121 getSourceFile: function (fileName, languageVersionOrOptions, onError) {
123122 var text;
123123 try {
123124 ts.performance.mark("beforeIORead");
123125 text = host.readFile(fileName, getCompilerOptions().charset);
123126 ts.performance.mark("afterIORead");
123127 ts.performance.measure("I/O Read", "beforeIORead", "afterIORead");
123128 }
123129 catch (e) {
123130 if (onError) {
123131 onError(e.message);
123132 }
123133 text = "";
123134 }
123135 return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions) : undefined;
123136 },
123137 getDefaultLibLocation: ts.maybeBind(host, host.getDefaultLibLocation),
123138 getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
123139 writeFile: writeFile,
123140 getCurrentDirectory: ts.memoize(function () { return host.getCurrentDirectory(); }),
123141 useCaseSensitiveFileNames: function () { return useCaseSensitiveFileNames; },
123142 getCanonicalFileName: ts.createGetCanonicalFileName(useCaseSensitiveFileNames),
123143 getNewLine: function () { return ts.getNewLineCharacter(getCompilerOptions(), hostGetNewLine); },
123144 fileExists: function (f) { return host.fileExists(f); },
123145 readFile: function (f) { return host.readFile(f); },
123146 trace: ts.maybeBind(host, host.trace),
123147 directoryExists: ts.maybeBind(directoryStructureHost, directoryStructureHost.directoryExists),
123148 getDirectories: ts.maybeBind(directoryStructureHost, directoryStructureHost.getDirectories),
123149 realpath: ts.maybeBind(host, host.realpath),
123150 getEnvironmentVariable: ts.maybeBind(host, host.getEnvironmentVariable) || (function () { return ""; }),
123151 createHash: ts.maybeBind(host, host.createHash),
123152 readDirectory: ts.maybeBind(host, host.readDirectory),
123153 disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
123154 storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
123155 };
123156 function writeFile(fileName, text, writeByteOrderMark, onError) {
123157 try {
123158 ts.performance.mark("beforeIOWrite");
123159 // NOTE: If patchWriteFileEnsuringDirectory has been called,
123160 // the host.writeFile will do its own directory creation and
123161 // the ensureDirectoriesExist call will always be redundant.
123162 ts.writeFileEnsuringDirectories(fileName, text, writeByteOrderMark, function (path, data, writeByteOrderMark) { return host.writeFile(path, data, writeByteOrderMark); }, function (path) { return host.createDirectory(path); }, function (path) { return host.directoryExists(path); });
123163 ts.performance.mark("afterIOWrite");
123164 ts.performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");
123165 }
123166 catch (e) {
123167 if (onError) {
123168 onError(e.message);
123169 }
123170 }
123171 }
123172 }
123173 ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;

Callers

nothing calls this directly

Calls 4

measureMethod · 0.80
onErrorFunction · 0.70
markMethod · 0.45
readFileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…