From 2ea4cfe23bf0648c099a79a8a1d976febb2e2610 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 12 Oct 2017 11:37:31 -0700 Subject: [PATCH] Insert a line break before a function at EOF if needed This is a pre-existing issue that became more obvious after refining trivia handling. --- src/harness/unittests/tsserverProjectSystem.ts | 2 +- src/services/refactors/extractSymbol.ts | 5 ++++- .../baselines/reference/extractFunction/extractFunction1.ts | 1 + .../baselines/reference/extractFunction/extractFunction10.ts | 1 + .../baselines/reference/extractFunction/extractFunction11.ts | 1 + .../baselines/reference/extractFunction/extractFunction13.ts | 1 + .../baselines/reference/extractFunction/extractFunction14.ts | 1 + .../baselines/reference/extractFunction/extractFunction15.ts | 1 + .../baselines/reference/extractFunction/extractFunction16.ts | 1 + .../baselines/reference/extractFunction/extractFunction17.ts | 1 + .../baselines/reference/extractFunction/extractFunction18.ts | 1 + .../baselines/reference/extractFunction/extractFunction19.ts | 1 + .../baselines/reference/extractFunction/extractFunction2.ts | 1 + .../baselines/reference/extractFunction/extractFunction20.js | 1 + .../baselines/reference/extractFunction/extractFunction20.ts | 1 + .../baselines/reference/extractFunction/extractFunction21.js | 1 + .../baselines/reference/extractFunction/extractFunction21.ts | 1 + .../baselines/reference/extractFunction/extractFunction22.js | 1 + .../baselines/reference/extractFunction/extractFunction22.ts | 1 + .../baselines/reference/extractFunction/extractFunction23.ts | 1 + .../baselines/reference/extractFunction/extractFunction24.js | 1 + .../baselines/reference/extractFunction/extractFunction24.ts | 1 + .../baselines/reference/extractFunction/extractFunction26.js | 1 + .../baselines/reference/extractFunction/extractFunction26.ts | 1 + .../baselines/reference/extractFunction/extractFunction27.js | 1 + .../baselines/reference/extractFunction/extractFunction27.ts | 1 + .../baselines/reference/extractFunction/extractFunction28.js | 1 + .../baselines/reference/extractFunction/extractFunction28.ts | 1 + .../baselines/reference/extractFunction/extractFunction3.ts | 1 + .../baselines/reference/extractFunction/extractFunction30.ts | 1 + .../baselines/reference/extractFunction/extractFunction31.ts | 1 + .../baselines/reference/extractFunction/extractFunction32.ts | 1 + .../baselines/reference/extractFunction/extractFunction33.js | 1 + .../baselines/reference/extractFunction/extractFunction33.ts | 1 + .../baselines/reference/extractFunction/extractFunction4.ts | 1 + .../baselines/reference/extractFunction/extractFunction5.ts | 1 + .../baselines/reference/extractFunction/extractFunction6.ts | 1 + .../baselines/reference/extractFunction/extractFunction7.ts | 1 + .../baselines/reference/extractFunction/extractFunction9.ts | 1 + .../extractFunction/extractFunction_PreserveTrivia.js | 1 + .../extractFunction/extractFunction_PreserveTrivia.ts | 1 + .../extractFunction/extractFunction_RepeatedSubstitution.ts | 1 + .../extractFunction_VariableDeclaration_ShorthandProperty.js | 1 + .../extractFunction_VariableDeclaration_ShorthandProperty.ts | 1 + ...xtractFunction_VariableDeclaration_Writes_Const_NoType.js | 1 + ...xtractFunction_VariableDeclaration_Writes_Const_NoType.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Const_Type.ts | 1 + ...ctFunction_VariableDeclaration_Writes_Let_LiteralType1.ts | 1 + ...ctFunction_VariableDeclaration_Writes_Let_LiteralType2.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Let_NoType.js | 1 + .../extractFunction_VariableDeclaration_Writes_Let_NoType.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Let_Type.ts | 1 + ...nction_VariableDeclaration_Writes_Let_TypeWithComments.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Mixed1.js | 1 + .../extractFunction_VariableDeclaration_Writes_Mixed1.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Mixed2.js | 1 + .../extractFunction_VariableDeclaration_Writes_Mixed2.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Mixed3.ts | 1 + ...ractFunction_VariableDeclaration_Writes_UnionUndefined.ts | 1 + .../extractFunction_VariableDeclaration_Writes_Var.js | 1 + .../extractFunction_VariableDeclaration_Writes_Var.ts | 1 + tests/cases/fourslash/extract-method-empty-namespace.ts | 1 + tests/cases/fourslash/extract-method-formatting.ts | 1 + tests/cases/fourslash/extract-method-uniqueName.ts | 1 + tests/cases/fourslash/extract-method10.ts | 1 + tests/cases/fourslash/extract-method14.ts | 1 + tests/cases/fourslash/extract-method15.ts | 1 + tests/cases/fourslash/extract-method18.ts | 1 + tests/cases/fourslash/extract-method2.ts | 1 + tests/cases/fourslash/extract-method24.ts | 1 + tests/cases/fourslash/extract-method7.ts | 1 + 71 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 40be5e02eea..4929cbfbaa5 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -4526,7 +4526,7 @@ namespace ts.projectSystem { { start: { line: 3, offset: 2 }, end: { line: 3, offset: 2 }, - newText: "\nfunction newFunction() {\n 1;\n}\n", + newText: "\n\nfunction newFunction() {\n 1;\n}\n", }, ] } diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 715b42b6bc8..ebe0cb4fa44 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -785,7 +785,10 @@ namespace ts.refactor.extractSymbol { changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newFunction, { suffix: context.newLineCharacter + context.newLineCharacter }); } else { - changeTracker.insertNodeBefore(context.file, scope.getLastToken(), newFunction, { prefix: context.newLineCharacter, suffix: context.newLineCharacter }); + changeTracker.insertNodeBefore(context.file, scope.getLastToken(), newFunction, { + prefix: isLineBreak(file.text.charCodeAt(scope.getLastToken().pos)) ? context.newLineCharacter : context.newLineCharacter + context.newLineCharacter, + suffix: context.newLineCharacter + }); } const newNodes: Node[] = []; diff --git a/tests/baselines/reference/extractFunction/extractFunction1.ts b/tests/baselines/reference/extractFunction/extractFunction1.ts index 8243644e1ef..4b0b7dd9f2e 100644 --- a/tests/baselines/reference/extractFunction/extractFunction1.ts +++ b/tests/baselines/reference/extractFunction/extractFunction1.ts @@ -89,6 +89,7 @@ namespace A { } } } + function newFunction(x: number, a: number, foo: () => void) { let y = 5; let z = x; diff --git a/tests/baselines/reference/extractFunction/extractFunction10.ts b/tests/baselines/reference/extractFunction/extractFunction10.ts index a15381c1a18..99651f03e88 100644 --- a/tests/baselines/reference/extractFunction/extractFunction10.ts +++ b/tests/baselines/reference/extractFunction/extractFunction10.ts @@ -49,6 +49,7 @@ namespace A { } } } + function newFunction() { let a1: A.I = { x: 1 }; return a1.x + 10; diff --git a/tests/baselines/reference/extractFunction/extractFunction11.ts b/tests/baselines/reference/extractFunction/extractFunction11.ts index 4bb88123a2f..baca3914b03 100644 --- a/tests/baselines/reference/extractFunction/extractFunction11.ts +++ b/tests/baselines/reference/extractFunction/extractFunction11.ts @@ -61,6 +61,7 @@ namespace A { } } } + function newFunction(y: number, z: number) { let a1 = { x: 1 }; y = 10; diff --git a/tests/baselines/reference/extractFunction/extractFunction13.ts b/tests/baselines/reference/extractFunction/extractFunction13.ts index 662701ebf41..e39476160c5 100644 --- a/tests/baselines/reference/extractFunction/extractFunction13.ts +++ b/tests/baselines/reference/extractFunction/extractFunction13.ts @@ -66,6 +66,7 @@ } } } + function newFunction(t1a: T1a, t2a: T2a, u1a: U1a, u2a: U2a, u3a: U3a) { t1a.toString(); t2a.toString(); diff --git a/tests/baselines/reference/extractFunction/extractFunction14.ts b/tests/baselines/reference/extractFunction/extractFunction14.ts index 53cabbe600f..86f8c9b5b63 100644 --- a/tests/baselines/reference/extractFunction/extractFunction14.ts +++ b/tests/baselines/reference/extractFunction/extractFunction14.ts @@ -33,6 +33,7 @@ function F(t1: T) { /*RENAME*/newFunction(t1, t2); } } + function newFunction(t1: T, t2: T) { t1.toString(); t2.toString(); diff --git a/tests/baselines/reference/extractFunction/extractFunction15.ts b/tests/baselines/reference/extractFunction/extractFunction15.ts index a09383282aa..3b291f4d86c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction15.ts +++ b/tests/baselines/reference/extractFunction/extractFunction15.ts @@ -30,6 +30,7 @@ function F(t1: T) { /*RENAME*/newFunction(t2); } } + function newFunction(t2: U) { t2.toString(); } diff --git a/tests/baselines/reference/extractFunction/extractFunction16.ts b/tests/baselines/reference/extractFunction/extractFunction16.ts index 79c72f31198..5800fa6945b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction16.ts +++ b/tests/baselines/reference/extractFunction/extractFunction16.ts @@ -14,6 +14,7 @@ function F() { function F() { const array: T[] = /*RENAME*/newFunction(); } + function newFunction(): T[] { return []; } diff --git a/tests/baselines/reference/extractFunction/extractFunction17.ts b/tests/baselines/reference/extractFunction/extractFunction17.ts index 733b1b27623..45d9953fb95 100644 --- a/tests/baselines/reference/extractFunction/extractFunction17.ts +++ b/tests/baselines/reference/extractFunction/extractFunction17.ts @@ -20,6 +20,7 @@ class C { /*RENAME*/newFunction(t1); } } + function newFunction(t1: T1) { t1.toString(); } diff --git a/tests/baselines/reference/extractFunction/extractFunction18.ts b/tests/baselines/reference/extractFunction/extractFunction18.ts index 8c44de12981..bdfcce6bbdc 100644 --- a/tests/baselines/reference/extractFunction/extractFunction18.ts +++ b/tests/baselines/reference/extractFunction/extractFunction18.ts @@ -20,6 +20,7 @@ class C { /*RENAME*/newFunction(t1); } } + function newFunction(t1: T1) { t1.toString(); } diff --git a/tests/baselines/reference/extractFunction/extractFunction19.ts b/tests/baselines/reference/extractFunction/extractFunction19.ts index 3a2723513f4..0b3192a49fb 100644 --- a/tests/baselines/reference/extractFunction/extractFunction19.ts +++ b/tests/baselines/reference/extractFunction/extractFunction19.ts @@ -14,6 +14,7 @@ function F(v: V) { function F(v: V) { /*RENAME*/newFunction(v); } + function newFunction(v: V) { v.toString(); } diff --git a/tests/baselines/reference/extractFunction/extractFunction2.ts b/tests/baselines/reference/extractFunction/extractFunction2.ts index 3872812b312..be72a7fd52f 100644 --- a/tests/baselines/reference/extractFunction/extractFunction2.ts +++ b/tests/baselines/reference/extractFunction/extractFunction2.ts @@ -78,6 +78,7 @@ namespace A { } } } + function newFunction(x: number, foo: () => void) { let y = 5; let z = x; diff --git a/tests/baselines/reference/extractFunction/extractFunction20.js b/tests/baselines/reference/extractFunction/extractFunction20.js index b65d3dae5da..17bef1c6044 100644 --- a/tests/baselines/reference/extractFunction/extractFunction20.js +++ b/tests/baselines/reference/extractFunction/extractFunction20.js @@ -22,6 +22,7 @@ const _ = class { return /*RENAME*/newFunction(); } } + function newFunction() { let a1 = { x: 1 }; return a1.x + 10; diff --git a/tests/baselines/reference/extractFunction/extractFunction20.ts b/tests/baselines/reference/extractFunction/extractFunction20.ts index 1fe72020ad7..ce09d4457d3 100644 --- a/tests/baselines/reference/extractFunction/extractFunction20.ts +++ b/tests/baselines/reference/extractFunction/extractFunction20.ts @@ -22,6 +22,7 @@ const _ = class { return /*RENAME*/newFunction(); } } + function newFunction() { let a1 = { x: 1 }; return a1.x + 10; diff --git a/tests/baselines/reference/extractFunction/extractFunction21.js b/tests/baselines/reference/extractFunction/extractFunction21.js index 4454f36ac62..08c4512fee7 100644 --- a/tests/baselines/reference/extractFunction/extractFunction21.js +++ b/tests/baselines/reference/extractFunction/extractFunction21.js @@ -20,6 +20,7 @@ function foo() { x = /*RENAME*/newFunction(x); return; } + function newFunction(x) { x++; return x; diff --git a/tests/baselines/reference/extractFunction/extractFunction21.ts b/tests/baselines/reference/extractFunction/extractFunction21.ts index 530a10bea95..4adb05f3bf1 100644 --- a/tests/baselines/reference/extractFunction/extractFunction21.ts +++ b/tests/baselines/reference/extractFunction/extractFunction21.ts @@ -20,6 +20,7 @@ function foo() { x = /*RENAME*/newFunction(x); return; } + function newFunction(x: number) { x++; return x; diff --git a/tests/baselines/reference/extractFunction/extractFunction22.js b/tests/baselines/reference/extractFunction/extractFunction22.js index 60891105c6e..0fb69c87b04 100644 --- a/tests/baselines/reference/extractFunction/extractFunction22.js +++ b/tests/baselines/reference/extractFunction/extractFunction22.js @@ -26,6 +26,7 @@ function test() { return /*RENAME*/newFunction(); } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction22.ts b/tests/baselines/reference/extractFunction/extractFunction22.ts index 60891105c6e..0fb69c87b04 100644 --- a/tests/baselines/reference/extractFunction/extractFunction22.ts +++ b/tests/baselines/reference/extractFunction/extractFunction22.ts @@ -26,6 +26,7 @@ function test() { return /*RENAME*/newFunction(); } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction23.ts b/tests/baselines/reference/extractFunction/extractFunction23.ts index 3092d6490ba..b3730a5b54f 100644 --- a/tests/baselines/reference/extractFunction/extractFunction23.ts +++ b/tests/baselines/reference/extractFunction/extractFunction23.ts @@ -38,6 +38,7 @@ namespace NS { } function M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction24.js b/tests/baselines/reference/extractFunction/extractFunction24.js index dbac567afc6..2c1d353f51a 100644 --- a/tests/baselines/reference/extractFunction/extractFunction24.js +++ b/tests/baselines/reference/extractFunction/extractFunction24.js @@ -38,6 +38,7 @@ function Outer() { } function M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction24.ts b/tests/baselines/reference/extractFunction/extractFunction24.ts index dbac567afc6..2c1d353f51a 100644 --- a/tests/baselines/reference/extractFunction/extractFunction24.ts +++ b/tests/baselines/reference/extractFunction/extractFunction24.ts @@ -38,6 +38,7 @@ function Outer() { } function M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction26.js b/tests/baselines/reference/extractFunction/extractFunction26.js index c05af641d4b..2c821c05ad1 100644 --- a/tests/baselines/reference/extractFunction/extractFunction26.js +++ b/tests/baselines/reference/extractFunction/extractFunction26.js @@ -26,6 +26,7 @@ class C { } M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction26.ts b/tests/baselines/reference/extractFunction/extractFunction26.ts index 37eba24bfde..300686c12ab 100644 --- a/tests/baselines/reference/extractFunction/extractFunction26.ts +++ b/tests/baselines/reference/extractFunction/extractFunction26.ts @@ -26,6 +26,7 @@ class C { } M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction27.js b/tests/baselines/reference/extractFunction/extractFunction27.js index 96bca6b24c5..702127b9d76 100644 --- a/tests/baselines/reference/extractFunction/extractFunction27.js +++ b/tests/baselines/reference/extractFunction/extractFunction27.js @@ -29,6 +29,7 @@ class C { constructor() { } M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction27.ts b/tests/baselines/reference/extractFunction/extractFunction27.ts index 335d74e002d..1acbe67707a 100644 --- a/tests/baselines/reference/extractFunction/extractFunction27.ts +++ b/tests/baselines/reference/extractFunction/extractFunction27.ts @@ -29,6 +29,7 @@ class C { constructor() { } M3() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction28.js b/tests/baselines/reference/extractFunction/extractFunction28.js index a82b864448d..cf0742626dd 100644 --- a/tests/baselines/reference/extractFunction/extractFunction28.js +++ b/tests/baselines/reference/extractFunction/extractFunction28.js @@ -29,6 +29,7 @@ class C { M3() { } constructor() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction28.ts b/tests/baselines/reference/extractFunction/extractFunction28.ts index bde2661f934..f15d7956f1c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction28.ts +++ b/tests/baselines/reference/extractFunction/extractFunction28.ts @@ -29,6 +29,7 @@ class C { M3() { } constructor() { } } + function newFunction() { return 1; } diff --git a/tests/baselines/reference/extractFunction/extractFunction3.ts b/tests/baselines/reference/extractFunction/extractFunction3.ts index 9c4c1aaa9d7..7a481e76cfa 100644 --- a/tests/baselines/reference/extractFunction/extractFunction3.ts +++ b/tests/baselines/reference/extractFunction/extractFunction3.ts @@ -73,6 +73,7 @@ namespace A { } } } + function* newFunction(z: number, foo: () => void) { let y = 5; yield z; diff --git a/tests/baselines/reference/extractFunction/extractFunction30.ts b/tests/baselines/reference/extractFunction/extractFunction30.ts index b57b48c30a9..f90548c333c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction30.ts +++ b/tests/baselines/reference/extractFunction/extractFunction30.ts @@ -14,6 +14,7 @@ function F() { function F() { /*RENAME*/newFunction(); } + function newFunction() { let t: T; } diff --git a/tests/baselines/reference/extractFunction/extractFunction31.ts b/tests/baselines/reference/extractFunction/extractFunction31.ts index d7252a14011..2dea17689b6 100644 --- a/tests/baselines/reference/extractFunction/extractFunction31.ts +++ b/tests/baselines/reference/extractFunction/extractFunction31.ts @@ -37,6 +37,7 @@ namespace N { f = /*RENAME*/newFunction(f); } } + function newFunction(f: () => number) { f = function(): number { return N.value; diff --git a/tests/baselines/reference/extractFunction/extractFunction32.ts b/tests/baselines/reference/extractFunction/extractFunction32.ts index 4070763b79f..720d0b227b0 100644 --- a/tests/baselines/reference/extractFunction/extractFunction32.ts +++ b/tests/baselines/reference/extractFunction/extractFunction32.ts @@ -37,6 +37,7 @@ namespace N { /*RENAME*/newFunction(); } } + function newFunction() { var c = class { M() { diff --git a/tests/baselines/reference/extractFunction/extractFunction33.js b/tests/baselines/reference/extractFunction/extractFunction33.js index 46c0f176b56..cc027a14b6c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction33.js +++ b/tests/baselines/reference/extractFunction/extractFunction33.js @@ -14,6 +14,7 @@ function F() { function F() { /*RENAME*/newFunction(); } + function newFunction() { function G() { } } diff --git a/tests/baselines/reference/extractFunction/extractFunction33.ts b/tests/baselines/reference/extractFunction/extractFunction33.ts index 46c0f176b56..cc027a14b6c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction33.ts +++ b/tests/baselines/reference/extractFunction/extractFunction33.ts @@ -14,6 +14,7 @@ function F() { function F() { /*RENAME*/newFunction(); } + function newFunction() { function G() { } } diff --git a/tests/baselines/reference/extractFunction/extractFunction4.ts b/tests/baselines/reference/extractFunction/extractFunction4.ts index 4108976b6b3..46aad65c68c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction4.ts +++ b/tests/baselines/reference/extractFunction/extractFunction4.ts @@ -81,6 +81,7 @@ namespace A { } } } + async function newFunction(z: number, z1: any, foo: () => void) { let y = 5; if (z) { diff --git a/tests/baselines/reference/extractFunction/extractFunction5.ts b/tests/baselines/reference/extractFunction/extractFunction5.ts index 3122ba24553..085a73fdf93 100644 --- a/tests/baselines/reference/extractFunction/extractFunction5.ts +++ b/tests/baselines/reference/extractFunction/extractFunction5.ts @@ -89,6 +89,7 @@ namespace A { } } } + function newFunction(x: number, a: number) { let y = 5; let z = x; diff --git a/tests/baselines/reference/extractFunction/extractFunction6.ts b/tests/baselines/reference/extractFunction/extractFunction6.ts index a01cb25e061..613635c658a 100644 --- a/tests/baselines/reference/extractFunction/extractFunction6.ts +++ b/tests/baselines/reference/extractFunction/extractFunction6.ts @@ -93,6 +93,7 @@ namespace A { } } } + function newFunction(x: number, a: number) { let y = 5; let z = x; diff --git a/tests/baselines/reference/extractFunction/extractFunction7.ts b/tests/baselines/reference/extractFunction/extractFunction7.ts index 4111558904c..0f57a0cfba8 100644 --- a/tests/baselines/reference/extractFunction/extractFunction7.ts +++ b/tests/baselines/reference/extractFunction/extractFunction7.ts @@ -103,6 +103,7 @@ namespace A { } } } + function newFunction(x: number, a: number) { let y = 5; let z = x; diff --git a/tests/baselines/reference/extractFunction/extractFunction9.ts b/tests/baselines/reference/extractFunction/extractFunction9.ts index 7db12096cbc..3df391c1fae 100644 --- a/tests/baselines/reference/extractFunction/extractFunction9.ts +++ b/tests/baselines/reference/extractFunction/extractFunction9.ts @@ -59,6 +59,7 @@ namespace A { } } } + function newFunction() { let a1: A.I = { x: 1 }; return a1.x + 10; diff --git a/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.js b/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.js index b5e4bc76c6e..b10a04e9ef0 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.js +++ b/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.js @@ -12,6 +12,7 @@ var q = /*b*/ //c var q = /*b*/ //c /*d*/ /*RENAME*/newFunction() /*k*/ //l /*m*/; /*n*/ //o + function newFunction() { return 1 /*e*/ //f /*g*/ + /*h*/ //i diff --git a/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.ts b/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.ts index b5e4bc76c6e..b10a04e9ef0 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_PreserveTrivia.ts @@ -12,6 +12,7 @@ var q = /*b*/ //c var q = /*b*/ //c /*d*/ /*RENAME*/newFunction() /*k*/ //l /*m*/; /*n*/ //o + function newFunction() { return 1 /*e*/ //f /*g*/ + /*h*/ //i diff --git a/tests/baselines/reference/extractFunction/extractFunction_RepeatedSubstitution.ts b/tests/baselines/reference/extractFunction/extractFunction_RepeatedSubstitution.ts index 68cc7d2248a..52ccce68059 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_RepeatedSubstitution.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_RepeatedSubstitution.ts @@ -17,6 +17,7 @@ namespace X { export const j = 10; export const y = /*RENAME*/newFunction(); } + function newFunction() { return X.j * X.j; } diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.js index 67b4f64290c..e8250613625 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.js @@ -21,6 +21,7 @@ function f() { let x = /*RENAME*/newFunction(); return { x }; } + function newFunction() { let x; return x; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.ts index 67b4f64290c..e8250613625 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_ShorthandProperty.ts @@ -21,6 +21,7 @@ function f() { let x = /*RENAME*/newFunction(); return { x }; } + function newFunction() { let x; return x; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.js index 1da5a568333..a8629d2907c 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.js @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a) { const x = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.ts index f93f43ceebf..c70dbe95c7b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_NoType.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { const x = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_Type.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_Type.ts index ec846f7f288..3c0912061aa 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_Type.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Const_Type.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { const x: number = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType1.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType1.ts index 50bad34efce..06de0fd4f36 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType1.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType1.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { let x: 0o10 | 10 | 0b10 = 10; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType2.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType2.ts index 2df8ab67e9f..4679b89f068 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType2.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_LiteralType2.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { let x: "a" | 'b' = 'a'; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.js index 2f298c8719f..a86870d72a3 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.js @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a) { let x = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.ts index e4afefa9da6..9b711765c95 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_NoType.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { let x = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_Type.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_Type.ts index 795effbeb7e..652faab4890 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_Type.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_Type.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { let x: number = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_TypeWithComments.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_TypeWithComments.ts index 53599c26d08..71c4d9b79ff 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_TypeWithComments.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Let_TypeWithComments.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { let x: /*A*/ "a" /*B*/ | /*C*/ 'b' /*D*/ = 'a'; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.js index c36557847f7..5de10b2cf76 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.js @@ -30,6 +30,7 @@ function f() { ({ x, y, a } = /*RENAME*/newFunction(a)); a; x; y; } + function newFunction(a) { const x = 1; let y = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.ts index eaeb781bc48..d4da8ffca7b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed1.ts @@ -30,6 +30,7 @@ function f() { ({ x, y, a } = /*RENAME*/newFunction(a)); a; x; y; } + function newFunction(a: number) { const x = 1; let y = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.js index 2d1151a549c..e1526a77ffd 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.js @@ -30,6 +30,7 @@ function f() { ({ x, y, a } = /*RENAME*/newFunction(a)); a; x; y; } + function newFunction(a) { var x = 1; let y = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.ts index 9466b5dc37f..ec3d62c039b 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed2.ts @@ -30,6 +30,7 @@ function f() { ({ x, y, a } = /*RENAME*/newFunction(a)); a; x; y; } + function newFunction(a: number) { var x = 1; let y = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts index 604d2a33c43..b2c53e3f160 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Mixed3.ts @@ -30,6 +30,7 @@ function f() { ({ x, y, a } = /*RENAME*/newFunction(a)); a; x; y; } + function newFunction(a: number) { let x: number = 1; let y = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts index 0cf71e45e28..b76bf6c4999 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_UnionUndefined.ts @@ -33,6 +33,7 @@ function f() { ({ x, y, z, a } = /*RENAME*/newFunction(a)); a; x; y; z; } + function newFunction(a: number) { let x: number | undefined = 1; let y: undefined | number = 2; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.js b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.js index 25e910713d8..6a7b821e5b1 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.js +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.js @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a) { var x = 1; a++; diff --git a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.ts b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.ts index e215e3d0978..e9cbe7ad345 100644 --- a/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.ts +++ b/tests/baselines/reference/extractFunction/extractFunction_VariableDeclaration_Writes_Var.ts @@ -27,6 +27,7 @@ function f() { ({ x, a } = /*RENAME*/newFunction(a)); a; x; } + function newFunction(a: number) { var x = 1; a++; diff --git a/tests/cases/fourslash/extract-method-empty-namespace.ts b/tests/cases/fourslash/extract-method-empty-namespace.ts index bef4cdd12fe..1655efccbb8 100644 --- a/tests/cases/fourslash/extract-method-empty-namespace.ts +++ b/tests/cases/fourslash/extract-method-empty-namespace.ts @@ -12,6 +12,7 @@ edit.applyRefactor({ newContent: `function f() { /*RENAME*/newFunction(); } + function newFunction() { namespace N { } } diff --git a/tests/cases/fourslash/extract-method-formatting.ts b/tests/cases/fourslash/extract-method-formatting.ts index d4c2836e815..d1f550f794e 100644 --- a/tests/cases/fourslash/extract-method-formatting.ts +++ b/tests/cases/fourslash/extract-method-formatting.ts @@ -13,6 +13,7 @@ edit.applyRefactor({ newContent: `function f(x: number): number { return /*RENAME*/newFunction(x); } + function newFunction(x: number) { switch (x) { case 0: diff --git a/tests/cases/fourslash/extract-method-uniqueName.ts b/tests/cases/fourslash/extract-method-uniqueName.ts index da4c68cfb7e..a02b2c5ec96 100644 --- a/tests/cases/fourslash/extract-method-uniqueName.ts +++ b/tests/cases/fourslash/extract-method-uniqueName.ts @@ -13,6 +13,7 @@ edit.applyRefactor({ newContent: `// newFunction /*RENAME*/newFunction_1(); + function newFunction_1() { 1 + 1; } diff --git a/tests/cases/fourslash/extract-method10.ts b/tests/cases/fourslash/extract-method10.ts index ed92e6b06ac..d2b9aeb0123 100644 --- a/tests/cases/fourslash/extract-method10.ts +++ b/tests/cases/fourslash/extract-method10.ts @@ -11,6 +11,7 @@ edit.applyRefactor({ newContent: `export {}; // Make this a module (x => x)(/*RENAME*/newFunction())(1); + function newFunction(): (x: any) => any { return x => x; } diff --git a/tests/cases/fourslash/extract-method14.ts b/tests/cases/fourslash/extract-method14.ts index ddfd8cbcbd6..11ea1f1b3fd 100644 --- a/tests/cases/fourslash/extract-method14.ts +++ b/tests/cases/fourslash/extract-method14.ts @@ -22,6 +22,7 @@ edit.applyRefactor({ ({ __return, i } = /*RENAME*/newFunction(i)); return __return; } + function newFunction(i) { return { __return: i++, i }; } diff --git a/tests/cases/fourslash/extract-method15.ts b/tests/cases/fourslash/extract-method15.ts index e46ff39ad6a..1b33a46b9a4 100644 --- a/tests/cases/fourslash/extract-method15.ts +++ b/tests/cases/fourslash/extract-method15.ts @@ -18,6 +18,7 @@ edit.applyRefactor({ var i = 10; i = /*RENAME*/newFunction(i); } + function newFunction(i: number) { i++; return i; diff --git a/tests/cases/fourslash/extract-method18.ts b/tests/cases/fourslash/extract-method18.ts index d53e79f4930..0a488a04106 100644 --- a/tests/cases/fourslash/extract-method18.ts +++ b/tests/cases/fourslash/extract-method18.ts @@ -18,6 +18,7 @@ edit.applyRefactor({ const x = { m: 1 }; /*RENAME*/newFunction(x); } + function newFunction(x: { m: number; }) { x.m = 3; } diff --git a/tests/cases/fourslash/extract-method2.ts b/tests/cases/fourslash/extract-method2.ts index 7f197d4775b..419d6379075 100644 --- a/tests/cases/fourslash/extract-method2.ts +++ b/tests/cases/fourslash/extract-method2.ts @@ -24,6 +24,7 @@ edit.applyRefactor({ } } } + function newFunction(m: number, j: string, k: { x: string; }) { return m + j + k; } diff --git a/tests/cases/fourslash/extract-method24.ts b/tests/cases/fourslash/extract-method24.ts index 8c750edd9f9..66ca5ecb227 100644 --- a/tests/cases/fourslash/extract-method24.ts +++ b/tests/cases/fourslash/extract-method24.ts @@ -17,6 +17,7 @@ edit.applyRefactor({ let x = 0; console.log(/*RENAME*/newFunction(a, x)); } + function newFunction(a: number[], x: number): any { return a[x]; } diff --git a/tests/cases/fourslash/extract-method7.ts b/tests/cases/fourslash/extract-method7.ts index 2998b6bbee3..38bc86cb5dc 100644 --- a/tests/cases/fourslash/extract-method7.ts +++ b/tests/cases/fourslash/extract-method7.ts @@ -14,6 +14,7 @@ edit.applyRefactor({ newContent: `function fn(x = /*RENAME*/newFunction()) { } + function newFunction() { return 3; }