@@ -614,14 +614,14 @@ export class TypeTable {
614
614
// cannot be written using TypeScript syntax - so we ignore them entirely.
615
615
return null ;
616
616
}
617
- return this . makeTypeStringVector ( "union" , unionType . types ) ;
617
+ return this . makeDeduplicatedTypeStringVector ( "union" , unionType . types ) ;
618
618
}
619
619
if ( flags & ts . TypeFlags . Intersection ) {
620
620
let intersectionType = type as ts . IntersectionType ;
621
621
if ( intersectionType . types . length === 0 ) {
622
622
return null ; // Ignore malformed type.
623
623
}
624
- return this . makeTypeStringVector ( "intersection" , intersectionType . types ) ;
624
+ return this . makeDeduplicatedTypeStringVector ( "intersection" , intersectionType . types ) ;
625
625
}
626
626
if ( isTypeReference ( type ) && ( type . target . objectFlags & ts . ObjectFlags . Tuple ) ) {
627
627
// Encode the minimum length and presence of rest element in the first two parts of the type string.
@@ -784,6 +784,27 @@ export class TypeTable {
784
784
return hash ;
785
785
}
786
786
787
+ /**
788
+ * Returns the given string with the IDs of the given types appended,
789
+ * ignoring duplicates, and each separated by `;`.
790
+ */
791
+ private makeDeduplicatedTypeStringVector ( tag : string , types : ReadonlyArray < ts . Type > , length = types . length ) : string | null {
792
+ let seenIds = new Set < number > ( ) ;
793
+ let numberOfSeenIds = 0 ;
794
+ let hash = tag ;
795
+ for ( let i = 0 ; i < length ; ++ i ) {
796
+ let id = this . getId ( types [ i ] , false ) ;
797
+ if ( id == null ) return null ;
798
+ seenIds . add ( id ) ;
799
+ if ( seenIds . size > numberOfSeenIds ) {
800
+ // This ID was not seen before
801
+ ++ numberOfSeenIds ;
802
+ hash += ";" + id ;
803
+ }
804
+ }
805
+ return hash ;
806
+ }
807
+
787
808
/** Returns the type of `symbol` or `null` if it could not be computed. */
788
809
private tryGetTypeOfSymbol ( symbol : ts . Symbol ) {
789
810
try {
0 commit comments