addMethodDeclaration codefix creates a generator function when target is child of a YieldExpression, resolves #24728
This commit is contained in:
parent
d0ae03c4cc
commit
acbda14450
|
@ -111,16 +111,18 @@ namespace ts.codefix {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMethodFromCallExpression(
|
export function createMethodFromCallExpression(
|
||||||
{ typeArguments, arguments: args }: CallExpression,
|
{ typeArguments, arguments: args, parent: parent }: CallExpression,
|
||||||
methodName: string,
|
methodName: string,
|
||||||
inJs: boolean,
|
inJs: boolean,
|
||||||
makeStatic: boolean,
|
makeStatic: boolean,
|
||||||
preferences: UserPreferences,
|
preferences: UserPreferences,
|
||||||
): MethodDeclaration {
|
): MethodDeclaration {
|
||||||
|
const asterisk = parent.kind === SyntaxKind.YieldExpression ? createToken(SyntaxKind.AsteriskToken) : undefined;
|
||||||
|
|
||||||
return createMethod(
|
return createMethod(
|
||||||
/*decorators*/ undefined,
|
/*decorators*/ undefined,
|
||||||
/*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined,
|
/*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined,
|
||||||
/*asteriskToken*/ undefined,
|
/*asteriskToken*/ asterisk,
|
||||||
methodName,
|
methodName,
|
||||||
/*questionToken*/ undefined,
|
/*questionToken*/ undefined,
|
||||||
/*typeParameters*/ inJs ? undefined : map(typeArguments, (_, i) =>
|
/*typeParameters*/ inJs ? undefined : map(typeArguments, (_, i) =>
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
////class C {
|
||||||
|
//// *method() {
|
||||||
|
//// yield* this.y();
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
|
||||||
|
verify.codeFixAll({
|
||||||
|
fixId: "addMissingMember",
|
||||||
|
fixAllDescription: "Add all missing members",
|
||||||
|
newFileContent:
|
||||||
|
`class C {
|
||||||
|
*method() {
|
||||||
|
yield* this.y();
|
||||||
|
}
|
||||||
|
*y(): any {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
});
|
|
@ -0,0 +1,21 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
////class C {
|
||||||
|
//// method() {
|
||||||
|
//// yield* this.y();
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
|
||||||
|
verify.codeFixAll({
|
||||||
|
fixId: "addMissingMember",
|
||||||
|
fixAllDescription: "Add all missing members",
|
||||||
|
newFileContent:
|
||||||
|
`class C {
|
||||||
|
method() {
|
||||||
|
yield* this.y();
|
||||||
|
}
|
||||||
|
y(): any {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
});
|
Loading…
Reference in a new issue