mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Prevent collision of imported type with exported declarations in current module (#31231)
* check for exported type name for conflict * refactor baseline tests for import/export name collision
This commit is contained in:
committed by
Andrew Branch
parent
e72937deff
commit
c0573c59c9
@@ -31965,7 +31965,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier) {
|
||||
const symbol = getSymbolOfNode(node);
|
||||
let symbol = getSymbolOfNode(node);
|
||||
const target = resolveAlias(symbol);
|
||||
|
||||
const shouldSkipWithJSExpandoTargets = symbol.flags & SymbolFlags.Assignment;
|
||||
@@ -31976,6 +31976,7 @@ namespace ts {
|
||||
// Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have,
|
||||
// otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
|
||||
// in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
|
||||
symbol = getMergedSymbol(symbol.exportSymbol || symbol);
|
||||
const excludedMeanings =
|
||||
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
|
||||
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
tests/cases/compiler/f2.ts(1,9): error TS2440: Import declaration conflicts with local declaration of 'N'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/f1.ts (0 errors) ====
|
||||
export namespace N { export var x = 1; }
|
||||
|
||||
==== tests/cases/compiler/f2.ts (1 errors) ====
|
||||
import {N} from "./f1";
|
||||
~
|
||||
!!! error TS2440: Import declaration conflicts with local declaration of 'N'.
|
||||
export namespace N {
|
||||
export interface I {x: any}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ export namespace N { export var x = 1; }
|
||||
|
||||
//// [f2.ts]
|
||||
import {N} from "./f1";
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export namespace N {
|
||||
export interface I {x: any}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ export namespace N { export var x = 1; }
|
||||
import {N} from "./f1";
|
||||
>N : Symbol(N, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))
|
||||
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export namespace N {
|
||||
>N : Symbol(N, Decl(f2.ts, 0, 23))
|
||||
|
||||
export interface I {x: any}
|
||||
>I : Symbol(I, Decl(f2.ts, 2, 20))
|
||||
>x : Symbol(I.x, Decl(f2.ts, 3, 24))
|
||||
>I : Symbol(I, Decl(f2.ts, 1, 20))
|
||||
>x : Symbol(I.x, Decl(f2.ts, 2, 24))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ export namespace N { export var x = 1; }
|
||||
import {N} from "./f1";
|
||||
>N : typeof N
|
||||
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export namespace N {
|
||||
export interface I {x: any}
|
||||
>x : any
|
||||
|
||||
11
tests/baselines/reference/mergeWithImportedType.errors.txt
Normal file
11
tests/baselines/reference/mergeWithImportedType.errors.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/f2.ts(1,9): error TS2440: Import declaration conflicts with local declaration of 'E'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/f1.ts (0 errors) ====
|
||||
export enum E {X}
|
||||
|
||||
==== tests/cases/compiler/f2.ts (1 errors) ====
|
||||
import {E} from "./f1";
|
||||
~
|
||||
!!! error TS2440: Import declaration conflicts with local declaration of 'E'.
|
||||
export type E = E;
|
||||
@@ -5,7 +5,6 @@ export enum E {X}
|
||||
|
||||
//// [f2.ts]
|
||||
import {E} from "./f1";
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export type E = E;
|
||||
|
||||
//// [f1.js]
|
||||
|
||||
@@ -7,7 +7,6 @@ export enum E {X}
|
||||
import {E} from "./f1";
|
||||
>E : Symbol(E, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))
|
||||
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export type E = E;
|
||||
>E : Symbol(E, Decl(f2.ts, 0, 23))
|
||||
>E : Symbol(E, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))
|
||||
|
||||
@@ -7,7 +7,6 @@ export enum E {X}
|
||||
import {E} from "./f1";
|
||||
>E : typeof E
|
||||
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export type E = E;
|
||||
>E : E
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ export namespace N { export var x = 1; }
|
||||
|
||||
// @filename: f2.ts
|
||||
import {N} from "./f1";
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export namespace N {
|
||||
export interface I {x: any}
|
||||
}
|
||||
@@ -4,5 +4,4 @@ export enum E {X}
|
||||
|
||||
// @filename: f2.ts
|
||||
import {E} from "./f1";
|
||||
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
|
||||
export type E = E;
|
||||
Reference in New Issue
Block a user