Skip to content

Commit f0b7843

Browse files
committed
Merge pull request #18508 from amcasey/ExtractSingleToken
Re-enable extraction of a single token (cherry picked from commit 47b61ac)
1 parent 063e8a7 commit f0b7843

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/harness/unittests/extractMethods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function test(x: number) {
402402
[
403403
"Cannot extract range containing conditional break or continue statements."
404404
]);
405-
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single token."]);
405+
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single identifier."]);
406406

407407
testExtractRangeFailed("extractRangeFailed9",
408408
`var x = ([#||]1 + 2);`,

src/services/refactors/extractMethod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ts.refactor.extractMethod {
9292
export const CannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators: DiagnosticMessage = createMessage("Cannot extract range containing writes to references located outside of the target range in generators.");
9393
export const TypeWillNotBeVisibleInTheNewScope = createMessage("Type will not visible in the new scope.");
9494
export const FunctionWillNotBeVisibleInTheNewScope = createMessage("Function will not visible in the new scope.");
95-
export const InsufficientSelection = createMessage("Select more than a single token.");
95+
export const InsufficientSelection = createMessage("Select more than a single identifier.");
9696
export const CannotExtractExportedEntity = createMessage("Cannot extract exported declaration");
9797
export const CannotCombineWritesAndReturns = createMessage("Cannot combine writes and returns");
9898
export const CannotExtractReadonlyPropertyInitializerOutsideConstructor = createMessage("Cannot move initialization of read-only class property outside of the constructor");
@@ -232,7 +232,7 @@ namespace ts.refactor.extractMethod {
232232
}
233233

234234
function checkRootNode(node: Node): Diagnostic[] | undefined {
235-
if (isToken(isExpressionStatement(node) ? node.expression : node)) {
235+
if (isIdentifier(isExpressionStatement(node) ? node.expression : node)) {
236236
return [createDiagnosticForNode(node, Messages.InsufficientSelection)];
237237
}
238238
return undefined;

tests/cases/fourslash/extract-method13.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
//// class C {
77
//// static j = /*c*/1 + 1/*d*/;
8-
//// constructor(q: string = /*a*/"a" + "b"/*b*/) {
8+
//// constructor(q: string = /*a*/"hello"/*b*/) {
99
//// }
1010
//// }
1111

@@ -21,7 +21,7 @@ edit.applyRefactor({
2121
}
2222
2323
private static newFunction(): string {
24-
return "a" + "b";
24+
return "hello";
2525
}
2626
}`
2727
});
@@ -42,7 +42,7 @@ edit.applyRefactor({
4242
}
4343
4444
private static newFunction(): string {
45-
return "a" + "b";
45+
return "hello";
4646
}
4747
}`
4848
});

tests/cases/fourslash/extract-method7.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// You cannot extract a function initializer into the function's body.
44
// The innermost scope (scope_0) is the sibling of the function, not the function itself.
55

6-
//// function fn(x = /*a*/1 + 1/*b*/) {
6+
//// function fn(x = /*a*/3/*b*/) {
77
//// }
88

99
goTo.select('a', 'b');
@@ -15,7 +15,7 @@ edit.applyRefactor({
1515
`function fn(x = /*RENAME*/newFunction()) {
1616
}
1717
function newFunction() {
18-
return 1 + 1;
18+
return 3;
1919
}
2020
`
2121
});

0 commit comments

Comments
 (0)