astro-ghostcms/.pnpm-store/v3/files/11/f39170c93ce08a7c56de69cd9de...

1 line
4.9 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
{"version":3,"names":["_index","require","getQualifiedName","node","isIdentifier","name","id","qualification","removeTypeDuplicates","nodesIn","nodes","Array","from","generics","Map","bases","typeGroups","Set","types","i","length","indexOf","isAnyTypeAnnotation","isFlowBaseAnnotation","set","type","isUnionTypeAnnotation","has","push","add","isGenericTypeAnnotation","existing","get","typeParameters","params","baseType","genericName"],"sources":["../../../src/modifications/flow/removeTypeDuplicates.ts"],"sourcesContent":["import {\n isAnyTypeAnnotation,\n isGenericTypeAnnotation,\n isUnionTypeAnnotation,\n isFlowBaseAnnotation,\n isIdentifier,\n} from \"../../validators/generated/index.ts\";\nimport type * as t from \"../../index.ts\";\n\nfunction getQualifiedName(node: t.GenericTypeAnnotation[\"id\"]): string {\n return isIdentifier(node)\n ? node.name\n : `${node.id.name}.${getQualifiedName(node.qualification)}`;\n}\n\n/**\n * Dedupe type annotations.\n */\nexport default function removeTypeDuplicates(\n nodesIn: ReadonlyArray<t.FlowType | false | null | undefined>,\n): t.FlowType[] {\n const nodes = Array.from(nodesIn);\n\n const generics = new Map<string, t.GenericTypeAnnotation>();\n const bases = new Map<t.FlowBaseAnnotation[\"type\"], t.FlowBaseAnnotation>();\n\n // store union type groups to circular references\n const typeGroups = new Set<t.FlowType[]>();\n\n const types: t.FlowType[] = [];\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 (isAnyTypeAnnotation(node)) {\n return [node];\n }\n\n if (isFlowBaseAnnotation(node)) {\n bases.set(node.type, node);\n continue;\n }\n\n if (isUnionTypeAnnotation(node)) {\n if (!typeGroups.has(node.types)) {\n nodes.push(...node.types);\n typeGroups.add(node.types);\n }\n continue;\n }\n\n // find a matching generic type and merge and deduplicate the type parameters\n if (isGenericTypeAnnotation(node)) {\n const name = getQualifiedName(node.id);\n\n if (generics.has(name)) {\n let existing: t.Flow = 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,EAAE,CAACD,IAAK,IAAGH,gBAAgB,CAACC,IAAI,CAACI,aAAa,CAAE,EAAC;AAC/D;AAKe,SAASC,oBAAoBA,CAC1CC,OAA6D,EAC/C;EACd,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAACH,OAAO,CAAC;EAEjC,MAAMI,QAAQ,GAAG,IAAIC,GAAG,CAAkC,CAAC;EAC3D,MAAMC,KAAK,GAAG,IAAID,GAAG,CAAqD,CAAC;EAG3E,MAAME,UAAU,GAAG,IAAIC,GAAG,CAAe,CAAC;EAE1C,MAAMC,KAAmB,GAAG,EAAE;EAE9B,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,0BAAmB,EAACnB,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