The example code at Private fields works as expected but the editor complains visually upon encountering a # symbol… the rest of the line is highlighted in red.
Is there a directive I could insert to prevent the lint functionality from visually complaining? Or is this a limitation of the current editor implementation?
Thanks!
Fabio
mnse
June 9, 2022, 8:46pm
2
Hi @fabiopettinati ,
Maybe you can check here and/or raise an issue…
p5.js-web-editor/issues
Cheers
— mnse
Hi @fabiopettinati ,
Looking at the p5-web-editor
code, I found that they use CodeMirror which is a code editor written in JavaScript.
For the private fields, looks like the issue has already been solved in 2020 on their GitHub repository:
opened 10:07AM - 27 Apr 20 UTC
closed 09:08AM - 28 Apr 20 UTC
Private fields (https://v8.dev/features/class-fields) use a `#` at the start of … the field declaration in a class. CodeMirror currently doesn't highlight these private fields as fields and its syntax highlighting marks the whole line as red. Example
```js
class Project {
#id;
constructor(name) {
this.name = name;
this.#id = Math.random();
}
get id() {
return this.#id;
}
#setId(id) {
this.#id = id;
}
aMethod() {}
static fromStore(id, name) {
const proj = new Project(name);
proj.#setId(id);
proj.aMethod();
return proj;
}
}
```
Current syntax highlighting:
<img width="318" alt="Screenshot 2020-04-27 at 11 01 05" src="https://user-images.githubusercontent.com/5948271/80359893-6cbc0000-8876-11ea-966b-ac0dcecffbbf.png">
(Code was pasted on https://codemirror.net/mode/javascript/index.html)
The expected syntax highlighting here is that private fields have the same color as normal fields (e.g. `name` in this example).
Downstream issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1073903
The thing is that p5-web-editor
uses codemirror ^5.62.0
which may not be up to date with the latest package .
As @mnse said, you can open an issue on the p5 editor repository.
2 Likes
Thanks to @mnse and @josephh for replying. I’ve opened an issue in the editor repository.
Syntax highlighting still not working for private fields (supported in ES2022)#2031
1 Like