Skip to content

Commit

Permalink
Stop requiring that the full range of a declaration fall within the
Browse files Browse the repository at this point in the history
selection

Fixes #18546

(cherry picked from commit af49c60)
  • Loading branch information
amcasey committed Sep 20, 2017
1 parent f0b7843 commit 27bede8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/harness/unittests/extractMethods.ts
Expand Up @@ -700,6 +700,11 @@ function parsePrimaryExpression(): any {
}
}|]
}
}`);
// Selection excludes leading trivia of declaration
testExtractMethod("extractMethod33",
`function F() {
[#|function G() { }|]
}`);
});

Expand Down
2 changes: 1 addition & 1 deletion src/services/refactors/extractMethod.ts
Expand Up @@ -1070,7 +1070,7 @@ namespace ts.refactor.extractMethod {
if (!declInFile) {
return undefined;
}
if (rangeContainsRange(enclosingTextRange, declInFile)) {
if (rangeContainsStartEnd(enclosingTextRange, declInFile.getStart(), declInFile.end)) {
// declaration is located in range to be extracted - do nothing
return undefined;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/extractMethod/extractMethod33.ts
@@ -0,0 +1,19 @@
// ==ORIGINAL==
function F() {
function G() { }
}
// ==SCOPE::function 'F'==
function F() {
/*RENAME*/newFunction();

function newFunction() {
function G() { }
}
}
// ==SCOPE::global scope==
function F() {
/*RENAME*/newFunction();
}
function newFunction() {
function G() { }
}
7 changes: 2 additions & 5 deletions tests/cases/fourslash/extract-method-empty-namespace.ts
@@ -1,8 +1,5 @@
/// <reference path='fourslash.ts' />

// TODO: GH#18546
// For now this tests that at least we don't crash.

////function f() {
//// /*start*/namespace N {}/*end*/
////}
Expand All @@ -13,9 +10,9 @@ edit.applyRefactor({
actionName: "scope_1",
actionDescription: "Extract function into global scope",
newContent: `function f() {
/*RENAME*/newFunction(N);
/*RENAME*/newFunction();
}
function newFunction(N: any) {
function newFunction() {
namespace N { }
}
`
Expand Down

0 comments on commit 27bede8

Please sign in to comment.