diff --git a/src/services/codefixes/fixAwaitInSyncFunction.ts b/src/services/codefixes/fixAwaitInSyncFunction.ts index e5b3a24dbea..55dd4bd0556 100644 --- a/src/services/codefixes/fixAwaitInSyncFunction.ts +++ b/src/services/codefixes/fixAwaitInSyncFunction.ts @@ -15,11 +15,14 @@ namespace ts.codefix { return [createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers)]; }, fixIds: [fixId], - getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => { - const nodes = getNodes(diag.file, diag.start); - if (!nodes) return; - doChange(changes, context.sourceFile, nodes); - }), + getAllCodeActions: context => { + const seen = createMap(); + return codeFixAll(context, errorCodes, (changes, diag) => { + const nodes = getNodes(diag.file, diag.start); + if (!nodes || !addToSeen(seen, getNodeId(nodes.insertBefore))) return; + doChange(changes, context.sourceFile, nodes); + }); + }, }); function getReturnType(expr: FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction) { diff --git a/tests/cases/fourslash/codeFixAwaitInSyncFunction_all.ts b/tests/cases/fourslash/codeFixAwaitInSyncFunction_all.ts index 4b5f7aea0a3..fadb5f30ca8 100644 --- a/tests/cases/fourslash/codeFixAwaitInSyncFunction_all.ts +++ b/tests/cases/fourslash/codeFixAwaitInSyncFunction_all.ts @@ -2,10 +2,12 @@ ////function f() { //// await Promise.resolve(); +//// await Promise.resolve(); ////} //// ////const g = () => { //// await f(); +//// await f(); ////} verify.codeFixAll({ @@ -14,9 +16,11 @@ verify.codeFixAll({ newFileContent: `async function f() { await Promise.resolve(); + await Promise.resolve(); } const g = async () => { await f(); + await f(); }`, });