fix class computed methods

This commit is contained in:
Sebastian McKenzie
2014-11-04 15:53:36 +11:00
parent d7ae3b506a
commit 5ff6f445b2
5 changed files with 31 additions and 21 deletions

View File

@@ -58,30 +58,35 @@ exports.sourceMapToComment = function (map) {
};
exports.pushMutatorMap = function (mutatorMap, key, kind, method) {
var alias = JSON.stringify(traverse.removeProperties(_.cloneDeep(key)));
var map;
if (_.has(mutatorMap, key)) {
map = mutatorMap[key];
if (_.has(mutatorMap, alias)) {
map = mutatorMap[alias];
} else {
map = {};
}
mutatorMap[key] = map;
mutatorMap[alias] = map;
if (map[kind]) {
throw new Error("a " + kind + " already exists for this property");
} else {
map[kind] = method;
map._key = key;
if (method.computed) {
map._computed = true;
}
map[kind] = method;
};
exports.buildDefineProperties = function (mutatorMap) {
var objExpr = t.objectExpression([]);
_.each(mutatorMap, function (map, key) {
_.each(mutatorMap, function (map) {
var mapNode = t.objectExpression([]);
var propNode = t.property("init", t.identifier(key), mapNode);
var propNode = t.property("init", map._key, mapNode, map._computed);
_.each(map, function (node, key) {
if (key[0] === "_") return;
node = _.clone(node);
if (t.isMethodDefinition(node)) node = node.value;
mapNode.properties.push(t.property("init", t.identifier(key), node));