From 139f10fb441ea2e531200116f0b43c93a1a1401f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Dec 2015 14:08:50 -0800 Subject: [PATCH 1/2] test for and fix #6043 --- src/compiler/checker.ts | 3 ++- tests/baselines/reference/typeAliasExport.js | 8 ++++++++ tests/baselines/reference/typeAliasExport.symbols | 10 ++++++++++ tests/baselines/reference/typeAliasExport.types | 10 ++++++++++ tests/cases/compiler/typeAliasExport.ts | 5 +++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typeAliasExport.js create mode 100644 tests/baselines/reference/typeAliasExport.symbols create mode 100644 tests/baselines/reference/typeAliasExport.types create mode 100644 tests/cases/compiler/typeAliasExport.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ee73756e57..1073e8eda9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14310,8 +14310,9 @@ namespace ts { continue; } const { declarations, flags } = exports[id]; + let declarationLength = declarations.length; // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. (TS Exceptions: namespaces, function overloads, enums, and interfaces) - if (!(flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) && declarations.length > 1) { + if (!(flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) && (flags & SymbolFlags.TypeAlias ? declarationLength-- : true) && declarationLength > 1) { const exportedDeclarations: Declaration[] = filter(declarations, isNotOverload); if (exportedDeclarations.length > 1) { for (const declaration of exportedDeclarations) { diff --git a/tests/baselines/reference/typeAliasExport.js b/tests/baselines/reference/typeAliasExport.js new file mode 100644 index 00000000000..fa864f571ea --- /dev/null +++ b/tests/baselines/reference/typeAliasExport.js @@ -0,0 +1,8 @@ +//// [typeAliasExport.ts] +declare module "a" { + export default 0 + export var a; + export type a = typeof a; +} + +//// [typeAliasExport.js] diff --git a/tests/baselines/reference/typeAliasExport.symbols b/tests/baselines/reference/typeAliasExport.symbols new file mode 100644 index 00000000000..1f580b03011 --- /dev/null +++ b/tests/baselines/reference/typeAliasExport.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/typeAliasExport.ts === +declare module "a" { + export default 0 + export var a; +>a : Symbol(a, Decl(typeAliasExport.ts, 2, 12), Decl(typeAliasExport.ts, 2, 15)) + + export type a = typeof a; +>a : Symbol(a, Decl(typeAliasExport.ts, 2, 12), Decl(typeAliasExport.ts, 2, 15)) +>a : Symbol(a, Decl(typeAliasExport.ts, 2, 12), Decl(typeAliasExport.ts, 2, 15)) +} diff --git a/tests/baselines/reference/typeAliasExport.types b/tests/baselines/reference/typeAliasExport.types new file mode 100644 index 00000000000..afa26073061 --- /dev/null +++ b/tests/baselines/reference/typeAliasExport.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/typeAliasExport.ts === +declare module "a" { + export default 0 + export var a; +>a : any + + export type a = typeof a; +>a : any +>a : any +} diff --git a/tests/cases/compiler/typeAliasExport.ts b/tests/cases/compiler/typeAliasExport.ts new file mode 100644 index 00000000000..706b731f0ab --- /dev/null +++ b/tests/cases/compiler/typeAliasExport.ts @@ -0,0 +1,5 @@ +declare module "a" { + export default 0 + export var a; + export type a = typeof a; +} \ No newline at end of file From ef6c137f9e73d29833fb443a0ff604a44a6162a1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Dec 2015 19:55:08 -0800 Subject: [PATCH 2/2] add feedback from PR --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1073e8eda9b..666d983bd52 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14310,9 +14310,8 @@ namespace ts { continue; } const { declarations, flags } = exports[id]; - let declarationLength = declarations.length; // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. (TS Exceptions: namespaces, function overloads, enums, and interfaces) - if (!(flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) && (flags & SymbolFlags.TypeAlias ? declarationLength-- : true) && declarationLength > 1) { + if (!(flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) && (flags & SymbolFlags.TypeAlias ? declarations.length - 1 : declarations.length) > 1) { const exportedDeclarations: Declaration[] = filter(declarations, isNotOverload); if (exportedDeclarations.length > 1) { for (const declaration of exportedDeclarations) {