Skip to content

Commit 3e5a731

Browse files
committed
Update removeTypeDuplicates
1 parent b5d80a6 commit 3e5a731

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

packages/babel-types/src/modifications/flow/removeTypeDuplicates.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function removeTypeDuplicates(
2424
const bases = {};
2525

2626
// store union type groups to circular references
27-
const typeGroups = [];
27+
const typeGroups = new Set<t.FlowType[]>();
2828

2929
const types = [];
3030

@@ -48,10 +48,10 @@ export default function removeTypeDuplicates(
4848
}
4949

5050
if (isUnionTypeAnnotation(node)) {
51-
if (typeGroups.indexOf(node.types) < 0) {
52-
// todo(babel-8): remove type casting
53-
(nodes as any).push(...node.types);
54-
typeGroups.push(node.types);
51+
if (!typeGroups.has(node.types)) {
52+
// todo(babel-8): use .push when nodes is mutable
53+
nodes = nodes.concat(node.types);
54+
typeGroups.add(node.types);
5555
}
5656
continue;
5757
}

packages/babel-types/src/modifications/typescript/removeTypeDuplicates.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function removeTypeDuplicates(
1515
const bases = {};
1616

1717
// store union type groups to circular references
18-
const typeGroups = [];
18+
const typeGroups = new Set<t.TSType[]>();
1919

2020
const types = [];
2121

@@ -40,9 +40,9 @@ export default function removeTypeDuplicates(
4040
}
4141

4242
if (isTSUnionType(node)) {
43-
if (typeGroups.indexOf(node.types) < 0) {
43+
if (!typeGroups.has(node.types)) {
4444
nodes.push(...node.types);
45-
typeGroups.push(node.types);
45+
typeGroups.add(node.types);
4646
}
4747
continue;
4848
}

0 commit comments

Comments
 (0)