Skip to content

Commit ec2eac5

Browse files
committed
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.
1 parent 9e8031c commit ec2eac5

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ namespace ts {
131131
}
132132

133133
if (symbolFlags & SymbolFlags.Value &&
134-
(!symbol.valueDeclaration || symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration)) {
134+
(!symbol.valueDeclaration ||
135+
(symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && node.kind !== SyntaxKind.ModuleDeclaration))) {
135136
// other kinds of value declarations take precedence over modules
136137
symbol.valueDeclaration = node;
137138
}

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ namespace ts {
294294
}
295295
target.flags |= source.flags;
296296
if (source.valueDeclaration &&
297-
(!target.valueDeclaration || target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration)) {
297+
(!target.valueDeclaration ||
298+
(target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) {
298299
// other kinds of value declarations take precedence over modules
299300
target.valueDeclaration = source.valueDeclaration;
300301
}

0 commit comments

Comments
 (0)