Properly determine whether an augmentation is a ValueModule or NamespaceModule

This commit is contained in:
Andy Hanson 2016-12-05 08:43:16 -08:00
parent 5c71de103a
commit 157a9b02fc
3 changed files with 44 additions and 7 deletions

View file

@ -1509,7 +1509,7 @@ namespace ts {
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
}
if (isExternalModuleAugmentation(node)) {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
declareModuleSymbol(node);
}
else {
let pattern: Pattern | undefined;
@ -1531,12 +1531,8 @@ namespace ts {
}
}
else {
const state = getModuleInstanceState(node);
if (state === ModuleInstanceState.NonInstantiated) {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
}
else {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
const state = declareModuleSymbol(node);
if (state !== ModuleInstanceState.NonInstantiated) {
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
@ -1557,6 +1553,15 @@ namespace ts {
}
}
function declareModuleSymbol(node: ModuleDeclaration): ModuleInstanceState {
const state = getModuleInstanceState(node);
const instantiated = state !== ModuleInstanceState.NonInstantiated;
declareSymbolAndAddToSymbolTable(node,
instantiated ? SymbolFlags.ValueModule : SymbolFlags.NamespaceModule,
instantiated ? SymbolFlags.ValueModuleExcludes : SymbolFlags.NamespaceModuleExcludes);
return state;
}
function bindFunctionOrConstructorType(node: SignatureDeclaration): void {
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
// to the one we would get for: { <...>(...): T }

View file

@ -0,0 +1,22 @@
/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2300: Duplicate identifier '"lib"'.
/node_modules/lib/index.d.ts(1,13): error TS2300: Duplicate identifier '"lib"'.
/node_modules/lib/index.d.ts(2,19): error TS2300: Duplicate identifier '"lib"'.
==== /node_modules/lib/index.d.ts (2 errors) ====
declare var lib: () => void;
~~~
!!! error TS2300: Duplicate identifier '"lib"'.
declare namespace lib {}
~~~
!!! error TS2300: Duplicate identifier '"lib"'.
export = lib;
==== /node_modules/@types/lib-extender/index.d.ts (1 errors) ====
import * as lib from "lib";
declare module "lib" {
~~~~~
!!! error TS2300: Duplicate identifier '"lib"'.
export function fn(): void;
}

View file

@ -0,0 +1,10 @@
// @Filename: /node_modules/lib/index.d.ts
declare var lib: () => void;
declare namespace lib {}
export = lib;
// @Filename: /node_modules/@types/lib-extender/index.d.ts
import * as lib from "lib";
declare module "lib" {
export function fn(): void;
}