From ec2eac53bf15f1729cbcc0c41b9928f53dd2e057 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Sun, 11 Oct 2015 15:33:17 -0700 Subject: [PATCH] Improved non-namespace overriding Per @ahejlsberg's suggestion, only overwrite a namespace `valueDeclaration` if the new declaration is not a namespace itself. This means that if there are multiple namespace declarations, and nothing else, `valueDeclaration` will be the first namespace declaration, not the last. --- src/compiler/binder.ts | 3 ++- src/compiler/checker.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 813a7e2cd43..57d610c931e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -131,7 +131,8 @@ namespace ts { } if (symbolFlags & SymbolFlags.Value && - (!symbol.valueDeclaration || symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration)) { + (!symbol.valueDeclaration || + (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && node.kind !== SyntaxKind.ModuleDeclaration))) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d22266d951f..6b3ddf9da32 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -294,7 +294,8 @@ namespace ts { } target.flags |= source.flags; if (source.valueDeclaration && - (!target.valueDeclaration || target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration)) { + (!target.valueDeclaration || + (target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) { // other kinds of value declarations take precedence over modules target.valueDeclaration = source.valueDeclaration; }