-
Notifications
You must be signed in to change notification settings - Fork 12.8k
add related error span for default exports #25396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
50a3c61
to
656fbc0
Compare
@@ -7,6 +7,7 @@ tests/cases/conformance/es6/modules/m1.ts(10,16): error TS2528: A module cannot | |||
export default class foo { | |||
~~~ | |||
!!! error TS2528: A module cannot have multiple default exports. | |||
!!! related TS2730 tests/cases/conformance/es6/modules/m1.ts:1:22: This export conflicts with the first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is because function bind first with bindEachFunctionsFirst
,
seems expect behavior
src/compiler/binder.ts
Outdated
const declarationName = getNameOfDeclaration(node) || node; | ||
const diag = createDiagnosticForNode(declarationName, message, getDisplayName(node)) | ||
file.bindDiagnostics.push( | ||
multipleDefaultExports ? addRelatedInfo(diag, createDiagnosticForNode(declarationName, Diagnostics.This_export_conflicts_with_the_first)) : diag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the related info and the original diagnostic have the same span here - seems wrong. The related span should be the first declaration, not this diagnostic's declaration.
src/compiler/diagnosticMessages.json
Outdated
@@ -2409,6 +2409,10 @@ | |||
"category": "Error", | |||
"code": 2729 | |||
}, | |||
"This export conflicts with the first.": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the original issue said the message should be This export conflicts with the first.
- but that would be if we issued only one diagnostic (on the first default export
), and then just added a bunch of related spans to it. In the case of what we're doing here (which I think is OK), we're keeping all the diagnostics, but adding related spans on them. In that case, I think the message should be The first export default is here.
for the non-first ones and Another export default is here
(for the first) ... and here.
(for the rest) for the first one.
So you get an error like
!!! error TS2528: A module cannot have multiple default exports.
!!! related TS2730 <first decl location> : The first export default is here
and
!!! error TS2528: A module cannot have multiple default exports.
!!! related TS2730 <other decl location 1> : Another export default is here
!!! related TS2730 <other decl location 2> : and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @DanielRosenwasser since you had the original issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
😂 have we already get this message?
656fbc0
to
2ffa94c
Compare
760bcff
to
c261ca2
Compare
@weswigham can u please review and merge |
@Kingwl can you add a test with >2 default exports so we can see a test with the |
@weswigham |
⬆️ |
Fixes #25032