mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
augment check for colliding declaration spaces
This commit is contained in:
@@ -4941,28 +4941,34 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
// run the check only for the first declaration in the list
|
||||
if (getDeclarationOfKind(symbol, node.kind) !== node) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
|
||||
// to denote disjoint declarationSpaces (without making new enum type).
|
||||
var declarationSpaces: SymbolFlags = 0;
|
||||
var hasExport: boolean;
|
||||
|
||||
var declarations = symbol.declarations;
|
||||
for (var i = 0, len = declarations.length; i < len; ++i) {
|
||||
var currentDeclarationSpaces = getDeclarationSpaces(declarations[i]);
|
||||
var currentDeclarationHasExport = (declarations[i].flags & NodeFlags.Export) !== 0;
|
||||
if (declarationSpaces & currentDeclarationSpaces) {
|
||||
if (hasExport !== undefined) {
|
||||
if (hasExport !== currentDeclarationHasExport) {
|
||||
error(declarations[i].name, Diagnostics.All_declarations_of_merged_declaration_0_must_be_exported_or_not_exported, symbolToString(symbol));
|
||||
}
|
||||
}
|
||||
var exportedDeclarationSpaces: SymbolFlags = 0;
|
||||
var nonExportedDeclarationSpaces: SymbolFlags = 0;
|
||||
forEach(symbol.declarations, d => {
|
||||
var declarationSpaces = getDeclarationSpaces(d);
|
||||
if (d.flags & NodeFlags.Export) {
|
||||
exportedDeclarationSpaces |= declarationSpaces;
|
||||
}
|
||||
hasExport = hasExport || currentDeclarationHasExport;
|
||||
declarationSpaces |= currentDeclarationSpaces;
|
||||
else {
|
||||
nonExportedDeclarationSpaces |= declarationSpaces;
|
||||
}
|
||||
});
|
||||
|
||||
var commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces
|
||||
|
||||
if (commonDeclarationSpace) {
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getDeclarationSpaces(d: Declaration): SymbolFlags {
|
||||
@@ -4977,8 +4983,10 @@ module ts {
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
var result: SymbolFlags = 0;
|
||||
var target = resolveImport(getSymbolOfNode(d));
|
||||
return target.flags & SymbolFlags.Export;
|
||||
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); } )
|
||||
return result;
|
||||
default:
|
||||
return SymbolFlags.ExportValue;
|
||||
}
|
||||
@@ -5000,10 +5008,10 @@ module ts {
|
||||
checkFunctionOrConstructorSymbol(localSymbol);
|
||||
}
|
||||
|
||||
if (symbol !== localSymbol) {
|
||||
// here we'll check exported side of the symbol
|
||||
Debug.assert(symbol.parent);
|
||||
if (symbol.parent) {
|
||||
// run check once for the first declaration
|
||||
if (getDeclarationOfKind(symbol, node.kind) === node) {
|
||||
// run check on export symbol to check that modifiers agree across all exported declarations
|
||||
checkFunctionOrConstructorSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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." },
|
||||
All_declarations_of_merged_declaration_0_must_be_exported_or_not_exported: { code: 2192, category: DiagnosticCategory.Error, key: "All declarations of merged declaration '{0}' must be exported or not exported." },
|
||||
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." },
|
||||
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." },
|
||||
|
||||
@@ -540,7 +540,7 @@
|
||||
"category": "Error",
|
||||
"code": 2190
|
||||
},
|
||||
"All declarations of merged declaration '{0}' must be exported or not exported.": {
|
||||
"Individual declarations in a merged declaration {0} must be all exported or all local.": {
|
||||
"category": "Error",
|
||||
"code": 2192
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user