Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 406
Adrian Avatar asked May 18 '26 13:05

Adrian


1 Answers

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.

like image 152
andrewJames Avatar answered May 20 '26 01:05

andrewJames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!