mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
add refactor of convert private field to getter and setter (#22143)
* add refactor of convert private field to getter and setter * fix refactor * stash * refactor accessor generate * revert merge union type * refeactor and accept baseline * add support of PropertyAssignment and StringLiteral * add support for js file * allow static modifier in js file
This commit is contained in:
Generated
+369
-416
File diff suppressed because it is too large
Load Diff
@@ -3122,8 +3122,8 @@ namespace ts {
|
||||
return (arg: T) => f(arg) && g(arg);
|
||||
}
|
||||
|
||||
export function or<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
|
||||
return (arg: T) => f(arg) || g(arg);
|
||||
export function or<T>(f: (arg: T) => boolean, g: (arg: T) => boolean, ...others: ((arg: T) => boolean)[]) {
|
||||
return (arg: T) => f(arg) || g(arg) || others.some(f => f(arg));
|
||||
}
|
||||
|
||||
export function assertTypeIsNever(_: never): void { } // tslint:disable-line no-empty
|
||||
|
||||
@@ -4161,5 +4161,9 @@
|
||||
"Convert all constructor functions to classes": {
|
||||
"category": "Message",
|
||||
"code": 95045
|
||||
},
|
||||
"Generate 'get' and 'set' accessors": {
|
||||
"category": "Message",
|
||||
"code": 95046
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4273,7 +4273,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isParameterPropertyDeclaration(node: Node): boolean {
|
||||
export function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration {
|
||||
return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -701,14 +701,6 @@ namespace ts.refactor.extractSymbol {
|
||||
Global,
|
||||
}
|
||||
|
||||
function getUniqueName(baseName: string, fileText: string): string {
|
||||
let nameText = baseName;
|
||||
for (let i = 1; stringContains(fileText, nameText); i++) {
|
||||
nameText = `${baseName}_${i}`;
|
||||
}
|
||||
return nameText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of 'extractRange' operation for a specific scope.
|
||||
* Stores either a list of changes that should be applied to extract a range or a list of errors
|
||||
@@ -1129,37 +1121,6 @@ namespace ts.refactor.extractSymbol {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The index of the (only) reference to the extracted symbol. We want the cursor
|
||||
* to be on the reference, rather than the declaration, because it's closer to where the
|
||||
* user was before extracting it.
|
||||
*/
|
||||
function getRenameLocation(edits: ReadonlyArray<FileTextChanges>, renameFilename: string, functionNameText: string, isDeclaredBeforeUse: boolean): number {
|
||||
let delta = 0;
|
||||
let lastPos = -1;
|
||||
for (const { fileName, textChanges } of edits) {
|
||||
Debug.assert(fileName === renameFilename);
|
||||
for (const change of textChanges) {
|
||||
const { span, newText } = change;
|
||||
const index = newText.indexOf(functionNameText);
|
||||
if (index !== -1) {
|
||||
lastPos = span.start + delta + index;
|
||||
|
||||
// If the reference comes first, return immediately.
|
||||
if (!isDeclaredBeforeUse) {
|
||||
return lastPos;
|
||||
}
|
||||
}
|
||||
delta += newText.length - span.length;
|
||||
}
|
||||
}
|
||||
|
||||
// If the declaration comes first, return the position of the last occurrence.
|
||||
Debug.assert(isDeclaredBeforeUse);
|
||||
Debug.assert(lastPos >= 0);
|
||||
return lastPos;
|
||||
}
|
||||
|
||||
function getFirstDeclaration(type: Type): Declaration | undefined {
|
||||
let firstDeclaration;
|
||||
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
/* @internal */
|
||||
namespace ts.refactor.generateGetAccessorAndSetAccessor {
|
||||
const actionName = "Generate 'get' and 'set' accessors";
|
||||
const actionDescription = Diagnostics.Generate_get_and_set_accessors.message;
|
||||
registerRefactor(actionName, { getEditsForAction, getAvailableActions });
|
||||
|
||||
type AccepedDeclaration = ParameterDeclaration | PropertyDeclaration | PropertyAssignment;
|
||||
type AccepedNameType = Identifier | StringLiteral;
|
||||
type ContainerDeclation = ClassLikeDeclaration | ObjectLiteralExpression;
|
||||
|
||||
interface DeclarationInfo {
|
||||
container: ContainerDeclation;
|
||||
isStatic: boolean;
|
||||
type: TypeNode | undefined;
|
||||
}
|
||||
|
||||
interface Info extends DeclarationInfo {
|
||||
declaration: AccepedDeclaration;
|
||||
fieldName: AccepedNameType;
|
||||
accessorName: AccepedNameType;
|
||||
}
|
||||
|
||||
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
|
||||
const { file, startPosition } = context;
|
||||
if (!getConvertibleFieldAtPosition(file, startPosition)) return undefined;
|
||||
|
||||
return [{
|
||||
name: actionName,
|
||||
description: actionDescription,
|
||||
actions: [
|
||||
{
|
||||
name: actionName,
|
||||
description: actionDescription
|
||||
}
|
||||
]
|
||||
}];
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, _actionName: string): RefactorEditInfo | undefined {
|
||||
const { file, startPosition } = context;
|
||||
|
||||
const fieldInfo = getConvertibleFieldAtPosition(file, startPosition);
|
||||
if (!fieldInfo) return undefined;
|
||||
|
||||
const isJS = isSourceFileJavaScript(file);
|
||||
const changeTracker = textChanges.ChangeTracker.fromContext(context);
|
||||
const { isStatic, fieldName, accessorName, type, container, declaration } = fieldInfo;
|
||||
|
||||
const isInClassLike = isClassLike(container);
|
||||
const accessorModifiers = getAccessorModifiers(isJS, declaration, isStatic, isInClassLike);
|
||||
const fieldModifiers = getFieldModifiers(isJS, isStatic, isInClassLike);
|
||||
|
||||
updateFieldDeclaration(changeTracker, file, declaration, fieldName, fieldModifiers, container);
|
||||
|
||||
const getAccessor = generateGetAccessor(fieldName, accessorName, type, accessorModifiers, isStatic, container);
|
||||
const setAccessor = generateSetAccessor(fieldName, accessorName, type, accessorModifiers, isStatic, container);
|
||||
|
||||
insertAccessor(changeTracker, file, getAccessor, declaration, container);
|
||||
insertAccessor(changeTracker, file, setAccessor, declaration, container);
|
||||
|
||||
const edits = changeTracker.getChanges();
|
||||
const renameFilename = file.fileName;
|
||||
const renameLocationOffset = isIdentifier(fieldName) ? 0 : -1;
|
||||
const renameLocation = renameLocationOffset + getRenameLocation(edits, renameFilename, fieldName.text, /*isDeclaredBeforeUse*/ false);
|
||||
return { renameFilename, renameLocation, edits };
|
||||
}
|
||||
|
||||
function isConvertableName (name: DeclarationName): name is AccepedNameType {
|
||||
return isIdentifier(name) || isStringLiteral(name);
|
||||
}
|
||||
|
||||
function createPropertyName (name: string, originalName: AccepedNameType) {
|
||||
return isIdentifier(originalName) ? createIdentifier(name) : createLiteral(name);
|
||||
}
|
||||
|
||||
function createAccessorAccessExpression (fieldName: AccepedNameType, isStatic: boolean, container: ContainerDeclation) {
|
||||
const leftHead = isStatic ? (<ClassLikeDeclaration>container).name : createThis();
|
||||
return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName));
|
||||
}
|
||||
|
||||
function getAccessorModifiers(isJS: boolean, declaration: AccepedDeclaration, isStatic: boolean, isClassLike: boolean): NodeArray<Modifier> | undefined {
|
||||
if (!isClassLike) return undefined;
|
||||
|
||||
if (!declaration.modifiers || getModifierFlags(declaration) & ModifierFlags.Private) {
|
||||
const modifiers = append<Modifier>(
|
||||
!isJS ? [createToken(SyntaxKind.PublicKeyword)] : undefined,
|
||||
isStatic ? createToken(SyntaxKind.StaticKeyword) : undefined
|
||||
);
|
||||
return modifiers && createNodeArray(modifiers);
|
||||
}
|
||||
return declaration.modifiers;
|
||||
}
|
||||
|
||||
function getFieldModifiers(isJS: boolean, isStatic: boolean, isClassLike: boolean): NodeArray<Modifier> | undefined {
|
||||
if (!isClassLike) return undefined;
|
||||
|
||||
const modifiers = append<Modifier>(
|
||||
!isJS ? [createToken(SyntaxKind.PrivateKeyword)] : undefined,
|
||||
isStatic ? createToken(SyntaxKind.StaticKeyword) : undefined
|
||||
);
|
||||
return modifiers && createNodeArray(modifiers);
|
||||
}
|
||||
|
||||
function getPropertyDeclarationInfo(propertyDeclaration: PropertyDeclaration): DeclarationInfo | undefined {
|
||||
if (!isClassLike(propertyDeclaration.parent) || !propertyDeclaration.parent.members) return undefined;
|
||||
|
||||
return {
|
||||
isStatic: hasStaticModifier(propertyDeclaration),
|
||||
type: propertyDeclaration.type,
|
||||
container: propertyDeclaration.parent
|
||||
};
|
||||
}
|
||||
|
||||
function getParameterPropertyDeclarationInfo(parameterDeclaration: ParameterDeclaration): DeclarationInfo | undefined {
|
||||
if (!isClassLike(parameterDeclaration.parent.parent) || !parameterDeclaration.parent.parent.members) return undefined;
|
||||
|
||||
return {
|
||||
isStatic: false,
|
||||
type: parameterDeclaration.type,
|
||||
container: parameterDeclaration.parent.parent
|
||||
};
|
||||
}
|
||||
|
||||
function getPropertyAssignmentDeclarationInfo(propertyAssignment: PropertyAssignment): DeclarationInfo | undefined {
|
||||
return {
|
||||
isStatic: false,
|
||||
type: undefined,
|
||||
container: propertyAssignment.parent
|
||||
};
|
||||
}
|
||||
|
||||
function getDeclarationInfo(declaration: AccepedDeclaration) {
|
||||
if (isPropertyDeclaration(declaration)) {
|
||||
return getPropertyDeclarationInfo(declaration);
|
||||
}
|
||||
else if (isPropertyAssignment(declaration)) {
|
||||
return getPropertyAssignmentDeclarationInfo(declaration);
|
||||
}
|
||||
else {
|
||||
return getParameterPropertyDeclarationInfo(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
function getConvertibleFieldAtPosition(file: SourceFile, startPosition: number): Info | undefined {
|
||||
const node = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
|
||||
const declaration = <AccepedDeclaration>findAncestor(node.parent, or(isParameterPropertyDeclaration, isPropertyDeclaration, isPropertyAssignment));
|
||||
// make sure propertyDeclaration have AccessibilityModifier or Static Modifier
|
||||
const meaning = ModifierFlags.AccessibilityModifier | ModifierFlags.Static;
|
||||
if (!declaration || !isConvertableName(declaration.name) || (getModifierFlags(declaration) | meaning) !== meaning) return undefined;
|
||||
|
||||
const info = getDeclarationInfo(declaration);
|
||||
const fieldName = createPropertyName(getUniqueName(`_${declaration.name.text}`, file.text), declaration.name);
|
||||
suppressLeadingAndTrailingTrivia(fieldName);
|
||||
suppressLeadingAndTrailingTrivia(declaration);
|
||||
return {
|
||||
...info,
|
||||
declaration,
|
||||
fieldName,
|
||||
accessorName: createPropertyName(declaration.name.text, declaration.name)
|
||||
};
|
||||
}
|
||||
|
||||
function generateGetAccessor(fieldName: AccepedNameType, accessorName: AccepedNameType, type: TypeNode, modifiers: ModifiersArray | undefined, isStatic: boolean, container: ContainerDeclation) {
|
||||
return createGetAccessor(
|
||||
/*decorators*/ undefined,
|
||||
modifiers,
|
||||
accessorName,
|
||||
/*parameters*/ undefined,
|
||||
type,
|
||||
createBlock([
|
||||
createReturn(
|
||||
createAccessorAccessExpression(fieldName, isStatic, container)
|
||||
)
|
||||
], /*multiLine*/ true)
|
||||
);
|
||||
}
|
||||
|
||||
function generateSetAccessor(fieldName: AccepedNameType, accessorName: AccepedNameType, type: TypeNode, modifiers: ModifiersArray | undefined, isStatic: boolean, container: ContainerDeclation) {
|
||||
return createSetAccessor(
|
||||
/*decorators*/ undefined,
|
||||
modifiers,
|
||||
accessorName,
|
||||
[createParameter(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*dotDotDotToken*/ undefined,
|
||||
createIdentifier("value"),
|
||||
/*questionToken*/ undefined,
|
||||
type
|
||||
)],
|
||||
createBlock([
|
||||
createStatement(
|
||||
createAssignment(
|
||||
createAccessorAccessExpression(fieldName, isStatic, container),
|
||||
createIdentifier("value")
|
||||
)
|
||||
)
|
||||
], /*multiLine*/ true)
|
||||
);
|
||||
}
|
||||
|
||||
function updatePropertyDeclaration(changeTracker: textChanges.ChangeTracker, file: SourceFile, declaration: PropertyDeclaration, fieldName: AccepedNameType, modifiers: ModifiersArray | undefined) {
|
||||
const property = updateProperty(
|
||||
declaration,
|
||||
declaration.decorators,
|
||||
modifiers,
|
||||
fieldName,
|
||||
declaration.questionToken || declaration.exclamationToken,
|
||||
declaration.type,
|
||||
declaration.initializer
|
||||
);
|
||||
|
||||
changeTracker.replaceNode(file, declaration, property);
|
||||
}
|
||||
|
||||
function updateParameterPropertyDeclaration(changeTracker: textChanges.ChangeTracker, file: SourceFile, declaration: ParameterDeclaration, fieldName: AccepedNameType, modifiers: ModifiersArray | undefined, classLikeContainer: ClassLikeDeclaration) {
|
||||
const property = createProperty(
|
||||
declaration.decorators,
|
||||
modifiers,
|
||||
fieldName,
|
||||
declaration.questionToken,
|
||||
declaration.type,
|
||||
declaration.initializer
|
||||
);
|
||||
|
||||
changeTracker.insertNodeAtClassStart(file, classLikeContainer, property);
|
||||
changeTracker.deleteNodeInList(file, declaration);
|
||||
}
|
||||
|
||||
function updatePropertyAssignmentDeclaration (changeTracker: textChanges.ChangeTracker, file: SourceFile, declaration: PropertyAssignment, fieldName: AccepedNameType) {
|
||||
const assignment = updatePropertyAssignment(declaration, fieldName, declaration.initializer);
|
||||
changeTracker.replacePropertyAssignment(file, declaration, assignment);
|
||||
}
|
||||
|
||||
function updateFieldDeclaration(changeTracker: textChanges.ChangeTracker, file: SourceFile, declaration: AccepedDeclaration, fieldName: AccepedNameType, modifiers: ModifiersArray | undefined, container: ContainerDeclation) {
|
||||
if (isPropertyDeclaration(declaration)) {
|
||||
updatePropertyDeclaration(changeTracker, file, declaration, fieldName, modifiers);
|
||||
}
|
||||
else if (isPropertyAssignment(declaration)) {
|
||||
updatePropertyAssignmentDeclaration(changeTracker, file, declaration, fieldName);
|
||||
}
|
||||
else {
|
||||
updateParameterPropertyDeclaration(changeTracker, file, declaration, fieldName, modifiers, <ClassLikeDeclaration>container);
|
||||
}
|
||||
}
|
||||
|
||||
function insertAccessor(changeTracker: textChanges.ChangeTracker, file: SourceFile, accessor: AccessorDeclaration, declaration: AccepedDeclaration, container: ContainerDeclation) {
|
||||
isParameterPropertyDeclaration(declaration)
|
||||
? changeTracker.insertNodeAtClassStart(file, <ClassLikeDeclaration>container, accessor)
|
||||
: changeTracker.insertNodeAfter(file, declaration, accessor);
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
/// <reference path="extractSymbol.ts" />
|
||||
/// <reference path="generateGetAccessorAndSetAccessor.ts" />
|
||||
|
||||
@@ -316,6 +316,12 @@ namespace ts.textChanges {
|
||||
return this.replaceRangeWithNodes(sourceFile, getAdjustedRange(sourceFile, startNode, endNode, options), newNodes, options);
|
||||
}
|
||||
|
||||
public replacePropertyAssignment(sourceFile: SourceFile, oldNode: PropertyAssignment, newNode: PropertyAssignment) {
|
||||
return this.replaceNode(sourceFile, oldNode, newNode, {
|
||||
suffix: "," + this.newLineCharacter
|
||||
});
|
||||
}
|
||||
|
||||
private insertNodeAt(sourceFile: SourceFile, pos: number, newNode: Node, options: InsertNodeOptions = {}) {
|
||||
this.replaceRange(sourceFile, createTextRange(pos), newNode, options);
|
||||
}
|
||||
@@ -468,6 +474,9 @@ namespace ts.textChanges {
|
||||
else if (isVariableDeclaration(node)) {
|
||||
return { prefix: ", " };
|
||||
}
|
||||
else if (isPropertyAssignment(node)) {
|
||||
return { suffix: "," + this.newLineCharacter };
|
||||
}
|
||||
else if (isParameter(node)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1526,4 +1526,45 @@ namespace ts {
|
||||
function getFirstChild(node: Node): Node | undefined {
|
||||
return node.forEachChild(child => child);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function getUniqueName(baseName: string, fileText: string): string {
|
||||
let nameText = baseName;
|
||||
for (let i = 1; stringContains(fileText, nameText); i++) {
|
||||
nameText = `${baseName}_${i}`;
|
||||
}
|
||||
return nameText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The index of the (only) reference to the extracted symbol. We want the cursor
|
||||
* to be on the reference, rather than the declaration, because it's closer to where the
|
||||
* user was before extracting it.
|
||||
*/
|
||||
/* @internal */
|
||||
export function getRenameLocation(edits: ReadonlyArray<FileTextChanges>, renameFilename: string, name: string, isDeclaredBeforeUse: boolean): number {
|
||||
let delta = 0;
|
||||
let lastPos = -1;
|
||||
for (const { fileName, textChanges } of edits) {
|
||||
Debug.assert(fileName === renameFilename);
|
||||
for (const change of textChanges) {
|
||||
const { span, newText } = change;
|
||||
const index = newText.indexOf(name);
|
||||
if (index !== -1) {
|
||||
lastPos = span.start + delta + index;
|
||||
|
||||
// If the reference comes first, return immediately.
|
||||
if (!isDeclaredBeforeUse) {
|
||||
return lastPos;
|
||||
}
|
||||
}
|
||||
delta += newText.length - span.length;
|
||||
}
|
||||
}
|
||||
|
||||
// If the declaration comes first, return the position of the last occurrence.
|
||||
Debug.assert(isDeclaredBeforeUse);
|
||||
Debug.assert(lastPos >= 0);
|
||||
return lastPos;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2955,7 +2955,7 @@ declare namespace ts {
|
||||
*/
|
||||
function collapseTextChangeRangesAcrossMultipleVersions(changes: ReadonlyArray<TextChangeRange>): TextChangeRange;
|
||||
function getTypeParameterOwner(d: Declaration): Declaration;
|
||||
function isParameterPropertyDeclaration(node: Node): boolean;
|
||||
function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration;
|
||||
function isEmptyBindingPattern(node: BindingName): node is BindingPattern;
|
||||
function isEmptyBindingElement(node: BindingElement): boolean;
|
||||
function getCombinedModifierFlags(node: Node): ModifierFlags;
|
||||
|
||||
+1
-1
@@ -3010,7 +3010,7 @@ declare namespace ts {
|
||||
*/
|
||||
function collapseTextChangeRangesAcrossMultipleVersions(changes: ReadonlyArray<TextChangeRange>): TextChangeRange;
|
||||
function getTypeParameterOwner(d: Declaration): Declaration;
|
||||
function isParameterPropertyDeclaration(node: Node): boolean;
|
||||
function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration;
|
||||
function isEmptyBindingPattern(node: BindingName): node is BindingPattern;
|
||||
function isEmptyBindingElement(node: BindingElement): boolean;
|
||||
function getCombinedModifierFlags(node: Node): ModifierFlags;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public a?: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a?: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public a!: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a!: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public get a/*b*/ () { return 1; }
|
||||
//// /*c*/public set a/*d*/ (v) { }
|
||||
//// /*e*/public ['b']/*f*/ () { }
|
||||
//// /*g*/public ['c'] = 1;/*h*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("c", "d");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("e", "f");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("g", "h");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public static a: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private static /*RENAME*/_a: string = "foo";
|
||||
public static get a(): string {
|
||||
return A._a;
|
||||
}
|
||||
public static set a(value: string) {
|
||||
A._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public readonly a: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
@@ -0,0 +1,46 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public _a: number = 1;/*b*/
|
||||
//// /*c*/public a: string = "foo";/*d*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: number = 1;
|
||||
public get _a(): number {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: number) {
|
||||
this.__a = value;
|
||||
}
|
||||
public a: string = "foo";
|
||||
}`,
|
||||
});
|
||||
|
||||
goTo.select("c", "d");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private __a: number = 1;
|
||||
public get _a(): number {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: number) {
|
||||
this.__a = value;
|
||||
}
|
||||
private /*RENAME*/_a_1: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a_1;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a_1 = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// constructor(public /*a*/a/*b*/: string) { }
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
constructor() { }
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// constructor(protected /*a*/a/*b*/: string) { }
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
protected get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
protected set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
constructor() { }
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// constructor(private /*a*/a/*b*/: string) { }
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
constructor() { }
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// constructor(/*a*/a/*b*/: string) { }
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/protected a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
protected get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
protected set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public a_1: number;
|
||||
//// /*a*/public a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
public a_1: number;
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public a_2: number;
|
||||
//// /*a*/public a_1: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
public a_2: number;
|
||||
private /*RENAME*/_a_1: string;
|
||||
public get a_1(): string {
|
||||
return this._a_1;
|
||||
}
|
||||
public set a_1(value: string) {
|
||||
this._a_1 = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public a_1: number;
|
||||
//// constructor(public /*a*/a/*b*/: string) { }
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
public a_1: number;
|
||||
constructor() { }
|
||||
}`,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public _a: number = 1;/*b*/
|
||||
//// /*c*/public a: string = "foo";/*d*/
|
||||
//// }
|
||||
|
||||
goTo.select("c", "d");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
public _a: number = 1;
|
||||
private /*RENAME*/_a_1: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a_1;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a_1 = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: number = 1;
|
||||
public get _a(): number {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: number) {
|
||||
this.__a = value;
|
||||
}
|
||||
private _a_1: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a_1;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a_1 = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public a: number = 1;/*b*/
|
||||
//// public _a: string = "foo";
|
||||
//// public _a_1: string = "bar";
|
||||
//// public _a_2: string = "baz";
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a_3: number = 1;
|
||||
public get a(): number {
|
||||
return this._a_3;
|
||||
}
|
||||
public set a(value: number) {
|
||||
this._a_3 = value;
|
||||
}
|
||||
public _a: string = "foo";
|
||||
public _a_1: string = "bar";
|
||||
public _a_2: string = "baz";
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public /*a*/"a"/*b*/: number = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/"_a": number = 1;
|
||||
public get "a"(): number {
|
||||
return this["_a"];
|
||||
}
|
||||
public set "a"(value: number) {
|
||||
this["_a"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public _a: string = "";
|
||||
//// /*a*/public "a": number = 1;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
public _a: string = "";
|
||||
private /*RENAME*/"_a_1": number = 1;
|
||||
public get "a"(): number {
|
||||
return this["_a_1"];
|
||||
}
|
||||
public set "a"(value: number) {
|
||||
this["_a_1"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public "a-b": number = 1;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/"_a-b": number = 1;
|
||||
public get "a-b"(): number {
|
||||
return this["_a-b"];
|
||||
}
|
||||
public set "a-b"(value: number) {
|
||||
this["_a-b"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public static "a": number = 1;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private static /*RENAME*/"_a": number = 1;
|
||||
public static get "a"(): number {
|
||||
return A["_a"];
|
||||
}
|
||||
public static set "a"(value: number) {
|
||||
A["_a"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const A = {
|
||||
//// /*a*/a/*b*/: 1
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `const A = {
|
||||
/*RENAME*/_a: 1,
|
||||
get a() {
|
||||
return this._a;
|
||||
},
|
||||
set a(value) {
|
||||
this._a = value;
|
||||
},
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/private a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string;
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const A = {
|
||||
//// /*a*/'a'/*b*/: 1
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `const A = {
|
||||
/*RENAME*/"_a": 1,
|
||||
get "a"() {
|
||||
return this["_a"];
|
||||
},
|
||||
set "a"(value) {
|
||||
this["_a"] = value;
|
||||
},
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// public /*a*/a/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a = 1;
|
||||
public get a() {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// /** Class comment */
|
||||
//// class A {
|
||||
//// // Field comment
|
||||
//// public /*a*/a/*b*/: number = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `/** Class comment */
|
||||
class A {
|
||||
// Field comment
|
||||
private /*RENAME*/_a: number = 1;
|
||||
public get a(): number {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: number) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/private _a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: string;
|
||||
public get _a(): string {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: string) {
|
||||
this.__a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/_a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: string;
|
||||
public get _a(): string {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: string) {
|
||||
this.__a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public _a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: string;
|
||||
public get _a(): string {
|
||||
return this.__a;
|
||||
}
|
||||
public set _a(value: string) {
|
||||
this.__a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/protected _a: string;/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/__a: string;
|
||||
protected get _a(): string {
|
||||
return this.__a;
|
||||
}
|
||||
protected set _a(value: string) {
|
||||
this.__a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public a: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
private /*RENAME*/_a: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// @foo
|
||||
//// /*a*/public a: string = "foo";/*b*/
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
@foo
|
||||
private /*RENAME*/_a: string = "foo";
|
||||
public get a(): string {
|
||||
return this._a;
|
||||
}
|
||||
public set a(value: string) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// const A = {
|
||||
//// /*a*/"a"/*b*/: 1
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `const A = {
|
||||
/*RENAME*/"_a": 1,
|
||||
get "a"() {
|
||||
return this["_a"];
|
||||
},
|
||||
set "a"(value) {
|
||||
this["_a"] = value;
|
||||
},
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// const A = {
|
||||
//// /*a*/a/*b*/: 1
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `const A = {
|
||||
/*RENAME*/_a: 1,
|
||||
get a() {
|
||||
return this._a;
|
||||
},
|
||||
set a(value) {
|
||||
this._a = value;
|
||||
},
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class A {
|
||||
//// /*a*/a/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
/*RENAME*/_a = 1;
|
||||
get a() {
|
||||
return this._a;
|
||||
}
|
||||
set a(value) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class A {
|
||||
//// /*a*/"a"/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
/*RENAME*/"_a" = 1;
|
||||
get "a"() {
|
||||
return this["_a"];
|
||||
}
|
||||
set "a"(value) {
|
||||
this["_a"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class A {
|
||||
//// _a = 2;
|
||||
//// /*a*/"a"/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
_a = 2;
|
||||
/*RENAME*/"_a_1" = 1;
|
||||
get "a"() {
|
||||
return this["_a_1"];
|
||||
}
|
||||
set "a"(value) {
|
||||
this["_a_1"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class A {
|
||||
//// "_a" = 2;
|
||||
//// /*a*/"a"/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
"_a" = 2;
|
||||
/*RENAME*/"_a_1" = 1;
|
||||
get "a"() {
|
||||
return this["_a_1"];
|
||||
}
|
||||
set "a"(value) {
|
||||
this["_a_1"] = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// const A = {
|
||||
//// _a: 2,
|
||||
//// /*a*/a/*b*/: 1
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `const A = {
|
||||
_a: 2,
|
||||
/*RENAME*/_a_1: 1,
|
||||
get a() {
|
||||
return this._a_1;
|
||||
},
|
||||
set a(value) {
|
||||
this._a_1 = value;
|
||||
},
|
||||
};`,
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// /** Class comment */
|
||||
//// class A {
|
||||
//// // Field comment
|
||||
//// /*a*/a/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `/** Class comment */
|
||||
class A {
|
||||
// Field comment
|
||||
/*RENAME*/_a = 1;
|
||||
get a() {
|
||||
return this._a;
|
||||
}
|
||||
set a(value) {
|
||||
this._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
//// class A {
|
||||
//// static /*a*/a/*b*/ = 1;
|
||||
//// }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Generate 'get' and 'set' accessors",
|
||||
actionName: "Generate 'get' and 'set' accessors",
|
||||
actionDescription: "Generate 'get' and 'set' accessors",
|
||||
newContent: `class A {
|
||||
static /*RENAME*/_a = 1;
|
||||
static get a() {
|
||||
return A._a;
|
||||
}
|
||||
static set a(value) {
|
||||
A._a = value;
|
||||
}
|
||||
}`,
|
||||
});
|
||||
Reference in New Issue
Block a user