mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
fix(43939): forbid converting getters to async/await (#43944)
This commit is contained in:
parent
97f5c62956
commit
e0d7703cf3
@ -54,7 +54,7 @@ namespace ts.codefix {
|
||||
functionToConvert = tokenAtPosition.parent.initializer;
|
||||
}
|
||||
else {
|
||||
functionToConvert = tryCast(getContainingFunction(getTokenAtPosition(sourceFile, position)), isFunctionLikeDeclaration);
|
||||
functionToConvert = tryCast(getContainingFunction(getTokenAtPosition(sourceFile, position)), canBeConvertedToAsync);
|
||||
}
|
||||
|
||||
if (!functionToConvert) {
|
||||
|
||||
@ -57,7 +57,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (isFunctionLikeDeclaration(node)) {
|
||||
if (canBeConvertedToAsync(node)) {
|
||||
addConvertToAsyncFunctionDiagnostics(node, checker, diags);
|
||||
}
|
||||
node.forEachChild(check);
|
||||
@ -213,4 +213,16 @@ namespace ts {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function canBeConvertedToAsync(node: Node): node is FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1698,6 +1698,14 @@ function [#|f|](x?: number): Promise<void> | number {
|
||||
if (x) return x;
|
||||
return fetch('').then(() => {});
|
||||
}
|
||||
`);
|
||||
|
||||
_testConvertToAsyncFunctionFailed("convertToAsyncFunction__NoSuggestionInGetters", `
|
||||
class Foo {
|
||||
get [#|m|](): Promise<number> {
|
||||
return Promise.resolve(1).then(n => n);
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user