Skip to content

add related error span for default exports#25396

Merged
weswigham merged 10 commits intomicrosoft:masterfrom
Kingwl:relatedExportDefault
Mar 12, 2019
Merged

add related error span for default exports#25396
weswigham merged 10 commits intomicrosoft:masterfrom
Kingwl:relatedExportDefault

Conversation

@Kingwl
Copy link
Copy Markdown
Contributor

@Kingwl Kingwl commented Jul 3, 2018

Fixes #25032

  • update baseline

@Kingwl Kingwl force-pushed the relatedExportDefault branch from 50a3c61 to 656fbc0 Compare July 4, 2018 06:04
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.
Copy link
Copy Markdown
Contributor Author

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

@Kingwl Kingwl changed the title [WIP] add related error span for default exports add related error span for default exports Jul 4, 2018
Comment thread 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
Copy link
Copy Markdown
Member

@weswigham weswigham Jul 5, 2018

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.

Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Error",
"code": 2729
},
"This export conflicts with the first.": {
Copy link
Copy Markdown
Member

@weswigham weswigham Jul 5, 2018

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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?

@Kingwl Kingwl force-pushed the relatedExportDefault branch from 656fbc0 to 2ffa94c Compare July 6, 2018 09:37
@Kingwl Kingwl force-pushed the relatedExportDefault branch from 760bcff to c261ca2 Compare July 11, 2018 10:32
@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Jul 18, 2018

@weswigham can u please review and merge

@weswigham
Copy link
Copy Markdown
Member

@Kingwl can you add a test with >2 default exports so we can see a test with the and here related message? Otherwise it looks good.

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Aug 1, 2018

@weswigham and here is not work as i last comment,
binder only have a file.bindDiagnostics but not DiagnosticCollection that i can only find the existed Diagnostic with O(n)
should i add the DiagnosticCollection for that?

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Aug 29, 2018

 ⬆️

@weswigham weswigham merged commit d247675 into microsoft:master Mar 12, 2019
@Kingwl Kingwl deleted the relatedExportDefault branch March 13, 2019 02:17
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants