Skip to content

Fully resolve aliases when checking symbol flags #50853

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

Merged
merged 9 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 94 additions & 36 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
21 changes: 21 additions & 0 deletions tests/baselines/reference/importElisionConstEnumMerge1.errors.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
42 changes: 40 additions & 2 deletions tests/baselines/reference/shadowedInternalModule.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(13,20): error TS2437: Module 'A' is hidden by a local declaration with the same name.
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(30,5): error TS2440: Import declaration conflicts with local declaration of 'Y'.
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(47,10): error TS2438: Import name cannot be 'any'.
tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts(62,3): error TS2440: Import declaration conflicts with local declaration of 'Q'.


==== tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts (2 errors) ====
==== tests/cases/conformance/internalModules/importDeclarations/shadowedInternalModule.ts (4 errors) ====
// all errors imported modules conflict with local variables

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

var Y = 12;
}
}

//

module a {
export type A = number;
}

module b {
export import A = a.A;
export module A {}
}

module c {
import any = b.A;
~~~
!!! error TS2438: Import name cannot be 'any'.
}

//

module q {
export const Q = {};
}

module r {
export import Q = q.Q;
export type Q = number;
}

module s {
import Q = r.Q;
~~~~~~~~~~~~~~~
!!! error TS2440: Import declaration conflicts with local declaration of 'Q'.
const Q = 0;
}

50 changes: 49 additions & 1 deletion tests/baselines/reference/shadowedInternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,39 @@ module Z {
import Y = X.Y;

var Y = 12;
}
}

//

module a {
export type A = number;
}

module b {
export import A = a.A;
export module A {}
}

module c {
import any = b.A;
}

//

module q {
export const Q = {};
}

module r {
export import Q = q.Q;
export type Q = number;
}

module s {
import Q = r.Q;
const Q = 0;
}


//// [shadowedInternalModule.js]
// all errors imported modules conflict with local variables
Expand All @@ -56,3 +88,19 @@ var Z;
(function (Z) {
var Y = 12;
})(Z || (Z = {}));
var b;
(function (b) {
})(b || (b = {}));
//
var q;
(function (q) {
q.Q = {};
})(q || (q = {}));
var r;
(function (r) {
r.Q = q.Q;
})(r || (r = {}));
var s;
(function (s) {
var Q = 0;
})(s || (s = {}));
Loading