-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Related error spans on "used before declared" error messages #25359
Conversation
ae1ccd0
to
282e682
Compare
@weswigham added the harness support for related spans in #25328. you will need to merge from master. |
src/compiler/checker.ts
Outdated
@@ -1592,18 +1592,34 @@ namespace ts { | |||
if (declaration === undefined) return Debug.fail("Declaration to checkResolvedBlockScopedVariable is undefined"); | |||
|
|||
if (!(declaration.flags & NodeFlags.Ambient) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) { | |||
let err; |
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.
nit. i would call this variable diagnosticMessage
.
src/compiler/checker.ts
Outdated
} | ||
} | ||
} | ||
|
||
function placeRelatedSpanOnLaterDeclaration(declarationName: string, declarationLocation: Declaration, diagnostic: Diagnostic) { |
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.
consider inlining this function, it is simple enough that it does not benefit from the indirection.
@DanielRosenwasser I think we could have a second message if the declaration is in a separate file (as I believe can happen for scripts), like |
@weswigham maybe; I'd rather get this in first, especially since modules are going to be the more common scenario. |
Ah, @DanielRosenwasser while you're undoing your harness changes, I should probably also mention that there's an |
282e682
to
f675798
Compare
diagnostic.relatedInformation = diagnostic.relatedInformation || []; | ||
diagnostic.relatedInformation.push(createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead)); | ||
Debug.assert(!diagnostic.relatedInformation); | ||
diagnostic.relatedInformation = [createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead)]; |
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.
If we're going to update this, we should probably just update it to use addRelatedInfo
. This can actually potentially stack with the related info provided by #25140, after all, since they're for the same (assignability) diagnostics.
Fixes #25003.