Skip to content

Commit 50a3c61

Browse files
committed
add related error span for default exports
1 parent e13fd0c commit 50a3c61

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/compiler/binder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ namespace ts {
410410
forEach(symbol.declarations, declaration => {
411411
file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(declaration) || declaration, message, getDisplayName(declaration)));
412412
});
413-
file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(node) || node, message, getDisplayName(node)));
413+
const declarationName = getNameOfDeclaration(node) || node;
414+
const diag = createDiagnosticForNode(declarationName, message, getDisplayName(node))
415+
file.bindDiagnostics.push(
416+
isDefaultExport ? addRelatedInfo( diag, createDiagnosticForNode(declarationName, Diagnostics.This_export_conflicts_with_the_first)) : diag
417+
);
414418

415419
symbol = createSymbol(SymbolFlags.None, name);
416420
}

src/compiler/checker.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,6 @@ namespace ts {
708708
}
709709
}
710710

711-
function addRelatedInfo(diagnostic: Diagnostic, ...relatedInformation: DiagnosticRelatedInformation[]) {
712-
if (!diagnostic.relatedInformation) {
713-
diagnostic.relatedInformation = [];
714-
}
715-
diagnostic.relatedInformation.push(...relatedInformation);
716-
return diagnostic;
717-
}
718-
719711
function error(location: Node | undefined, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic {
720712
const diagnostic = location
721713
? createDiagnosticForNode(location, message, arg0, arg1, arg2, arg3)

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,10 @@
24012401
"category": "Error",
24022402
"code": 2728
24032403
},
2404+
"This export conflicts with the first.": {
2405+
"category": "Error",
2406+
"code": 2729
2407+
},
24042408

24052409
"Import declaration '{0}' is using private name '{1}'.": {
24062410
"category": "Error",

src/compiler/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8106,4 +8106,12 @@ namespace ts {
81068106

81078107
return findBestPatternMatch(patterns, _ => _, candidate);
81088108
}
8109+
8110+
export function addRelatedInfo<T extends Diagnostic>(diagnostic: T, ...relatedInformation: DiagnosticRelatedInformation[]): T {
8111+
if (!diagnostic.relatedInformation) {
8112+
diagnostic.relatedInformation = [];
8113+
}
8114+
diagnostic.relatedInformation.push(...relatedInformation);
8115+
return diagnostic;
8116+
}
81098117
}

0 commit comments

Comments
 (0)