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

Function changeCompilerHostLikeToUseCache

test/fixtures/snapshot/typescript.js:115883–115985  ·  view source on GitHub ↗
(host, toPath, getSourceFile)

Source from the content-addressed store, hash-verified

115881 ts.createCompilerHostWorker = createCompilerHostWorker;
115882 /*@internal*/
115883 function changeCompilerHostLikeToUseCache(host, toPath, getSourceFile) {
115884 var originalReadFile = host.readFile;
115885 var originalFileExists = host.fileExists;
115886 var originalDirectoryExists = host.directoryExists;
115887 var originalCreateDirectory = host.createDirectory;
115888 var originalWriteFile = host.writeFile;
115889 var readFileCache = new ts.Map();
115890 var fileExistsCache = new ts.Map();
115891 var directoryExistsCache = new ts.Map();
115892 var sourceFileCache = new ts.Map();
115893 var readFileWithCache = function (fileName) {
115894 var key = toPath(fileName);
115895 var value = readFileCache.get(key);
115896 if (value !== undefined)
115897 return value !== false ? value : undefined;
115898 return setReadFileCache(key, fileName);
115899 };
115900 var setReadFileCache = function (key, fileName) {
115901 var newValue = originalReadFile.call(host, fileName);
115902 readFileCache.set(key, newValue !== undefined ? newValue : false);
115903 return newValue;
115904 };
115905 host.readFile = function (fileName) {
115906 var key = toPath(fileName);
115907 var value = readFileCache.get(key);
115908 if (value !== undefined)
115909 return value !== false ? value : undefined; // could be .d.ts from output
115910 // Cache json or buildInfo
115911 if (!ts.fileExtensionIs(fileName, ".json" /* Extension.Json */) && !ts.isBuildInfoFile(fileName)) {
115912 return originalReadFile.call(host, fileName);
115913 }
115914 return setReadFileCache(key, fileName);
115915 };
115916 var getSourceFileWithCache = getSourceFile ? function (fileName, languageVersion, onError, shouldCreateNewSourceFile) {
115917 var key = toPath(fileName);
115918 var value = sourceFileCache.get(key);
115919 if (value)
115920 return value;
115921 var sourceFile = getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
115922 if (sourceFile && (ts.isDeclarationFileName(fileName) || ts.fileExtensionIs(fileName, ".json" /* Extension.Json */))) {
115923 sourceFileCache.set(key, sourceFile);
115924 }
115925 return sourceFile;
115926 } : undefined;
115927 // fileExists for any kind of extension
115928 host.fileExists = function (fileName) {
115929 var key = toPath(fileName);
115930 var value = fileExistsCache.get(key);
115931 if (value !== undefined)
115932 return value;
115933 var newValue = originalFileExists.call(host, fileName);
115934 fileExistsCache.set(key, !!newValue);
115935 return newValue;
115936 };
115937 if (originalWriteFile) {
115938 host.writeFile = function (fileName, data) {
115939 var rest = [];
115940 for (var _i = 2; _i < arguments.length; _i++) {

Callers

nothing calls this directly

Calls 8

toPathFunction · 0.85
setReadFileCacheFunction · 0.85
getSourceFileFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
callMethod · 0.45
setMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…