Skip to content

Static properties on classes are currently not supported #160

@JobLeonard

Description

@JobLeonard

Describe the bug

No worries, I know there's a simple workaround for now (just add the property to the prototype after the class definition), but still: this is technically a bug

The following snippet comes straight from MDN and uses the correct class syntax to initialize a static property:

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  static displayName = "Point";
  static distance(a, b) {
    const dx = a.x - b.x;
    const dy = a.y - b.y;

    return Math.hypot(dx, dy);
  }
}

However, the observable compiler currently trips over this (it does work for static methods though).

Example: https://observablehq.com/d/bffd1e6e498d8879 (screenshot below for future reference)

To Reproduce

Steps to reproduce the behavior:

  1. Type the above class into a javascript cell

Expected behavior

Class syntax being in line with official class syntax.

Screenshots

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions