Skip to content

fix(48540): Extract to typedef from (invalid) type with comments in JS file causes assertion failure #48545

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 4 commits into from
Apr 5, 2022

Conversation

MQuy
Copy link
Contributor

@MQuy MQuy commented Apr 3, 2022

Fixes #48540

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Apr 3, 2022
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.

Maybe @rbuckton or @sandersn have ideas on what to do here.

Comment on lines 258 to 266
switch (node.kind) {
case SyntaxKind.UnionType:
members = (node as UnionTypeNode).types;
break;

case SyntaxKind.TypeLiteral:
members = (node as TypeLiteralNode).members;
break;
}
Copy link
Member

@DanielRosenwasser DanielRosenwasser Apr 4, 2022

Choose a reason for hiding this comment

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

I think this fix is too limited - we really have to remove the comments deeply from every type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I make changes to support removing comments from node's descendants, I am not sure which other types need to be removed or is there a better way to do it?

@@ -229,6 +229,8 @@ namespace ts.refactor {
function doTypedefChange(changes: textChanges.ChangeTracker, file: SourceFile, name: string, info: ExtractInfo) {
const { firstStatement, selection, typeParameters } = info;

removeCommentsFromTypeNode(selection);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would setting EmitFlags.NoComments | EmitFlags.NoNestedComments work instead?

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 definitely better 👍

@DanielRosenwasser DanielRosenwasser dismissed rbuckton’s stale review April 5, 2022 23:50

Feedback should be addressed.

@DanielRosenwasser DanielRosenwasser merged commit 50a5bc8 into microsoft:main Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract to typedef from (invalid) type with comments in JS file causes assertion failure
4 participants