Skip to content

Fix crash in extract type and generate get/set refactors #52803

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 2 commits into from
Feb 16, 2023
Merged

Conversation

rbuckton
Copy link
Contributor

This PR fixes two crashes in refactors related to an attempt to refactor in the presence of a grammar error. This also removes FunctionType from the list of nodes that can have illegal modifiers, since isStartOfFunctionOrConstructorType already guards against a function type having modifiers.

Fixes #52751

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Feb 16, 2023
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

LGTM besides the compile error.

@@ -265,6 +266,7 @@ import {
isFunctionLike,
isFunctionLikeDeclaration,
isFunctionLikeOrClassStaticBlockDeclaration,
isFunctionTypeNode,
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be unused.

Comment on lines +266 to +268
(assignment as Mutable<PropertyAssignment>).modifiers = undefined;
(assignment as Mutable<PropertyAssignment>).questionToken = undefined;
(assignment as Mutable<PropertyAssignment>).exclamationToken = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Is this because update doesn't necessarily create a new node, but the result should still omit error recovery children?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, update only conditionally replaces the node.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Not a huge fan that formatting now has to be resilient against every weird grammar recovery node like this. I wish we could just get rid of these nodes from the tree itself - but this seems like a reasonable work-around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'Extract type' from property signature with erroneous initializer causes assertion failure
4 participants