Skip to content

Commit 49be2e2

Browse files
author
Andy
authored
Merge pull request #11957 from Microsoft/fix_realpathmap
Fix realPathMap in test harness: Must be used in `directoryExists`
2 parents e6f6a5e + ebebac9 commit 49be2e2

7 files changed

+96
-101
lines changed

src/harness/harness.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1029,21 +1029,15 @@ namespace Harness {
10291029
},
10301030
realpath: realPathMap && ((f: string) => {
10311031
const path = ts.toPath(f, currentDirectory, getCanonicalFileName);
1032-
return realPathMap.contains(path) ? realPathMap.get(path) : path;
1032+
return realPathMap.get(path) || path;
10331033
}),
10341034
directoryExists: dir => {
10351035
let path = ts.toPath(dir, currentDirectory, getCanonicalFileName);
10361036
// Strip trailing /, which may exist if the path is a drive root
10371037
if (path[path.length - 1] === "/") {
10381038
path = <ts.Path>path.substr(0, path.length - 1);
10391039
}
1040-
let exists = false;
1041-
fileMap.forEachValue(key => {
1042-
if (key.indexOf(path) === 0 && key[path.length] === "/") {
1043-
exists = true;
1044-
}
1045-
});
1046-
return exists;
1040+
return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap);
10471041
},
10481042
getDirectories: d => {
10491043
const path = ts.toPath(d, currentDirectory, getCanonicalFileName);
@@ -1064,6 +1058,19 @@ namespace Harness {
10641058
};
10651059
}
10661060

1061+
function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.FileMap<any>): boolean {
1062+
if (!map) {
1063+
return false;
1064+
}
1065+
let exists = false;
1066+
map.forEachValue(fileName => {
1067+
if (!exists && ts.startsWith(fileName, directoryPath) && fileName[directoryPath.length] === "/") {
1068+
exists = true;
1069+
}
1070+
});
1071+
return exists;
1072+
}
1073+
10671074
interface HarnessOptions {
10681075
useCaseSensitiveFileNames?: boolean;
10691076
includeBuiltFile?: string;

tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt

-21
This file was deleted.

tests/baselines/reference/moduleResolutionWithSymlinks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//// [index.ts]
44

5-
export class MyClass{}
5+
export class MyClass { private x: number; }
66

77
//// [index.ts]
88
import {MyClass} from "library-a";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== /src/app.ts ===
2+
import { MyClass } from "./library-a";
3+
>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8))
4+
5+
import { MyClass2 } from "./library-b";
6+
>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8))
7+
8+
let x: MyClass;
9+
>x : Symbol(x, Decl(app.ts, 3, 3))
10+
>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8))
11+
12+
let y: MyClass2;
13+
>y : Symbol(y, Decl(app.ts, 4, 3))
14+
>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8))
15+
16+
x = y;
17+
>x : Symbol(x, Decl(app.ts, 3, 3))
18+
>y : Symbol(y, Decl(app.ts, 4, 3))
19+
20+
y = x;
21+
>y : Symbol(y, Decl(app.ts, 4, 3))
22+
>x : Symbol(x, Decl(app.ts, 3, 3))
23+
24+
=== /src/library-a/index.ts ===
25+
26+
export class MyClass { private x: number; }
27+
>MyClass : Symbol(MyClass, Decl(index.ts, 0, 0))
28+
>x : Symbol(MyClass.x, Decl(index.ts, 1, 22))
29+
30+
=== /src/library-b/index.ts ===
31+
import {MyClass} from "library-a";
32+
>MyClass : Symbol(MyClass, Decl(index.ts, 0, 8))
33+
34+
export { MyClass as MyClass2 }
35+
>MyClass : Symbol(MyClass2, Decl(index.ts, 1, 8))
36+
>MyClass2 : Symbol(MyClass2, Decl(index.ts, 1, 8))
37+

tests/baselines/reference/moduleResolutionWithSymlinks.trace.json

+3-70
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,7 @@
2626
"File '/src/library-b/node_modules/library-a.tsx' does not exist.",
2727
"File '/src/library-b/node_modules/library-a.d.ts' does not exist.",
2828
"File '/src/library-b/node_modules/library-a/package.json' does not exist.",
29-
"File '/src/library-b/node_modules/library-a/index.ts' does not exist.",
30-
"File '/src/library-b/node_modules/library-a/index.tsx' does not exist.",
31-
"File '/src/library-b/node_modules/library-a/index.d.ts' does not exist.",
32-
"File '/src/library-b/node_modules/@types/library-a.ts' does not exist.",
33-
"File '/src/library-b/node_modules/@types/library-a.tsx' does not exist.",
34-
"File '/src/library-b/node_modules/@types/library-a.d.ts' does not exist.",
35-
"File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.",
36-
"File '/src/library-b/node_modules/@types/library-a/index.ts' does not exist.",
37-
"File '/src/library-b/node_modules/@types/library-a/index.tsx' does not exist.",
38-
"File '/src/library-b/node_modules/@types/library-a/index.d.ts' does not exist.",
39-
"File '/src/node_modules/library-a.ts' does not exist.",
40-
"File '/src/node_modules/library-a.tsx' does not exist.",
41-
"File '/src/node_modules/library-a.d.ts' does not exist.",
42-
"File '/src/node_modules/library-a/package.json' does not exist.",
43-
"File '/src/node_modules/library-a/index.ts' does not exist.",
44-
"File '/src/node_modules/library-a/index.tsx' does not exist.",
45-
"File '/src/node_modules/library-a/index.d.ts' does not exist.",
46-
"File '/src/node_modules/@types/library-a.ts' does not exist.",
47-
"File '/src/node_modules/@types/library-a.tsx' does not exist.",
48-
"File '/src/node_modules/@types/library-a.d.ts' does not exist.",
49-
"File '/src/node_modules/@types/library-a/package.json' does not exist.",
50-
"File '/src/node_modules/@types/library-a/index.ts' does not exist.",
51-
"File '/src/node_modules/@types/library-a/index.tsx' does not exist.",
52-
"File '/src/node_modules/@types/library-a/index.d.ts' does not exist.",
53-
"File '/node_modules/library-a.ts' does not exist.",
54-
"File '/node_modules/library-a.tsx' does not exist.",
55-
"File '/node_modules/library-a.d.ts' does not exist.",
56-
"File '/node_modules/library-a/package.json' does not exist.",
57-
"File '/node_modules/library-a/index.ts' does not exist.",
58-
"File '/node_modules/library-a/index.tsx' does not exist.",
59-
"File '/node_modules/library-a/index.d.ts' does not exist.",
60-
"File '/node_modules/@types/library-a.ts' does not exist.",
61-
"File '/node_modules/@types/library-a.tsx' does not exist.",
62-
"File '/node_modules/@types/library-a.d.ts' does not exist.",
63-
"File '/node_modules/@types/library-a/package.json' does not exist.",
64-
"File '/node_modules/@types/library-a/index.ts' does not exist.",
65-
"File '/node_modules/@types/library-a/index.tsx' does not exist.",
66-
"File '/node_modules/@types/library-a/index.d.ts' does not exist.",
67-
"Loading module 'library-a' from 'node_modules' folder.",
68-
"File '/src/library-b/node_modules/library-a.js' does not exist.",
69-
"File '/src/library-b/node_modules/library-a.jsx' does not exist.",
70-
"File '/src/library-b/node_modules/library-a/package.json' does not exist.",
71-
"File '/src/library-b/node_modules/library-a/index.js' does not exist.",
72-
"File '/src/library-b/node_modules/library-a/index.jsx' does not exist.",
73-
"File '/src/library-b/node_modules/@types/library-a.js' does not exist.",
74-
"File '/src/library-b/node_modules/@types/library-a.jsx' does not exist.",
75-
"File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.",
76-
"File '/src/library-b/node_modules/@types/library-a/index.js' does not exist.",
77-
"File '/src/library-b/node_modules/@types/library-a/index.jsx' does not exist.",
78-
"File '/src/node_modules/library-a.js' does not exist.",
79-
"File '/src/node_modules/library-a.jsx' does not exist.",
80-
"File '/src/node_modules/library-a/package.json' does not exist.",
81-
"File '/src/node_modules/library-a/index.js' does not exist.",
82-
"File '/src/node_modules/library-a/index.jsx' does not exist.",
83-
"File '/src/node_modules/@types/library-a.js' does not exist.",
84-
"File '/src/node_modules/@types/library-a.jsx' does not exist.",
85-
"File '/src/node_modules/@types/library-a/package.json' does not exist.",
86-
"File '/src/node_modules/@types/library-a/index.js' does not exist.",
87-
"File '/src/node_modules/@types/library-a/index.jsx' does not exist.",
88-
"File '/node_modules/library-a.js' does not exist.",
89-
"File '/node_modules/library-a.jsx' does not exist.",
90-
"File '/node_modules/library-a/package.json' does not exist.",
91-
"File '/node_modules/library-a/index.js' does not exist.",
92-
"File '/node_modules/library-a/index.jsx' does not exist.",
93-
"File '/node_modules/@types/library-a.js' does not exist.",
94-
"File '/node_modules/@types/library-a.jsx' does not exist.",
95-
"File '/node_modules/@types/library-a/package.json' does not exist.",
96-
"File '/node_modules/@types/library-a/index.js' does not exist.",
97-
"File '/node_modules/@types/library-a/index.jsx' does not exist.",
98-
"======== Module name 'library-a' was not resolved. ========"
29+
"File '/src/library-b/node_modules/library-a/index.ts' exist - use it as a name resolution result.",
30+
"Resolving real path for '/src/library-b/node_modules/library-a/index.ts', result '/src/library-a/index.ts'",
31+
"======== Module name 'library-a' was successfully resolved to '/src/library-a/index.ts'. ========"
9932
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== /src/app.ts ===
2+
import { MyClass } from "./library-a";
3+
>MyClass : typeof MyClass
4+
5+
import { MyClass2 } from "./library-b";
6+
>MyClass2 : typeof MyClass
7+
8+
let x: MyClass;
9+
>x : MyClass
10+
>MyClass : MyClass
11+
12+
let y: MyClass2;
13+
>y : MyClass
14+
>MyClass2 : MyClass
15+
16+
x = y;
17+
>x = y : MyClass
18+
>x : MyClass
19+
>y : MyClass
20+
21+
y = x;
22+
>y = x : MyClass
23+
>y : MyClass
24+
>x : MyClass
25+
26+
=== /src/library-a/index.ts ===
27+
28+
export class MyClass { private x: number; }
29+
>MyClass : MyClass
30+
>x : number
31+
32+
=== /src/library-b/index.ts ===
33+
import {MyClass} from "library-a";
34+
>MyClass : typeof MyClass
35+
36+
export { MyClass as MyClass2 }
37+
>MyClass : typeof MyClass
38+
>MyClass2 : typeof MyClass
39+

tests/cases/compiler/moduleResolutionWithSymlinks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @filename: /src/library-a/index.ts
66
// @symlink: /src/library-b/node_modules/library-a/index.ts
7-
export class MyClass{}
7+
export class MyClass { private x: number; }
88

99
// @filename: /src/library-b/index.ts
1010
import {MyClass} from "library-a";

0 commit comments

Comments
 (0)