Sha256: 8f88404e2f54b4657fb5a4136750bfa960da0b75a06eded8c4f9238a07fc6ec3

Contents?: true

Size: 1.82 KB

Versions: 106

Compression:

Stored size: 1.82 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.right.name}.${getQualifiedName(node.left)}`;
}
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.includes(node)) {
      continue;
    }
    if ((0, _index.isTSAnyKeyword)(node)) {
      return [node];
    }
    if ((0, _index.isTSBaseType)(node)) {
      bases.set(node.type, node);
      continue;
    }
    if ((0, _index.isTSUnionType)(node)) {
      if (!typeGroups.has(node.types)) {
        nodes.push(...node.types);
        typeGroups.add(node.types);
      }
      continue;
    }
    if ((0, _index.isTSTypeReference)(node) && node.typeParameters) {
      const name = getQualifiedName(node.typeName);
      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

106 entries across 7 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-react-jsx/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-modules-systemjs/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-function-name/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-computed-properties/node_modules/@babel/template/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-classes/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-classes/node_modules/@babel/helper-replace-supers/node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-transform-async-generator-functions/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/helper-remap-async-to-generator/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.46 node_modules/@babel/helper-builder-binary-assignment-operator-visitor/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/helper-remap-async-to-generator/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-react-jsx/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-object-super/node_modules/@babel/helper-replace-supers/node_modules/@babel/helper-member-expression-to-functions/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-modules-systemjs/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-function-name/node_modules/@babel/traverse/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
immosquare-cleaner-0.1.45 node_modules/@babel/plugin-transform-computed-properties/node_modules/@babel/template/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js