Skip to content

Commit f0c7713

Browse files
author
Arthur Ozga
committed
implement getters/setters as property
1 parent 0c1772b commit f0c7713

File tree

5 files changed

+57
-47
lines changed

5 files changed

+57
-47
lines changed

src/services/codefixes/helpers.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace ts.codefix {
2828
}
2929
const node = declarations[0];
3030
const visibility = getVisibilityPrefix(getModifierFlags(node));
31-
let getOrSetPrefix: string = undefined;
3231
switch (node.kind) {
32+
case SyntaxKind.GetAccessor:
33+
case SyntaxKind.SetAccessor:
3334
case SyntaxKind.PropertySignature:
3435
case SyntaxKind.PropertyDeclaration:
3536
const typeString = checker.typeToString(type, enclosingDeclaration, TypeFormatFlags.None);
@@ -45,19 +46,13 @@ namespace ts.codefix {
4546
const sigString = checker.signatureToString(signatures[0], enclosingDeclaration, TypeFormatFlags.SuppressAnyReturnType, SignatureKind.Call);
4647

4748
return `${visibility}${name}${sigString}${getMethodBodyStub(newlineChar)}`;
48-
case SyntaxKind.GetAccessor:
49-
getOrSetPrefix = "get";
50-
case SyntaxKind.SetAccessor:
51-
getOrSetPrefix = getOrSetPrefix ? getOrSetPrefix : "set";
52-
53-
throw new Error('Not implemented, getter and setter.');
5449
case SyntaxKind.ComputedPropertyName:
5550
if (hasDynamicName(node)) {
5651
return "";
5752
}
58-
throw new Error('Not implemented, computed property name.');
53+
throw new Error("Not implemented, computed property name.");
5954
case SyntaxKind.IndexSignature:
60-
throw new Error('Not implemented.');
55+
throw new Error("Not implemented.");
6156

6257
default:
6358
return "";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// abstract class A {
4+
//// abstract get b(): number;
5+
//// }
6+
////
7+
//// class C extends A {[| |]}
8+
9+
verify.rangeAfterCodeFix(`
10+
b: number;
11+
`);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// abstract class A {
4+
//// private _a: string;
5+
////
6+
//// abstract get a(): string;
7+
//// abstract set a(newName: string);
8+
//// }
9+
////
10+
//// // Don't need to add anything in this case.
11+
//// abstract class B extends A {}
12+
////
13+
//// class C extends A {[| |]}
14+
15+
verify.rangeAfterCodeFix(`
16+
a: string;
17+
`);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// abstract class A {
4+
//// abstract set c(arg: number | string);
5+
//// }
6+
////
7+
//// class C extends A {[| |]}
8+
9+
verify.rangeAfterCodeFix(`
10+
c: string | number;
11+
`);
Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
/// <reference path='fourslash.ts' />
22

3-
//// namespace N1 {
4-
//// export interface I1 {
5-
//// f1():string;
6-
//// }
7-
//// }
8-
//// interface I1 {
9-
//// f1();
3+
//// abstract class A {
4+
//// private _a: string;
5+
////
6+
//// abstract get a(): string;
7+
//// abstract set a(newName: string);
8+
////
9+
//// abstract get b(): number;
10+
////
11+
//// abstract set c(arg: number | string);
1012
//// }
1113
////
12-
//// class C1 implements N1.I1 {[|
13-
//// |]}
14-
15-
let passcode = "secret passcode";
16-
17-
abstract class A {
18-
private _a: string;
14+
//// class C implements A {[| |]}
1915

20-
abstract get a(): string;
21-
abstract set a(newName: string);
22-
}
23-
24-
class B extends A {
16+
verify.rangeAfterCodeFix(`
2517
a: string;
26-
}
27-
28-
29-
abstract class AA {
30-
private _a: string;
31-
32-
abstract get a(): string {
33-
return this._a;
34-
}
35-
36-
abstract set a(newName: string) {
37-
this._a = newName;
38-
}
39-
}
40-
41-
verify.rangeAfterCodeFix(`f1(): string{
42-
throw new Error('Method not implemented.');
43-
}
44-
`);
18+
b: number;
19+
c: string | number;
20+
`);

0 commit comments

Comments
 (0)