assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

[Feature] Supports (parse & compile) function expressions as instance and class members

Open MaxGraey opened this issue 1 year ago • 2 comments

class Foo {
  static a = (): i32 => { //   ERROR TS1110: Type expected.
    return 1;
  }
  b = (): i32 => { //   ERROR TS1110: Type expected.
    return 2;
  }
}

Instance method automatically lower it to simple FunctionDeclaration due to class members are immutable in AS while class (static) function members can be reassigned so premature optimization is not possible.

Same for interfaces:

interface IFoo {
  a: () => i32
}

MaxGraey avatar Sep 05 '22 11:09 MaxGraey

due to class members are immutable in AS

Static class members can in fact be re-assigned, like Foo.a = .... These become globals underneath. We would need to know that re-assignments never happen to make these fully static.

dcodeIO avatar Sep 05 '22 12:09 dcodeIO

Hmm, perhaps we can support reassignment for static function members. Will add note

MaxGraey avatar Sep 05 '22 13:09 MaxGraey