fix duplicate async modifier codefix

This commit is contained in:
kingwl
2019-09-14 02:22:59 +08:00
parent a4bacf3bfa
commit 93a250b9a6
2 changed files with 12 additions and 5 deletions

View File

@@ -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<true>();
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) {

View File

@@ -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();
}`,
});