Skip to content

Getters/Setters in Superclass called when loose defining Subclass #7771

@jridgewell

Description

@jridgewell

Given:

class Base {
  get test() {
  }
}

class Obj extends Base {
  // Redefining method here
  test() { }
}

This outputs:

var Base = function () {
  function Base() {}

  _createClass(Base, [{
    key: "test",
    get: function get() {}
  }]);

  return Base;
}();

var Obj = function (_Base) {
  _inheritsLoose(Obj, _Base);

  function Obj() {
    return _Base.apply(this, arguments) || this;
  }

  var _proto = Obj.prototype;

  // Redefining method here
  _proto.test = function test() {};

  return Obj;
}(Base);

Notice we do _inheritsLoose(Obj, _Base) immediately, then do Obj.prototype.test = function() {}. This tries to set to a inherited property that's only a getter, so it throws in strict mode.

We could just do the _inheritsLoose after defining the prototype methods?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Spec: ClassesoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions