mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
disallow acesssor generate in function like initializer
This commit is contained in:
@@ -119,7 +119,12 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
|
||||
|
||||
function getConvertibleFieldAtPosition(file: SourceFile, startPosition: number): Info | undefined {
|
||||
const node = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
|
||||
const declaration = findAncestor(node.parent, isAcceptedDeclaration);
|
||||
const declaration = <AcceptedDeclaration>findAncestor(node.parent, n => {
|
||||
if (isFunctionLikeDeclaration(n)) {
|
||||
return "quit";
|
||||
}
|
||||
return isAcceptedDeclaration(n);
|
||||
});
|
||||
// make sure declaration have AccessibilityModifier or Static Modifier or Readonly Modifier
|
||||
const meaning = ModifierFlags.AccessibilityModifier | ModifierFlags.Static | ModifierFlags.Readonly;
|
||||
if (!declaration || !isConvertableName(declaration.name) || (getModifierFlags(declaration) | meaning) !== meaning) return undefined;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// /*a*/public/*b*/ /*c*/a/*d*/ = () => {
|
||||
//// /*e*/return/*f*/ /*g*/1/*h*/;
|
||||
//// }
|
||||
//// /*i*/b/*j*/: /*k*/number/*l*/ = /*m*/1/*n*/
|
||||
//// };
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("c", "d");
|
||||
verify.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");
|
||||
|
||||
goTo.select("i", "j");
|
||||
verify.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("k", "l");
|
||||
verify.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
|
||||
goTo.select("m", "n");
|
||||
verify.refactorAvailable("Generate 'get' and 'set' accessors");
|
||||
Reference in New Issue
Block a user