mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 09:24:19 -06:00
Merge pull request #18563 from amcasey/GH18546
Stop requiring that the full range of a declaration fall within the selection
This commit is contained in:
commit
cb63ea5242
@ -768,6 +768,11 @@ function parsePrimaryExpression(): any {
|
||||
}
|
||||
}|]
|
||||
}
|
||||
}`);
|
||||
// Selection excludes leading trivia of declaration
|
||||
testExtractMethod("extractMethod33",
|
||||
`function F() {
|
||||
[#|function G() { }|]
|
||||
}`);
|
||||
});
|
||||
|
||||
|
||||
@ -1205,7 +1205,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;
|
||||
}
|
||||
|
||||
19
tests/baselines/reference/extractMethod/extractMethod33.ts
Normal file
19
tests/baselines/reference/extractMethod/extractMethod33.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// ==ORIGINAL==
|
||||
function F() {
|
||||
function G() { }
|
||||
}
|
||||
// ==SCOPE::inner function in function 'F'==
|
||||
function F() {
|
||||
/*RENAME*/newFunction();
|
||||
|
||||
function newFunction() {
|
||||
function G() { }
|
||||
}
|
||||
}
|
||||
// ==SCOPE::function in global scope==
|
||||
function F() {
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
function newFunction() {
|
||||
function G() { }
|
||||
}
|
||||
@ -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*/
|
||||
////}
|
||||
@ -13,9 +10,9 @@ edit.applyRefactor({
|
||||
actionName: "scope_1",
|
||||
actionDescription: "Extract to function in global scope",
|
||||
newContent: `function f() {
|
||||
/*RENAME*/newFunction(N);
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
function newFunction(N: any) {
|
||||
function newFunction() {
|
||||
namespace N { }
|
||||
}
|
||||
`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user