index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. exports.__esModule = true;
  3. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  4. var _getIterator3 = _interopRequireDefault(_getIterator2);
  5. var _create = require("babel-runtime/core-js/object/create");
  6. var _create2 = _interopRequireDefault(_create);
  7. exports.default = function () {
  8. return {
  9. visitor: {
  10. ObjectExpression: function ObjectExpression(path) {
  11. var node = path.node;
  12. var plainProps = node.properties.filter(function (prop) {
  13. return !t.isSpreadProperty(prop) && !prop.computed;
  14. });
  15. var alreadySeenData = (0, _create2.default)(null);
  16. var alreadySeenGetters = (0, _create2.default)(null);
  17. var alreadySeenSetters = (0, _create2.default)(null);
  18. for (var _iterator = plainProps, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  19. var _ref;
  20. if (_isArray) {
  21. if (_i >= _iterator.length) break;
  22. _ref = _iterator[_i++];
  23. } else {
  24. _i = _iterator.next();
  25. if (_i.done) break;
  26. _ref = _i.value;
  27. }
  28. var prop = _ref;
  29. var name = getName(prop.key);
  30. var isDuplicate = false;
  31. switch (prop.kind) {
  32. case "get":
  33. if (alreadySeenData[name] || alreadySeenGetters[name]) {
  34. isDuplicate = true;
  35. }
  36. alreadySeenGetters[name] = true;
  37. break;
  38. case "set":
  39. if (alreadySeenData[name] || alreadySeenSetters[name]) {
  40. isDuplicate = true;
  41. }
  42. alreadySeenSetters[name] = true;
  43. break;
  44. default:
  45. if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
  46. isDuplicate = true;
  47. }
  48. alreadySeenData[name] = true;
  49. }
  50. if (isDuplicate) {
  51. prop.computed = true;
  52. prop.key = t.stringLiteral(name);
  53. }
  54. }
  55. }
  56. }
  57. };
  58. };
  59. var _babelTypes = require("babel-types");
  60. var t = _interopRequireWildcard(_babelTypes);
  61. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  62. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  63. function getName(key) {
  64. if (t.isIdentifier(key)) {
  65. return key.name;
  66. }
  67. return key.value.toString();
  68. }
  69. module.exports = exports["default"];