add types.toComputedPropertyKey helper

This commit is contained in:
Sebastian McKenzie
2015-01-03 20:08:39 +11:00
parent d20ab0eb05
commit 71132c3538

View File

@@ -64,6 +64,21 @@ _.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
addAssert(type, is);
});
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
t.toComputedPropertyKey = function (prop) {
var key = prop.key;
if (!prop.computed) {
if (t.isIdentifier(key)) key = t.literal(key.name);
}
return key;
};
/*
* Shallowly checks to see if the passed `node` will evaluate to a
* falsy. This is if `node` is a `Literal` and `value` is falsy or