Skip to content

Fix crash when binding jsdoc-style inner namepaths#25106

Merged
sandersn merged 4 commits into
masterfrom
fix-crash-when-binding-inner-namepaths
Jun 21, 2018
Merged

Fix crash when binding jsdoc-style inner namepaths#25106
sandersn merged 4 commits into
masterfrom
fix-crash-when-binding-inner-namepaths

Conversation

@sandersn
Copy link
Copy Markdown
Member

getNameOfDeclaration actually doesn't handle all declarations, only those that produce names that could be reasonably used as an identifier. Until now, getDeclarationIdentifier assumed that getNameOfDeclaration always returned a name. This caused crashes whenever we tried to get the name of something like a Constructor.

Fixes #25104

sandersn added 2 commits June 20, 2018 13:39
getNameOfDeclaration actually doesn't handle all declarations, only
those that produce names that could be reasonably used as an identifier.
Until now, getDeclarationIdentifier assumed that getNameOfDeclaration
always returned a name. This caused crashes whenever we tried to get the
name of something like a Constructor.
@sandersn sandersn requested review from a user and sheetalkamat June 20, 2018 20:49
Comment thread src/compiler/utilities.ts
@@ -4847,7 +4847,7 @@ namespace ts {

function getDeclarationIdentifier(node: Declaration | Expression): Identifier | undefined {
const name = getNameOfDeclaration(node);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fix getNameOfDeclaration as well to return nullable type? i do not know where else our assumptions are wrong, and this seems like a good time as any to fix them once and for all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try. It's used a lot of places without checking, but many of these follow a similar error-reporting pattern that might be supportable with a non-nullable overload or something.

sandersn added 2 commits June 21, 2018 09:33
This requires all callers to handle it, which turns out now to be too
disruptive.
Comment thread src/compiler/checker.ts
}

function isIdentifierThatStartsWithUnderScore(node: Node) {
function isIdentifierThatStartsWithUnderscore(node: Node) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also eliminated the now-redundant parameterNameStartsWithUnderscore and fixed the capitalisation of isIdentifierThatStartsWithUnderscore.

@sandersn sandersn merged commit 43d0794 into master Jun 21, 2018
@sandersn sandersn deleted the fix-crash-when-binding-inner-namepaths branch June 21, 2018 17:01
Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@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.

2 participants