Sha256: 87fdaf40ffa61eedb7b3e3a340ef0c4aded0f4774768ff7ecff694e24f66a4a5

Contents?: true

Size: 1.83 KB

Versions: 58

Compression:

Stored size: 1.83 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = removeTypeDuplicates;
var _index = require("../../validators/generated/index.js");
function getQualifiedName(node) {
  return (0, _index.isIdentifier)(node) ? node.name : `${node.id.name}.${getQualifiedName(node.qualification)}`;
}
function removeTypeDuplicates(nodesIn) {
  const nodes = Array.from(nodesIn);
  const generics = new Map();
  const bases = new Map();
  const typeGroups = new Set();
  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, _index.isAnyTypeAnnotation)(node)) {
      return [node];
    }
    if ((0, _index.isFlowBaseAnnotation)(node)) {
      bases.set(node.type, node);
      continue;
    }
    if ((0, _index.isUnionTypeAnnotation)(node)) {
      if (!typeGroups.has(node.types)) {
        nodes.push(...node.types);
        typeGroups.add(node.types);
      }
      continue;
    }
    if ((0, _index.isGenericTypeAnnotation)(node)) {
      const name = getQualifiedName(node.id);
      if (generics.has(name)) {
        let existing = generics.get(name);
        if (existing.typeParameters) {
          if (node.typeParameters) {
            existing.typeParameters.params.push(...node.typeParameters.params);
            existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params);
          }
        } else {
          existing = node.typeParameters;
        }
      } else {
        generics.set(name, node);
      }
      continue;
    }
    types.push(node);
  }
  for (const [, baseType] of bases) {
    types.push(baseType);
  }
  for (const [, genericName] of generics) {
    types.push(genericName);
  }
  return types;
}

//# sourceMappingURL=removeTypeDuplicates.js.map

Version data entries

58 entries across 16 versions & 3 rubygems

Version Path
trusty-cms-6.3.1 node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-6.3.1 node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
trusty-cms-6.3.1 node_modules/@babel/helper-function-name/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-split-export-declaration/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-simple-access/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-optimise-call-expression/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/jscodeshift/node_modules/@babel/core/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-function-name/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-hoist-variables/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-module-imports/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-environment-visitor/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-skip-transparent-expression-wrappers/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-annotate-as-pure/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-module-imports/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-optimise-call-expression/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-hoist-variables/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-simple-access/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-environment-visitor/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js