Skip to content

Commit 9774cd5

Browse files
mjbvzAndy
authored andcommitted
Fix await code action crashes when await is not in a function (microsoft#22623)
Fixes microsoft#22614
1 parent b9f6056 commit 9774cd5

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/services/codefixes/fixAwaitInSyncFunction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ namespace ts.codefix {
3636
function getNodes(sourceFile: SourceFile, start: number): { insertBefore: Node, returnType: TypeNode | undefined } | undefined {
3737
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
3838
const containingFunction = getContainingFunction(token);
39+
if (!containingFunction) {
40+
return;
41+
}
42+
3943
let insertBefore: Node | undefined;
4044
switch (containingFunction.kind) {
4145
case SyntaxKind.MethodDeclaration:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////await a
4+
5+
verify.not.codeFixAvailable();

0 commit comments

Comments
 (0)