From 9df64ef68972b7cdf2d5d15b68ac06bf87182e87 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Fri, 3 May 2019 17:06:34 +0300 Subject: [PATCH 1/2] check for exported type name for conflict --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfd83efeb31aa..af995a7dcd487 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30078,7 +30078,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; @@ -30089,6 +30089,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) | From 4b08941ca633c767e280e578a3bf62b7fe0a1002 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Fri, 3 May 2019 17:40:03 +0300 Subject: [PATCH 2/2] refactor baseline tests for import/export name collision --- .../reference/mergeWithImportedNamespace.errors.txt | 13 +++++++++++++ .../reference/mergeWithImportedNamespace.js | 1 - .../reference/mergeWithImportedNamespace.symbols | 5 ++--- .../reference/mergeWithImportedNamespace.types | 1 - .../reference/mergeWithImportedType.errors.txt | 11 +++++++++++ tests/baselines/reference/mergeWithImportedType.js | 1 - .../reference/mergeWithImportedType.symbols | 1 - .../baselines/reference/mergeWithImportedType.types | 1 - tests/cases/compiler/mergeWithImportedNamespace.ts | 1 - tests/cases/compiler/mergeWithImportedType.ts | 1 - 10 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/mergeWithImportedNamespace.errors.txt create mode 100644 tests/baselines/reference/mergeWithImportedType.errors.txt diff --git a/tests/baselines/reference/mergeWithImportedNamespace.errors.txt b/tests/baselines/reference/mergeWithImportedNamespace.errors.txt new file mode 100644 index 0000000000000..7839264b604c8 --- /dev/null +++ b/tests/baselines/reference/mergeWithImportedNamespace.errors.txt @@ -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} + } \ No newline at end of file diff --git a/tests/baselines/reference/mergeWithImportedNamespace.js b/tests/baselines/reference/mergeWithImportedNamespace.js index ec2eb4a1087cb..ff7248a68f33a 100644 --- a/tests/baselines/reference/mergeWithImportedNamespace.js +++ b/tests/baselines/reference/mergeWithImportedNamespace.js @@ -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} } diff --git a/tests/baselines/reference/mergeWithImportedNamespace.symbols b/tests/baselines/reference/mergeWithImportedNamespace.symbols index 58b0f0a811fd1..2b82ea26252e5 100644 --- a/tests/baselines/reference/mergeWithImportedNamespace.symbols +++ b/tests/baselines/reference/mergeWithImportedNamespace.symbols @@ -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)) } diff --git a/tests/baselines/reference/mergeWithImportedNamespace.types b/tests/baselines/reference/mergeWithImportedNamespace.types index b0b55435636f3..950d52aff387e 100644 --- a/tests/baselines/reference/mergeWithImportedNamespace.types +++ b/tests/baselines/reference/mergeWithImportedNamespace.types @@ -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 diff --git a/tests/baselines/reference/mergeWithImportedType.errors.txt b/tests/baselines/reference/mergeWithImportedType.errors.txt new file mode 100644 index 0000000000000..1ac48946a040a --- /dev/null +++ b/tests/baselines/reference/mergeWithImportedType.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/mergeWithImportedType.js b/tests/baselines/reference/mergeWithImportedType.js index efa95d7763064..27622372a8357 100644 --- a/tests/baselines/reference/mergeWithImportedType.js +++ b/tests/baselines/reference/mergeWithImportedType.js @@ -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] diff --git a/tests/baselines/reference/mergeWithImportedType.symbols b/tests/baselines/reference/mergeWithImportedType.symbols index d14d76f91e7b4..acfaef80c6de6 100644 --- a/tests/baselines/reference/mergeWithImportedType.symbols +++ b/tests/baselines/reference/mergeWithImportedType.symbols @@ -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)) diff --git a/tests/baselines/reference/mergeWithImportedType.types b/tests/baselines/reference/mergeWithImportedType.types index 7ba671ce46850..84b9cc2813805 100644 --- a/tests/baselines/reference/mergeWithImportedType.types +++ b/tests/baselines/reference/mergeWithImportedType.types @@ -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 diff --git a/tests/cases/compiler/mergeWithImportedNamespace.ts b/tests/cases/compiler/mergeWithImportedNamespace.ts index 79a94fd0ba4e8..0b112da86e85a 100644 --- a/tests/cases/compiler/mergeWithImportedNamespace.ts +++ b/tests/cases/compiler/mergeWithImportedNamespace.ts @@ -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} } \ No newline at end of file diff --git a/tests/cases/compiler/mergeWithImportedType.ts b/tests/cases/compiler/mergeWithImportedType.ts index 2310022012f32..d31f16f8d92f7 100644 --- a/tests/cases/compiler/mergeWithImportedType.ts +++ b/tests/cases/compiler/mergeWithImportedType.ts @@ -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; \ No newline at end of file