Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/services/refactors/extractMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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 identifier.");
export const InsufficientSelection = createMessage("Select more than a single token.");
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 @@ -239,7 +239,7 @@ namespace ts.refactor.extractMethod {
}

function checkRootNode(node: Node): Diagnostic[] | undefined {
if (isIdentifier(node)) {
if (isToken(node)) {
return [createDiagnosticForNode(node, Messages.InsufficientSelection)];
}
return undefined;
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/fourslash/extract-method-not-for-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference path='fourslash.ts' />

////"/**/foo";

goTo.marker("");
verify.not.refactorAvailable('Extract Method');
8 changes: 4 additions & 4 deletions tests/cases/fourslash/extract-method13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Also checks that we correctly find non-conflicting names in static contexts.

//// class C {
//// static j = /*c*/100/*d*/;
//// constructor(q: string = /*a*/"hello"/*b*/) {
//// static j = /*c*/1 + 1/*d*/;
//// constructor(q: string = /*a*/"a" + "b"/*b*/) {
//// }
//// }

Expand All @@ -29,10 +29,10 @@ verify.currentFileContentIs(`class C {
}

private static newFunction(): string {
return "hello";
return "a" + "b";
}

private static newFunction_1() {
return 100;
return 1 + 1;
}
}`);
5 changes: 3 additions & 2 deletions tests/cases/fourslash/extract-method5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// annotation in the extracted function

//// function f() {
//// var x: 1 | 2 | 3 = /*start*/2/*end*/;
//// var x: 1 | 2 | 3 = /*start*/1 + 1 === 2 ? 1 : 2/*end*/;
//// }

goTo.select('start', 'end');
Expand All @@ -14,11 +14,12 @@ edit.applyRefactor({
actionName: "scope_0",
actionDescription: "Extract function into function 'f'",
});
// TODO: GH#18091 (fix formatting to use `2 ? 1 :` and not `2?1:`)
verify.currentFileContentIs(
`function f() {
var x: 1 | 2 | 3 = newFunction();

function newFunction(): 1 | 2 | 3 {
return 2;
return 1 + 1 === 2?1: 2;
}
}`);
4 changes: 2 additions & 2 deletions tests/cases/fourslash/extract-method7.ts
Original file line number Diff line number Diff line change
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*/3/*b*/) {
//// function fn(x = /*a*/1 + 1/*b*/) {
//// }

goTo.select('a', 'b');
Expand All @@ -15,6 +15,6 @@ edit.applyRefactor({
verify.currentFileContentIs(`function fn(x = newFunction()) {
}
function newFunction() {
return 3;
return 1 + 1;
}
`);