@@ -59,7 +59,7 @@ namespace ts {
59
59
}
60
60
61
61
declare const Map : { new < T > ( ) : NativeMap < T > } | undefined ;
62
- const realMaps = typeof Map !== "undefined" ; //false;
62
+ const realMaps = typeof Map !== "undefined" ;
63
63
64
64
const createObject = Object . create ;
65
65
const hasOwnProperty = Object . prototype . hasOwnProperty ;
@@ -92,8 +92,6 @@ namespace ts {
92
92
return map ;
93
93
}
94
94
95
- //PRIMITIVE OPERATIONS: Need a different strategy for real map vs {}
96
-
97
95
export const _g : < T > ( map : Map < T > , key : string ) => T = realMaps
98
96
? < T > ( map : NativeMap < T > , key : string ) => map . get ( key )
99
97
: < T > ( map : MapLike < T > , key : string ) => map [ key ] ;
@@ -139,7 +137,6 @@ namespace ts {
139
137
140
138
export const _find : < T , U > ( map : Map < T > , f : ( key : string , value : T ) => U | undefined ) => U | undefined = realMaps
141
139
? < T , U > ( map : NativeMap < T > , f : ( key : string , value : T ) => U | undefined ) => {
142
- //use forEach?
143
140
const iter = map . entries ( ) ;
144
141
while ( true ) {
145
142
const { value : pair , done } = iter . next ( ) ;
@@ -321,11 +318,6 @@ namespace ts {
321
318
}
322
319
return undefined ;
323
320
} ;
324
-
325
- //kill
326
- export function checkNotNativeMap ( value : MapLike < any > ) {
327
- Debug . assert ( ! ( value instanceof Map ) ) ;
328
- }
329
321
}
330
322
331
323
@@ -366,12 +358,18 @@ namespace ts {
366
358
* @param source A map from which properties should be copied.
367
359
* @param target A map to which properties should be copied.
368
360
*/
361
+ //rename : "entries", not "properties"
369
362
export function copyMapPropertiesFromTo < T > ( source : Map < T > , target : Map < T > ) : void {
370
363
_each ( source , ( key , value ) => {
371
364
_s ( target , key , value ) ;
372
365
} ) ;
373
366
}
374
367
368
+ //move
369
+ export function copySetValuesFromTo < T > ( source : Set , target : Set ) : void {
370
+ _eachInSet ( source , value => _add ( target , value ) ) ;
371
+ }
372
+
375
373
//kill?
376
374
/**
377
375
* Reduce the properties of a map.
@@ -497,16 +495,39 @@ namespace ts {
497
495
declare const Set : { new ( ) : NativeSet } | undefined ;
498
496
const realSets = typeof Set !== "undefined" ;
499
497
498
+ /*interface StringSetModule {
499
+ createSet(): Set
500
+ add(set: Set, value: string): string;
501
+ }
502
+ const StringSet: StringSetModule = realSets ?
503
+ {
504
+ createSet: () => new Set(),
505
+ add(set: NativeSet, value: string) {
506
+ set.add(value);
507
+ return value;
508
+ }
509
+ }
510
+ :
511
+ {
512
+ createSet: () => createDictionaryModeObject(),
513
+ add(set: SetLike, value: string) {
514
+ set[value] = true;
515
+ return value;
516
+ }
517
+ }*/
518
+
500
519
export const createSet : ( ) => Set = realSets
501
520
? ( ) => new Set ( )
502
521
: ( ) => createDictionaryModeObject ( ) ;
503
522
504
- export const _add : ( set : Set , value : string ) => void = realSets
523
+ export const _add : ( set : Set , value : string ) => string = realSets
505
524
? ( set : NativeSet , value : string ) => {
506
525
set . add ( value ) ;
526
+ return value ;
507
527
}
508
528
: ( set : SetLike , value : string ) => {
509
529
set [ value ] = true ;
530
+ return value ;
510
531
}
511
532
512
533
export const _setHas : ( set : Set , value : string ) => boolean = realSets
@@ -537,15 +558,9 @@ namespace ts {
537
558
for ( const value in set )
538
559
f ( value ) ;
539
560
}
540
-
541
- //todo: more iteration helpers
542
561
}
543
562
544
-
545
-
546
-
547
-
548
- //MAPLIKE CRAP
563
+ //MAPLIKE
549
564
/* @internal */
550
565
namespace ts {
551
566
const hasOwnProperty = Object . prototype . hasOwnProperty ; //neater
@@ -570,7 +585,6 @@ namespace ts {
570
585
* @param key A property key.
571
586
*/
572
587
export function hasProperty < T > ( map : MapLike < T > , key : string ) : boolean {
573
- checkNotNativeMap ( map ) ;
574
588
return hasOwnProperty . call ( map , key ) ;
575
589
}
576
590
@@ -584,7 +598,6 @@ namespace ts {
584
598
* @param key A property key.
585
599
*/
586
600
export function getProperty < T > ( map : MapLike < T > , key : string ) : T | undefined {
587
- checkNotNativeMap ( map ) ;
588
601
return hasOwnProperty . call ( map , key ) ? map [ key ] : undefined ;
589
602
}
590
603
@@ -597,7 +610,6 @@ namespace ts {
597
610
* @param map A map-like.
598
611
*/
599
612
export function getOwnKeys < T > ( map : MapLike < T > ) : string [ ] {
600
- checkNotNativeMap ( map ) ;
601
613
const keys : string [ ] = [ ] ;
602
614
for ( const key in map ) if ( hasOwnProperty . call ( map , key ) ) {
603
615
keys . push ( key ) ;
@@ -609,9 +621,7 @@ namespace ts {
609
621
export function assign < T1 extends MapLike < { } > , T2 > ( t : T1 , arg1 : T2 ) : T1 & T2 ;
610
622
export function assign < T1 extends MapLike < { } > > ( t : T1 , ...args : any [ ] ) : any ;
611
623
export function assign < T1 extends MapLike < { } > > ( t : T1 , ...args : any [ ] ) {
612
- checkNotNativeMap ( t ) ;
613
624
for ( const arg of args ) {
614
- checkNotNativeMap ( arg ) ;
615
625
for ( const p of getOwnKeys ( arg ) ) {
616
626
t [ p ] = arg [ p ] ;
617
627
}
@@ -630,7 +640,6 @@ namespace ts {
630
640
* @param initial The initial value for the reduction.
631
641
*/
632
642
export function reduceOwnProperties < T , U > ( map : MapLike < T > , callback : ( aggregate : U , value : T , key : string ) => U , initial : U ) : U {
633
- checkNotNativeMap ( map ) ;
634
643
let result = initial ;
635
644
for ( const key in map ) if ( hasOwnProperty . call ( map , key ) ) {
636
645
result = callback ( result , map [ key ] , String ( key ) ) ;
@@ -645,8 +654,6 @@ namespace ts {
645
654
* @param right A map-like whose properties should be compared.
646
655
*/
647
656
export function equalOwnProperties < T > ( left : MapLike < T > , right : MapLike < T > , equalityComparer ?: ( left : T , right : T ) => boolean ) {
648
- checkNotNativeMap ( left ) ;
649
- checkNotNativeMap ( right ) ;
650
657
if ( left === right ) return true ;
651
658
if ( ! left || ! right ) return false ;
652
659
for ( const key in left ) if ( hasOwnProperty . call ( left , key ) ) {
@@ -660,8 +667,6 @@ namespace ts {
660
667
}
661
668
662
669
export function extend < T1 , T2 > ( first : T1 , second : T2 ) : T1 & T2 {
663
- checkNotNativeMap ( first ) ;
664
- checkNotNativeMap ( second ) ;
665
670
const result : T1 & T2 = < any > { } ;
666
671
for ( const id in second ) if ( hasOwnProperty . call ( second , id ) ) {
667
672
( result as any ) [ id ] = ( second as any ) [ id ] ;
0 commit comments