Improve “Add missing await” fix-all#32922
Merged
andrewbranch merged 3 commits intoAug 20, 2019
Merged
Conversation
88d35f8 to
92a8466
Compare
orta
approved these changes
Aug 16, 2019
| !variableName || | ||
| !isInsideAwaitableBody(declaration.initializer)) { | ||
| isCompleteFix = false; | ||
| continue; |
Contributor
There was a problem hiding this comment.
wow, this is quite the if statement
RyanCavanaugh
approved these changes
Aug 16, 2019
c9a9e8f to
1242019
Compare
timsuchanek
pushed a commit
to timsuchanek/TypeScript
that referenced
this pull request
Sep 11, 2019
* Improve codeFixAll for add missing await * Improve add missing await for initializers and fix-all * Fix when only one side of a binary expression can have its initializer fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I saw @mjbvz’s tweet showing a screen cap of turning on checking for an existing JS file where a Promise value had been misused multiple times throughout the file, and doing the fix-all to add missing awaits. The result was an
awaitadded at every use site of the Promise, when it could have been added at the initializer. Someone even pointed out that the resulting code had unnecessarily manyawaits in it.The original codefix operated under the assumption that if a symbol from a variable declaration is referenced more than once, we shouldn’t change its initializer, to avoid a situation where something like
would turn into
However, the enabling of checking for existing JavaScript shows a great example of why a Promise might be referenced many times, but wrongly every time, in such a way that the initializer can be awaited.
This PR fixes that example, along with a couple other scenarios where we should have been offering a fix for a variable initializer but weren’t.