File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,22 @@ function postprocess(ast, options) {
2727 } ) ;
2828 }
2929 break ;
30+ case "EnumDeclaration" :
31+ // A workaround for what looks like a bug in Flow.
32+ // Flow assigns the same range to enum nodes and enum body nodes.
33+ if (
34+ options . parser === "flow" &&
35+ node . body . range [ 0 ] === node . range [ 0 ] &&
36+ node . body . range [ 1 ] === node . range [ 1 ]
37+ ) {
38+ node . body . range = [ node . id . range [ 1 ] , node . range [ 1 ] - 1 ] ;
39+ }
40+ // Babel does strange things as well. E.g. node.body.start > node.body.end can be true.
41+ if ( options . parser === "babel-flow" ) {
42+ node . body . start = node . id . end ;
43+ node . body . end = node . end - 1 ;
44+ }
45+ break ;
3046 }
3147 } ) ;
3248
Original file line number Diff line number Diff line change @@ -50,6 +50,72 @@ enum E {
5050================================================================================
5151` ;
5252
53+ exports [` enum-comments.js 1` ] = `
54+ ====================================options=====================================
55+ parsers: ["flow", "babel-flow"]
56+ printWidth: 80
57+ trailingComma: "all"
58+ | printWidth
59+ =====================================input======================================
60+ enum E1 {
61+ A = 0 ,
62+ // B = 1,
63+ C = 2
64+ }
65+
66+ enum E2 of number {
67+ // AA = -1,
68+ A = 0 ,
69+ // B = 1,
70+ C = 2
71+ // D = 100
72+ }
73+
74+ enum E3 { /* Q*/ }
75+
76+ enum E4 of /*Q*/ string {
77+ Foo = " foo"
78+ }
79+
80+ enum E5 of string { // Q
81+ Bar = " bar"
82+ }
83+
84+ enum /*Q*/ E6 of string { }
85+
86+ =====================================output=====================================
87+ enum E1 {
88+ A = 0 ,
89+ // B = 1,
90+ C = 2 ,
91+ }
92+
93+ enum E2 of number {
94+ // AA = -1,
95+ A = 0 ,
96+ // B = 1,
97+ C = 2 ,
98+ // D = 100
99+ }
100+
101+ enum E3 {
102+ /* Q*/
103+ }
104+
105+ enum E4 of string {
106+ /* Q*/ Foo = " foo" ,
107+ }
108+
109+ enum E5 of string {
110+ // Q
111+ Bar = " bar" ,
112+ }
113+
114+ enum /*Q*/ E6 of string { }
115+
116+ ================================================================================
117+ ` ;
118+
53119exports [` enum-empty.js 1` ] = `
54120====================================options=====================================
55121parsers: ["flow", "babel-flow"]
Original file line number Diff line number Diff line change 1+ enum E1 {
2+ A = 0 ,
3+ // B = 1,
4+ C = 2
5+ }
6+
7+ enum E2 of number {
8+ // AA = -1,
9+ A = 0 ,
10+ // B = 1,
11+ C = 2
12+ // D = 100
13+ }
14+
15+ enum E3 { /*Q*/ }
16+
17+ enum E4 of /*Q*/ string {
18+ Foo = "foo"
19+ }
20+
21+ enum E5 of string { // Q
22+ Bar = "bar"
23+ }
24+
25+ enum /*Q*/ E6 of string { }
You can’t perform that action at this time.
0 commit comments