Merge pull request #18508 from amcasey/ExtractSingleToken

Re-enable extraction of a single token

(cherry picked from commit 47b61ac18c304028036914bba1cc65220b4732f9)
This commit is contained in:
Andrew Casey 2017-09-15 13:15:31 -07:00 committed by Andrew Casey
parent 063e8a72ec
commit f0b78437f8
5 changed files with 8 additions and 8 deletions

View File

@ -402,7 +402,7 @@ function test(x: number) {
[
"Cannot extract range containing conditional break or continue statements."
]);
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single token."]);
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single identifier."]);
testExtractRangeFailed("extractRangeFailed9",
`var x = ([#||]1 + 2);`,

View File

@ -92,7 +92,7 @@ namespace ts.refactor.extractMethod {
export const CannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators: DiagnosticMessage = createMessage("Cannot extract range containing writes to references located outside of the target range in generators.");
export const TypeWillNotBeVisibleInTheNewScope = createMessage("Type will not visible in the new scope.");
export const FunctionWillNotBeVisibleInTheNewScope = createMessage("Function will not visible in the new scope.");
export const InsufficientSelection = createMessage("Select more than a single token.");
export const InsufficientSelection = createMessage("Select more than a single identifier.");
export const CannotExtractExportedEntity = createMessage("Cannot extract exported declaration");
export const CannotCombineWritesAndReturns = createMessage("Cannot combine writes and returns");
export const CannotExtractReadonlyPropertyInitializerOutsideConstructor = createMessage("Cannot move initialization of read-only class property outside of the constructor");
@ -232,7 +232,7 @@ namespace ts.refactor.extractMethod {
}
function checkRootNode(node: Node): Diagnostic[] | undefined {
if (isToken(isExpressionStatement(node) ? node.expression : node)) {
if (isIdentifier(isExpressionStatement(node) ? node.expression : node)) {
return [createDiagnosticForNode(node, Messages.InsufficientSelection)];
}
return undefined;

View File

@ -5,7 +5,7 @@
//// class C {
//// static j = /*c*/1 + 1/*d*/;
//// constructor(q: string = /*a*/"a" + "b"/*b*/) {
//// constructor(q: string = /*a*/"hello"/*b*/) {
//// }
//// }
@ -21,7 +21,7 @@ edit.applyRefactor({
}
private static newFunction(): string {
return "a" + "b";
return "hello";
}
}`
});
@ -42,7 +42,7 @@ edit.applyRefactor({
}
private static newFunction(): string {
return "a" + "b";
return "hello";
}
}`
});

View File

@ -3,7 +3,7 @@
// You cannot extract a function initializer into the function's body.
// The innermost scope (scope_0) is the sibling of the function, not the function itself.
//// function fn(x = /*a*/1 + 1/*b*/) {
//// function fn(x = /*a*/3/*b*/) {
//// }
goTo.select('a', 'b');
@ -15,7 +15,7 @@ edit.applyRefactor({
`function fn(x = /*RENAME*/newFunction()) {
}
function newFunction() {
return 1 + 1;
return 3;
}
`
});