babel/lib/6to5/transformation/transformers/spec-no-duplicate-properties.js
Sebastian McKenzie 2fb6c7820c microoptimizations
2014-12-15 13:59:54 +11:00

26 lines
559 B
JavaScript

var t = require("../../types");
exports.ObjectExpression = function (node, parent, file) {
var keys = [];
for (var i in node.properties) {
var prop = node.properties[i];
if (prop.computed || prop.kind !== "init") continue;
var key = prop.key;
if (t.isIdentifier(key)) {
key = key.name;
} else if (t.isLiteral(key)) {
key = key.value;
} else {
continue;
}
if (keys.indexOf(key) >= 0) {
throw file.errorWithNode(prop.key, "Duplicate property key");
} else {
keys.push(key);
}
}
};