Skip to content

Commit 042da56

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR: add comment
1 parent 75de324 commit 042da56

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/compiler/binder.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,24 @@ namespace ts {
337337
? Diagnostics.Cannot_redeclare_block_scoped_variable_0
338338
: Diagnostics.Duplicate_identifier_0;
339339

340-
// If the current node has NodeFlags.Default (e.g. if the node is class declaration or function declaration)
341-
// and there is already another default export (i.e. symbol.declarations is not empty), we need to report such error
340+
// If the current node is a default export of some sort, then check if
341+
// there are any other default exports that we need to error on.
342+
// We'll know whether we have other default exports depending on if `symbol` already has a declaration list set.
342343
if (isDefaultExport && symbol.declarations) {
343344
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
344345
}
345-
346-
forEach(symbol.declarations, declaration => {
347-
// Error on multiple export default in the following case:
348-
// 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
349-
// 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
350-
if ((declaration.flags & NodeFlags.Default) ||
351-
(declaration.kind === SyntaxKind.ExportAssignment && !(<ExportAssignment>node).isExportEquals)) {
352-
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
353-
}
354-
});
346+
else {
347+
// This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration.
348+
forEach(symbol.declarations, declaration => {
349+
// Error on multiple export default in the following case:
350+
// 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
351+
// 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
352+
if ((declaration.flags & NodeFlags.Default) ||
353+
(declaration.kind === SyntaxKind.ExportAssignment && !(<ExportAssignment>node).isExportEquals)) {
354+
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
355+
}
356+
});
357+
}
355358

356359
forEach(symbol.declarations, declaration => {
357360
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));

0 commit comments

Comments
 (0)