astro-ghostcms/.pnpm-store/v3/files/98/090b215e15beaea0af87167d3f5...

1 line
4.8 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
{"version":3,"names":["_index","require","getQualifiedName","node","isIdentifier","name","right","left","removeTypeDuplicates","nodesIn","nodes","Array","from","generics","Map","bases","typeGroups","Set","types","i","length","indexOf","isTSAnyKeyword","isTSBaseType","set","type","isTSUnionType","has","push","add","isTSTypeReference","typeParameters","typeName","existing","get","params","baseType","genericName"],"sources":["../../../src/modifications/typescript/removeTypeDuplicates.ts"],"sourcesContent":["import {\n isIdentifier,\n isTSAnyKeyword,\n isTSTypeReference,\n isTSUnionType,\n isTSBaseType,\n} from \"../../validators/generated/index.ts\";\nimport type * as t from \"../../index.ts\";\n\nfunction getQualifiedName(node: t.TSTypeReference[\"typeName\"]): string {\n return isIdentifier(node)\n ? node.name\n : `${node.right.name}.${getQualifiedName(node.left)}`;\n}\n\n/**\n * Dedupe type annotations.\n */\nexport default function removeTypeDuplicates(\n nodesIn: ReadonlyArray<t.TSType>,\n): Array<t.TSType> {\n const nodes = Array.from(nodesIn);\n\n const generics = new Map<string, t.TSTypeReference>();\n const bases = new Map<t.TSBaseType[\"type\"], t.TSBaseType>();\n\n // store union type groups to circular references\n const typeGroups = new Set<t.TSType[]>();\n\n const types: t.TSType[] = [];\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (!node) continue;\n\n // detect duplicates\n if (types.indexOf(node) >= 0) {\n continue;\n }\n\n // this type matches anything\n if (isTSAnyKeyword(node)) {\n return [node];\n }\n\n // Analogue of FlowBaseAnnotation\n if (isTSBaseType(node)) {\n bases.set(node.type, node);\n continue;\n }\n\n if (isTSUnionType(node)) {\n if (!typeGroups.has(node.types)) {\n nodes.push(...node.types);\n typeGroups.add(node.types);\n }\n continue;\n }\n\n // todo: support merging tuples: number[]\n if (isTSTypeReference(node) && node.typeParameters) {\n const name = getQualifiedName(node.typeName);\n\n if (generics.has(name)) {\n let existing: t.TypeScript = generics.get(name);\n if (existing.typeParameters) {\n if (node.typeParameters) {\n existing.typeParameters.params.push(...node.typeParameters.params);\n existing.typeParameters.params = removeTypeDuplicates(\n existing.typeParameters.params,\n );\n }\n } else {\n existing = node.typeParameters;\n }\n } else {\n generics.set(name, node);\n }\n\n continue;\n }\n\n types.push(node);\n }\n\n // add back in bases\n for (const [, baseType] of bases) {\n types.push(baseType);\n }\n\n // add back in generics\n for (const [, genericName] of generics) {\n types.push(genericName);\n }\n\n return types;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AASA,SAASC,gBAAgBA,CAACC,IAAmC,EAAU;EACrE,OAAO,IAAAC,mBAAY,EAACD,IAAI,CAAC,GACrBA,IAAI,CAACE,IAAI,GACR,GAAEF,IAAI,CAACG,KAAK,CAACD,IAAK,IAAGH,gBAAgB,CAACC,IAAI,CAACI,IAAI,CAAE,EAAC;AACzD;AAKe,SAASC,oBAAoBA,CAC1CC,OAAgC,EACf;EACjB,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAACH,OAAO,CAAC;EAEjC,MAAMI,QAAQ,GAAG,IAAIC,GAAG,CAA4B,CAAC;EACrD,MAAMC,KAAK,GAAG,IAAID,GAAG,CAAqC,CAAC;EAG3D,MAAME,UAAU,GAAG,IAAIC,GAAG,CAAa,CAAC;EAExC,MAAMC,KAAiB,GAAG,EAAE;EAE5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGT,KAAK,CAACU,MAAM,EAAED,CAAC,EAAE,EAAE;IACrC,MAAMhB,IAAI,GAAGO,KAAK,CAACS,CAAC,CAAC;IACrB,IAAI,CAAChB,IAAI,EAAE;IAGX,IAAIe,KAAK,CAACG,OAAO,CAAClB,IAAI,CAAC,IAAI,CAAC,EAAE;MAC5B;IACF;IAGA,IAAI,IAAAmB,qBAAc,EAACnB,IAAI,CAAC,EAAE;MACxB,OAAO,CAACA,IAAI,CAAC;IACf;IAGA,IAAI,IAA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