Skip to content

Commit

Permalink
Merge pull request #18508 from amcasey/ExtractSingleToken
Browse files Browse the repository at this point in the history
Re-enable extraction of a single token

(cherry picked from commit 47b61ac)
  • Loading branch information
amcasey committed Sep 20, 2017
1 parent 063e8a7 commit f0b7843
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/harness/unittests/extractMethods.ts
Expand Up @@ -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);`,
Expand Down
4 changes: 2 additions & 2 deletions src/services/refactors/extractMethod.ts
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/cases/fourslash/extract-method13.ts
Expand Up @@ -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*/) {
//// }
//// }

Expand All @@ -21,7 +21,7 @@ edit.applyRefactor({
}
private static newFunction(): string {
return "a" + "b";
return "hello";
}
}`
});
Expand All @@ -42,7 +42,7 @@ edit.applyRefactor({
}
private static newFunction(): string {
return "a" + "b";
return "hello";
}
}`
});
4 changes: 2 additions & 2 deletions tests/cases/fourslash/extract-method7.ts
Expand Up @@ -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');
Expand All @@ -15,7 +15,7 @@ edit.applyRefactor({
`function fn(x = /*RENAME*/newFunction()) {
}
function newFunction() {
return 1 + 1;
return 3;
}
`
});

0 comments on commit f0b7843

Please sign in to comment.