Skip to content
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
16 changes: 14 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9178,8 +9178,20 @@ module ts {

function isUniqueLocalName(name: string, container: Node): boolean {
for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
if (node.locals && hasProperty(node.locals, name) && node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
return false;
if (node.locals && hasProperty(node.locals, name)) {
var symbolWithRelevantName = node.locals[name];
if (symbolWithRelevantName.flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
return false;
}

// An import can be emitted too, if it is referenced as a value.
// Make sure the name in question does not collide with an import.
if (symbolWithRelevantName.flags & SymbolFlags.Import) {
var importDeclarationWithRelevantName = <ImportDeclaration>getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportDeclaration);
if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test case for when you don't reference the import.

return false;
}
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [moduleSharesNameWithImportDeclarationInsideIt.ts]
module Z.M {
export function bar() {
return "";
}
}
module A.M {
import M = Z.M;
export function bar() {
}
M.bar(); // Should call Z.M.bar
}

//// [moduleSharesNameWithImportDeclarationInsideIt.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (_M) {
var M = Z.M;
function bar() {
}
_M.bar = bar;
M.bar(); // Should call Z.M.bar
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt.ts ===
module Z.M {
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => string

return "";
}
}
module A.M {
>A : typeof A
>M : typeof A.M

import M = Z.M;
>M : typeof M
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => void
}
M.bar(); // Should call Z.M.bar
>M.bar() : string
>M.bar : () => string
>M : typeof M
>bar : () => string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [moduleSharesNameWithImportDeclarationInsideIt2.ts]
module Z.M {
export function bar() {
return "";
}
}
module A.M {
export import M = Z.M;
export function bar() {
}
M.bar(); // Should call Z.M.bar
}

//// [moduleSharesNameWithImportDeclarationInsideIt2.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (M) {
M.M = Z.M;
function bar() {
}
M.bar = bar;
M.M.bar(); // Should call Z.M.bar
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt2.ts ===
module Z.M {
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => string

return "";
}
}
module A.M {
>A : typeof A
>M : typeof A.M

export import M = Z.M;
>M : typeof M
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => void
}
M.bar(); // Should call Z.M.bar
>M.bar() : string
>M.bar : () => string
>M : typeof M
>bar : () => string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts(10,12): error TS2300: Duplicate identifier 'M'.
tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts(11,12): error TS2300: Duplicate identifier 'M'.


==== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts (2 errors) ====
module Z {
export module M {
export function bar() {
return "";
}
}
export interface I { }
}
module A.M {
import M = Z.M;
~
!!! error TS2300: Duplicate identifier 'M'.
import M = Z.I;
~
!!! error TS2300: Duplicate identifier 'M'.

export function bar() {
}
M.bar(); // Should call Z.M.bar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [moduleSharesNameWithImportDeclarationInsideIt3.ts]
module Z {
export module M {
export function bar() {
return "";
}
}
export interface I { }
}
module A.M {
import M = Z.M;
import M = Z.I;

export function bar() {
}
M.bar(); // Should call Z.M.bar
}

//// [moduleSharesNameWithImportDeclarationInsideIt3.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (_M) {
var M = Z.M;
function bar() {
}
_M.bar = bar;
M.bar(); // Should call Z.M.bar
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [moduleSharesNameWithImportDeclarationInsideIt4.ts]
module Z.M {
export function bar() {
return "";
}
}
module A.M {
interface M { }
import M = Z.M;
export function bar() {
}
M.bar(); // Should call Z.M.bar
}

//// [moduleSharesNameWithImportDeclarationInsideIt4.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (_M) {
var M = Z.M;
function bar() {
}
_M.bar = bar;
M.bar(); // Should call Z.M.bar
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt4.ts ===
module Z.M {
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => string

return "";
}
}
module A.M {
>A : typeof A
>M : typeof A.M

interface M { }
>M : M

import M = Z.M;
>M : typeof M
>Z : typeof Z
>M : typeof M

export function bar() {
>bar : () => void
}
M.bar(); // Should call Z.M.bar
>M.bar() : string
>M.bar : () => string
>M : typeof M
>bar : () => string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts(10,12): error TS2300: Duplicate identifier 'M'.
tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts(11,12): error TS2300: Duplicate identifier 'M'.


==== tests/cases/compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts (2 errors) ====
module Z {
export module M {
export function bar() {
return "";
}
}
export interface I { }
}
module A.M {
import M = Z.I;
~
!!! error TS2300: Duplicate identifier 'M'.
import M = Z.M;
~
!!! error TS2300: Duplicate identifier 'M'.

export function bar() {
}
M.bar(); // Should call Z.M.bar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//// [moduleSharesNameWithImportDeclarationInsideIt5.ts]
module Z {
export module M {
export function bar() {
return "";
}
}
export interface I { }
}
module A.M {
import M = Z.I;
import M = Z.M;

export function bar() {
}
M.bar(); // Should call Z.M.bar
}

//// [moduleSharesNameWithImportDeclarationInsideIt5.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (M) {
function bar() {
}
M.bar = bar;
M.bar(); // Should call Z.M.bar
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [moduleSharesNameWithImportDeclarationInsideIt6.ts]
module Z.M {
export function bar() {
return "";
}
}
module A.M {
import M = Z.M;
export function bar() {
}
}

//// [moduleSharesNameWithImportDeclarationInsideIt6.js]
var Z;
(function (Z) {
var M;
(function (M) {
function bar() {
return "";
}
M.bar = bar;
})(M = Z.M || (Z.M = {}));
})(Z || (Z = {}));
var A;
(function (A) {
var M;
(function (M) {
function bar() {
}
M.bar = bar;
})(M = A.M || (A.M = {}));
})(A || (A = {}));
Loading