move super reference into closure

This commit is contained in:
Sebastian McKenzie
2015-01-10 22:26:51 +11:00
parent 1985146760
commit 54b05f33f2
8 changed files with 41 additions and 55 deletions

View File

@@ -58,15 +58,23 @@ Class.prototype.run = function () {
t.variableDeclarator(className, constructor)
]));
var closureArgs = [];
var closureParams = [];
//
if (superName) {
// so we're only evaluating it once
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(superRef, superName)
]));
superName = superRef;
closureArgs.push(superName);
if (!t.isIdentifier(superName)) {
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(superRef, superName)
]));
superName = superRef;
}
closureParams.push(superName);
this.superName = superName;
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
@@ -84,8 +92,8 @@ Class.prototype.run = function () {
} else {
body.push(t.returnStatement(className));
init = t.callExpression(
t.functionExpression(null, [], t.blockStatement(body)),
[]
t.functionExpression(null, closureParams, t.blockStatement(body)),
closureArgs
);
}
@@ -212,25 +220,12 @@ Class.prototype.superProperty = function (property, isStatic, isComputed) {
this.file.addHelper("get"),
[
t.callExpression(
t.memberExpression(
t.identifier("Object"),
t.identifier("getPrototypeOf"),
false
),
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
[
isStatic ?
this.className :
t.memberExpression(
this.className,
t.identifier("prototype"),
false
)
isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
]
),
isComputed ?
property :
t.literal(property.name),
t.thisExpression()
isComputed ? property : t.literal(property.name), t.thisExpression()
]
);
};

View File

@@ -38,8 +38,7 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
var _get2, _get3, _get4, _get5;
woops["super"].test();
@@ -53,7 +52,7 @@ var Test = (function () {
(_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments)));
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
Test.prototype.test = function () {
var _get6, _get7;
@@ -70,5 +69,4 @@ var Test = (function () {
};
return Test;
})();
})(Foo);

View File

@@ -37,15 +37,13 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
_get(Object.getPrototypeOf(Test.prototype), "test", this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever;
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
return Test;
})();
})(Foo);

View File

@@ -37,19 +37,17 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever();
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
Test.test = function () {
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
};
return Test;
})();
})(Foo);

View File

@@ -19,13 +19,12 @@ var Test = function Test() {
this.state = "test";
};
var Foo = (function () {
var _Bar = Bar;
var Foo = (function (Bar) {
var Foo = function Foo() {
this.state = "test";
};
_inherits(Foo, _Bar);
_inherits(Foo, Bar);
return Foo;
})();
})(Bar);

View File

@@ -15,7 +15,7 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var BaseController = (function () {
var BaseController = (function (_Chaplin$Controller) {
var _Chaplin$Controller = Chaplin.Controller;
var BaseController = function BaseController() {
if (Object.getPrototypeOf(BaseController) !== null) {
@@ -26,9 +26,9 @@ var BaseController = (function () {
_inherits(BaseController, _Chaplin$Controller);
return BaseController;
})();
})(Chaplin.Controller);
var BaseController2 = (function () {
var BaseController2 = (function (_Chaplin$Controller$Another) {
var _Chaplin$Controller$Another = Chaplin.Controller.Another;
var BaseController2 = function BaseController2() {
if (Object.getPrototypeOf(BaseController2) !== null) {
@@ -39,4 +39,4 @@ var BaseController2 = (function () {
_inherits(BaseController2, _Chaplin$Controller$Another);
return BaseController2;
})();
})(Chaplin.Controller.Another);

View File

@@ -15,15 +15,14 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
if (Object.getPrototypeOf(Test) !== null) {
Object.getPrototypeOf(Test).apply(this, arguments);
}
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
return Test;
})();
})(Foo);

View File

@@ -25,15 +25,14 @@ var _inherits = function (child, parent) {
if (parent) _defaults(child, parent);
};
var Foo = (function () {
var _Bar = Bar;
var Foo = (function (Bar) {
var Foo = function Foo() {
if (Object.getPrototypeOf(Foo) !== null) {
Object.getPrototypeOf(Foo).apply(this, arguments);
}
};
_inherits(Foo, _Bar);
_inherits(Foo, Bar);
return Foo;
})();
})(Bar);