overlookmotel/livepack

Cannot serialize arrow function in class which extends a super class which uses `this` if `super()` not called yet

overlookmotel opened this issue · 1 comments

Very odd case but legal:

class SuperKlass {
  constructor(x) {
    this.x = x;
  }
}

class Klass extends SuperKlass {
  constructor() {
    return {
      init: () => super(123),
      get: () => this.x
    };
  }
}

const o = new Klass();
export default o;

It is legitimate to call o.init() followed by o.get(), and the latter returns 123.

The above cannot be serialized though. It throws Error: Failed to extract scope vars from function due to underlying error in trying to serialize .get ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor.

The error is thrown in the tracker function as it tries to access this.

Similar problem to #323 with vars in temporal dead zone. Solution will be much the same.

Same problem with super:

class Klass extends SuperKlass {
  constructor() {
    return {
      init: () => super(),
      call: () => super.foo()
    };
  }
}
return new Klass();