Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
overlookmotel opened this issue Dec 30, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@overlookmotel
Copy link
Owner

overlookmotel commented Dec 30, 2021

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.

@overlookmotel overlookmotel added the bug Something isn't working label Dec 30, 2021
@overlookmotel
Copy link
Owner Author

Same problem with super:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant