Merge pull request #21205 from uniqueiniquity/resolveTripleSlashReferencePaths

Fix Windows-style absolute paths in triple-slash directives
This commit is contained in:
Benjamin Lichtman 2018-01-17 12:31:46 -08:00 committed by GitHub
commit 8f6c516ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 1 deletions

View File

@ -1909,7 +1909,7 @@ namespace ts {
return p2 + 1;
}
if (path.charCodeAt(1) === CharacterCodes.colon) {
if (path.charCodeAt(2) === CharacterCodes.slash) return 3;
if (path.charCodeAt(2) === CharacterCodes.slash || path.charCodeAt(2) === CharacterCodes.backslash) return 3;
}
// Per RFC 1738 'file' URI schema has the shape file://<host>/<path>
// if <host> is omitted then it is assumed that host value is 'localhost',

View File

@ -2821,6 +2821,31 @@ namespace ts.projectSystem {
checkWatchedDirectories(host, watchedRecursiveDirectories, /*recursive*/ true);
});
it("Properly handle Windows-style outDir", () => {
const configFile: FileOrFolder = {
path: "C:\\a\\tsconfig.json",
content: JSON.stringify({
compilerOptions: {
outDir: `C:\\a\\b`
},
include: ["*.ts"]
})
};
const file1: FileOrFolder = {
path: "C:\\a\\f1.ts",
content: "let x = 1;"
};
const host = createServerHost([file1, configFile], { useWindowsStylePaths: true });
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
const project = configuredProjectAt(projectService, 0);
checkProjectActualFiles(project, [normalizePath(file1.path), normalizePath(configFile.path)]);
const options = project.getCompilerOptions();
assert.equal(options.outDir, "C:/a/b", "");
});
});
describe("tsserverProjectSystem Proper errors", () => {

View File

@ -0,0 +1,14 @@
//// [tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts] ////
//// [c.ts]
const x = 5;
//// [d.ts]
/// <reference path="C:\a\b\c.ts" />
const y = x + 3;
//// [c.js]
var x = 5;
//// [d.js]
/// <reference path="C:\a\b\c.ts" />
var y = x + 3;

View File

@ -0,0 +1,10 @@
=== C:/a/b/d.ts ===
/// <reference path="C:\a\b\c.ts" />
const y = x + 3;
>y : Symbol(y, Decl(d.ts, 1, 5))
>x : Symbol(x, Decl(c.ts, 0, 5))
=== C:/a/b/c.ts ===
const x = 5;
>x : Symbol(x, Decl(c.ts, 0, 5))

View File

@ -0,0 +1,13 @@
=== C:/a/b/d.ts ===
/// <reference path="C:\a\b\c.ts" />
const y = x + 3;
>y : number
>x + 3 : number
>x : 5
>3 : 3
=== C:/a/b/c.ts ===
const x = 5;
>x : 5
>5 : 5

View File

@ -0,0 +1,6 @@
//@Filename: C:\a\b\c.ts
const x = 5;
//@Filename: C:\a\b\d.ts
/// <reference path="C:\a\b\c.ts" />
const y = x + 3;