text: "use strict";
  
  var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  var resolver_1 = require('./resolver');
  var colors = require('colors');
  var path = require('path');
  var fs = require('fs');
  require('babel-polyfill');
  (function (MessageType) {
      MessageType[MessageType["Init"] = 'init'] = "Init";
      MessageType[MessageType["Compile"] = 'compile'] = "Compile";
  })(exports.MessageType || (exports.MessageType = {}));
  var MessageType = exports.MessageType;
  var env = {};
  
  var ModuleResolutionHost = (function () {
      function ModuleResolutionHost(servicesHost) {
          _classCallCheck(this, ModuleResolutionHost);
  
          this.servicesHost = servicesHost;
      }
  
      _createClass(ModuleResolutionHost, [{
          key: 'fileExists',
          value: function fileExists(fileName) {
              return this.servicesHost.getScriptSnapshot(fileName) !== undefined;
          }
      }, {
          key: 'readFile',
          value: function readFile(fileName) {
              var snapshot = this.servicesHost.getScriptSnapshot(fileName);
              return snapshot && snapshot.getText(0, snapshot.getLength());
          }
      }]);
  
      return ModuleResolutionHost;
  })();
  
  exports.ModuleResolutionHost = ModuleResolutionHost;
  
  var Host = (function () {
      function Host() {
          _classCallCheck(this, Host);
  
          this.moduleResolutionHost = new ModuleResolutionHost(this);
          this.resolver = resolver_1.default(env.webpackOptions);
      }
  
      _createClass(Host, [{
          key: 'normalizePath',
          value: function normalizePath(filePath) {
              return path.normalize(filePath);
          }
      }, {
          key: 'getScriptFileNames',
          value: function getScriptFileNames() {
              return Object.keys(env.files);
          }
      }, {
          key: 'getScriptVersion',
          value: function getScriptVersion(fileName) {
              if (env.files[fileName]) {
                  return env.files[fileName].version.toString();
              }
          }
      }, {
          key: 'getScriptSnapshot',
          value: function getScriptSnapshot(fileName) {
              var fileName_ = path.normalize(fileName);
              var file = env.files[fileName_];
              if (!file) {
                  try {
                      file = {
                          version: 0,
                          text: fs.readFileSync(fileName, { encoding: 'utf8' }).toString()
                      };
                      if (path.basename(fileName) !== 'package.json') {
                          env.files[fileName_] = file;
                      }
                  } catch (e) {
                      return;
                  }
              }
              return env.compiler.ScriptSnapshot.fromString(file.text);
          }
      }, {
          key: 'getCurrentDirectory',
          value: function getCurrentDirectory() {
              return process.cwd();
          }
      }, {
          key: 'getScriptIsOpen',
          value: function getScriptIsOpen() {
              return true;
          }
      }, {
          key: 'getCompilationSettings',
          value: function getCompilationSettings() {
              return env.options;
          }
      }, {
          key: 'resolveModuleNames',
          value: function resolveModuleNames(moduleNames, containingFile) {
              var resolvedModules = [];
              var _iteratorNormalCompletion = true;
              var _didIteratorError = false;
              var _iteratorError = undefined;
  
              try {
                  for (var _iterator = moduleNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                      var moduleName = _step.value;
  
                      var cached = env.resolutionCache[containingFile + '::' + moduleName];
                      if (cached) {
                          resolvedModules.push(cached);
                      } else {
                          var resolvedFileName = undefined;
                          var resolvedModule = undefined;
                          try {
                              resolvedFileName = this.resolver.resolveSync(this.normalizePath(path.dirname(containingFile)), moduleName);
                              if (!resolvedFileName.match(/\.tsx?$/)) {
                                  resolvedFileName = null;
                              }
                          } catch (e) {
                              resolvedFileName = null;
                          }
                          var tsResolved = env.compiler.resolveModuleName(resolvedFileName || moduleName, containingFile, env.options, this.moduleResolutionHost);
                          if (tsResolved.resolvedModule) {
                              resolvedModule = tsResolved.resolvedModule;
                          } else {
                              resolvedModule = {
                                  resolvedFileName: resolvedFileName || ''
                              };
                          }
                          resolvedModules.push(resolvedModule);
                      }
                  }
              } catch (err) {
                  _didIteratorError = true;
                  _iteratorError = err;
              } finally {
                  try {
                      if (!_iteratorNormalCompletion && _iterator.return) {
                          _iterator.return();
                      }
                  } finally {
                      if (_didIteratorError) {
                          throw _iteratorError;
                      }
                  }
              }
  
              return resolvedModules;
          }
      }, {
          key: 'getDefaultLibFileName',
          value: function getDefaultLibFileName(options) {
              return options.target === env.compiler.ScriptTarget.ES6 ? env.compilerInfo.lib6.fileName : env.compilerInfo.lib5.fileName;
          }
      }, {
          key: 'log',
          value: function log(message) {}
      }]);
  
      return Host;
  })();
  
  exports.Host = Host;
  function processInit(payload) {
      env.compiler = require(payload.compilerInfo.compilerName);
      env.compilerInfo = payload.compilerInfo;
      env.options = payload.compilerOptions;
      env.webpackOptions = payload.webpackOptions;
      env.host = new Host();
      env.service = env.compiler.createLanguageService(env.host, env.compiler.createDocumentRegistry());
  }
  function processCompile(payload) {
      var instanceName = env.options.instanceName || 'default';
      var silent = !!env.options.forkCheckerSilent;
      if (!silent) {
          console.log(colors.cyan('[' + instanceName + '] Checking started in a separate process...'));
      }
      var timeStart = +new Date();
      process.send({
          messageType: 'progress',
          payload: {
              inProgress: true
          }
      });
      env.files = payload.files;
      env.resolutionCache = payload.resolutionCache;
      var program = env.program = env.service.getProgram();
      var allDiagnostics = env.compiler.getPreEmitDiagnostics(program);
      if (allDiagnostics.length) {
          allDiagnostics.forEach(function (diagnostic) {
              var message = env.compiler.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
              if (diagnostic.file) {
                  var _diagnostic$file$getL = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
  
                  var line = _diagnostic$file$getL.line;
                  var character = _diagnostic$file$getL.character;
  
                  console.error('[' + instanceName + '] ' + colors.red(diagnostic.file.fileName) + ' (' + (line + 1) + ',' + (character + 1) + '):\n    ' + colors.red(message));
              } else {
                  console.error(colors.red('[' + instanceName + '] ' + message));
              }
          });
      } else {
          if (!silent) {
              var timeEnd = +new Date();
              console.log(colors.green('[' + instanceName + '] Ok, ' + (timeEnd - timeStart) / 1000 + ' sec.'));
          }
      }
      process.send({
          messageType: 'progress',
          payload: {
              inProgress: false
          }
      });
  }
  process.on('message', function (msg) {
      switch (msg.messageType) {
          case MessageType.Init:
              processInit(msg.payload);
              break;
          case MessageType.Compile:
              processCompile(msg.payload);
              break;
      }
  });
  //# sourceMappingURL=checker-runtime.js.map