Skip to content

Commit bb4080c

Browse files
authored
Collect _all_ symlinks a file may have witnessed when attempting to generate specifiers (#31571)
1 parent 8ab0a25 commit bb4080c

9 files changed

+284
-3
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ namespace ts.moduleSpecifiers {
175175

176176
function discoverProbableSymlinks(files: ReadonlyArray<SourceFile>, getCanonicalFileName: GetCanonicalFileName, cwd: string): ReadonlyMap<string> {
177177
const result = createMap<string>();
178-
const symlinks = mapDefined(files, sf =>
179-
sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res =>
180-
res && res.originalPath && res.resolvedFileName !== res.originalPath ? [res.resolvedFileName, res.originalPath] : undefined));
178+
const symlinks = flatten<readonly [string, string]>(mapDefined(files, sf =>
179+
sf.resolvedModules && compact(arrayFrom(mapIterator(sf.resolvedModules.values(), res =>
180+
res && res.originalPath && res.resolvedFileName !== res.originalPath ? [res.resolvedFileName, res.originalPath] as const : undefined)))));
181181
for (const [resolvedPath, originalPath] of symlinks) {
182182
const [commonResolved, commonOriginal] = guessDirectorySymlink(resolvedPath, originalPath, cwd, getCanonicalFileName);
183183
result.set(commonOriginal, commonResolved);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//// [tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts] ////
2+
3+
//// [impl.d.ts]
4+
export function getA(): A;
5+
export enum A {
6+
Val
7+
}
8+
//// [index.d.ts]
9+
export * from "./src/impl";
10+
//// [package.json]
11+
{
12+
"name": "typescript-fsa",
13+
"version": "1.0.0"
14+
}
15+
//// [impl.d.ts]
16+
export function getA(): A;
17+
export enum A {
18+
Val
19+
}
20+
//// [index.d.ts]
21+
export * from "./src/impl";
22+
//// [package.json]
23+
{
24+
"name": "typescript-fsa",
25+
"version": "1.0.0"
26+
}
27+
//// [index.ts]
28+
import * as _whatever from "p2";
29+
import { getA } from "typescript-fsa";
30+
31+
export const a = getA();
32+
//// [index.d.ts]
33+
export const a: import("typescript-fsa").A;
34+
35+
36+
37+
//// [index.js]
38+
"use strict";
39+
exports.__esModule = true;
40+
var typescript_fsa_1 = require("typescript-fsa");
41+
exports.a = typescript_fsa_1.getA();
42+
43+
44+
//// [index.d.ts]
45+
export declare const a: import("typescript-fsa").A;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== /p1/node_modules/typescript-fsa/src/impl.d.ts ===
2+
export function getA(): A;
3+
>getA : Symbol(getA, Decl(impl.d.ts, 0, 0))
4+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
5+
6+
export enum A {
7+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
8+
9+
Val
10+
>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15))
11+
}
12+
=== /p1/node_modules/typescript-fsa/index.d.ts ===
13+
export * from "./src/impl";
14+
No type information for this code.=== /p2/node_modules/typescript-fsa/src/impl.d.ts ===
15+
export function getA(): A;
16+
>getA : Symbol(getA, Decl(impl.d.ts, 0, 0))
17+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
18+
19+
export enum A {
20+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
21+
22+
Val
23+
>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15))
24+
}
25+
=== /p2/node_modules/typescript-fsa/index.d.ts ===
26+
export * from "./src/impl";
27+
No type information for this code.=== /p1/index.ts ===
28+
import * as _whatever from "p2";
29+
>_whatever : Symbol(_whatever, Decl(index.ts, 0, 6))
30+
31+
import { getA } from "typescript-fsa";
32+
>getA : Symbol(getA, Decl(index.ts, 1, 8))
33+
34+
export const a = getA();
35+
>a : Symbol(a, Decl(index.ts, 3, 12))
36+
>getA : Symbol(getA, Decl(index.ts, 1, 8))
37+
38+
=== /p2/index.d.ts ===
39+
export const a: import("typescript-fsa").A;
40+
>a : Symbol(a, Decl(index.d.ts, 0, 12))
41+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
42+
43+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== /p1/node_modules/typescript-fsa/src/impl.d.ts ===
2+
export function getA(): A;
3+
>getA : () => A
4+
5+
export enum A {
6+
>A : A
7+
8+
Val
9+
>Val : A
10+
}
11+
=== /p1/node_modules/typescript-fsa/index.d.ts ===
12+
export * from "./src/impl";
13+
No type information for this code.=== /p2/node_modules/typescript-fsa/src/impl.d.ts ===
14+
export function getA(): A;
15+
>getA : () => A
16+
17+
export enum A {
18+
>A : A
19+
20+
Val
21+
>Val : A
22+
}
23+
=== /p2/node_modules/typescript-fsa/index.d.ts ===
24+
export * from "./src/impl";
25+
No type information for this code.=== /p1/index.ts ===
26+
import * as _whatever from "p2";
27+
>_whatever : typeof _whatever
28+
29+
import { getA } from "typescript-fsa";
30+
>getA : () => import("/p1/node_modules/typescript-fsa/index").A
31+
32+
export const a = getA();
33+
>a : import("/p1/node_modules/typescript-fsa/index").A
34+
>getA() : import("/p1/node_modules/typescript-fsa/index").A
35+
>getA : () => import("/p1/node_modules/typescript-fsa/index").A
36+
37+
=== /p2/index.d.ts ===
38+
export const a: import("typescript-fsa").A;
39+
>a : import("/p2/node_modules/typescript-fsa/index").A
40+
41+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts] ////
2+
3+
//// [impl.d.ts]
4+
export function getA(): A;
5+
export enum A {
6+
Val
7+
}
8+
//// [index.d.ts]
9+
export * from "./src/impl";
10+
//// [package.json]
11+
{
12+
"name": "typescript-fsa",
13+
"version": "1.0.0"
14+
}
15+
//// [index.ts]
16+
import * as _whatever from "p2";
17+
import { getA } from "typescript-fsa";
18+
19+
export const a = getA();
20+
//// [index.d.ts]
21+
export const a: import("typescript-fsa").A;
22+
23+
24+
25+
//// [index.js]
26+
"use strict";
27+
exports.__esModule = true;
28+
var typescript_fsa_1 = require("typescript-fsa");
29+
exports.a = typescript_fsa_1.getA();
30+
31+
32+
//// [index.d.ts]
33+
export declare const a: import("typescript-fsa").A;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== /cache/typescript-fsa/src/impl.d.ts ===
2+
export function getA(): A;
3+
>getA : Symbol(getA, Decl(impl.d.ts, 0, 0))
4+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
5+
6+
export enum A {
7+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
8+
9+
Val
10+
>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15))
11+
}
12+
=== /cache/typescript-fsa/index.d.ts ===
13+
export * from "./src/impl";
14+
No type information for this code.=== /p1/index.ts ===
15+
import * as _whatever from "p2";
16+
>_whatever : Symbol(_whatever, Decl(index.ts, 0, 6))
17+
18+
import { getA } from "typescript-fsa";
19+
>getA : Symbol(getA, Decl(index.ts, 1, 8))
20+
21+
export const a = getA();
22+
>a : Symbol(a, Decl(index.ts, 3, 12))
23+
>getA : Symbol(getA, Decl(index.ts, 1, 8))
24+
25+
=== /p2/index.d.ts ===
26+
export const a: import("typescript-fsa").A;
27+
>a : Symbol(a, Decl(index.d.ts, 0, 12))
28+
>A : Symbol(A, Decl(impl.d.ts, 0, 26))
29+
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== /cache/typescript-fsa/src/impl.d.ts ===
2+
export function getA(): A;
3+
>getA : () => A
4+
5+
export enum A {
6+
>A : A
7+
8+
Val
9+
>Val : A
10+
}
11+
=== /cache/typescript-fsa/index.d.ts ===
12+
export * from "./src/impl";
13+
No type information for this code.=== /p1/index.ts ===
14+
import * as _whatever from "p2";
15+
>_whatever : typeof _whatever
16+
17+
import { getA } from "typescript-fsa";
18+
>getA : () => import("/cache/typescript-fsa/index").A
19+
20+
export const a = getA();
21+
>a : import("/cache/typescript-fsa/index").A
22+
>getA() : import("/cache/typescript-fsa/index").A
23+
>getA : () => import("/cache/typescript-fsa/index").A
24+
25+
=== /p2/index.d.ts ===
26+
export const a: import("typescript-fsa").A;
27+
>a : import("/cache/typescript-fsa/index").A
28+
29+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @useCaseSensitiveFilenames: true
2+
// @declaration: true
3+
// @filename: /p1/node_modules/typescript-fsa/src/impl.d.ts
4+
export function getA(): A;
5+
export enum A {
6+
Val
7+
}
8+
// @filename: /p1/node_modules/typescript-fsa/index.d.ts
9+
export * from "./src/impl";
10+
// @filename: /p1/node_modules/typescript-fsa/package.json
11+
{
12+
"name": "typescript-fsa",
13+
"version": "1.0.0"
14+
}
15+
// @filename: /p2/node_modules/typescript-fsa/src/impl.d.ts
16+
export function getA(): A;
17+
export enum A {
18+
Val
19+
}
20+
// @filename: /p2/node_modules/typescript-fsa/index.d.ts
21+
export * from "./src/impl";
22+
// @filename: /p2/node_modules/typescript-fsa/package.json
23+
{
24+
"name": "typescript-fsa",
25+
"version": "1.0.0"
26+
}
27+
// @filename: /p1/index.ts
28+
import * as _whatever from "p2";
29+
import { getA } from "typescript-fsa";
30+
31+
export const a = getA();
32+
// @filename: /p2/index.d.ts
33+
export const a: import("typescript-fsa").A;
34+
35+
// @link: /p2 -> /p1/node_modules/p2
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @useCaseSensitiveFilenames: true
2+
// @declaration: true
3+
// @filename: /cache/typescript-fsa/src/impl.d.ts
4+
export function getA(): A;
5+
export enum A {
6+
Val
7+
}
8+
// @filename: /cache/typescript-fsa/index.d.ts
9+
export * from "./src/impl";
10+
// @filename: /cache/typescript-fsa/package.json
11+
{
12+
"name": "typescript-fsa",
13+
"version": "1.0.0"
14+
}
15+
// @filename: /p1/index.ts
16+
import * as _whatever from "p2";
17+
import { getA } from "typescript-fsa";
18+
19+
export const a = getA();
20+
// @filename: /p2/index.d.ts
21+
export const a: import("typescript-fsa").A;
22+
23+
// @link: /p2 -> /p1/node_modules/p2
24+
// @link: /cache/typescript-fsa -> /p1/node_modules/typescript-fsa
25+
// @link: /cache/typescript-fsa -> /p2/node_modules/typescript-fsa

0 commit comments

Comments
 (0)