inline back the super constructor call helper - fixes #684

This commit is contained in:
Sebastian McKenzie 2015-02-04 08:39:45 +11:00
parent 86fbba08d8
commit 8d81a382f7
5 changed files with 20 additions and 28 deletions

View File

@ -1,5 +1,3 @@
(function (instance, Constructor) {
if (Object.getPrototypeOf(Constructor) !== null) {
Object.getPrototypeOf(Constructor).apply(instance, arguments);
}
});
if (Object.getPrototypeOf(CLASS_NAME) !== null) {
Object.getPrototypeOf(CLASS_NAME).apply(instance, arguments);
}

View File

@ -169,19 +169,11 @@ Class.prototype.buildBody = function () {
// we have no constructor, we have a super, and the super doesn't appear to be falsy
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
var helperName = "class-super-constructor-call";
if (this.isLoose) {
constructor.body.body.push(util.template(helperName + "-loose", {
CLASS_NAME: className,
SUPER_NAME: this.superName
}, true));
} else {
constructor.body.body.push(
t.expressionStatement(
t.callExpression(this.file.addHelper(helperName), [t.thisExpression(), className])
)
);
}
if (this.isLoose) helperName += "-loose"
constructor.body.body.push(util.template(helperName, {
CLASS_NAME: className,
SUPER_NAME: this.superName
}, true));
}
var instanceProps;

View File

@ -1,7 +1,5 @@
"use strict";
var _classSuperConstructorCall = function (instance, Constructor) { if (Object.getPrototypeOf(Constructor) !== null) { Object.getPrototypeOf(Constructor).apply(instance, arguments); } };
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
@ -10,7 +8,9 @@ var BaseController = (function (_Chaplin$Controller) {
function BaseController() {
_classCallCheck(this, BaseController);
_classSuperConstructorCall(this, BaseController);
if (Object.getPrototypeOf(BaseController) !== null) {
Object.getPrototypeOf(BaseController).apply(instance, arguments);
}
}
_inherits(BaseController, _Chaplin$Controller);
@ -22,7 +22,9 @@ var BaseController2 = (function (_Chaplin$Controller$Another) {
function BaseController2() {
_classCallCheck(this, BaseController2);
_classSuperConstructorCall(this, BaseController2);
if (Object.getPrototypeOf(BaseController2) !== null) {
Object.getPrototypeOf(BaseController2).apply(instance, arguments);
}
}
_inherits(BaseController2, _Chaplin$Controller$Another);

View File

@ -1,7 +1,5 @@
"use strict";
var _classSuperConstructorCall = function (instance, Constructor) { if (Object.getPrototypeOf(Constructor) !== null) { Object.getPrototypeOf(Constructor).apply(instance, arguments); } };
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
@ -10,7 +8,9 @@ var Test = (function (Foo) {
function Test() {
_classCallCheck(this, Test);
_classSuperConstructorCall(this, Test);
if (Object.getPrototypeOf(Test) !== null) {
Object.getPrototypeOf(Test).apply(instance, arguments);
}
}
_inherits(Test, Foo);

View File

@ -2,8 +2,6 @@
var _defaults = function (obj, defaults) { for (var key in defaults) { if (obj[key] === undefined) { obj[key] = defaults[key]; } } return obj; };
var _classSuperConstructorCall = function (instance, Constructor) { if (Object.getPrototypeOf(Constructor) !== null) { Object.getPrototypeOf(Constructor).apply(instance, arguments); } };
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _defaults(subClass, superClass); };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
@ -12,7 +10,9 @@ var Foo = (function (Bar) {
function Foo() {
_classCallCheck(this, Foo);
_classSuperConstructorCall(this, Foo);
if (Object.getPrototypeOf(Foo) !== null) {
Object.getPrototypeOf(Foo).apply(instance, arguments);
}
}
_inherits(Foo, Bar);