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

43 files changed

Lines changed: 1158 additions & 56 deletions

Some content is hidden

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

‎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

0 commit comments

Comments
 (0)