Sha256: a45af1f2bd89779d81019db03b135171bdb7f0663af9399ca0a5a52dbb6a3457

Contents?: true

Size: 1.8 KB

Versions: 24

Compression:

Stored size: 1.8 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 = (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);
          }
        }
      }

    }
  };
});

exports.default = _default;

Version data entries

24 entries across 23 versions & 7 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.15.2 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.18.4 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.18.1 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.14.0 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
tang-0.2.1 spec/tang_app/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
tang-0.2.0 spec/tang_app/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
tang-0.1.0 spec/tang_app/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
tang-0.0.9 spec/tang_app/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
enju_library-0.3.8 spec/dummy/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
condenser-0.3 lib/condenser/processors/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
condenser-0.2 lib/condenser/processors/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js
condenser-0.1 lib/condenser/processors/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js