Sha256: bf60f2ff08b63f381e268a7db663485ed4c90b28e848df1820aa8369f1e9dcfc

Contents?: true

Size: 1.56 KB

Versions: 56

Compression:

Stored size: 1.56 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = removeTypeDuplicates;

var _generated = require("../../validators/generated");

function removeTypeDuplicates(nodes) {
  const generics = {};
  const bases = {};
  const typeGroups = [];
  const types = [];

  for (let i = 0; i < nodes.length; i++) {
    const node = nodes[i];
    if (!node) continue;

    if (types.indexOf(node) >= 0) {
      continue;
    }

    if ((0, _generated.isAnyTypeAnnotation)(node)) {
      return [node];
    }

    if ((0, _generated.isFlowBaseAnnotation)(node)) {
      bases[node.type] = node;
      continue;
    }

    if ((0, _generated.isUnionTypeAnnotation)(node)) {
      if (typeGroups.indexOf(node.types) < 0) {
        nodes = nodes.concat(node.types);
        typeGroups.push(node.types);
      }

      continue;
    }

    if ((0, _generated.isGenericTypeAnnotation)(node)) {
      const name = node.id.name;

      if (generics[name]) {
        let existing = generics[name];

        if (existing.typeParameters) {
          if (node.typeParameters) {
            existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params.concat(node.typeParameters.params));
          }
        } else {
          existing = node.typeParameters;
        }
      } else {
        generics[name] = node;
      }

      continue;
    }

    types.push(node);
  }

  for (const type of Object.keys(bases)) {
    types.push(bases[type]);
  }

  for (const name of Object.keys(generics)) {
    types.push(generics[name]);
  }

  return types;
}

Version data entries

56 entries across 56 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.18.0 test/dummy/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.18.2 test/dummy/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.7 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.6 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.5 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.4 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.15.2 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.3 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.2 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.18.4 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.18.1 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.14.0 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.1 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-4.3.5 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-5.0.0 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-4.3.4 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js