mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
implement getters/setters as property
This commit is contained in:
@@ -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 "";
|
||||
|
||||
11
tests/cases/fourslash/codeFixClassExtendsAbstractGetter.ts
Normal file
11
tests/cases/fourslash/codeFixClassExtendsAbstractGetter.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract get b(): number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
b: number;
|
||||
`);
|
||||
@@ -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;
|
||||
`);
|
||||
11
tests/cases/fourslash/codeFixClassExtendsAbstractSetter.ts
Normal file
11
tests/cases/fourslash/codeFixClassExtendsAbstractSetter.ts
Normal 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;
|
||||
`);
|
||||
@@ -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;
|
||||
`);
|
||||
Reference in New Issue
Block a user