Skip to content

Support deleting all unused type parameters in a list, and deleting @template tag #25748

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
2 commits merged into from
Jul 27, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 18, 2018

Previously code-fix-all at function f<T, U>() {} would produce function f<>() {}. And at /** @template T,U */ function f() {} it would crash.
Incidentally fixes #24130.

@ghost ghost mentioned this pull request Jul 18, 2018
@ghost ghost force-pushed the unusedTypeParameters branch from 5577315 to 966aa80 Compare July 18, 2018 17:16
@ghost
Copy link
Author

ghost commented Jul 18, 2018

Latest commit fixes #25594

@ghost ghost requested review from amcasey and sheetalkamat July 18, 2018 20:02

const name = idText(typeParameter.name);
const { parent } = typeParameter;
if (parent.kind !== SyntaxKind.InferType && parent.typeParameters!.every(isTypeParameterUnused)) {
Copy link
Member

Choose a reason for hiding this comment

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

You dont have to iterate on all parameters here, why not just iterate over the type parameters in the current loop and report error in the end of the loop instead?

Copy link
Author

Choose a reason for hiding this comment

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

We need to know whether to report an error at each type parameter individually, or once for the whole list.
So when looking at a type parameter, we need to know whether all future type parameters are also unused. That needs at least two loops -- one to check isTypeParameterUnused for everything, and one to report errors individually if necessary. (We could cache the result of isTypeParameterUnused, but that's a simple function so probably not important to do.)

It's possible that we could calculate parent.typeParameters!.every(isTypeParameterUnused) eagerly instead of potentially once per loop, but the common case is that every type parameter is used. So in the common case, we only calculate isTypeParameterUnused once per type parameter, which is as efficient as it gets.

Copy link
Author

Choose a reason for hiding this comment

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

@sheetalkamat OK to merge?

@ghost ghost merged commit d40d549 into master Jul 27, 2018
@ghost ghost deleted the unusedTypeParameters branch July 27, 2018 18:55
@ghost ghost mentioned this pull request Jul 27, 2018
This pull request was closed.
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.

JSDoc template tag text includes "\n "
1 participant