Skip to content
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

fixUnusedIdentifier: Remove arguments corresponding to unused parameters #25011

Merged
9 commits merged into from
Jun 27, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 15, 2018

Fixes #24789

@@ -82,12 +86,16 @@ namespace ts.codefix {
},
});

function hasDeletedAncestor(deletedAncestors: ReadonlyNodeSet, node: Node): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test where the ranges are nested:

function f(a: any, unused: any) { a; }

f(1, {
    prop: f(2, [
        f(3, f(4, undefined))
    ])
});

Copy link
Contributor

Choose a reason for hiding this comment

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

or even more interesting if the first one is the nested reference:

function f(a: any, unused: any) { a; }
function g(a: any, unused: any) { a; }

g(1, {
    prop: f(2, [
        g(3, f(4, undefined))
    ])
});

Copy link
Author

Choose a reason for hiding this comment

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

After testing more, looks like the previous strategy wouldn't work because it relied on us deleting higher-leve nodes before lower-level ones. Changed this to just collect a list of deletions and do them all at the end, when we can know what all the high-level deletions are.

@ghost
Copy link
Author

ghost commented Jun 23, 2018

@mhegazy Could you re-review?

@@ -11624,6 +11633,15 @@ declare namespace ts.codefix {
}
declare namespace ts.codefix {
}
declare namespace ts.codefix {
class Deleter {
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this defined? i can not see to find it in this PR?

Copy link
Author

Choose a reason for hiding this comment

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

Bottom of fixUnusedIdentifier.ts. It's internal but those are currently being included in the API (#24966).

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks! can we move this to the change tracker instead?

if (delDestructure.length) {
return [createCodeFixAction(fixName, delDestructure, Diagnostics.Remove_destructuring, fixIdDelete, Diagnostics.Delete_all_unused_declarations)];
}
const delVar = textChanges.ChangeTracker.with(context, t => tryDeleteFullVariableStatement(t, sourceFile, startToken, /*deleted*/ undefined));
const delVar = Deleter.with(context, d => tryDeleteFullVariableStatement(sourceFile, token, d));
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do this in the change tracker instead? the change tracker will track the changes, and will only do them at the end, so we can do the filtering of deleted ranges then instead of having a special deleter object.

@ghost ghost merged commit d957b1c into master Jun 27, 2018
@ghost ghost deleted the fixUnusedParameter_unusedArguments branch June 27, 2018 16:26
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.

1 participant