File: extractFunctionWithSyntheticNodes.ts

package info (click to toggle)
node-typescript 4.8.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 523,068 kB
  • sloc: javascript: 1,735,777; makefile: 7; sh: 1
file content (62 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// <reference path="fourslash.ts" />

// @filename: /project/tsconfig.json
//// {}

// @filename: /project/index.esm.d.ts
//// export declare class Chart {
////     constructor(config: ChartConfiguration);
//// }
//// 
//// export interface ChartConfiguration {
////     options?: Partial<TickOptions>;
//// }
//// 
//// export interface TickOptions {
////     callback: (this: Scale, tickValue: number | string) => string | string[] | number | number[] | null | undefined;
//// }
//// 
//// export interface CoreScaleOptions {
////     opt: boolean;
//// }
////   
//// export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> {
////     opts: O;
////     getLabelForValue(value: number): string;
//// }
  
// @filename: /project/options.ts
//// import { Chart } from './index.esm';
//// 
//// const chart = new Chart({
////     options: {
////         callback(tickValue) {
////             /*a*/const value = this.getLabelForValue(tickValue as number);/*b*/
////             return '$' + value;
////         }
////     }
//// });

goTo.file("/project/options.ts");
verify.noErrors();
goTo.select("a", "b");
edit.applyRefactor({
    refactorName: "Extract Symbol",
    actionName: "function_scope_0",
    actionDescription: "Extract to inner function in method 'callback'",
    newContent:
`import { Chart } from './index.esm';

const chart = new Chart({
    options: {
        callback(tickValue) {
            const value = /*RENAME*/newFunction.call(this);
            return '$' + value;

            function newFunction(this: import("/project/index.esm").Scale<import("/project/index.esm").CoreScaleOptions>) {
                return this.getLabelForValue(tickValue as number);
            }
        }
    }
});`
});