a zip code crypto-currency system good for red ONLY

compiler-host.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var path_1 = require("path");
  4. var typescript_1 = require("typescript");
  5. var typescript_utils_1 = require("../util/typescript-utils");
  6. var logger_1 = require("../logger/logger");
  7. var InMemoryCompilerHost = (function () {
  8. function InMemoryCompilerHost(options, fileSystem, setParentNodes) {
  9. if (setParentNodes === void 0) { setParentNodes = true; }
  10. this.options = options;
  11. this.fileSystem = fileSystem;
  12. this.setParentNodes = setParentNodes;
  13. this.diskCompilerHost = typescript_1.createCompilerHost(this.options, this.setParentNodes);
  14. this.sourceFileMap = new Map();
  15. }
  16. InMemoryCompilerHost.prototype.fileExists = function (filePath) {
  17. filePath = path_1.normalize(filePath);
  18. var fileContent = this.fileSystem.getFileContent(filePath);
  19. if (fileContent) {
  20. return true;
  21. }
  22. return this.diskCompilerHost.fileExists(filePath);
  23. };
  24. InMemoryCompilerHost.prototype.readFile = function (filePath) {
  25. filePath = path_1.normalize(filePath);
  26. var fileContent = this.fileSystem.getFileContent(filePath);
  27. if (fileContent) {
  28. return fileContent;
  29. }
  30. return this.diskCompilerHost.readFile(filePath);
  31. };
  32. InMemoryCompilerHost.prototype.directoryExists = function (directoryPath) {
  33. directoryPath = path_1.normalize(directoryPath);
  34. var stats = this.fileSystem.getDirectoryStats(directoryPath);
  35. if (stats) {
  36. return true;
  37. }
  38. return this.diskCompilerHost.directoryExists(directoryPath);
  39. };
  40. InMemoryCompilerHost.prototype.getFiles = function (directoryPath) {
  41. directoryPath = path_1.normalize(directoryPath);
  42. return this.fileSystem.getFileNamesInDirectory(directoryPath);
  43. };
  44. InMemoryCompilerHost.prototype.getDirectories = function (directoryPath) {
  45. directoryPath = path_1.normalize(directoryPath);
  46. var subdirs = this.fileSystem.getSubDirs(directoryPath);
  47. var delegated;
  48. try {
  49. delegated = this.diskCompilerHost.getDirectories(directoryPath);
  50. }
  51. catch (e) {
  52. delegated = [];
  53. }
  54. return delegated.concat(subdirs);
  55. };
  56. InMemoryCompilerHost.prototype.getSourceFile = function (filePath, languageVersion, onError) {
  57. filePath = path_1.normalize(filePath);
  58. var existingSourceFile = this.sourceFileMap.get(filePath);
  59. if (existingSourceFile) {
  60. return existingSourceFile;
  61. }
  62. // we haven't created a source file for this yet, so try to use what's in memory
  63. var fileContentFromMemory = this.fileSystem.getFileContent(filePath);
  64. if (fileContentFromMemory) {
  65. var typescriptSourceFile = typescript_utils_1.getTypescriptSourceFile(filePath, fileContentFromMemory, languageVersion, this.setParentNodes);
  66. this.sourceFileMap.set(filePath, typescriptSourceFile);
  67. return typescriptSourceFile;
  68. }
  69. var diskSourceFile = this.diskCompilerHost.getSourceFile(filePath, languageVersion, onError);
  70. this.sourceFileMap.set(filePath, diskSourceFile);
  71. return diskSourceFile;
  72. };
  73. InMemoryCompilerHost.prototype.getCancellationToken = function () {
  74. return this.diskCompilerHost.getCancellationToken();
  75. };
  76. InMemoryCompilerHost.prototype.getDefaultLibFileName = function (options) {
  77. return this.diskCompilerHost.getDefaultLibFileName(options);
  78. };
  79. InMemoryCompilerHost.prototype.writeFile = function (fileName, data, writeByteOrderMark, onError) {
  80. fileName = path_1.normalize(fileName);
  81. logger_1.Logger.debug("[NgcCompilerHost] writeFile: adding " + fileName + " to virtual file system");
  82. this.fileSystem.addVirtualFile(fileName, data);
  83. };
  84. InMemoryCompilerHost.prototype.getCurrentDirectory = function () {
  85. return this.diskCompilerHost.getCurrentDirectory();
  86. };
  87. InMemoryCompilerHost.prototype.getCanonicalFileName = function (fileName) {
  88. return this.diskCompilerHost.getCanonicalFileName(fileName);
  89. };
  90. InMemoryCompilerHost.prototype.useCaseSensitiveFileNames = function () {
  91. return this.diskCompilerHost.useCaseSensitiveFileNames();
  92. };
  93. InMemoryCompilerHost.prototype.getNewLine = function () {
  94. return this.diskCompilerHost.getNewLine();
  95. };
  96. return InMemoryCompilerHost;
  97. }());
  98. exports.InMemoryCompilerHost = InMemoryCompilerHost;