Skip to content

Commit 157a9b0

Browse files
author
Andy Hanson
committed
Properly determine whether an augmentation is a ValueModule or NamespaceModule
1 parent 5c71de1 commit 157a9b0

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

src/compiler/binder.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ namespace ts {
15091509
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
15101510
}
15111511
if (isExternalModuleAugmentation(node)) {
1512-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
1512+
declareModuleSymbol(node);
15131513
}
15141514
else {
15151515
let pattern: Pattern | undefined;
@@ -1531,12 +1531,8 @@ namespace ts {
15311531
}
15321532
}
15331533
else {
1534-
const state = getModuleInstanceState(node);
1535-
if (state === ModuleInstanceState.NonInstantiated) {
1536-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
1537-
}
1538-
else {
1539-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
1534+
const state = declareModuleSymbol(node);
1535+
if (state !== ModuleInstanceState.NonInstantiated) {
15401536
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
15411537
// if module was already merged with some function, class or non-const enum
15421538
// treat is a non-const-enum-only
@@ -1557,6 +1553,15 @@ namespace ts {
15571553
}
15581554
}
15591555

1556+
function declareModuleSymbol(node: ModuleDeclaration): ModuleInstanceState {
1557+
const state = getModuleInstanceState(node);
1558+
const instantiated = state !== ModuleInstanceState.NonInstantiated;
1559+
declareSymbolAndAddToSymbolTable(node,
1560+
instantiated ? SymbolFlags.ValueModule : SymbolFlags.NamespaceModule,
1561+
instantiated ? SymbolFlags.ValueModuleExcludes : SymbolFlags.NamespaceModuleExcludes);
1562+
return state;
1563+
}
1564+
15601565
function bindFunctionOrConstructorType(node: SignatureDeclaration): void {
15611566
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
15621567
// to the one we would get for: { <...>(...): T }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2300: Duplicate identifier '"lib"'.
2+
/node_modules/lib/index.d.ts(1,13): error TS2300: Duplicate identifier '"lib"'.
3+
/node_modules/lib/index.d.ts(2,19): error TS2300: Duplicate identifier '"lib"'.
4+
5+
6+
==== /node_modules/lib/index.d.ts (2 errors) ====
7+
declare var lib: () => void;
8+
~~~
9+
!!! error TS2300: Duplicate identifier '"lib"'.
10+
declare namespace lib {}
11+
~~~
12+
!!! error TS2300: Duplicate identifier '"lib"'.
13+
export = lib;
14+
15+
==== /node_modules/@types/lib-extender/index.d.ts (1 errors) ====
16+
import * as lib from "lib";
17+
declare module "lib" {
18+
~~~~~
19+
!!! error TS2300: Duplicate identifier '"lib"'.
20+
export function fn(): void;
21+
}
22+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @Filename: /node_modules/lib/index.d.ts
2+
declare var lib: () => void;
3+
declare namespace lib {}
4+
export = lib;
5+
6+
// @Filename: /node_modules/@types/lib-extender/index.d.ts
7+
import * as lib from "lib";
8+
declare module "lib" {
9+
export function fn(): void;
10+
}

0 commit comments

Comments
 (0)