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

super relies on name of base class #259

Open
kumavis opened this issue May 29, 2020 · 5 comments
Open

super relies on name of base class #259

kumavis opened this issue May 29, 2020 · 5 comments
Labels

Comments

@kumavis
Copy link

kumavis commented May 29, 2020

class Base { xyz () {} }
const Enhanced = enhance(Base)
const inst = new Enhanced()

inst.xyz()

function enhance (Klass) {
  Klass = class extends Klass {
    xyz () {
      super.xyz()
    }
  }
  return Klass
}
$ cat abc.js | node

$ npx buble abc.js | node
[stdin]:20
    Klass.prototype.xyz = function xyz () {
                                       ^

RangeError: Maximum call stack size exceeded
    at Klass.xyz ([stdin]:20:40)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
    at Klass.xyz ([stdin]:21:27)
@kumavis
Copy link
Author

kumavis commented May 29, 2020

this pattern can be found in this acorn plugin

which is run under buble in acorn-node. it has a manual workaround for this case.

@kumavis
Copy link
Author

kumavis commented May 29, 2020

transpiled output

var Base = function Base () {};

Base.prototype.xyz = function xyz () {};
var Enhanced = enhance(Base)
var inst = new Enhanced()

inst.xyz()

function enhance (Klass) {
  Klass = /*@__PURE__*/(function (Klass$1) {
    function Klass () {
      Klass$1.apply(this, arguments);
    }

    if ( Klass$1 ) Klass.__proto__ = Klass$1;
    Klass.prototype = Object.create( Klass$1 && Klass$1.prototype );
    Klass.prototype.constructor = Klass;

    Klass.prototype.xyz = function xyz () {
      Klass.prototype.xyz.call(this)
    };

    return Klass;
  }(Klass))
  return Klass
}

the super.xyz() call is rendered as

Klass.prototype.xyz.call(this)

but it should be

Klass$1.prototype.xyz.call(this)

@mourner mourner added the bug label May 29, 2020
@goto-bus-stop
Copy link
Contributor

I believe 0c06cae attempted to fix this—we didn't upgrade to the latest Bublé yet in acorn-node. Not sure if it's still an issue in 0.20.0

@kumavis
Copy link
Author

kumavis commented May 29, 2020

I verified it's an issue on 0.20.0, the transpired output above is from that version

@goto-bus-stop
Copy link
Contributor

Ohh I see, this is about super.xyz(), but the earlier fix was for super() in the constructor call only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants