From e2c16962f3308c852918edcb125b118aa0f37160 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 17:38:51 -0700 Subject: [PATCH 01/22] Added tests. --- .../modules/defaultExportsCannotMerge01.ts | 31 +++++++++++++++++++ .../modules/defaultExportsCannotMerge02.ts | 19 ++++++++++++ .../modules/defaultExportsCannotMerge03.ts | 16 ++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts new file mode 100644 index 0000000000000..7caa9caf57412 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts @@ -0,0 +1,31 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default function Decl() { + return 0; +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; + +Entity.x; +Entity.y; \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts new file mode 100644 index 0000000000000..84172248e9384 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts @@ -0,0 +1,19 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class foo { + +} + +export default function bar() { + +} + +var x = 10; +export default x; + +// @filename: m2.ts +import Entity from "m1" + +Entity(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts new file mode 100644 index 0000000000000..1e9c8dabc1373 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts @@ -0,0 +1,16 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default function foo() { + +} + +export default function bar() { + +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); \ No newline at end of file From 17593bf444f7a5b7843e71b02798008dd578c7b5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 17:51:11 -0700 Subject: [PATCH 02/22] Accepted baselines. --- .../defaultExportsCannotMerge01.errors.txt | 43 ++++++++++++++++ .../reference/defaultExportsCannotMerge01.js | 49 +++++++++++++++++++ .../defaultExportsCannotMerge02.errors.txt | 31 ++++++++++++ .../reference/defaultExportsCannotMerge02.js | 35 +++++++++++++ .../defaultExportsCannotMerge03.errors.txt | 22 +++++++++ .../reference/defaultExportsCannotMerge03.js | 27 ++++++++++ 6 files changed, 207 insertions(+) create mode 100644 tests/baselines/reference/defaultExportsCannotMerge01.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge01.js create mode 100644 tests/baselines/reference/defaultExportsCannotMerge02.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge02.js create mode 100644 tests/baselines/reference/defaultExportsCannotMerge03.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge03.js diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt new file mode 100644 index 0000000000000..6eece36e07796 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -0,0 +1,43 @@ +tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. +tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does not exist on type '() => number'. + + +==== tests/cases/conformance/es6/modules/m1.ts (0 errors) ==== + + export default function Decl() { + return 0; + } + + export interface Decl { + p1: number; + p2: number; + } + + export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + + var x: Entity; + ~~~~~~ +!!! error TS2304: Cannot find name 'Entity'. + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + + Entity.x; + ~ +!!! error TS2339: Property 'x' does not exist on type '() => number'. + Entity.y; + ~ +!!! error TS2339: Property 'y' does not exist on type '() => number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.js b/tests/baselines/reference/defaultExportsCannotMerge01.js new file mode 100644 index 0000000000000..3e0a61d54d406 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts] //// + +//// [m1.ts] + +export default function Decl() { + return 0; +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; + +Entity.x; +Entity.y; + +//// [m1.js] +function Decl() { + return 0; +} +exports.default = Decl; +var Decl; +(function (Decl) { + Decl.x = 10; + Decl.y = 20; +})(Decl = exports.Decl || (exports.Decl = {})); +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +m1_1.default.x; +m1_1.default.y; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt new file mode 100644 index 0000000000000..7b49afe1a4e35 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2300: Duplicate identifier 'bar'. +tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2300: Duplicate identifier 'default'. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class foo { + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. + + } + + export default function bar() { + ~~~ +!!! error TS2300: Duplicate identifier 'bar'. + + } + + var x = 10; + export default x; + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. + +==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/defaultExportsCannotMerge02.js new file mode 100644 index 0000000000000..54d4e284c71fa --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts] //// + +//// [m1.ts] + +export default class foo { + +} + +export default function bar() { + +} + +var x = 10; +export default x; + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +var foo = (function () { + function foo() { + } + return foo; +})(); +exports.default = foo; +function bar() { +} +exports.default = bar; +var x = 10; +exports.default = x; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt new file mode 100644 index 0000000000000..51220ecfae262 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default function foo() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + + export default function bar() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + +==== tests/cases/conformance/es6/modules/m2.ts (0 errors) ==== + import Entity from "m1" + + Entity(); \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.js b/tests/baselines/reference/defaultExportsCannotMerge03.js new file mode 100644 index 0000000000000..cf9003a97c857 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts] //// + +//// [m1.ts] + +export default function foo() { + +} + +export default function bar() { + +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +function foo() { +} +exports.default = foo; +function bar() { +} +exports.default = bar; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); From b403da3ea22aecd722d4225b5618e24710e0ce98 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 17:51:50 -0700 Subject: [PATCH 03/22] Removed baselines Ryan forgot to remove. --- .../reference/tsxAttributeResolution9.symbols | 47 ------------------ .../reference/tsxAttributeResolution9.types | 49 ------------------- 2 files changed, 96 deletions(-) delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.symbols delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.types diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols deleted file mode 100644 index 081482d5d47a4..0000000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.symbols +++ /dev/null @@ -1,47 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : Symbol(JSX, Decl(react.d.ts, 0, 0)) - - interface Element { } ->Element : Symbol(Element, Decl(react.d.ts, 1, 20)) - - interface IntrinsicElements { ->IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22)) - } - interface ElementAttributesProperty { ->ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2)) - - props; ->props : Symbol(props, Decl(react.d.ts, 5, 38)) - } -} - -interface Props { ->Props : Symbol(Props, Decl(react.d.ts, 8, 1)) - - foo: string; ->foo : Symbol(foo, Decl(react.d.ts, 10, 17)) -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) - - render() { ->render : Symbol(render, Decl(file.tsx, 0, 26)) - } - - props: { foo: string; } ->props : Symbol(props, Decl(file.tsx, 2, 3)) ->foo : Symbol(foo, Decl(file.tsx, 4, 10)) -} - -; // ok ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - -; // should be an error ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types deleted file mode 100644 index 1b2c6d423896a..0000000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : any - - interface Element { } ->Element : Element - - interface IntrinsicElements { ->IntrinsicElements : IntrinsicElements - } - interface ElementAttributesProperty { ->ElementAttributesProperty : ElementAttributesProperty - - props; ->props : any - } -} - -interface Props { ->Props : Props - - foo: string; ->foo : string -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : MyComponent - - render() { ->render : () => void - } - - props: { foo: string; } ->props : { foo: string; } ->foo : string -} - -; // ok -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - -; // should be an error -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - From 3e2928926ecfa92e9b0f9d256b1e045a0bae2f38 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 18:04:05 -0700 Subject: [PATCH 04/22] Minor cleanup. --- src/compiler/checker.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8bafa7a38fff..3536152ee353c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10661,9 +10661,6 @@ namespace ts { return; } - // Exports should be checked only if enclosing module contains both exported and non exported declarations. - // In case if all declarations are non-exported check is unnecessary. - // if localSymbol is defined on node then node itself is exported - check is required let symbol = node.localSymbol; if (!symbol) { @@ -10683,9 +10680,9 @@ namespace ts { // we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace // to denote disjoint declarationSpaces (without making new enum type). - let exportedDeclarationSpaces: SymbolFlags = 0; - let nonExportedDeclarationSpaces: SymbolFlags = 0; - forEach(symbol.declarations, d => { + let exportedDeclarationSpaces = SymbolFlags.None; + let nonExportedDeclarationSpaces = SymbolFlags.None; + for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { exportedDeclarationSpaces |= declarationSpaces; @@ -10693,17 +10690,17 @@ namespace ts { else { nonExportedDeclarationSpaces |= declarationSpaces; } - }); + } let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; if (commonDeclarationSpace) { // declaration spaces for exported and non-exported declarations intersect - forEach(symbol.declarations, d => { + for (let d of symbol.declarations) { if (getDeclarationSpaces(d) & commonDeclarationSpace) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } - }); + } } function getDeclarationSpaces(d: Declaration): SymbolFlags { From 89398e640dda9eeebe79a2e78751b10eb49c1dfd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 12:09:10 -0700 Subject: [PATCH 05/22] Added single quotes around the declaration name in an error. --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a0a95d47c8c53..c17a49484b86f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -293,7 +293,7 @@ namespace ts { Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, Duplicate_function_implementation: { code: 2393, category: DiagnosticCategory.Error, key: "Duplicate function implementation." }, Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." }, - Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." }, + Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." }, Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." }, Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." }, Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index acf4e74ae9fc6..d01084c1bc8d0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1161,7 +1161,7 @@ "category": "Error", "code": 2394 }, - "Individual declarations in merged declaration {0} must be all exported or all local.": { + "Individual declarations in merged declaration '{0}' must be all exported or all local.": { "category": "Error", "code": 2395 }, From d0fb339666c2f2c615987f40da8f55c8265dc38a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 12:09:49 -0700 Subject: [PATCH 06/22] Accepted baselines. --- .../duplicateSymbolsExportMatching.errors.txt | 68 +++++++++---------- .../reference/innerModExport2.errors.txt | 8 +-- tests/baselines/reference/multivar.errors.txt | 8 +-- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt index df4f8f13c31d8..85dd29b78a3d6 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration F must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged -tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration F must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration D must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration D must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. ==== tests/cases/compiler/duplicateSymbolsExportMatching.ts (18 errors) ==== @@ -44,28 +44,28 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module N2 { interface I { } ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface I { } // error ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface E { } ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. interface E { } // error ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. } // Should report error only once for instantiated module module M { module inst { ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } export module inst { // one error ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } } @@ -74,41 +74,41 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module M2 { var v: string; ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. export var v: string; // one error (visibility) ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. var w: number; ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. export var w: string; // two errors (visibility and type mismatch) ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. } module M { module F { ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. ~ !!! error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged var t; } export function F() { } // Only one error for duplicate identifier (don't consider visibility) ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. } module M { class C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. module C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. export module C { // Two visibility errors (one for the clodule symbol, and one for the merged container symbol) ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. var t; } } @@ -116,7 +116,7 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind // Top level interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. export interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. \ No newline at end of file +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. \ No newline at end of file diff --git a/tests/baselines/reference/innerModExport2.errors.txt b/tests/baselines/reference/innerModExport2.errors.txt index 52a9d01c99739..f9568bb45a4e1 100644 --- a/tests/baselines/reference/innerModExport2.errors.txt +++ b/tests/baselines/reference/innerModExport2.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/innerModExport2.ts(5,5): error TS2304: Cannot find name 'module'. tests/cases/compiler/innerModExport2.ts(5,12): error TS1005: ';' expected. -tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. -tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExportFunc' does not exist on type 'typeof Outer'. @@ -18,7 +18,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport var non_export_var = 0; export var export_var = 1; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. function NonExportFunc() { return 0; } @@ -26,7 +26,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport } var export_var: number; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. export var outer_var_export = 0; export function outerFuncExport() { return 0; } diff --git a/tests/baselines/reference/multivar.errors.txt b/tests/baselines/reference/multivar.errors.txt index 931e61de5aef7..44061b9d74c77 100644 --- a/tests/baselines/reference/multivar.errors.txt +++ b/tests/baselines/reference/multivar.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. -tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. +tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. ==== tests/cases/compiler/multivar.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in export var a, b2: number = 10, b; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. var m1; var a2, b22: number = 10, b222; var m3; @@ -28,7 +28,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in declare var d1, d2; var b2; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. declare var v1; } From 90f3153eac46609f6fe5711f9201eca273548711 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:43:15 -0700 Subject: [PATCH 07/22] Renamed tests. --- ...defaultExportsCannotMerge02.ts => multipleDefaultExports01.ts} | 0 ...defaultExportsCannotMerge03.ts => multipleDefaultExports02.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/conformance/es6/modules/{defaultExportsCannotMerge02.ts => multipleDefaultExports01.ts} (100%) rename tests/cases/conformance/es6/modules/{defaultExportsCannotMerge03.ts => multipleDefaultExports02.ts} (100%) diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts b/tests/cases/conformance/es6/modules/multipleDefaultExports01.ts similarity index 100% rename from tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts rename to tests/cases/conformance/es6/modules/multipleDefaultExports01.ts diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts b/tests/cases/conformance/es6/modules/multipleDefaultExports02.ts similarity index 100% rename from tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts rename to tests/cases/conformance/es6/modules/multipleDefaultExports02.ts From a38dec0cdf7d90638e97ef0b0de3b5fa40805c9e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:44:07 -0700 Subject: [PATCH 08/22] Renamed/accepted baselines. --- ...otMerge02.errors.txt => multipleDefaultExports01.errors.txt} | 0 ...faultExportsCannotMerge02.js => multipleDefaultExports01.js} | 2 +- ...otMerge03.errors.txt => multipleDefaultExports02.errors.txt} | 0 ...faultExportsCannotMerge03.js => multipleDefaultExports02.js} | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/baselines/reference/{defaultExportsCannotMerge02.errors.txt => multipleDefaultExports01.errors.txt} (100%) rename tests/baselines/reference/{defaultExportsCannotMerge02.js => multipleDefaultExports01.js} (79%) rename tests/baselines/reference/{defaultExportsCannotMerge03.errors.txt => multipleDefaultExports02.errors.txt} (100%) rename tests/baselines/reference/{defaultExportsCannotMerge03.js => multipleDefaultExports02.js} (75%) diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt similarity index 100% rename from tests/baselines/reference/defaultExportsCannotMerge02.errors.txt rename to tests/baselines/reference/multipleDefaultExports01.errors.txt diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/multipleDefaultExports01.js similarity index 79% rename from tests/baselines/reference/defaultExportsCannotMerge02.js rename to tests/baselines/reference/multipleDefaultExports01.js index 54d4e284c71fa..8faf33388c6a6 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge02.js +++ b/tests/baselines/reference/multipleDefaultExports01.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts] //// +//// [tests/cases/conformance/es6/modules/multipleDefaultExports01.ts] //// //// [m1.ts] diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/multipleDefaultExports02.errors.txt similarity index 100% rename from tests/baselines/reference/defaultExportsCannotMerge03.errors.txt rename to tests/baselines/reference/multipleDefaultExports02.errors.txt diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.js b/tests/baselines/reference/multipleDefaultExports02.js similarity index 75% rename from tests/baselines/reference/defaultExportsCannotMerge03.js rename to tests/baselines/reference/multipleDefaultExports02.js index cf9003a97c857..faec7c9d2b4e9 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge03.js +++ b/tests/baselines/reference/multipleDefaultExports02.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts] //// +//// [tests/cases/conformance/es6/modules/multipleDefaultExports02.ts] //// //// [m1.ts] From f631a201403e3a6928fac4d0072f8651d5dc8601 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:12:50 -0700 Subject: [PATCH 09/22] Added another test. --- .../modules/defaultExportsCannotMerge02.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts new file mode 100644 index 0000000000000..f7312ec2e6615 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class Decl { +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 \ No newline at end of file From 7e464458f8035aba05666f639df6fb5adc6572a2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:13:16 -0700 Subject: [PATCH 10/22] Accepted baselines. --- .../defaultExportsCannotMerge02.errors.txt | 38 +++++++++++++++++ .../reference/defaultExportsCannotMerge02.js | 41 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/baselines/reference/defaultExportsCannotMerge02.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge02.js diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt new file mode 100644 index 0000000000000..52e00547a8923 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (0 errors) ==== + + export default class Decl { + } + + export interface Decl { + p1: number; + p2: number; + } + + export namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/defaultExportsCannotMerge02.js new file mode 100644 index 0000000000000..72a8e3c5f1d41 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; From 8d5d73eb9191ffa25875eecabf3d922e63d484eb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:22:14 -0700 Subject: [PATCH 11/22] Take default export spaces into account when checking merged declarations. --- src/compiler/checker.ts | 21 +++++++++++++++---- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3536152ee353c..e09df418b2aab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10682,10 +10682,18 @@ namespace ts { // to denote disjoint declarationSpaces (without making new enum type). let exportedDeclarationSpaces = SymbolFlags.None; let nonExportedDeclarationSpaces = SymbolFlags.None; + let defaultExportedDeclarationFlags = SymbolFlags.None; for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); - if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { - exportedDeclarationSpaces |= declarationSpaces; + let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default); + + if (effectiveDeclarationFlags & NodeFlags.Export) { + if (effectiveDeclarationFlags & NodeFlags.Default) { + defaultExportedDeclarationFlags |= declarationSpaces; + } + else { + exportedDeclarationSpaces |= declarationSpaces; + } } else { nonExportedDeclarationSpaces |= declarationSpaces; @@ -10693,11 +10701,16 @@ namespace ts { } let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpaceForDefault = defaultExportedDeclarationFlags & (exportedDeclarationSpaces | nonExportedDeclarationSpaces); - if (commonDeclarationSpace) { + if (commonDeclarationSpace || commonDeclarationSpaceForDefault) { // declaration spaces for exported and non-exported declarations intersect for (let d of symbol.declarations) { - if (getDeclarationSpaces(d) & commonDeclarationSpace) { + let declarationSpaces = getDeclarationSpaces(d); + if (declarationSpaces & commonDeclarationSpaceForDefault) { + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration, declarationNameToString(d.name)); + } + else if (declarationSpaces & commonDeclarationSpace) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c17a49484b86f..c1afb8c9706ba 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -424,6 +424,7 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, + Merged_declaration_0_cannot_include_a_default_export_declaration: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d01084c1bc8d0..fa792639556e7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1685,6 +1685,10 @@ "category": "Error", "code": 2650 }, + "Merged declaration '{0}' cannot include a default export declaration.": { + "category": "Error", + "code": 2651 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 From be44bc651c45d31c080323b14b5f3ed77118b1b1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:22:56 -0700 Subject: [PATCH 12/22] Accepted baselines. --- .../reference/defaultExportsCannotMerge01.errors.txt | 8 +++++++- .../reference/defaultExportsCannotMerge02.errors.txt | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt index 6eece36e07796..4b1ad1424bd5e 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -1,12 +1,16 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does not exist on type '() => number'. -==== tests/cases/conformance/es6/modules/m1.ts (0 errors) ==== +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== export default function Decl() { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. return 0; } @@ -16,6 +20,8 @@ tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does } export namespace Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. export var x = 10; export var y = 20; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt index 52e00547a8923..e1abe6068fef0 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -1,15 +1,21 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. -==== tests/cases/conformance/es6/modules/m1.ts (0 errors) ==== +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== export default class Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. } export interface Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. p1: number; p2: number; } From 18e36b898c3904985a117cab8533241fd6bad4c7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:47:15 -0700 Subject: [PATCH 13/22] Add suggestion to error message. --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e09df418b2aab..a51f07512727b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10708,7 +10708,7 @@ namespace ts { for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); if (declarationSpaces & commonDeclarationSpaceForDefault) { - error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration, declarationNameToString(d.name)); + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration, declarationNameToString(d.name)); } else if (declarationSpaces & commonDeclarationSpace) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c1afb8c9706ba..03026ee0547e6 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -424,7 +424,7 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, - Merged_declaration_0_cannot_include_a_default_export_declaration: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration." }, + Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0};' declaration." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fa792639556e7..bb6430a1344f0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1685,7 +1685,7 @@ "category": "Error", "code": 2650 }, - "Merged declaration '{0}' cannot include a default export declaration.": { + "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0};' declaration.": { "category": "Error", "code": 2651 }, From beff65191f6e3a8538c4d81878a7c2454be59b4f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Jul 2015 17:47:53 -0700 Subject: [PATCH 14/22] Accepted baselines. --- .../reference/defaultExportsCannotMerge01.errors.txt | 8 ++++---- .../reference/defaultExportsCannotMerge02.errors.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt index 4b1ad1424bd5e..ee0f549aa97d4 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. -tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. @@ -10,7 +10,7 @@ tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does export default function Decl() { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. return 0; } @@ -21,7 +21,7 @@ tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does export namespace Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. export var x = 10; export var y = 20; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt index e1abe6068fef0..fbf7076eb5176 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. -tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. @@ -10,12 +10,12 @@ tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' doe export default class Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. } export interface Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. p1: number; p2: number; } From 0f828ca91b75b79c391aeda9c5f494d70db5937f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 22 Jul 2015 12:05:30 -0700 Subject: [PATCH 15/22] Accepted baselines. --- tests/baselines/reference/defaultExportsCannotMerge01.js | 1 + tests/baselines/reference/defaultExportsCannotMerge02.js | 1 + tests/baselines/reference/multipleDefaultExports01.js | 3 +++ tests/baselines/reference/multipleDefaultExports02.js | 2 ++ 4 files changed, 7 insertions(+) diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.js b/tests/baselines/reference/defaultExportsCannotMerge01.js index 3e0a61d54d406..99b8ecab1d325 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge01.js +++ b/tests/baselines/reference/defaultExportsCannotMerge01.js @@ -34,6 +34,7 @@ Entity.y; function Decl() { return 0; } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Decl; var Decl; (function (Decl) { diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/defaultExportsCannotMerge02.js index 72a8e3c5f1d41..e3897395c74fd 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge02.js +++ b/tests/baselines/reference/defaultExportsCannotMerge02.js @@ -31,6 +31,7 @@ var Decl = (function () { } return Decl; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Decl; //// [m2.js] var m1_1 = require("m1"); diff --git a/tests/baselines/reference/multipleDefaultExports01.js b/tests/baselines/reference/multipleDefaultExports01.js index 8faf33388c6a6..e633cf69f550d 100644 --- a/tests/baselines/reference/multipleDefaultExports01.js +++ b/tests/baselines/reference/multipleDefaultExports01.js @@ -24,11 +24,14 @@ var foo = (function () { } return foo; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = foo; function bar() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = bar; var x = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = x; //// [m2.js] var m1_1 = require("m1"); diff --git a/tests/baselines/reference/multipleDefaultExports02.js b/tests/baselines/reference/multipleDefaultExports02.js index faec7c9d2b4e9..3d1b84ff6a630 100644 --- a/tests/baselines/reference/multipleDefaultExports02.js +++ b/tests/baselines/reference/multipleDefaultExports02.js @@ -18,9 +18,11 @@ Entity(); //// [m1.js] function foo() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = foo; function bar() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = bar; //// [m2.js] var m1_1 = require("m1"); From cf801efb20ab0b1045350280febc297177fbfc65 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 10:12:52 -0700 Subject: [PATCH 16/22] Added test. --- .../modules/defaultExportsCannotMerge03.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts new file mode 100644 index 0000000000000..dad8431812b03 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class Decl { +} + +interface Decl { + p1: number; + p2: number; +} + +namespace Decl { + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 \ No newline at end of file From b84e4071a543254a0c6980489eb48dc834497f00 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 10:23:05 -0700 Subject: [PATCH 17/22] Accepted baselines. --- .../defaultExportsCannotMerge03.errors.txt | 47 +++++++++++++++++++ .../reference/defaultExportsCannotMerge03.js | 42 +++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/baselines/reference/defaultExportsCannotMerge03.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge03.js diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt new file mode 100644 index 0000000000000..5babb6ac743c9 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -0,0 +1,47 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. + } + + interface Decl { + ~~~~ +!!! error TS2518: Only an ambient class can be merged with an interface. + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. + p1: number; + p2: number; + } + + namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.js b/tests/baselines/reference/defaultExportsCannotMerge03.js new file mode 100644 index 0000000000000..05e7de9412087 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +interface Decl { + p1: number; + p2: number; +} + +namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; From bad5919fa88246556e8380aecee51c9937226800 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 11:14:13 -0700 Subject: [PATCH 18/22] Addressed CR feedback. --- src/compiler/checker.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 206d263522a25..cad42974a337c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4363,11 +4363,11 @@ namespace ts { return getInferredType(context, i); } } - return t; + return t; }; mapper.context = context; - return mapper; + return mapper; } function identityMapper(type: Type): Type { @@ -10870,14 +10870,14 @@ namespace ts { // to denote disjoint declarationSpaces (without making new enum type). let exportedDeclarationSpaces = SymbolFlags.None; let nonExportedDeclarationSpaces = SymbolFlags.None; - let defaultExportedDeclarationFlags = SymbolFlags.None; + let defaultExportedDeclarationSpaces = SymbolFlags.None; for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default); if (effectiveDeclarationFlags & NodeFlags.Export) { if (effectiveDeclarationFlags & NodeFlags.Default) { - defaultExportedDeclarationFlags |= declarationSpaces; + defaultExportedDeclarationSpaces |= declarationSpaces; } else { exportedDeclarationSpaces |= declarationSpaces; @@ -10888,17 +10888,22 @@ namespace ts { } } - let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; - let commonDeclarationSpaceForDefault = defaultExportedDeclarationFlags & (exportedDeclarationSpaces | nonExportedDeclarationSpaces); + // Spaces for anyting not declared a 'default export'. + let nonDefaultExportedDeclarationsSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; + + let commonDeclarationSpaceForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpaceForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationsSpaces; - if (commonDeclarationSpace || commonDeclarationSpaceForDefault) { + if (commonDeclarationSpaceForExportsAndLocals || commonDeclarationSpaceForDefaultAndNonDefault) { // declaration spaces for exported and non-exported declarations intersect for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); - if (declarationSpaces & commonDeclarationSpaceForDefault) { + + // Only error on the declarations that conributed to the intersecting spaces. + if (declarationSpaces & commonDeclarationSpaceForDefaultAndNonDefault) { error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration, declarationNameToString(d.name)); } - else if (declarationSpaces & commonDeclarationSpace) { + else if (declarationSpaces & commonDeclarationSpaceForExportsAndLocals) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } } From a8f0491d62af9fadcb6c5ac4f6319e992febfe29 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 11:17:23 -0700 Subject: [PATCH 19/22] space -> spaces --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cad42974a337c..1b8cd56e12cd4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10889,21 +10889,21 @@ namespace ts { } // Spaces for anyting not declared a 'default export'. - let nonDefaultExportedDeclarationsSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; + let nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; - let commonDeclarationSpaceForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; - let commonDeclarationSpaceForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationsSpaces; + let commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces; - if (commonDeclarationSpaceForExportsAndLocals || commonDeclarationSpaceForDefaultAndNonDefault) { + if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) { // declaration spaces for exported and non-exported declarations intersect for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); // Only error on the declarations that conributed to the intersecting spaces. - if (declarationSpaces & commonDeclarationSpaceForDefaultAndNonDefault) { + if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) { error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration, declarationNameToString(d.name)); } - else if (declarationSpaces & commonDeclarationSpaceForExportsAndLocals) { + else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } } From 92902011ce09d0059d04cf7e6a7cd804b46aa895 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 11:45:10 -0700 Subject: [PATCH 20/22] Added a test. --- .../es6/modules/defaultExportsCannotMerge04.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts new file mode 100644 index 0000000000000..ab72d10504a12 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts @@ -0,0 +1,15 @@ +// @module: commonjs +// @target: ES5 + +export default function Foo() { +} + +namespace Foo { + export var x; +} + +interface Foo { +} + +export interface Foo { +} \ No newline at end of file From 157235f5dab788663a78a28f1279859ea3cd69a6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 11:45:22 -0700 Subject: [PATCH 21/22] Fixed test message. --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b8cd56e12cd4..32b67123a680e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10901,7 +10901,7 @@ namespace ts { // Only error on the declarations that conributed to the intersecting spaces. if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) { - error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration, declarationNameToString(d.name)); + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, declarationNameToString(d.name)); } else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f6f50c3ba8e41..b7526a1dd435b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -425,7 +425,7 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, - Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0};' declaration." }, + Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fecfbb7dcab5c..f28ad54b58e80 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1689,7 +1689,7 @@ "category": "Error", "code": 2650 }, - "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0};' declaration.": { + "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": { "category": "Error", "code": 2651 }, From 28ce0a1a84eb5d46d05269e2cb0377eb91d2a755 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Jul 2015 11:51:53 -0700 Subject: [PATCH 22/22] Accepted baselines. --- .../defaultExportsCannotMerge01.errors.txt | 8 +++--- .../defaultExportsCannotMerge02.errors.txt | 8 +++--- .../defaultExportsCannotMerge03.errors.txt | 8 +++--- .../defaultExportsCannotMerge04.errors.txt | 28 +++++++++++++++++++ .../reference/defaultExportsCannotMerge04.js | 23 +++++++++++++++ 5 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/defaultExportsCannotMerge04.errors.txt create mode 100644 tests/baselines/reference/defaultExportsCannotMerge04.js diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt index ee0f549aa97d4..6e3955b4ef86a 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. -tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. @@ -10,7 +10,7 @@ tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does export default function Decl() { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. return 0; } @@ -21,7 +21,7 @@ tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does export namespace Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. export var x = 10; export var y = 20; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt index fbf7076eb5176..ef4ecdccfc31d 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. -tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. @@ -10,12 +10,12 @@ tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' doe export default class Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. } export interface Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. p1: number; p2: number; } diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt index 5babb6ac743c9..219b59a56336c 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. @@ -11,14 +11,14 @@ tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' doe export default class Decl { ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. } interface Decl { ~~~~ !!! error TS2518: Only an ambient class can be merged with an interface. ~~~~ -!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl;' declaration. +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. p1: number; p2: number; } diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt new file mode 100644 index 0000000000000..ee36491e0c767 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(2,25): error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(5,11): error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(9,11): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(12,18): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + + +==== tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts (4 errors) ==== + + export default function Foo() { + ~~~ +!!! error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + } + + namespace Foo { + ~~~ +!!! error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + export var x; + } + + interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } + + export interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.js b/tests/baselines/reference/defaultExportsCannotMerge04.js new file mode 100644 index 0000000000000..eb1122a819743 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.js @@ -0,0 +1,23 @@ +//// [defaultExportsCannotMerge04.ts] + +export default function Foo() { +} + +namespace Foo { + export var x; +} + +interface Foo { +} + +export interface Foo { +} + +//// [defaultExportsCannotMerge04.js] +function Foo() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Foo; +var Foo; +(function (Foo) { +})(Foo || (Foo = {}));