Skip to content

Invalid output from async-to-generator transform when async arrow function in class constructor #7792

@overlookmotel

Description

@overlookmotel

Input:

class C extends S {
  constructor() {
    super();
    this.f = async () => this;
  }
}

Transformed by async-to-generator:

class C extends S {
  constructor() {
    var _this = this;
    super();
    this.f = _asyncToGenerator(function*() {
      return _this;
    });
  }
}

Oxc Playground

Problem is that this is now accessed before super(), which is an error.

Babel puts _this = this after super():

class C extends S {
  constructor() {
    var _this;
    super();
    _this = this;
    this.f = _asyncToGenerator(function*() {
      return _this;
    });
  }
}

Note it gets a bit more complicated than that: Babel REPL

Metadata

Metadata

Assignees

Labels

A-transformerArea - Transformer / TranspilerC-bugCategory - Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions