implement getters/setters as property

This commit is contained in:
Arthur Ozga
2016-12-05 14:52:08 -08:00
parent 0c1772b7e0
commit f0c771303d
5 changed files with 57 additions and 47 deletions

View File

@@ -28,8 +28,9 @@ namespace ts.codefix {
}
const node = declarations[0];
const visibility = getVisibilityPrefix(getModifierFlags(node));
let getOrSetPrefix: string = undefined;
switch (node.kind) {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyDeclaration:
const typeString = checker.typeToString(type, enclosingDeclaration, TypeFormatFlags.None);
@@ -45,19 +46,13 @@ namespace ts.codefix {
const sigString = checker.signatureToString(signatures[0], enclosingDeclaration, TypeFormatFlags.SuppressAnyReturnType, SignatureKind.Call);
return `${visibility}${name}${sigString}${getMethodBodyStub(newlineChar)}`;
case SyntaxKind.GetAccessor:
getOrSetPrefix = "get";
case SyntaxKind.SetAccessor:
getOrSetPrefix = getOrSetPrefix ? getOrSetPrefix : "set";
throw new Error('Not implemented, getter and setter.');
case SyntaxKind.ComputedPropertyName:
if (hasDynamicName(node)) {
return "";
}
throw new Error('Not implemented, computed property name.');
throw new Error("Not implemented, computed property name.");
case SyntaxKind.IndexSignature:
throw new Error('Not implemented.');
throw new Error("Not implemented.");
default:
return "";

View File

@@ -0,0 +1,11 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
//// abstract get b(): number;
//// }
////
//// class C extends A {[| |]}
verify.rangeAfterCodeFix(`
b: number;
`);

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
//// private _a: string;
////
//// abstract get a(): string;
//// abstract set a(newName: string);
//// }
////
//// // Don't need to add anything in this case.
//// abstract class B extends A {}
////
//// class C extends A {[| |]}
verify.rangeAfterCodeFix(`
a: string;
`);

View File

@@ -0,0 +1,11 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
//// abstract set c(arg: number | string);
//// }
////
//// class C extends A {[| |]}
verify.rangeAfterCodeFix(`
c: string | number;
`);

View File

@@ -1,44 +1,20 @@
/// <reference path='fourslash.ts' />
//// namespace N1 {
//// export interface I1 {
//// f1():string;
//// }
//// }
//// interface I1 {
//// f1();
//// abstract class A {
//// private _a: string;
////
//// abstract get a(): string;
//// abstract set a(newName: string);
////
//// abstract get b(): number;
////
//// abstract set c(arg: number | string);
//// }
////
//// class C1 implements N1.I1 {[|
//// |]}
//// class C implements A {[| |]}
let passcode = "secret passcode";
abstract class A {
private _a: string;
abstract get a(): string;
abstract set a(newName: string);
}
class B extends A {
verify.rangeAfterCodeFix(`
a: string;
}
abstract class AA {
private _a: string;
abstract get a(): string {
return this._a;
}
abstract set a(newName: string) {
this._a = newName;
}
}
verify.rangeAfterCodeFix(`f1(): string{
throw new Error('Method not implemented.');
}
`);
b: number;
c: string | number;
`);