Skip to content

Commit b4dea5e

Browse files
authored
Merge pull request microsoft#24760 from krk/codefix-asterisk
addMethodDeclaration codefix creates a generator function when target…
2 parents 17eaf50 + d7a0619 commit b4dea5e

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/services/codefixes/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace ts.codefix {
111111
}
112112

113113
export function createMethodFromCallExpression(
114-
{ typeArguments, arguments: args }: CallExpression,
114+
{ typeArguments, arguments: args, parent: parent }: CallExpression,
115115
methodName: string,
116116
inJs: boolean,
117117
makeStatic: boolean,
@@ -120,7 +120,7 @@ namespace ts.codefix {
120120
return createMethod(
121121
/*decorators*/ undefined,
122122
/*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined,
123-
/*asteriskToken*/ undefined,
123+
/*asteriskToken*/ isYieldExpression(parent) ? createToken(SyntaxKind.AsteriskToken) : undefined,
124124
methodName,
125125
/*questionToken*/ undefined,
126126
/*typeParameters*/ inJs ? undefined : map(typeArguments, (_, i) =>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
//// *method() {
5+
//// yield* this.y();
6+
//// }
7+
////}
8+
9+
verify.codeFixAll({
10+
fixId: "addMissingMember",
11+
fixAllDescription: "Add all missing members",
12+
newFileContent:
13+
`class C {
14+
*method() {
15+
yield* this.y();
16+
}
17+
*y(): any {
18+
throw new Error("Method not implemented.");
19+
}
20+
}`,
21+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
//// method() {
5+
//// yield* this.y();
6+
//// }
7+
////}
8+
9+
verify.codeFixAll({
10+
fixId: "addMissingMember",
11+
fixAllDescription: "Add all missing members",
12+
newFileContent:
13+
`class C {
14+
method() {
15+
yield* this.y();
16+
}
17+
y(): any {
18+
throw new Error("Method not implemented.");
19+
}
20+
}`,
21+
});

0 commit comments

Comments
 (0)