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/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", () => { 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