Skip to content

Ensure async code fix renaming can do more than one rename #27031

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 13 commits into from
Sep 14, 2018

Conversation

uniqueiniquity
Copy link
Contributor

Fixes #26376.
Currently, if we are performing an async code fix, we inspect each variable to see if it will collide with any other variables used after the code has been changed. However, for a conflicting variable foo, we will always rename it foo_1, even if another variable has also been renamed to foo_1. This PR stores the original names of variables during the rename operation so that the numbering can be done correctly.

@uniqueiniquity uniqueiniquity added this to the TypeScript 3.1 milestone Sep 11, 2018
@uniqueiniquity uniqueiniquity requested review from amcasey and a user September 11, 2018 18:31
@@ -1671,7 +1671,7 @@ namespace ts {
}

if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
if (callback && node) callback(node!, clone);
if (callback && node && clone) callback(node!, clone);
Copy link

Choose a reason for hiding this comment

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

Looks like this wasn't detected due to a compiler bug. #27050

@amcasey
Copy link
Member

amcasey commented Sep 13, 2018

export function getSynthesizedDeepCloneWithRenames<T extends Node | undefined>(node: T, includeTrivia = true, renameMap?: Map<Identifier>, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T {

Maybe return early if node is undefined?


Refers to: src/services/utilities.ts:1657 in 95e5f7d. [](commit_id = 95e5f7d, deletion_comment = False)

// ==ASYNC FUNCTION::Convert to async function==

async function f() {
let x_2;
Copy link
Member

Choose a reason for hiding this comment

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

x_2 [](start = 5, length = 3)

Nit: It's kind of weird that the catch parameter got "1".

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's just because we rename from left to right in the pre-fixed form. Not sure if that's worth fixing at this point.

@@ -25,15 +25,16 @@ namespace ts.codefix {
numberOfAssignmentsOriginal: number;
}

interface SymbolAndIdentifier {
Copy link
Member

Choose a reason for hiding this comment

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

As we discussed offline, this might be more readable if the original names were tracked in a frequency table on the side.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

LGTM, modulo suggestions

@uniqueiniquity uniqueiniquity merged commit bce34ad into microsoft:master Sep 14, 2018
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.

Async / Await Refactoring - Catch Block Parameter are not checked for collisions
2 participants