use getEffectiveDeclarationFlags to get Export flag

This commit is contained in:
Vladimir Matveev 2014-07-25 11:15:19 -07:00
parent 81da2cb7b9
commit 42df260eb5
8 changed files with 57 additions and 50 deletions

View File

@ -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 = <FunctionDeclaration>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));
}
});
}

View File

@ -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." },

View File

@ -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
},

View File

@ -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 {
~

View File

@ -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.
!!! Individual declarations in merged declaration D must be all exported or all local.

View File

@ -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]

View File

@ -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;
}

View File

@ -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}
}