Skip to content

Commit

Permalink
- normalizing paths used as snapshot cache keys (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezolenko committed Apr 3, 2017
1 parent f4cd9b4 commit 65fb883
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dist/rollup-plugin-typescript2.cjs.js
Expand Up @@ -127,12 +127,14 @@ var LanguageServiceHost = (function () {
this.versions = {};
};
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
fileName = this.normalize(fileName);
var snapshot = ts.ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return snapshot;
};
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
fileName = this.normalize(fileName);
if (_.has(this.snapshots, fileName))
return this.snapshots[fileName];
if (fs.existsSync(fileName)) {
Expand All @@ -146,6 +148,7 @@ var LanguageServiceHost = (function () {
return this.cwd;
};
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
fileName = this.normalize(fileName);
return (this.versions[fileName] || 0).toString();
};
LanguageServiceHost.prototype.getScriptFileNames = function () {
Expand All @@ -157,6 +160,9 @@ var LanguageServiceHost = (function () {
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
return ts.getDefaultLibFilePath(opts);
};
LanguageServiceHost.prototype.normalize = function (fileName) {
return fileName.split("\\").join("/");
};
return LanguageServiceHost;
}());

Expand Down
6 changes: 6 additions & 0 deletions dist/rollup-plugin-typescript2.es.js
Expand Up @@ -133,12 +133,14 @@ var LanguageServiceHost = (function () {
this.versions = {};
};
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
fileName = this.normalize(fileName);
var snapshot = ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return snapshot;
};
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
fileName = this.normalize(fileName);
if (has(this.snapshots, fileName))
return this.snapshots[fileName];
if (existsSync(fileName)) {
Expand All @@ -152,6 +154,7 @@ var LanguageServiceHost = (function () {
return this.cwd;
};
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
fileName = this.normalize(fileName);
return (this.versions[fileName] || 0).toString();
};
LanguageServiceHost.prototype.getScriptFileNames = function () {
Expand All @@ -163,6 +166,9 @@ var LanguageServiceHost = (function () {
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
return getDefaultLibFilePath(opts);
};
LanguageServiceHost.prototype.normalize = function (fileName) {
return fileName.split("\\").join("/");
};
return LanguageServiceHost;
}());

Expand Down
11 changes: 11 additions & 0 deletions src/host.ts
Expand Up @@ -20,6 +20,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost

public setSnapshot(fileName: string, data: string): ts.IScriptSnapshot
{
fileName = this.normalize(fileName);

let snapshot = ts.ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
Expand All @@ -28,6 +30,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost

public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined
{
fileName = this.normalize(fileName);

if (_.has(this.snapshots, fileName))
return this.snapshots[fileName];

Expand All @@ -48,6 +52,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost

public getScriptVersion(fileName: string)
{
fileName = this.normalize(fileName);

return (this.versions[fileName] || 0).toString();
}

Expand All @@ -65,4 +71,9 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
{
return ts.getDefaultLibFilePath(opts);
}

private normalize(fileName: string)
{
return fileName.split("\\").join("/");
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -11,7 +11,7 @@
"listFiles": true,
"pretty": true,
"moduleResolution": "node",
"noEmitOnError": true,
"noEmitOnError": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true
Expand Down

0 comments on commit 65fb883

Please sign in to comment.