simplify define property by using a helper in playground object getter memoization
This commit is contained in:
@@ -3,7 +3,7 @@ var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property =
|
||||
exports.MethodDefinition = function (node) {
|
||||
exports.MethodDefinition = function (node, parent, file) {
|
||||
if (node.kind !== "memo") return;
|
||||
node.kind = "get";
|
||||
|
||||
@@ -21,10 +21,11 @@ exports.MethodDefinition = function (node) {
|
||||
if (t.isFunction(node)) return;
|
||||
|
||||
if (t.isReturnStatement(node) && node.argument) {
|
||||
node.argument = t.memberExpression(util.template("object-getter-memoization", {
|
||||
KEY: key,
|
||||
VALUE: node.argument
|
||||
}), key, true);
|
||||
node.argument = t.memberExpression(t.callExpression(file.addDeclaration("define-property"), [
|
||||
t.thisExpression(),
|
||||
key,
|
||||
node.argument
|
||||
]), key, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,60 +5,24 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
var _defineProperty = function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
};
|
||||
|
||||
var Foo = function Foo() {};
|
||||
|
||||
_prototypeProperties(Foo, null, (function (_ref) {
|
||||
_ref[bar] = {
|
||||
get: function () {
|
||||
return Object.defineProperty(this, bar, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: complex()
|
||||
})[bar];
|
||||
},
|
||||
enumerable: true
|
||||
};
|
||||
return _ref;
|
||||
})({
|
||||
bar: {
|
||||
get: function () {
|
||||
return Object.defineProperty(this, "bar", {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: complex()
|
||||
}).bar;
|
||||
},
|
||||
enumerable: true
|
||||
}
|
||||
_prototypeProperties(Foo, null, _defineProperty({}, bar, {
|
||||
get: function () {
|
||||
return _defineProperty(this, bar, complex())[bar];
|
||||
},
|
||||
enumerable: true
|
||||
}));
|
||||
|
||||
var foo = (function (_foo) {
|
||||
_foo[bar] = function () {
|
||||
return Object.defineProperty(this, bar, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: complex()
|
||||
})[bar];
|
||||
};
|
||||
|
||||
return _foo;
|
||||
})((function (_ref2) {
|
||||
Object.defineProperties(_ref2, {
|
||||
bar: {
|
||||
get: function () {
|
||||
return Object.defineProperty(this, "bar", {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: complex()
|
||||
}).bar;
|
||||
},
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
|
||||
return _ref2;
|
||||
})({}));
|
||||
var foo = _defineProperty({}, bar, function () {
|
||||
return _defineProperty(this, bar, complex())[bar];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user