From af1912ab7af99a4cfed061e49d7e1ad454410c7f Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Thu, 8 Jan 2015 09:31:18 -0800 Subject: [PATCH] Ensure constructors use the current super class. This is an extension of 324a4a1b22c5cd6b624d7689f8ec97a8c36eb165. --- .../templates/class-super-constructor-call.js | 4 ++-- lib/6to5/transformation/transformers/es6-classes.js | 2 +- .../super-class-id-member-expression/expected.js | 8 ++++---- .../transformation/es6-classes/super-class/expected.js | 4 ++-- .../optional-proto-to-assign/class/expected.js | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/6to5/transformation/templates/class-super-constructor-call.js b/lib/6to5/transformation/templates/class-super-constructor-call.js index c9b822f013..21034b6201 100644 --- a/lib/6to5/transformation/templates/class-super-constructor-call.js +++ b/lib/6to5/transformation/templates/class-super-constructor-call.js @@ -1,3 +1,3 @@ -if (SUPER_NAME !== null) { - SUPER_NAME.apply(this, arguments); +if (Object.getPrototypeOf(CLASS_NAME) !== null) { + Object.getPrototypeOf(CLASS_NAME).apply(this, arguments); } diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index 593164be90..9c780bf741 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -149,7 +149,7 @@ Class.prototype.buildBody = function () { if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) { constructor.body.body.push(util.template("class-super-constructor-call", { - SUPER_NAME: superName + CLASS_NAME: className }, true)); } diff --git a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js index d9a40e4753..a8ecac411b 100644 --- a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js @@ -18,8 +18,8 @@ var _inherits = function (child, parent) { var BaseController = (function () { var _Chaplin$Controller = Chaplin.Controller; var BaseController = function BaseController() { - if (_Chaplin$Controller !== null) { - _Chaplin$Controller.apply(this, arguments); + if (Object.getPrototypeOf(BaseController) !== null) { + Object.getPrototypeOf(BaseController).apply(this, arguments); } }; @@ -31,8 +31,8 @@ var BaseController = (function () { var BaseController2 = (function () { var _Chaplin$Controller$Another = Chaplin.Controller.Another; var BaseController2 = function BaseController2() { - if (_Chaplin$Controller$Another !== null) { - _Chaplin$Controller$Another.apply(this, arguments); + if (Object.getPrototypeOf(BaseController2) !== null) { + Object.getPrototypeOf(BaseController2).apply(this, arguments); } }; diff --git a/test/fixtures/transformation/es6-classes/super-class/expected.js b/test/fixtures/transformation/es6-classes/super-class/expected.js index 01534a385f..fdd356cf96 100644 --- a/test/fixtures/transformation/es6-classes/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class/expected.js @@ -18,8 +18,8 @@ var _inherits = function (child, parent) { var Test = (function () { var _Foo = Foo; var Test = function Test() { - if (_Foo !== null) { - _Foo.apply(this, arguments); + if (Object.getPrototypeOf(Test) !== null) { + Object.getPrototypeOf(Test).apply(this, arguments); } }; diff --git a/test/fixtures/transformation/optional-proto-to-assign/class/expected.js b/test/fixtures/transformation/optional-proto-to-assign/class/expected.js index 2d7d562265..b6517c4263 100644 --- a/test/fixtures/transformation/optional-proto-to-assign/class/expected.js +++ b/test/fixtures/transformation/optional-proto-to-assign/class/expected.js @@ -28,8 +28,8 @@ var _inherits = function (child, parent) { var Foo = (function () { var _Bar = Bar; var Foo = function Foo() { - if (_Bar !== null) { - _Bar.apply(this, arguments); + if (Object.getPrototypeOf(Foo) !== null) { + Object.getPrototypeOf(Foo).apply(this, arguments); } };