-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Ensure async code fix renaming can do more than one rename #27031
Conversation
src/services/utilities.ts
Outdated
@@ -1671,7 +1671,7 @@ namespace ts { | |||
} | |||
|
|||
if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone); | |||
if (callback && node) callback(node!, clone); | |||
if (callback && node && clone) callback(node!, clone); |
There was a problem hiding this comment.
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
tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerVarNameConflict.ts
Outdated
Show resolved
Hide resolved
Maybe return early if Refers to: src/services/utilities.ts:1657 in 95e5f7d. [](commit_id = 95e5f7d, deletion_comment = False) |
tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts
Outdated
Show resolved
Hide resolved
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f() { | ||
let x_2; |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleReturns2.ts
Outdated
Show resolved
Hide resolved
@@ -25,15 +25,16 @@ namespace ts.codefix { | |||
numberOfAssignmentsOriginal: number; | |||
} | |||
|
|||
interface SymbolAndIdentifier { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, modulo suggestions
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 itfoo_1
, even if another variable has also been renamed tofoo_1
. This PR stores the original names of variables during the rename operation so that the numbering can be done correctly.