Support private class properties
See original GitHub issuePrettier 1.14.3 Playground link
--parser babylon
Input:
// @flow
class Test {
#privateField: number;
constructor() {
this.#privateField = 1;
}
}
Output:
SyntaxError: Unexpected token, expected ";" (4:16)
2 |
3 | class Test {
> 4 | #privateField: number;
| ^
5 |
6 | constructor() {
7 | this.#privateField = 1;
Expected behavior: It should format the code without any error.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Private class features - JavaScript - MDN Web Docs - Mozilla
These features are collectively called private properties. However, constructors cannot be private in JavaScript. To prevent classes from ...
Read more >JavaScript classes: Private class fields | Can I use... Support ...
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and ... JavaScript classes: Private class fields....
Read more >Private properties in JavaScript ES6 classes - Stack Overflow
Short answer, no, there is no native support for private properties with ES6 classes. But you could mimic that behaviour by not attaching...
Read more >Doing it Right: Private Class Properties in JavaScript
Class fields are designed to simplify the process of creating private class properties. The syntax is very simple: add a # before the...
Read more >JavaScript's New Private Class Fields, and How to Use Them
Class fields (also referred to as class properties) aim to deliver simpler constructors with private and static members.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The second is because Flow AST is
whereas the Babylon is
Interestingly, when using the Flow parser instead of Babylon the code parses and prints but generates invalid code:
Prettier 1.14.3 Playground link
Input:
Output:
Second Output: