From 68aad1b85e57f48b34ab2add6d5424dc17fa355a Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Tue, 16 Jan 2018 09:50:14 -0800 Subject: [PATCH 1/4] Normalize triple slash reference paths at resolve time --- src/compiler/program.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0d1bbf233a3..8f3cadcddc5 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -15,7 +15,8 @@ namespace ts { export function resolveTripleslashReference(moduleName: string, containingFile: string): string { const basePath = getDirectoryPath(containingFile); - const referencedFileName = isRootedDiskPath(moduleName) ? moduleName : combinePaths(basePath, moduleName); + const normalizedModuleName = normalizePath(moduleName); + const referencedFileName = isRootedDiskPath(normalizedModuleName) ? normalizedModuleName : combinePaths(basePath, normalizedModuleName); return normalizePath(referencedFileName); } From 5ea43db6ecee7db00586e4438131200e18cea2b8 Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Tue, 16 Jan 2018 11:25:54 -0800 Subject: [PATCH 2/4] Add test --- .../tripleSlashReferenceAbsoluteWindowsPath.js | 14 ++++++++++++++ ...tripleSlashReferenceAbsoluteWindowsPath.symbols | 10 ++++++++++ .../tripleSlashReferenceAbsoluteWindowsPath.types | 13 +++++++++++++ .../tripleSlashReferenceAbsoluteWindowsPath.ts | 6 ++++++ 4 files changed, 43 insertions(+) create mode 100644 tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.js create mode 100644 tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.symbols create mode 100644 tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.types create mode 100644 tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts diff --git a/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.js b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.js new file mode 100644 index 00000000000..3e719abde5f --- /dev/null +++ b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts] //// + +//// [c.ts] +const x = 5; + +//// [d.ts] +/// +const y = x + 3; + +//// [c.js] +var x = 5; +//// [d.js] +/// +var y = x + 3; diff --git a/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.symbols b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.symbols new file mode 100644 index 00000000000..0a3b6aedc6b --- /dev/null +++ b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.symbols @@ -0,0 +1,10 @@ +=== C:/a/b/d.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)) + diff --git a/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.types b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.types new file mode 100644 index 00000000000..fdc37ae2faf --- /dev/null +++ b/tests/baselines/reference/tripleSlashReferenceAbsoluteWindowsPath.types @@ -0,0 +1,13 @@ +=== C:/a/b/d.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 + diff --git a/tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts b/tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts new file mode 100644 index 00000000000..b45e2a52b65 --- /dev/null +++ b/tests/cases/compiler/tripleSlashReferenceAbsoluteWindowsPath.ts @@ -0,0 +1,6 @@ +//@Filename: C:\a\b\c.ts +const x = 5; + +//@Filename: C:\a\b\d.ts +/// +const y = x + 3; \ No newline at end of file From 5320ce25528e27612116d0063c11ed702964bef8 Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Tue, 16 Jan 2018 17:04:14 -0800 Subject: [PATCH 3/4] Revert path normalization in favor of checking for backslash --- src/compiler/core.ts | 2 +- src/compiler/program.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0faabbda2a0..d92a02661e8 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -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:/// // if is omitted then it is assumed that host value is 'localhost', diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8f3cadcddc5..0d1bbf233a3 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -15,8 +15,7 @@ namespace ts { export function resolveTripleslashReference(moduleName: string, containingFile: string): string { const basePath = getDirectoryPath(containingFile); - const normalizedModuleName = normalizePath(moduleName); - const referencedFileName = isRootedDiskPath(normalizedModuleName) ? normalizedModuleName : combinePaths(basePath, normalizedModuleName); + const referencedFileName = isRootedDiskPath(moduleName) ? moduleName : combinePaths(basePath, moduleName); return normalizePath(referencedFileName); } From 543b48d031f0127e0b57197dcf66e4a02a3c690f Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Wed, 17 Jan 2018 10:58:25 -0800 Subject: [PATCH 4/4] Add test for file path in tsconfig --- .../unittests/tsserverProjectSystem.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 565c20ac9cd..68fbc1ecba0 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -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", () => {