File: typeExtractionDoesNotDuplicateTrailingComment.ts

package info (click to toggle)
node-typescript 4.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 396,552 kB
  • sloc: javascript: 1,444,377; makefile: 7; sh: 3
file content (67 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (5)
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
63
64
65
66
67
/// <reference path='fourslash.ts' />
/// Doesn't duplicate comments - #31629

//// type a = /*a*/{ x: string } /* foo */ | string /* bar *//*b*/;
//// type b = /*c*//* leading */{ x: string } /* trailing *//*d*/;
//// type c = /*e*/{ x: string } /* inner */ | string// trailing/*f*/
////

goTo.select("a", "b");
edit.applyRefactor({
  refactorName: "Extract type",
  actionName: "Extract to type alias",
  actionDescription: "Extract to type alias",
  newContent: `type /*RENAME*/NewType = {
    x: string;
} /* foo */ | string /* bar */;

type a = NewType;
type b = /* leading */{ x: string } /* trailing */;
type c = { x: string } /* inner */ | string// trailing
`,
});

// Extract to interface
goTo.select("c", "d");
edit.applyRefactor({
  refactorName: "Extract type",
  actionName: "Extract to interface",
  actionDescription: "Extract to interface",
  newContent: `type NewType = {
    x: string;
} /* foo */ | string /* bar */;

type a = NewType;
interface /*RENAME*/NewType_1 {
    x: string;
} /* trailing */

type b = /* leading */NewType_1;
type c = { x: string } /* inner */ | string// trailing
`,
});

// Trailing comment using '//'
goTo.select("e", "f");
edit.applyRefactor({
  refactorName: "Extract type",
  actionName: "Extract to type alias",
  actionDescription: "Extract to type alias",
  newContent: `type NewType = {
    x: string;
} /* foo */ | string /* bar */;

type a = NewType;
interface NewType_1 {
    x: string;
} /* trailing */

type b = /* leading */NewType_1;
type /*RENAME*/NewType_2 = {
    x: string;
} /* inner */ | string // trailing
    ;

type c = NewType_2
`,
});