From 42df260eb5f57e1662ae0217e01aee531e7d2bd6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 25 Jul 2014 11:15:19 -0700 Subject: [PATCH] use getEffectiveDeclarationFlags to get Export flag --- src/compiler/checker.ts | 39 +++++++++---------- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../reference/anonymousModules.errors.txt | 4 +- .../duplicateSymbolsExportMatching.errors.txt | 34 ++++++++-------- tests/baselines/reference/mixedExports.js | 11 ++++-- tests/baselines/reference/multivar.errors.txt | 4 +- tests/cases/compiler/mixedExports.ts | 11 ++++-- 8 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e39ad3fcbca..2ed99353dff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4793,24 +4793,21 @@ module ts { error(signatureDeclarationNode, Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature); } - function checkFunctionOrConstructorSymbol(symbol: Symbol) { - function getEffectiveFlagsForFunctionCheck(n: Node) { - var flags = n.flags; - // We want to determine if an overload is effectively ambient, which can happen if it - // is nested in an ambient context. However, do not treat members of interfaces differently - // based on whether the interface itself is in an ambient context. Interfaces should never - // be considered ambient for purposes of comparing overload attributes. - if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) { - if (!(flags & NodeFlags.Ambient)) { - // It is nested in an ambient context, which means it is automatically exported - flags |= NodeFlags.Export; - } - flags |= NodeFlags.Ambient; + function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags) { + var flags = n.flags; + if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) { + if (!(flags & NodeFlags.Ambient)) { + // It is nested in an ambient context, which means it is automatically exported + flags |= NodeFlags.Export; } - - return flags & flagsToCheck; + flags |= NodeFlags.Ambient; } + return flags & flagsToCheck; + } + + function checkFunctionOrConstructorSymbol(symbol: Symbol) { + function checkFlagAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionDeclaration, flagsToCheck: NodeFlags, someOverloadFlags: NodeFlags, allOverloadFlags: NodeFlags): void { // Error if some overloads have a flag that is not shared by all overloads. To find the // deviations, we XOR someOverloadFlags with allOverloadFlags @@ -4823,10 +4820,10 @@ module ts { // the canonical signature only if it is in the same container as the first overload var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent; var canonicalFlags = implementationSharesContainerWithFirstOverload - ? getEffectiveFlagsForFunctionCheck(implementation) - : getEffectiveFlagsForFunctionCheck(overloads[0]); + ? getEffectiveDeclarationFlags(implementation, flagsToCheck) + : getEffectiveDeclarationFlags(overloads[0], flagsToCheck); forEach(overloads, o => { - var deviation = getEffectiveFlagsForFunctionCheck(o) ^ canonicalFlags; + var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags; if (deviation & NodeFlags.Export) { error(o.name, Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported); } @@ -4854,7 +4851,7 @@ module ts { for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor) { - var currentNodeFlags = getEffectiveFlagsForFunctionCheck(node); + var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -4954,7 +4951,7 @@ module ts { var nonExportedDeclarationSpaces: SymbolFlags = 0; forEach(symbol.declarations, d => { var declarationSpaces = getDeclarationSpaces(d); - if (d.flags & NodeFlags.Export) { + if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { exportedDeclarationSpaces |= declarationSpaces; } else { @@ -4968,7 +4965,7 @@ module ts { // declaration spaces for exported and non-exported declarations intersect forEach(symbol.declarations, d => { if (getDeclarationSpaces(d) & commonDeclarationSpace) { - error(d.name, Diagnostics.Individual_declarations_in_a_merged_declaration_0_must_be_all_exported_or_all_local, identifierToString(d.name)); + error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, identifierToString(d.name)); } }); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 11809aca067..e26442355f0 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -137,7 +137,7 @@ module ts { A_signature_with_an_implementation_cannot_use_a_string_literal_type: { code: 2163, category: DiagnosticCategory.Error, key: "A signature with an implementation cannot use a string literal type." }, Interface_0_cannot_simultaneously_extend_types_1_and_2_Colon: { code: 2189, category: DiagnosticCategory.Error, key: "Interface '{0}' cannot simultaneously extend types '{1}' and '{2}':" }, Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: { code: 2190, category: DiagnosticCategory.Error, key: "Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it." }, - Individual_declarations_in_a_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2192, category: DiagnosticCategory.Error, key: "Individual declarations in a merged declaration {0} must be all exported or all local." }, + Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2192, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." }, super_cannot_be_referenced_in_constructor_arguments: { code: 2193, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." }, Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: { code: 2194, category: DiagnosticCategory.Error, key: "Return type of constructor signature must be assignable to the instance type of the class" }, Ambient_external_module_declaration_cannot_specify_relative_module_name: { code: 2196, category: DiagnosticCategory.Error, key: "Ambient external module declaration cannot specify relative module name." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d3a34d2733e..105a1fbcdb4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -540,7 +540,7 @@ "category": "Error", "code": 2190 }, - "Individual declarations in a 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": 2192 }, diff --git a/tests/baselines/reference/anonymousModules.errors.txt b/tests/baselines/reference/anonymousModules.errors.txt index 9f07d998510..b50f7591968 100644 --- a/tests/baselines/reference/anonymousModules.errors.txt +++ b/tests/baselines/reference/anonymousModules.errors.txt @@ -19,14 +19,14 @@ ~~~~~~ !!! Statement expected. ~~~ -!!! Individual declarations in a merged declaration bar must be all exported or all local. +!!! Individual declarations in merged declaration bar must be all exported or all local. } ~ !!! Declaration or statement expected. var bar = 2; ~~~ -!!! Individual declarations in a merged declaration bar must be all exported or all local. +!!! Individual declarations in merged declaration bar must be all exported or all local. module { ~ diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt index ba20d24b55c..c6d3b03e9fb 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt @@ -24,28 +24,28 @@ module N2 { interface I { } ~ -!!! Individual declarations in a merged declaration I must be all exported or all local. +!!! Individual declarations in merged declaration I must be all exported or all local. export interface I { } // error ~ -!!! Individual declarations in a merged declaration I must be all exported or all local. +!!! Individual declarations in merged declaration I must be all exported or all local. export interface E { } ~ -!!! Individual declarations in a merged declaration E must be all exported or all local. +!!! Individual declarations in merged declaration E must be all exported or all local. interface E { } // error ~ -!!! Individual declarations in a merged declaration E must be all exported or all local. +!!! 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 { ~~~~ -!!! Individual declarations in a merged declaration inst must be all exported or all local. +!!! Individual declarations in merged declaration inst must be all exported or all local. var t; } export module inst { // one error ~~~~ -!!! Individual declarations in a merged declaration inst must be all exported or all local. +!!! Individual declarations in merged declaration inst must be all exported or all local. var t; } } @@ -54,16 +54,16 @@ module M2 { var v: string; ~ -!!! Individual declarations in a merged declaration v must be all exported or all local. +!!! Individual declarations in merged declaration v must be all exported or all local. export var v: string; // one error (visibility) ~ -!!! Individual declarations in a merged declaration v must be all exported or all local. +!!! Individual declarations in merged declaration v must be all exported or all local. var w: number; ~ -!!! Individual declarations in a merged declaration w must be all exported or all local. +!!! Individual declarations in merged declaration w must be all exported or all local. export var w: string; // two errors (visibility and type mismatch) ~ -!!! Individual declarations in a merged declaration w must be all exported or all local. +!!! Individual declarations in merged declaration w must be all exported or all local. } module M { @@ -71,24 +71,24 @@ ~ !!! A module declaration cannot be located prior to a class or function with which it is merged ~ -!!! Individual declarations in a merged declaration F must be all exported or all local. +!!! Individual declarations in merged declaration F must be all exported or all local. var t; } export function F() { } // Only one error for duplicate identifier (don't consider visibility) ~ -!!! Individual declarations in a merged declaration F must be all exported or all local. +!!! Individual declarations in merged declaration F must be all exported or all local. } module M { class C { } ~ -!!! Individual declarations in a merged declaration C must be all exported or all local. +!!! Individual declarations in merged declaration C must be all exported or all local. module C { } ~ -!!! Individual declarations in a merged declaration C must be all exported or all local. +!!! 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) ~ -!!! Individual declarations in a merged declaration C must be all exported or all local. +!!! Individual declarations in merged declaration C must be all exported or all local. var t; } } @@ -96,7 +96,7 @@ // Top level interface D { } ~ -!!! Individual declarations in a merged declaration D must be all exported or all local. +!!! Individual declarations in merged declaration D must be all exported or all local. export interface D { } ~ -!!! Individual declarations in a merged declaration D must be all exported or all local. \ No newline at end of file +!!! 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/mixedExports.js b/tests/baselines/reference/mixedExports.js index eb650667e8d..1e99ad3c720 100644 --- a/tests/baselines/reference/mixedExports.js +++ b/tests/baselines/reference/mixedExports.js @@ -5,10 +5,15 @@ declare module M { function foo(); } +declare module M1 { + export interface Foo {} + interface Foo {} +} + module A { - interface X {x} - export module X {} - interface X {y} + interface X {x} + export module X {} + interface X {y} } //// [mixedExports.js] diff --git a/tests/baselines/reference/multivar.errors.txt b/tests/baselines/reference/multivar.errors.txt index 0a1496f4a92..655a5f42e6d 100644 --- a/tests/baselines/reference/multivar.errors.txt +++ b/tests/baselines/reference/multivar.errors.txt @@ -6,7 +6,7 @@ export var a, b2: number = 10, b; ~~ -!!! Individual declarations in a merged declaration b2 must be all exported or all local. +!!! Individual declarations in merged declaration b2 must be all exported or all local. var m1; var a2, b22: number = 10, b222; var m3; @@ -24,7 +24,7 @@ declare var d1, d2; var b2; ~~ -!!! Individual declarations in a merged declaration b2 must be all exported or all local. +!!! Individual declarations in merged declaration b2 must be all exported or all local. declare var v1; } diff --git a/tests/cases/compiler/mixedExports.ts b/tests/cases/compiler/mixedExports.ts index bad962c8e1e..c3ad54846a9 100644 --- a/tests/cases/compiler/mixedExports.ts +++ b/tests/cases/compiler/mixedExports.ts @@ -4,8 +4,13 @@ declare module M { function foo(); } +declare module M1 { + export interface Foo {} + interface Foo {} +} + module A { - interface X {x} - export module X {} - interface X {y} + interface X {x} + export module X {} + interface X {y} } \ No newline at end of file