ParseError: Unexpected token = when trying to save in google Apps Script editor

I reduced the issue to this simple bit of code:

class X {
  static a = 5;
}

I don't know why this is a problem. It seems to be valid code. Any ideas?

Image of error


Response from Google:


Apps Script V8 runtime supports EMCA2015 standards which mean static class properties are not supported at the moment. There are two workarounds available:

1 - Assign the property to the class:

// Caused an error
class MyClass {
  static a = 1;
}
// ECMA2015 compatible
class MyClass {}
MyClass.a = 1;

2 - Develop the Apps Scripts with Clasp: https://github.com/google/clasp which also supports TypeScript and many other new features.


Full details are in this ticket.


No static variables, but static functions are supported. So, technically you could use this:

class X {
  static a(){return 5;}
}
X.a();

It's not a variable.. but oh well, gets the job done!