FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve keyword class property print (#13997) · prettier/prettier@985b895 · GitHub

Repository navigation

Commit 985b895

Browse files
authored
Improve keyword class property print (#13997)
1 parent 617f077 commit 985b895

4 files changed

Lines changed: 168 additions & 1 deletion

File tree

‎src/language-js/print/statement.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ const isClassProperty = ({ type }) =>
176176
* @returns {boolean}
177177
*/
178178
function shouldPrintSemicolonAfterClassProperty(node, nextNode) {
179-
const { name } = node.key;
179+
const { type, name } = node.key;
180180
if (
181+
!node.computed &&
182+
type === "Identifier" &&
181183
(name === "static" ||
182184
name === "get" ||
183185
name === "set" ||

‎tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,67 @@ class B {
6161
================================================================================
6262
`;
6363

64+
exports[`computed.js - {"semi":false} format 1`] = `
65+
====================================options=====================================
66+
parsers: ["babel", "flow", "typescript"]
67+
printWidth: 80
68+
semi: false
69+
| printWidth
70+
=====================================input======================================
71+
class B {
72+
[get];
73+
foo() {}
74+
}
75+
76+
class C {
77+
[set];
78+
foo(v) {}
79+
}
80+
81+
=====================================output=====================================
82+
class B {
83+
[get]
84+
foo() {}
85+
}
86+
87+
class C {
88+
[set]
89+
foo(v) {}
90+
}
91+
92+
================================================================================
93+
`;
94+
95+
exports[`computed.js format 1`] = `
96+
====================================options=====================================
97+
parsers: ["babel", "flow", "typescript"]
98+
printWidth: 80
99+
| printWidth
100+
=====================================input======================================
101+
class B {
102+
[get];
103+
foo() {}
104+
}
105+
106+
class C {
107+
[set];
108+
foo(v) {}
109+
}
110+
111+
=====================================output=====================================
112+
class B {
113+
[get];
114+
foo() {}
115+
}
116+
117+
class C {
118+
[set];
119+
foo(v) {}
120+
}
121+
122+
================================================================================
123+
`;
124+
64125
exports[`get.js - {"semi":false} format 1`] = `
65126
====================================options=====================================
66127
parsers: ["babel", "flow", "typescript"]
@@ -122,6 +183,87 @@ class B {
122183
================================================================================
123184
`;
124185

186+
exports[`private.js - {"semi":false} format 1`] = `
187+
====================================options=====================================
188+
parsers: ["babel", "flow", "typescript"]
189+
printWidth: 80
190+
semi: false
191+
| printWidth
192+
=====================================input======================================
193+
class A {
194+
#static;
195+
foo() {}
196+
}
197+
198+
class B {
199+
#get;
200+
foo() {}
201+
}
202+
203+
class C {
204+
#set;
205+
foo(v) {}
206+
}
207+
208+
=====================================output=====================================
209+
class A {
210+
#static
211+
foo() {}
212+
}
213+
214+
class B {
215+
#get
216+
foo() {}
217+
}
218+
219+
class C {
220+
#set
221+
foo(v) {}
222+
}
223+
224+
================================================================================
225+
`;
226+
227+
exports[`private.js format 1`] = `
228+
====================================options=====================================
229+
parsers: ["babel", "flow", "typescript"]
230+
printWidth: 80
231+
| printWidth
232+
=====================================input======================================
233+
class A {
234+
#static;
235+
foo() {}
236+
}
237+
238+
class B {
239+
#get;
240+
foo() {}
241+
}
242+
243+
class C {
244+
#set;
245+
foo(v) {}
246+
}
247+
248+
=====================================output=====================================
249+
class A {
250+
#static;
251+
foo() {}
252+
}
253+
254+
class B {
255+
#get;
256+
foo() {}
257+
}
258+
259+
class C {
260+
#set;
261+
foo(v) {}
262+
}
263+
264+
================================================================================
265+
`;
266+
125267
exports[`set.js - {"semi":false} format 1`] = `
126268
====================================options=====================================
127269
parsers: ["babel", "flow", "typescript"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class B {
2+
[get];
3+
foo() {}
4+
}
5+
6+
class C {
7+
[set];
8+
foo(v) {}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class A {
2+
#static;
3+
foo() {}
4+
}
5+
6+
class B {
7+
#get;
8+
foo() {}
9+
}
10+
11+
class C {
12+
#set;
13+
foo(v) {}
14+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL