Add "A module cannot have multiple default exports." message for multiple "default" exports

This commit is contained in:
Martin Vseticka
2015-10-02 21:54:32 +02:00
parent 543cce5e43
commit 69ff6f5090
13 changed files with 154 additions and 7 deletions

View File

@@ -185,8 +185,9 @@ namespace ts {
function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
Debug.assert(!hasDynamicName(node));
let isDefaultExport = node.flags & NodeFlags.Default;
// The exported symbol for an export default function/class node is always named "default"
let name = node.flags & NodeFlags.Default && parent ? "default" : getDeclarationName(node);
let name = isDefaultExport && parent ? "default" : getDeclarationName(node);
let symbol: Symbol;
if (name !== undefined) {
@@ -227,6 +228,13 @@ namespace ts {
let message = symbol.flags & SymbolFlags.BlockScopedVariable
? Diagnostics.Cannot_redeclare_block_scoped_variable_0
: Diagnostics.Duplicate_identifier_0;
forEach(symbol.declarations, declaration => {
if (declaration.flags & NodeFlags.Default) {
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
}
});
forEach(symbol.declarations, declaration => {
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
});

View File

@@ -1656,6 +1656,10 @@
"category": "Error",
"code": 2527
},
"A module cannot have multiple default exports.": {
"category": "Error",
"code": 2528
},
"JSX element attributes type '{0}' must be an object type.": {
"category": "Error",
"code": 2600