Sha256: 245fbcd2d7d869d23f3628160f9ce3b34f4f728bb9532dca12ec131f62fabb47

Contents?: true

Size: 1.81 KB

Versions: 18

Compression:

Stored size: 1.81 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _core = require("@babel/core");
function getName(key) {
  if (_core.types.isIdentifier(key)) {
    return key.name;
  }
  return key.value.toString();
}
var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
  api.assertVersion(7);
  return {
    name: "transform-duplicate-keys",
    visitor: {
      ObjectExpression(path) {
        const {
          node
        } = path;
        const plainProps = node.properties.filter(prop => !_core.types.isSpreadElement(prop) && !prop.computed);
        const alreadySeenData = Object.create(null);
        const alreadySeenGetters = Object.create(null);
        const alreadySeenSetters = Object.create(null);
        for (const prop of plainProps) {
          const name = getName(prop.key);
          let isDuplicate = false;
          switch (prop.kind) {
            case "get":
              if (alreadySeenData[name] || alreadySeenGetters[name]) {
                isDuplicate = true;
              }
              alreadySeenGetters[name] = true;
              break;
            case "set":
              if (alreadySeenData[name] || alreadySeenSetters[name]) {
                isDuplicate = true;
              }
              alreadySeenSetters[name] = true;
              break;
            default:
              if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
                isDuplicate = true;
              }
              alreadySeenData[name] = true;
          }
          if (isDuplicate) {
            prop.computed = true;
            prop.key = _core.types.stringLiteral(name);
          }
        }
      }
    }
  };
});

//# sourceMappingURL=index.js.map

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.61 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.60 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js