1
1
/// <reference path="extractTestHelpers.ts" />
2
2
3
3
namespace ts {
4
- describe ( "extractMethods " , ( ) => {
5
- testExtractMethod ( "extractMethod1 ",
4
+ describe ( "extractFunctions " , ( ) => {
5
+ testExtractFunction ( "extractFunction1 ",
6
6
`namespace A {
7
7
let x = 1;
8
8
function foo() {
@@ -18,7 +18,7 @@ namespace ts {
18
18
}
19
19
}
20
20
}` ) ;
21
- testExtractMethod ( "extractMethod2 ",
21
+ testExtractFunction ( "extractFunction2 ",
22
22
`namespace A {
23
23
let x = 1;
24
24
function foo() {
@@ -32,7 +32,7 @@ namespace ts {
32
32
}
33
33
}
34
34
}` ) ;
35
- testExtractMethod ( "extractMethod3 ",
35
+ testExtractFunction ( "extractFunction3 ",
36
36
`namespace A {
37
37
function foo() {
38
38
}
@@ -45,7 +45,7 @@ namespace ts {
45
45
}
46
46
}
47
47
}` ) ;
48
- testExtractMethod ( "extractMethod4 ",
48
+ testExtractFunction ( "extractFunction4 ",
49
49
`namespace A {
50
50
function foo() {
51
51
}
@@ -60,7 +60,7 @@ namespace ts {
60
60
}
61
61
}
62
62
}` ) ;
63
- testExtractMethod ( "extractMethod5 ",
63
+ testExtractFunction ( "extractFunction5 ",
64
64
`namespace A {
65
65
let x = 1;
66
66
export function foo() {
@@ -76,7 +76,7 @@ namespace ts {
76
76
}
77
77
}
78
78
}` ) ;
79
- testExtractMethod ( "extractMethod6 ",
79
+ testExtractFunction ( "extractFunction6 ",
80
80
`namespace A {
81
81
let x = 1;
82
82
export function foo() {
@@ -92,7 +92,7 @@ namespace ts {
92
92
}
93
93
}
94
94
}` ) ;
95
- testExtractMethod ( "extractMethod7 ",
95
+ testExtractFunction ( "extractFunction7 ",
96
96
`namespace A {
97
97
let x = 1;
98
98
export namespace C {
@@ -110,7 +110,7 @@ namespace ts {
110
110
}
111
111
}
112
112
}` ) ;
113
- testExtractMethod ( "extractMethod8 ",
113
+ testExtractFunction ( "extractFunction8 ",
114
114
`namespace A {
115
115
let x = 1;
116
116
namespace B {
@@ -120,7 +120,7 @@ namespace ts {
120
120
}
121
121
}
122
122
}` ) ;
123
- testExtractMethod ( "extractMethod9 ",
123
+ testExtractFunction ( "extractFunction9 ",
124
124
`namespace A {
125
125
export interface I { x: number };
126
126
namespace B {
@@ -130,7 +130,7 @@ namespace ts {
130
130
}
131
131
}
132
132
}` ) ;
133
- testExtractMethod ( "extractMethod10 ",
133
+ testExtractFunction ( "extractFunction10 ",
134
134
`namespace A {
135
135
export interface I { x: number };
136
136
class C {
@@ -141,7 +141,7 @@ namespace ts {
141
141
}
142
142
}
143
143
}` ) ;
144
- testExtractMethod ( "extractMethod11 ",
144
+ testExtractFunction ( "extractFunction11 ",
145
145
`namespace A {
146
146
let y = 1;
147
147
class C {
@@ -154,7 +154,7 @@ namespace ts {
154
154
}
155
155
}
156
156
}` ) ;
157
- testExtractMethod ( "extractMethod12 ",
157
+ testExtractFunction ( "extractFunction12 ",
158
158
`namespace A {
159
159
let y = 1;
160
160
class C {
@@ -174,7 +174,7 @@ namespace ts {
174
174
// In all cases, we could use type inference, rather than passing explicit type arguments.
175
175
// Note the inclusion of arrow functions to ensure that some type parameters are not from
176
176
// targetable scopes.
177
- testExtractMethod ( "extractMethod13 ",
177
+ testExtractFunction ( "extractFunction13 ",
178
178
`<U1a, U1b>(u1a: U1a, u1b: U1b) => {
179
179
function F1<T1a, T1b>(t1a: T1a, t1b: T1b) {
180
180
<U2a, U2b>(u2a: U2a, u2b: U2b) => {
@@ -192,61 +192,61 @@ namespace ts {
192
192
}` ) ;
193
193
// This test is descriptive, rather than normative. The current implementation
194
194
// doesn't handle type parameter shadowing.
195
- testExtractMethod ( "extractMethod14 ",
195
+ testExtractFunction ( "extractFunction14 ",
196
196
`function F<T>(t1: T) {
197
197
function G<T>(t2: T) {
198
198
[#|t1.toString();
199
199
t2.toString();|]
200
200
}
201
201
}` ) ;
202
202
// Confirm that the constraint is preserved.
203
- testExtractMethod ( "extractMethod15 ",
203
+ testExtractFunction ( "extractFunction15 ",
204
204
`function F<T>(t1: T) {
205
205
function G<U extends T[]>(t2: U) {
206
206
[#|t2.toString();|]
207
207
}
208
208
}` ) ;
209
209
// Confirm that the contextual type of an extracted expression counts as a use.
210
- testExtractMethod ( "extractMethod16 ",
210
+ testExtractFunction ( "extractFunction16 ",
211
211
`function F<T>() {
212
212
const array: T[] = [#|[]|];
213
213
}` ) ;
214
214
// Class type parameter
215
- testExtractMethod ( "extractMethod17 ",
215
+ testExtractFunction ( "extractFunction17 ",
216
216
`class C<T1, T2> {
217
217
M(t1: T1, t2: T2) {
218
218
[#|t1.toString()|];
219
219
}
220
220
}` ) ;
221
- // Method type parameter
222
- testExtractMethod ( "extractMethod18 ",
221
+ // Function type parameter
222
+ testExtractFunction ( "extractFunction18 ",
223
223
`class C {
224
224
M<T1, T2>(t1: T1, t2: T2) {
225
225
[#|t1.toString()|];
226
226
}
227
227
}` ) ;
228
228
// Coupled constraints
229
- testExtractMethod ( "extractMethod19 ",
229
+ testExtractFunction ( "extractFunction19 ",
230
230
`function F<T, U extends T[], V extends U[]>(v: V) {
231
231
[#|v.toString()|];
232
232
}` ) ;
233
233
234
- testExtractMethod ( "extractMethod20 ",
234
+ testExtractFunction ( "extractFunction20 ",
235
235
`const _ = class {
236
236
a() {
237
237
[#|let a1 = { x: 1 };
238
238
return a1.x + 10;|]
239
239
}
240
240
}` ) ;
241
241
// Write + void return
242
- testExtractMethod ( "extractMethod21 ",
242
+ testExtractFunction ( "extractFunction21 ",
243
243
`function foo() {
244
244
let x = 10;
245
245
[#|x++;
246
246
return;|]
247
247
}` ) ;
248
248
// Return in finally block
249
- testExtractMethod ( "extractMethod22 ",
249
+ testExtractFunction ( "extractFunction22 ",
250
250
`function test() {
251
251
try {
252
252
}
@@ -255,7 +255,7 @@ namespace ts {
255
255
}
256
256
}` ) ;
257
257
// Extraction position - namespace
258
- testExtractMethod ( "extractMethod23 ",
258
+ testExtractFunction ( "extractFunction23 ",
259
259
`namespace NS {
260
260
function M1() { }
261
261
function M2() {
@@ -264,7 +264,7 @@ namespace ts {
264
264
function M3() { }
265
265
}` ) ;
266
266
// Extraction position - function
267
- testExtractMethod ( "extractMethod24 ",
267
+ testExtractFunction ( "extractFunction24 ",
268
268
`function Outer() {
269
269
function M1() { }
270
270
function M2() {
@@ -273,14 +273,14 @@ namespace ts {
273
273
function M3() { }
274
274
}` ) ;
275
275
// Extraction position - file
276
- testExtractMethod ( "extractMethod25 ",
276
+ testExtractFunction ( "extractFunction25 ",
277
277
`function M1() { }
278
278
function M2() {
279
279
[#|return 1;|]
280
280
}
281
281
function M3() { }` ) ;
282
282
// Extraction position - class without ctor
283
- testExtractMethod ( "extractMethod26 ",
283
+ testExtractFunction ( "extractFunction26 ",
284
284
`class C {
285
285
M1() { }
286
286
M2() {
@@ -289,7 +289,7 @@ function M3() { }`);
289
289
M3() { }
290
290
}` ) ;
291
291
// Extraction position - class with ctor in middle
292
- testExtractMethod ( "extractMethod27 ",
292
+ testExtractFunction ( "extractFunction27 ",
293
293
`class C {
294
294
M1() { }
295
295
M2() {
@@ -299,7 +299,7 @@ function M3() { }`);
299
299
M3() { }
300
300
}` ) ;
301
301
// Extraction position - class with ctor at end
302
- testExtractMethod ( "extractMethod28 ",
302
+ testExtractFunction ( "extractFunction28 ",
303
303
`class C {
304
304
M1() { }
305
305
M2() {
@@ -309,7 +309,7 @@ function M3() { }`);
309
309
constructor() { }
310
310
}` ) ;
311
311
// Shorthand property names
312
- testExtractMethod ( "extractMethod29 ",
312
+ testExtractFunction ( "extractFunction29 ",
313
313
`interface UnaryExpression {
314
314
kind: "Unary";
315
315
operator: string;
@@ -328,12 +328,12 @@ function parsePrimaryExpression(): any {
328
328
throw "Not implemented";
329
329
}` ) ;
330
330
// Type parameter as declared type
331
- testExtractMethod ( "extractMethod30 ",
331
+ testExtractFunction ( "extractFunction30 ",
332
332
`function F<T>() {
333
333
[#|let t: T;|]
334
334
}` ) ;
335
335
// Return in nested function
336
- testExtractMethod ( "extractMethod31 ",
336
+ testExtractFunction ( "extractFunction31 ",
337
337
`namespace N {
338
338
339
339
export const value = 1;
@@ -346,7 +346,7 @@ function parsePrimaryExpression(): any {
346
346
}
347
347
}` ) ;
348
348
// Return in nested class
349
- testExtractMethod ( "extractMethod32 ",
349
+ testExtractFunction ( "extractFunction32 ",
350
350
`namespace N {
351
351
352
352
export const value = 1;
@@ -360,20 +360,20 @@ function parsePrimaryExpression(): any {
360
360
}
361
361
}` ) ;
362
362
// Selection excludes leading trivia of declaration
363
- testExtractMethod ( "extractMethod33 ",
363
+ testExtractFunction ( "extractFunction33 ",
364
364
`function F() {
365
365
[#|function G() { }|]
366
366
}` ) ;
367
367
368
368
// TODO (acasey): handle repeated substitution
369
- // testExtractMethod("extractMethod_RepeatedSubstitution ",
369
+ // testExtractFunction("extractFunction_RepeatedSubstitution ",
370
370
// `namespace X {
371
371
// export const j = 10;
372
372
// export const y = [#|j * j|];
373
373
// }`);
374
374
} ) ;
375
375
376
- function testExtractMethod ( caption : string , text : string ) {
377
- testExtractSymbol ( caption , text , "extractMethod " , Diagnostics . Extract_function ) ;
376
+ function testExtractFunction ( caption : string , text : string ) {
377
+ testExtractSymbol ( caption , text , "extractFunction " , Diagnostics . Extract_function ) ;
378
378
}
379
379
}
0 commit comments