Fix issue #1503 with modules and imports sharing a name
This commit is contained in:
parent
60f3b9b317
commit
ab33a65d30
|
@ -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)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -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 = {}));
|
|
@ -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
|
||||
}
|
|
@ -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 = {}));
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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 = {}));
|
|
@ -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 = {}));
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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 = {}));
|
|
@ -0,0 +1,11 @@
|
|||
module Z.M {
|
||||
export function bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
module A.M {
|
||||
import M = Z.M;
|
||||
export function bar() {
|
||||
}
|
||||
M.bar(); // Should call Z.M.bar
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
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
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
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
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
}
|
Loading…
Reference in a new issue