Skip to content

Syntax highlighting not working for private fields #6249

Closed
@TimvdLippe

Description

@TimvdLippe

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

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:

Screenshot 2020-04-27 at 11 01 05

(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions