addMethodDeclaration codefix creates a generator function when target is child of a YieldExpression, resolves #24728

This commit is contained in:
krk 2018-06-07 20:51:11 +03:00
parent d0ae03c4cc
commit acbda14450
3 changed files with 46 additions and 2 deletions

View file

@ -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) =>

View file

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

View file

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