Skip to content

Commit eb0fc89

Browse files
committed
add related error span for default exports
1 parent 7a082d4 commit eb0fc89

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
@@ -710,14 +710,6 @@ namespace ts {
710710
}
711711
}
712712

713-
function addRelatedInfo(diagnostic: Diagnostic, ...relatedInformation: DiagnosticRelatedInformation[]) {
714-
if (!diagnostic.relatedInformation) {
715-
diagnostic.relatedInformation = [];
716-
}
717-
diagnostic.relatedInformation.push(...relatedInformation);
718-
return diagnostic;
719-
}
720-
721713
function error(location: Node | undefined, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic {
722714
const diagnostic = location
723715
? 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
@@ -2409,6 +2409,10 @@
24092409
"category": "Error",
24102410
"code": 2729
24112411
},
2412+
"This export conflicts with the first.": {
2413+
"category": "Error",
2414+
"code": 2730
2415+
},
24122416

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

src/compiler/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8108,4 +8108,12 @@ namespace ts {
81088108
}
81098109

81108110
export type Mutable<T extends object> = { -readonly [K in keyof T]: T[K] };
8111+
8112+
export function addRelatedInfo<T extends Diagnostic>(diagnostic: T, ...relatedInformation: DiagnosticRelatedInformation[]): T {
8113+
if (!diagnostic.relatedInformation) {
8114+
diagnostic.relatedInformation = [];
8115+
}
8116+
diagnostic.relatedInformation.push(...relatedInformation);
8117+
return diagnostic;
8118+
}
81118119
}

0 commit comments

Comments
 (0)