Skip to content

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

Merged
merged 10 commits into from
Mar 12, 2019

Conversation

Kingwl
Copy link
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
@@ -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.
Copy link
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
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
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.

@@ -2409,6 +2409,10 @@
"category": "Error",
"code": 2729
},
"This export conflicts with the first.": {
Copy link
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
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
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
Contributor

mhegazy commented Jul 18, 2018

@weswigham can u please review and merge

@weswigham
Copy link
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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants