mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 14:34:35 -06:00
Merge pull request #21205 from uniqueiniquity/resolveTripleSlashReferencePaths
Fix Windows-style absolute paths in triple-slash directives
This commit is contained in:
commit
8f6c516ef9
@ -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',
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
@ -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;
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user