ignore computed property literals that are valid identifiers

This commit is contained in:
Sebastian McKenzie
2014-11-07 20:51:01 +11:00
parent 37a7c92500
commit 49ea641314

View File

@@ -1,14 +1,26 @@
var util = require("../util");
var t = require("../types");
var _ = require("lodash");
var esutils = require("esutils");
var util = require("../util");
var t = require("../types");
var _ = require("lodash");
exports.ObjectExpression = function (node, parent, file) {
var hasComputed = false;
var computed = [];
node.properties = node.properties.filter(function (prop) {
var props = node.properties.filter(function (prop) {
if (prop.computed) {
// ignore literals that are valid identifiers
var key = prop.key;
if (t.isLiteral(key) && esutils.keyword.isIdentifierName(key.value)) {
key.type = "Identifier";
key.name = key.value;
delete key.value;
prop.computed = false;
return true;
}
hasComputed = true;
computed.unshift(prop);
return false;
@@ -19,6 +31,8 @@ exports.ObjectExpression = function (node, parent, file) {
if (!hasComputed) return;
node.properties = props;
var objId = util.getUid(parent, file);
var container = util.template("function-return-obj", {