Skip to content

Commit

Permalink
Update LKG
Browse files Browse the repository at this point in the history
  • Loading branch information
ivogabe committed Apr 3, 2016
1 parent 9626d68 commit d7161e4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions release/host.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
///<reference path='../typings/tsd.d.ts'/>
"use strict";
var tsApi = require('./tsapi');
var utils = require('./utils');
var fs = require('fs');
var path = require('path');
var libDirectory = '__lib/';
var Host = (function () {
function Host(typescript, currentDirectory, input, externalResolve, libFileName) {
var _this = this;
Expand All @@ -15,7 +15,18 @@ var Host = (function () {
};
this.getSourceFile = function (fileName, languageVersion, onError) {
if (fileName === '__lib.d.ts') {
return Host.getLibDefault(_this.typescript, _this.libFileName);
return Host.getLibDefault(_this.typescript, _this.libFileName, fileName);
}
if (fileName.substring(0, libDirectory.length) === libDirectory) {
try {
return Host.getLibDefault(_this.typescript, fileName.substring(libDirectory.length), fileName);
}
catch (e) { }
try {
return Host.getLibDefault(_this.typescript, 'lib.' + fileName.substring(libDirectory.length), fileName);
}
catch (e) { }
return undefined;
}
var sourceFile = _this.input.getFile(fileName);
if (sourceFile)
Expand All @@ -41,7 +52,7 @@ var Host = (function () {
this.libFileName = libFileName;
this.reset();
}
Host.getLibDefault = function (typescript, libFileName) {
Host.getLibDefault = function (typescript, libFileName, originalFileName) {
var fileName;
for (var i in require.cache) {
if (!Object.prototype.hasOwnProperty.call(require.cache, i) || require.cache[i] === undefined)
Expand All @@ -58,7 +69,7 @@ var Host = (function () {
return this.libDefault[fileName]; // Already loaded
}
var content = fs.readFileSync(fileName).toString('utf8');
return this.libDefault[fileName] = tsApi.createSourceFile(typescript, '__lib.d.ts', content, typescript.ScriptTarget.ES3); // Will also work for ES5 & 6
return this.libDefault[fileName] = tsApi.createSourceFile(typescript, originalFileName, content, typescript.ScriptTarget.ES3); // Will also work for ES5 & 6
};
Host.prototype.reset = function () {
this.output = {};
Expand All @@ -78,6 +89,9 @@ var Host = (function () {
Host.prototype.getDefaultLibFileName = function () {
return '__lib.d.ts';
};
Host.prototype.getDefaultLibLocation = function () {
return libDirectory;
};
Host.prototype.fileExists = function (fileName) {
if (fileName === '__lib.d.ts') {
return true;
Expand Down

0 comments on commit d7161e4

Please sign in to comment.