Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,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;
Expand All @@ -1534,12 +1534,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
Expand All @@ -1560,6 +1556,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 }
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ namespace ts {
}
recordMergedSymbol(target, source);
}
else if (target.flags & SymbolFlags.NamespaceModule) {
error(source.valueDeclaration.name, Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target));
}
else {
const message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable
? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,10 @@
"category": "Error",
"code": 2609
},
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",
"code": 2649
},
"Cannot emit namespaced JSX elements in React": {
"category": "Error",
"code": 2650
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/augmentExportEquals7.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity.


==== /node_modules/lib/index.d.ts (0 errors) ====
declare var lib: () => void;
declare namespace lib {}
export = lib;

==== /node_modules/@types/lib-extender/index.d.ts (1 errors) ====
import * as lib from "lib";
declare module "lib" {
~~~~~
!!! error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity.
export function fn(): void;
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export { };

declare global {
>global : any
>global : typeof global

var x: number;
>x : number
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/compiler/augmentExportEquals7.ts
Original file line number Diff line number Diff line change
@@ -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;
}