use assignment instead of define for fast classes

This commit is contained in:
Sebastian McKenzie 2015-01-13 23:18:38 +11:00
parent f8915333b0
commit 1c2bafe0e1
3 changed files with 33 additions and 35 deletions

View File

@ -188,6 +188,19 @@ Class.prototype.pushMethod = function (node) {
} }
if (kind === "") { if (kind === "") {
if (this.isFast) {
// use assignments instead of define properties for fast classes
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
return;
}
kind = "value"; kind = "value";
} }

View File

@ -37,31 +37,21 @@ var Test = (function (Foo) {
_inherits(Test, Foo); _inherits(Test, Foo);
_prototypeProperties(Test, { Test.prototype.test = function () {
foo: {
value: function () {
var _Foo$foo, _Foo$foo2;
Foo.foo.call(this);
(_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
(_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
},
writable: true,
enumerable: true,
configurable: true
}
}, {
test: {
value: function () {
var _Foo$prototype$test3, _Foo$prototype$test4; var _Foo$prototype$test3, _Foo$prototype$test4;
Foo.prototype.test.call(this); Foo.prototype.test.call(this);
(_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments))); (_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments))); (_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments)));
}, };
writable: true,
enumerable: true, Test.foo = function () {
configurable: true var _Foo$foo, _Foo$foo2;
} Foo.foo.call(this);
}); (_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
(_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
};
_prototypeProperties(Test, {}, {});
return Test; return Test;
})(Foo); })(Foo);

View File

@ -28,16 +28,11 @@ var Test = (function (Foo) {
_inherits(Test, Foo); _inherits(Test, Foo);
_prototypeProperties(Test, { Test.test = function () {
test: {
value: function () {
return Foo.wow.call(this); return Foo.wow.call(this);
}, };
writable: true,
enumerable: true, _prototypeProperties(Test, {});
configurable: true
}
});
return Test; return Test;
})(Foo); })(Foo);