diff --git a/lib/6to5/transformation/helpers/replace-supers.js b/lib/6to5/transformation/helpers/replace-supers.js index 66048ab4d9..abb7600233 100644 --- a/lib/6to5/transformation/helpers/replace-supers.js +++ b/lib/6to5/transformation/helpers/replace-supers.js @@ -37,7 +37,12 @@ ReplaceSupers.prototype.setSuperProperty = function (property, value, isStatic, return t.callExpression( this.file.addHelper("set"), [ - isStatic ? this.superName : t.memberExpression(this.superName, t.identifier("prototype")), + t.callExpression( + t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), + [ + isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype")) + ] + ), isComputed ? property : t.literal(property.name), value, thisExpression @@ -63,7 +68,12 @@ ReplaceSupers.prototype.getSuperProperty = function (property, isStatic, isCompu return t.callExpression( this.file.addHelper("get"), [ - isStatic ? this.superName : t.memberExpression(this.superName, t.identifier("prototype")), + t.callExpression( + t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), + [ + isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype")) + ] + ), isComputed ? property : t.literal(property.name), thisExpression ] diff --git a/test/fixtures/esnext/es6-classes/super-change-proto.js b/test/fixtures/esnext/es6-classes/super-change-proto.js new file mode 100644 index 0000000000..01058549c9 --- /dev/null +++ b/test/fixtures/esnext/es6-classes/super-change-proto.js @@ -0,0 +1,21 @@ +var log = ''; + +class Base { + p() { log += '[Base]'; } +} + +class OtherBase { + p() { log += '[OtherBase]'; } +} + +class Derived extends Base { + p() { + log += '[Derived]'; + super.p(); + Derived.prototype.__proto__ = OtherBase.prototype; + super.p(); + } +} + +new Derived().p(); +assert.equal(log, '[Derived][Base][OtherBase]'); diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index 7f6a1389dc..a8f74b0cb7 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -15,14 +15,14 @@ var Test = (function (Foo) { _classCallCheck(this, Test); woops["super"].test(); - _get(Foo.prototype, "constructor", this).call(this); - _get(Foo.prototype, "test", this).call(this); + _get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); + _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); - _get(Foo.prototype, "constructor", this).apply(this, arguments); - (_get2 = _get(Foo.prototype, "constructor", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); + (_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); - _get(Foo.prototype, "test", this).apply(this, arguments); - (_get3 = _get(Foo.prototype, "test", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_get3 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments))); } _inherits(Test, Foo); @@ -31,9 +31,9 @@ var Test = (function (Foo) { foo: { value: function foo() { var _get2; - _get(Foo, "foo", this).call(this); - _get(Foo, "foo", this).apply(this, arguments); - (_get2 = _get(Foo, "foo", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test), "foo", this).call(this); + _get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments); + (_get2 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); }, writable: true, configurable: true @@ -42,9 +42,9 @@ var Test = (function (Foo) { test: { value: function test() { var _get2; - _get(Foo.prototype, "test", this).call(this); - _get(Foo.prototype, "test", this).apply(this, arguments); - (_get2 = _get(Foo.prototype, "test", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_get2 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); }, writable: true, configurable: true diff --git a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js index 9112ab7d1d..7ee14a53f1 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js @@ -10,8 +10,8 @@ var Test = (function (Foo) { function Test() { _classCallCheck(this, Test); - _get(Foo.prototype, "test", this); - _get(Foo.prototype, "test", this).whatever; + _get(Object.getPrototypeOf(Test.prototype), "test", this); + _get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; } _inherits(Test, Foo); diff --git a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js index e0fcb1292a..4ae369971d 100644 --- a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js @@ -12,8 +12,8 @@ var Test = (function (Foo) { function Test() { _classCallCheck(this, Test); - _get(Foo.prototype, "test", this).whatever(); - _get(Foo.prototype, "test", this).call(this); + _get(Object.getPrototypeOf(Test.prototype), "test", this).whatever(); + _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); } _inherits(Test, Foo); @@ -21,7 +21,7 @@ var Test = (function (Foo) { _prototypeProperties(Test, { test: { value: function test() { - return _get(Foo, "wow", this).call(this); + return _get(Object.getPrototypeOf(Test), "wow", this).call(this); }, writable: true, configurable: true diff --git a/test/fixtures/transformation/es6-classes/super-change-proto/exec.js b/test/fixtures/transformation/es6-classes/super-change-proto/exec.js new file mode 100644 index 0000000000..01058549c9 --- /dev/null +++ b/test/fixtures/transformation/es6-classes/super-change-proto/exec.js @@ -0,0 +1,21 @@ +var log = ''; + +class Base { + p() { log += '[Base]'; } +} + +class OtherBase { + p() { log += '[OtherBase]'; } +} + +class Derived extends Base { + p() { + log += '[Derived]'; + super.p(); + Derived.prototype.__proto__ = OtherBase.prototype; + super.p(); + } +} + +new Derived().p(); +assert.equal(log, '[Derived][Base][OtherBase]'); diff --git a/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js b/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js index 13bf3b8d41..e278a09b33 100644 --- a/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js +++ b/test/fixtures/transformation/es6-classes/super-function-fallback/expected.js @@ -7,5 +7,5 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instance var Test = function Test() { _classCallCheck(this, Test); - _get(Function.prototype, "hasOwnProperty", this).call(this, "test"); -}; + _get(Object.getPrototypeOf(Test.prototype), "hasOwnProperty", this).call(this, "test"); +}; \ No newline at end of file