[bug] inherited accessors (getters/setters) don't work.
Accessors with Buble only work without inheritance. But with inheritance, the context of an accessor is wrong (the this
).
For example, in
class Foo {
set foo(v) {console.log('set foo')}
get foo() {return console.log('get foo')}
}
class Bar extends Foo {
set foo(v) {super.foo = v}
get foo() {return super.foo}
}
the Buble output will be something like
var Foo = function Foo () {};
var prototypeAccessors = { foo: {} };
prototypeAccessors.foo.set = function (v) {console.log('set foo')};
prototypeAccessors.foo.get = function () {return console.log('get foo')};
Object.defineProperties( Foo.prototype, prototypeAccessors );
var Bar = (function (Foo) {
function Bar () {
Foo.apply(this, arguments);
}
if ( Foo ) Bar.__proto__ = Foo;
Bar.prototype = Object.create( Foo && Foo.prototype );
Bar.prototype.constructor = Bar;
var prototypeAccessors$1 = { foo: {} };
// --------------- ERROR -----------------------------------------------------
prototypeAccessors$1.foo.set = function (v) {Foo.prototype.foo = v};
prototypeAccessors$1.foo.get = function () {return Foo.prototype.foo};
Object.defineProperties( Bar.prototype, prototypeAccessors$1 );
return Bar;
}(Foo));
and as you can see it will attempt to run Foo.prototype.foo = v
and return Foo.prototype.foo
for the extending accessors.
This obviously won't work because this
inside of the parent class accessors will be Foo.prototype
rather than an instance of Bar
.
To fix this problem, maybe Buble can output something like this instead:
prototypeAccessors$1.foo.set = function (v) {Object.getOwnPropertyDescriptor(Foo.prototype, 'foo').set.call(this, v)};
prototypeAccessors$1.foo.get = function () {return Object.getOwnPropertyDescriptor(Foo.prototype, 'foo').get.call(this)};
Edited by username-removed-281802