Skip to content

Commit 09d6cbc

Browse files
author
Orta
authored
Merge pull request microsoft#33418 from Kingwl/duplicate_async
fix duplicate async modifier codefix
2 parents 038d951 + 93a250b commit 09d6cbc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/services/codefixes/fixAwaitInSyncFunction.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ namespace ts.codefix {
1515
return [createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers)];
1616
},
1717
fixIds: [fixId],
18-
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
19-
const nodes = getNodes(diag.file, diag.start);
20-
if (!nodes) return;
21-
doChange(changes, context.sourceFile, nodes);
22-
}),
18+
getAllCodeActions: context => {
19+
const seen = createMap<true>();
20+
return codeFixAll(context, errorCodes, (changes, diag) => {
21+
const nodes = getNodes(diag.file, diag.start);
22+
if (!nodes || !addToSeen(seen, getNodeId(nodes.insertBefore))) return;
23+
doChange(changes, context.sourceFile, nodes);
24+
});
25+
},
2326
});
2427

2528
function getReturnType(expr: FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction) {

tests/cases/fourslash/codeFixAwaitInSyncFunction_all.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
////function f() {
44
//// await Promise.resolve();
5+
//// await Promise.resolve();
56
////}
67
////
78
////const g = () => {
89
//// await f();
10+
//// await f();
911
////}
1012

1113
verify.codeFixAll({
@@ -14,9 +16,11 @@ verify.codeFixAll({
1416
newFileContent:
1517
`async function f() {
1618
await Promise.resolve();
19+
await Promise.resolve();
1720
}
1821
1922
const g = async () => {
2023
await f();
24+
await f();
2125
}`,
2226
});

0 commit comments

Comments
 (0)