google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 580 forks source link

Super in async methods with generators #2104

Open arv opened 8 years ago

arv commented 8 years ago

When compiling async functions to generators, super in async methods do not work correctly.

// Options: --async-functions --generators=parse --classes=parse

class B {
  m() {
    console.log('B-m');
  }
}
class C extends B {
  async m() {
    super.m();
  }
}
new C().m();

compiles to:

$traceurRuntime.ModuleStore.getAnonymousModule(function() {
  "use strict";
  class B {
    m() {
      console.log('B-m');
    }
  }
  class C extends B {
    m() {
      return $traceurRuntime.spawn(this, null, function*() {
        super.m();
      });
    }
  }
  new C().m();
  return {};
});
//# sourceURL=traceured.js

which of course does not work.

We need to transform that super.m using the SuperTransformer to:

$traceurRuntime.superGet(this, C.prototype, "m").call(this);