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(
|
||||
{ typeArguments, arguments: args }: CallExpression,
|
||||
{ typeArguments, arguments: args, parent: parent }: CallExpression,
|
||||
methodName: string,
|
||||
inJs: boolean,
|
||||
makeStatic: boolean,
|
||||
preferences: UserPreferences,
|
||||
): MethodDeclaration {
|
||||
const asterisk = parent.kind === SyntaxKind.YieldExpression ? createToken(SyntaxKind.AsteriskToken) : undefined;
|
||||
|
||||
return createMethod(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined,
|
||||
/*asteriskToken*/ undefined,
|
||||
/*asteriskToken*/ asterisk,
|
||||
methodName,
|
||||
/*questionToken*/ undefined,
|
||||
/*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