Skip to content

Commit

Permalink
Rework way the dependency graph is built (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrantly committed May 9, 2015
1 parent 0da8c63 commit 7d454a3
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,19 @@ function ensureTypeScriptInstance(options: Options, loader: any): TSInstance {
getScriptSnapshot: fileName => {
fileName = path.normalize(fileName);
var file = files[fileName];
if (!file) return undefined;

if (!file) {
try {
file = files[fileName] = {
version: 0,
text: fs.readFileSync(fileName, {encoding: 'utf8'})
}
}
catch (e) {
return;
}
}

return compiler.ScriptSnapshot.fromString(file.text);
},
getCurrentDirectory: () => process.cwd(),
Expand Down Expand Up @@ -202,26 +214,14 @@ function loader(contents) {
configFileName: 'tsconfig.json'
}, options);

var instance = ensureTypeScriptInstance(options, this);

if (!Object.prototype.hasOwnProperty.call(instance.files, filePath)) {

var filePaths = Object.keys(instance.files);
filePaths.push(filePath)
var instance = ensureTypeScriptInstance(options, this),
file = instance.files[filePath],
langService = instance.languageService;

var program = instance.compiler.createProgram(filePaths, instance.compilerOptions, instance.compiler.createCompilerHost(instance.compilerOptions));

program.getSourceFiles().forEach(file => {
var filePath = path.normalize(file.fileName);
if (!Object.prototype.hasOwnProperty.call(instance.files, filePath)) {
instance.files[filePath] = { version: 0, text: file.text };
}
})
if (!file) {
file = instance.files[filePath] = <TSFile>{};
}

var file = instance.files[filePath],
langService = instance.languageService;

file.text = contents;
file.version++;

Expand Down

0 comments on commit 7d454a3

Please sign in to comment.