Skip to content

Commit d1586de

Browse files
authored
Fully resolve aliases when checking symbol flags (#50853)
* Resolve aliases past first merge in `resolveName` * WIP * Fix when a namespace merges with an alias that resolves to a type merged with an alias that resolves to a value 😵 * Audit all resolveSymbol and resolveName calls * Fix qualification in re-exporting global cases * Fix infinite loop detection * Update baselines * Just make getAllSymbolFlags default to All
1 parent 45148dd commit d1586de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1158
-56
lines changed

src/compiler/checker.ts

Lines changed: 94 additions & 36 deletions
Large diffs are not rendered by default.

tests/baselines/reference/allowImportClausesToMergeWithTypes.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
tests/cases/compiler/index.ts(4,1): error TS2693: 'zzz' only refers to a type, but is being used as a value here.
21
tests/cases/compiler/index.ts(9,10): error TS2749: 'originalZZZ' refers to a value, but is being used as a type here. Did you mean 'typeof originalZZZ'?
32

43

@@ -18,13 +17,11 @@ tests/cases/compiler/index.ts(9,10): error TS2749: 'originalZZZ' refers to a val
1817

1918
export { zzz as default };
2019

21-
==== tests/cases/compiler/index.ts (2 errors) ====
20+
==== tests/cases/compiler/index.ts (1 errors) ====
2221
import zzz from "./a";
2322

2423
const x: zzz = { x: "" };
2524
zzz;
26-
~~~
27-
!!! error TS2693: 'zzz' only refers to a type, but is being used as a value here.
2825

2926
import originalZZZ from "./b";
3027
originalZZZ;

tests/baselines/reference/allowImportClausesToMergeWithTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ b_1["default"];
4444
//// [index.js]
4545
"use strict";
4646
exports.__esModule = true;
47+
var a_1 = require("./a");
4748
var x = { x: "" };
4849
a_1["default"];
4950
var b_1 = require("./b");

tests/baselines/reference/allowImportClausesToMergeWithTypes.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const x: zzz = { x: "" };
3838
>x : Symbol(x, Decl(index.ts, 2, 16))
3939

4040
zzz;
41+
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))
4142

4243
import originalZZZ from "./b";
4344
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))

tests/baselines/reference/allowImportClausesToMergeWithTypes.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export { zzz as default };
3030

3131
=== tests/cases/compiler/index.ts ===
3232
import zzz from "./a";
33-
>zzz : any
33+
>zzz : 123
3434

3535
const x: zzz = { x: "" };
3636
>x : zzz
@@ -39,7 +39,7 @@ const x: zzz = { x: "" };
3939
>"" : ""
4040

4141
zzz;
42-
>zzz : any
42+
>zzz : 123
4343

4444
import originalZZZ from "./b";
4545
>originalZZZ : 123
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tests/cases/conformance/constEnums/merge.ts(1,10): error TS2440: Import declaration conflicts with local declaration of 'Enum'.
2+
3+
4+
==== tests/cases/conformance/constEnums/enum.ts (0 errors) ====
5+
export const enum Enum {
6+
One = 1,
7+
}
8+
9+
==== tests/cases/conformance/constEnums/merge.ts (1 errors) ====
10+
import { Enum } from "./enum";
11+
~~~~
12+
!!! error TS2440: Import declaration conflicts with local declaration of 'Enum'.
13+
namespace Enum {
14+
export type Foo = number;
15+
}
16+
export { Enum };
17+
18+
==== tests/cases/conformance/constEnums/index.ts (0 errors) ====
19+
import { Enum } from "./merge";
20+
Enum.One;
21+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/conformance/constEnums/importElisionConstEnumMerge1.ts] ////
2+
3+
//// [enum.ts]
4+
export const enum Enum {
5+
One = 1,
6+
}
7+
8+
//// [merge.ts]
9+
import { Enum } from "./enum";
10+
namespace Enum {
11+
export type Foo = number;
12+
}
13+
export { Enum };
14+
15+
//// [index.ts]
16+
import { Enum } from "./merge";
17+
Enum.One;
18+
19+
20+
//// [enum.js]
21+
"use strict";
22+
exports.__esModule = true;
23+
//// [merge.js]
24+
"use strict";
25+
exports.__esModule = true;
26+
exports.Enum = void 0;
27+
//// [index.js]
28+
"use strict";
29+
exports.__esModule = true;
30+
var merge_1 = require("./merge");
31+
1 /* Enum.One */;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/conformance/constEnums/enum.ts ===
2+
export const enum Enum {
3+
>Enum : Symbol(Enum, Decl(enum.ts, 0, 0))
4+
5+
One = 1,
6+
>One : Symbol(Enum.One, Decl(enum.ts, 0, 24))
7+
}
8+
9+
=== tests/cases/conformance/constEnums/merge.ts ===
10+
import { Enum } from "./enum";
11+
>Enum : Symbol(Enum, Decl(merge.ts, 0, 8), Decl(merge.ts, 0, 30))
12+
13+
namespace Enum {
14+
>Enum : Symbol(Enum, Decl(merge.ts, 0, 8), Decl(merge.ts, 0, 30))
15+
16+
export type Foo = number;
17+
>Foo : Symbol(Foo, Decl(merge.ts, 1, 16))
18+
}
19+
export { Enum };
20+
>Enum : Symbol(Enum, Decl(merge.ts, 4, 8))
21+
22+
=== tests/cases/conformance/constEnums/index.ts ===
23+
import { Enum } from "./merge";
24+
>Enum : Symbol(Enum, Decl(index.ts, 0, 8))
25+
26+
Enum.One;
27+
>Enum.One : Symbol(Enum.One, Decl(enum.ts, 0, 24))
28+
>Enum : Symbol(Enum, Decl(index.ts, 0, 8))
29+
>One : Symbol(Enum.One, Decl(enum.ts, 0, 24))
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/constEnums/enum.ts ===
2+
export const enum Enum {
3+
>Enum : Enum
4+
5+
One = 1,
6+
>One : Enum.One
7+
>1 : 1
8+
}
9+
10+
=== tests/cases/conformance/constEnums/merge.ts ===
11+
import { Enum } from "./enum";
12+
>Enum : typeof Enum
13+
14+
namespace Enum {
15+
export type Foo = number;
16+
>Foo : number
17+
}
18+
export { Enum };
19+
>Enum : typeof Enum
20+
21+
=== tests/cases/conformance/constEnums/index.ts ===
22+
import { Enum } from "./merge";
23+
>Enum : typeof import("tests/cases/conformance/constEnums/enum").Enum
24+
25+
Enum.One;
26+
>Enum.One : import("tests/cases/conformance/constEnums/enum").Enum
27+
>Enum : typeof import("tests/cases/conformance/constEnums/enum").Enum
28+
>One : import("tests/cases/conformance/constEnums/enum").Enum
29+

tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export {myTypes};
2626

2727
=== tests/cases/conformance/jsdoc/declarations/file2.js ===
2828
import {myTypes} from './file.js';
29-
>myTypes : any
29+
>myTypes : { [x: string]: any; }
3030

3131
/**
3232
* @namespace testFnTypes

tests/baselines/reference/noCrashOnImportShadowing.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
tests/cases/compiler/index.ts(4,1): error TS2693: 'B' only refers to a type, but is being used as a value here.
21
tests/cases/compiler/index.ts(9,10): error TS2709: Cannot use namespace 'OriginalB' as a type.
32

43

@@ -17,13 +16,11 @@ tests/cases/compiler/index.ts(9,10): error TS2709: Cannot use namespace 'Origina
1716

1817
export { B };
1918

20-
==== tests/cases/compiler/index.ts (2 errors) ====
19+
==== tests/cases/compiler/index.ts (1 errors) ====
2120
import { B } from "./a";
2221

2322
const x: B = { x: "" };
2423
B.zzz;
25-
~
26-
!!! error TS2693: 'B' only refers to a type, but is being used as a value here.
2724

2825
import * as OriginalB from "./b";
2926
OriginalB.zzz;

tests/baselines/reference/noCrashOnImportShadowing.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ exports.zzz = 123;
3434
//// [a.js]
3535
"use strict";
3636
exports.__esModule = true;
37+
exports.B = void 0;
3738
var B = require("./b");
39+
exports.B = B;
3840
var x = { x: "" };
3941
B.zzz;
4042
//// [index.js]
4143
"use strict";
4244
exports.__esModule = true;
45+
var a_1 = require("./a");
4346
var x = { x: "" };
4447
a_1.B.zzz;
4548
var OriginalB = require("./b");

tests/baselines/reference/noCrashOnImportShadowing.symbols

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const x: B = { x: "" };
3636
>x : Symbol(x, Decl(index.ts, 2, 14))
3737

3838
B.zzz;
39+
>B.zzz : Symbol(OriginalB.zzz, Decl(b.ts, 0, 12))
40+
>B : Symbol(B, Decl(index.ts, 0, 8))
41+
>zzz : Symbol(OriginalB.zzz, Decl(b.ts, 0, 12))
3942

4043
import * as OriginalB from "./b";
4144
>OriginalB : Symbol(OriginalB, Decl(index.ts, 5, 6))

tests/baselines/reference/noCrashOnImportShadowing.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ B.zzz;
2424
>zzz : 123
2525

2626
export { B };
27-
>B : any
27+
>B : typeof B
2828

2929
=== tests/cases/compiler/index.ts ===
3030
import { B } from "./a";
31-
>B : any
31+
>B : typeof OriginalB
3232

3333
const x: B = { x: "" };
3434
>x : B
@@ -37,9 +37,9 @@ const x: B = { x: "" };
3737
>"" : ""
3838

3939
B.zzz;
40-
>B.zzz : any
41-
>B : any
42-
>zzz : any
40+
>B.zzz : 123
41+
>B : typeof OriginalB
42+
>zzz : 123
4343

4444
import * as OriginalB from "./b";
4545
>OriginalB : typeof OriginalB

tests/baselines/reference/shadowedInternalModule.errors.txt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(13,20): error TS2437: Module 'A' is hidden by a local declaration with the same name.
22
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(30,5): error TS2440: Import declaration conflicts with local declaration of 'Y'.
3+
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(47,10): error TS2438: Import name cannot be 'any'.
4+
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(62,3): error TS2440: Import declaration conflicts with local declaration of 'Q'.
35

46

5-
==== tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts (2 errors) ====
7+
==== tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts (4 errors) ====
68
// all errors imported modules conflict with local variables
79

810
module A {
@@ -39,4 +41,40 @@ tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModul
3941
!!! error TS2440: Import declaration conflicts with local declaration of 'Y'.
4042

4143
var Y = 12;
42-
}
44+
}
45+
46+
//
47+
48+
module a {
49+
export type A = number;
50+
}
51+
52+
module b {
53+
export import A = a.A;
54+
export module A {}
55+
}
56+
57+
module c {
58+
import any = b.A;
59+
~~~
60+
!!! error TS2438: Import name cannot be 'any'.
61+
}
62+
63+
//
64+
65+
module q {
66+
export const Q = {};
67+
}
68+
69+
module r {
70+
export import Q = q.Q;
71+
export type Q = number;
72+
}
73+
74+
module s {
75+
import Q = r.Q;
76+
~~~~~~~~~~~~~~~
77+
!!! error TS2440: Import declaration conflicts with local declaration of 'Q'.
78+
const Q = 0;
79+
}
80+

tests/baselines/reference/shadowedInternalModule.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,39 @@ module Z {
3131
import Y = X.Y;
3232

3333
var Y = 12;
34-
}
34+
}
35+
36+
//
37+
38+
module a {
39+
export type A = number;
40+
}
41+
42+
module b {
43+
export import A = a.A;
44+
export module A {}
45+
}
46+
47+
module c {
48+
import any = b.A;
49+
}
50+
51+
//
52+
53+
module q {
54+
export const Q = {};
55+
}
56+
57+
module r {
58+
export import Q = q.Q;
59+
export type Q = number;
60+
}
61+
62+
module s {
63+
import Q = r.Q;
64+
const Q = 0;
65+
}
66+
3567

3668
//// [shadowedInternalModule.js]
3769
// all errors imported modules conflict with local variables
@@ -56,3 +88,19 @@ var Z;
5688
(function (Z) {
5789
var Y = 12;
5890
})(Z || (Z = {}));
91+
var b;
92+
(function (b) {
93+
})(b || (b = {}));
94+
//
95+
var q;
96+
(function (q) {
97+
q.Q = {};
98+
})(q || (q = {}));
99+
var r;
100+
(function (r) {
101+
r.Q = q.Q;
102+
})(r || (r = {}));
103+
var s;
104+
(function (s) {
105+
var Q = 0;
106+
})(s || (s = {}));

0 commit comments

Comments
 (0)