Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully resolve aliases when checking symbol flags #50853

Merged
merged 9 commits into from Sep 29, 2022
126 changes: 91 additions & 35 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

@@ -1,4 +1,3 @@
tests/cases/compiler/index.ts(4,1): error TS2693: 'zzz' only refers to a type, but is being used as a value here.
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'?


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

export { zzz as default };

==== tests/cases/compiler/index.ts (2 errors) ====
==== tests/cases/compiler/index.ts (1 errors) ====
import zzz from "./a";

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

import originalZZZ from "./b";
originalZZZ;
Expand Down
Expand Up @@ -44,6 +44,7 @@ b_1["default"];
//// [index.js]
"use strict";
exports.__esModule = true;
var a_1 = require("./a");
var x = { x: "" };
a_1["default"];
var b_1 = require("./b");
Expand Down
Expand Up @@ -38,6 +38,7 @@ const x: zzz = { x: "" };
>x : Symbol(x, Decl(index.ts, 2, 16))

zzz;
>zzz : Symbol(zzz, Decl(index.ts, 0, 6))

import originalZZZ from "./b";
>originalZZZ : Symbol(originalZZZ, Decl(index.ts, 5, 6))
Expand Down
Expand Up @@ -30,7 +30,7 @@ export { zzz as default };

=== tests/cases/compiler/index.ts ===
import zzz from "./a";
>zzz : any
>zzz : 123

const x: zzz = { x: "" };
>x : zzz
Expand All @@ -39,7 +39,7 @@ const x: zzz = { x: "" };
>"" : ""

zzz;
>zzz : any
>zzz : 123

import originalZZZ from "./b";
>originalZZZ : 123
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/exportSpecifierForAGlobal.js
Expand Up @@ -24,4 +24,4 @@ exports.f = f;

//// [b.d.ts]
export { X };
export declare function f(): X;
export declare function f(): globalThis.X;
8 changes: 4 additions & 4 deletions tests/baselines/reference/exportSpecifierForAGlobal.types
Expand Up @@ -4,15 +4,15 @@ declare class X { }

=== tests/cases/compiler/b.ts ===
export {X};
>X : typeof X
>X : typeof globalThis.X

export function f() {
>f : () => X
>f : () => globalThis.X

var x: X;
>x : X
>x : globalThis.X

return x;
>x : X
>x : globalThis.X
}

Expand Up @@ -12,5 +12,5 @@ declare module "m" {
export function foo(): X.bar;
>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 17))
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0))
>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))
>bar : Symbol(globalThis.X.bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))
}
Expand Up @@ -10,5 +10,5 @@ export { X };
export declare function foo(): X.bar;
>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration2_B.ts, 0, 13))
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 0))
>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18))
>bar : Symbol(globalThis.X.bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18))

21 changes: 21 additions & 0 deletions tests/baselines/reference/importElisionConstEnumMerge1.errors.txt
@@ -0,0 +1,21 @@
tests/cases/conformance/constEnums/merge.ts(1,10): error TS2440: Import declaration conflicts with local declaration of 'Enum'.


==== tests/cases/conformance/constEnums/enum.ts (0 errors) ====
export const enum Enum {
One = 1,
}

==== tests/cases/conformance/constEnums/merge.ts (1 errors) ====
import { Enum } from "./enum";
~~~~
!!! error TS2440: Import declaration conflicts with local declaration of 'Enum'.
namespace Enum {
export type Foo = number;
}
export { Enum };

==== tests/cases/conformance/constEnums/index.ts (0 errors) ====
import { Enum } from "./merge";
Enum.One;

31 changes: 31 additions & 0 deletions tests/baselines/reference/importElisionConstEnumMerge1.js
@@ -0,0 +1,31 @@
//// [tests/cases/conformance/constEnums/importElisionConstEnumMerge1.ts] ////

//// [enum.ts]
export const enum Enum {
One = 1,
}

//// [merge.ts]
import { Enum } from "./enum";
namespace Enum {
export type Foo = number;
}
export { Enum };

//// [index.ts]
import { Enum } from "./merge";
Enum.One;


//// [enum.js]
"use strict";
exports.__esModule = true;
//// [merge.js]
"use strict";
exports.__esModule = true;
exports.Enum = void 0;
//// [index.js]
"use strict";
exports.__esModule = true;
var merge_1 = require("./merge");
1 /* Enum.One */;
30 changes: 30 additions & 0 deletions tests/baselines/reference/importElisionConstEnumMerge1.symbols
@@ -0,0 +1,30 @@
=== tests/cases/conformance/constEnums/enum.ts ===
export const enum Enum {
>Enum : Symbol(Enum, Decl(enum.ts, 0, 0))

One = 1,
>One : Symbol(Enum.One, Decl(enum.ts, 0, 24))
}

=== tests/cases/conformance/constEnums/merge.ts ===
import { Enum } from "./enum";
>Enum : Symbol(Enum, Decl(merge.ts, 0, 8), Decl(merge.ts, 0, 30))

namespace Enum {
>Enum : Symbol(Enum, Decl(merge.ts, 0, 8), Decl(merge.ts, 0, 30))

export type Foo = number;
>Foo : Symbol(Foo, Decl(merge.ts, 1, 16))
}
export { Enum };
>Enum : Symbol(Enum, Decl(merge.ts, 4, 8))

=== tests/cases/conformance/constEnums/index.ts ===
import { Enum } from "./merge";
>Enum : Symbol(Enum, Decl(index.ts, 0, 8))

Enum.One;
>Enum.One : Symbol(Enum.One, Decl(enum.ts, 0, 24))
>Enum : Symbol(Enum, Decl(index.ts, 0, 8))
>One : Symbol(Enum.One, Decl(enum.ts, 0, 24))

29 changes: 29 additions & 0 deletions tests/baselines/reference/importElisionConstEnumMerge1.types
@@ -0,0 +1,29 @@
=== tests/cases/conformance/constEnums/enum.ts ===
export const enum Enum {
>Enum : Enum

One = 1,
>One : Enum.One
>1 : 1
}

=== tests/cases/conformance/constEnums/merge.ts ===
import { Enum } from "./enum";
>Enum : typeof Enum

namespace Enum {
export type Foo = number;
>Foo : number
}
export { Enum };
>Enum : typeof Enum

=== tests/cases/conformance/constEnums/index.ts ===
import { Enum } from "./merge";
>Enum : typeof import("tests/cases/conformance/constEnums/enum").Enum

Enum.One;
>Enum.One : import("tests/cases/conformance/constEnums/enum").Enum
>Enum : typeof import("tests/cases/conformance/constEnums/enum").Enum
>One : import("tests/cases/conformance/constEnums/enum").Enum

Expand Up @@ -26,7 +26,7 @@ export {myTypes};

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

/**
* @namespace testFnTypes
Expand Down
@@ -1,4 +1,3 @@
tests/cases/compiler/index.ts(4,1): error TS2693: 'B' only refers to a type, but is being used as a value here.
tests/cases/compiler/index.ts(9,10): error TS2709: Cannot use namespace 'OriginalB' as a type.


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

export { B };

==== tests/cases/compiler/index.ts (2 errors) ====
==== tests/cases/compiler/index.ts (1 errors) ====
import { B } from "./a";

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

import * as OriginalB from "./b";
OriginalB.zzz;
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/noCrashOnImportShadowing.js
Expand Up @@ -34,12 +34,15 @@ exports.zzz = 123;
//// [a.js]
"use strict";
exports.__esModule = true;
exports.B = void 0;
var B = require("./b");
exports.B = B;
var x = { x: "" };
B.zzz;
//// [index.js]
"use strict";
exports.__esModule = true;
var a_1 = require("./a");
var x = { x: "" };
a_1.B.zzz;
var OriginalB = require("./b");
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/noCrashOnImportShadowing.symbols
Expand Up @@ -36,6 +36,9 @@ const x: B = { x: "" };
>x : Symbol(x, Decl(index.ts, 2, 14))

B.zzz;
>B.zzz : Symbol(OriginalB.zzz, Decl(b.ts, 0, 12))
>B : Symbol(B, Decl(index.ts, 0, 8))
>zzz : Symbol(OriginalB.zzz, Decl(b.ts, 0, 12))

import * as OriginalB from "./b";
>OriginalB : Symbol(OriginalB, Decl(index.ts, 5, 6))
Expand Down
10 changes: 5 additions & 5 deletions tests/baselines/reference/noCrashOnImportShadowing.types
Expand Up @@ -24,11 +24,11 @@ B.zzz;
>zzz : 123

export { B };
>B : any
>B : typeof B

=== tests/cases/compiler/index.ts ===
import { B } from "./a";
>B : any
>B : typeof OriginalB

const x: B = { x: "" };
>x : B
Expand All @@ -37,9 +37,9 @@ const x: B = { x: "" };
>"" : ""

B.zzz;
>B.zzz : any
>B : any
>zzz : any
>B.zzz : 123
>B : typeof OriginalB
>zzz : 123

import * as OriginalB from "./b";
>OriginalB : typeof OriginalB
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/reExportGlobalDeclaration3.types
Expand Up @@ -15,20 +15,20 @@ declare namespace NS2 {

=== tests/cases/compiler/file2.ts ===
export {NS1, NS1 as NNS1};
>NS1 : typeof NS1
>NS1 : typeof NS1
>NNS1 : typeof NS1
>NS1 : typeof globalThis.NS1
>NS1 : typeof globalThis.NS1
>NNS1 : typeof globalThis.NS1

export {NS2, NS2 as NNS2};
>NS2 : typeof NS2
>NS2 : typeof NS2
>NNS2 : typeof NS2
>NS2 : typeof globalThis.NS2
>NS2 : typeof globalThis.NS2
>NNS2 : typeof globalThis.NS2

export {NS1 as NNNS1};
>NS1 : typeof NS1
>NNNS1 : typeof NS1
>NS1 : typeof globalThis.NS1
>NNNS1 : typeof globalThis.NS1

export {NS2 as NNNS2};
>NS2 : typeof NS2
>NNNS2 : typeof NS2
>NS2 : typeof globalThis.NS2
>NNNS2 : typeof globalThis.NS2

20 changes: 10 additions & 10 deletions tests/baselines/reference/reExportGlobalDeclaration4.types
Expand Up @@ -15,20 +15,20 @@ declare class Cls2 {

=== tests/cases/compiler/file2.ts ===
export {Cls1, Cls1 as CCls1};
>Cls1 : typeof Cls1
>Cls1 : typeof Cls1
>CCls1 : typeof Cls1
>Cls1 : typeof globalThis.Cls1
>Cls1 : typeof globalThis.Cls1
>CCls1 : typeof globalThis.Cls1

export {Cls2, Cls2 as CCls2};
>Cls2 : typeof Cls2
>Cls2 : typeof Cls2
>CCls2 : typeof Cls2
>Cls2 : typeof globalThis.Cls2
>Cls2 : typeof globalThis.Cls2
>CCls2 : typeof globalThis.Cls2

export {Cls1 as CCCls1};
>Cls1 : typeof Cls1
>CCCls1 : typeof Cls1
>Cls1 : typeof globalThis.Cls1
>CCCls1 : typeof globalThis.Cls1

export {Cls2 as CCCls2};
>Cls2 : typeof Cls2
>CCCls2 : typeof Cls2
>Cls2 : typeof globalThis.Cls2
>CCCls2 : typeof globalThis.Cls2