@@ -30,8 +30,10 @@ namespace ts {
30
30
map [ "__" ] = undefined ;
31
31
delete map [ "__" ] ;
32
32
33
- if ( template ) {
34
- copyOwnProperties ( template , map ) ;
33
+ // Copies keys/values from template. Note that for..in will not throw if
34
+ // template is undefined, and instead will just exit the loop.
35
+ for ( const key in template ) if ( hasOwnProperty . call ( template , key ) ) {
36
+ map [ key ] = template [ key ] ;
35
37
}
36
38
37
39
return map ;
@@ -412,9 +414,6 @@ namespace ts {
412
414
/**
413
415
* Enumerates the properties of a Map<T>, invoking a callback and returning the first truthy result.
414
416
*
415
- * NOTE: This is intended for use with Map<T> objects. For MapLike<T> objects, use
416
- * forEachOwnProperties instead as it offers better runtime safety.
417
- *
418
417
* @param map A map for which properties should be enumerated.
419
418
* @param callback A callback to invoke for each property.
420
419
*/
@@ -426,53 +425,6 @@ namespace ts {
426
425
return result ;
427
426
}
428
427
429
- /**
430
- * Enumerates the owned properties of a MapLike<T>, invoking a callback and returning the first truthy result.
431
- *
432
- * NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
433
- * forEachProperty instead as it offers better performance.
434
- *
435
- * @param map A map for which properties should be enumerated.
436
- * @param callback A callback to invoke for each property.
437
- */
438
- export function forEachOwnProperty < T , U > ( map : MapLike < T > , callback : ( value : T , key : string ) => U ) : U {
439
- let result : U ;
440
- for ( const key in map ) if ( hasOwnProperty . call ( map , key ) ) {
441
- if ( result = callback ( map [ key ] , key ) ) break ;
442
- }
443
- return result ;
444
- }
445
-
446
- /**
447
- * Maps key-value pairs of a map into a new map.
448
- *
449
- * NOTE: The key-value pair passed to the callback is *not* safe to cache between invocations
450
- * of the callback.
451
- *
452
- * @param map A map.
453
- * @param callback A callback that maps a key-value pair into a new key-value pair.
454
- */
455
- export function mapPairs < T , U > ( map : Map < T > , callback : ( entry : [ string , T ] ) => [ string , U ] ) : Map < U > {
456
- let result : Map < U > ;
457
- if ( map ) {
458
- result = createMap < U > ( ) ;
459
- let inPair : [ string , T ] ;
460
- for ( const key in map ) {
461
- if ( inPair ) {
462
- inPair [ 0 ] = key ;
463
- inPair [ 1 ] = map [ key ] ;
464
- }
465
- else {
466
- inPair = [ key , map [ key ] ] ;
467
- }
468
-
469
- const outPair = callback ( inPair ) ;
470
- result [ outPair [ 0 ] ] = outPair [ 1 ] ;
471
- }
472
- }
473
- return result ;
474
- }
475
-
476
428
/**
477
429
* Returns true if a Map<T> has some matching property.
478
430
*
@@ -489,9 +441,6 @@ namespace ts {
489
441
/**
490
442
* Performs a shallow copy of the properties from a source Map<T> to a target MapLike<T>
491
443
*
492
- * NOTE: This is intended for use with Map<T> objects. For MapLike<T> objects, use
493
- * copyOwnProperties instead as it offers better runtime safety.
494
- *
495
444
* @param source A map from which properties should be copied.
496
445
* @param target A map to which properties should be copied.
497
446
*/
@@ -501,21 +450,6 @@ namespace ts {
501
450
}
502
451
}
503
452
504
- /**
505
- * Performs a shallow copy of the owned properties from a source map to a target map-like.
506
- *
507
- * NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
508
- * copyProperties instead as it offers better performance.
509
- *
510
- * @param source A map-like from which properties should be copied.
511
- * @param target A map-like to which properties should be copied.
512
- */
513
- export function copyOwnProperties < T > ( source : MapLike < T > , target : MapLike < T > ) : void {
514
- for ( const key in source ) if ( hasOwnProperty . call ( source , key ) ) {
515
- target [ key ] = source [ key ] ;
516
- }
517
- }
518
-
519
453
/**
520
454
* Reduce the properties of a map.
521
455
*
@@ -552,72 +486,9 @@ namespace ts {
552
486
return result ;
553
487
}
554
488
555
- /**
556
- * Counts the properties of a map.
557
- *
558
- * NOTE: This is intended for use with Map<T> objects. For MapLike<T> objects, use
559
- * countOwnProperties instead as it offers better runtime safety.
560
- *
561
- * @param map A map whose properties should be counted.
562
- * @param predicate An optional callback used to limit which properties should be counted.
563
- */
564
- export function countProperties < T > ( map : Map < T > , predicate ?: ( value : T , key : string ) => boolean ) {
565
- let count = 0 ;
566
- for ( const key in map ) {
567
- if ( ! predicate || predicate ( map [ key ] , key ) ) {
568
- count ++ ;
569
- }
570
- }
571
- return count ;
572
- }
573
-
574
- /**
575
- * Counts the owned properties of a map-like.
576
- *
577
- * NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
578
- * countProperties instead as it offers better performance.
579
- *
580
- * @param map A map-like whose properties should be counted.
581
- * @param predicate An optional callback used to limit which properties should be counted.
582
- */
583
- export function countOwnProperties < T > ( map : MapLike < T > , predicate ?: ( value : T , key : string ) => boolean ) {
584
- let count = 0 ;
585
- for ( const key in map ) if ( hasOwnProperty . call ( map , key ) ) {
586
- if ( ! predicate || predicate ( map [ key ] , key ) ) {
587
- count ++ ;
588
- }
589
- }
590
- return count ;
591
- }
592
-
593
- /**
594
- * Performs a shallow equality comparison of the contents of two maps.
595
- *
596
- * NOTE: This is intended for use with Map<T> objects. For MapLike<T> objects, use
597
- * equalOwnProperties instead as it offers better runtime safety.
598
- *
599
- * @param left A map whose properties should be compared.
600
- * @param right A map whose properties should be compared.
601
- */
602
- export function equalProperties < T > ( left : Map < T > , right : Map < T > , equalityComparer ?: ( left : T , right : T ) => boolean ) {
603
- if ( left === right ) return true ;
604
- if ( ! left || ! right ) return false ;
605
- for ( const key in left ) {
606
- if ( ! ( key in right ) ) return false ;
607
- if ( equalityComparer ? ! equalityComparer ( left [ key ] , right [ key ] ) : left [ key ] !== right [ key ] ) return false ;
608
- }
609
- for ( const key in right ) {
610
- if ( ! ( key in left ) ) return false ;
611
- }
612
- return true ;
613
- }
614
-
615
489
/**
616
490
* Performs a shallow equality comparison of the contents of two map-likes.
617
491
*
618
- * NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
619
- * equalProperties instead as it offers better performance.
620
- *
621
492
* @param left A map-like whose properties should be compared.
622
493
* @param right A map-like whose properties should be compared.
623
494
*/
@@ -670,17 +541,13 @@ namespace ts {
670
541
return result ;
671
542
}
672
543
673
- export function extend < T1 extends MapLike < { } > , T2 extends MapLike < { } > > ( first : T1 , second : T2 ) : T1 & T2 {
544
+ export function extend < T1 , T2 > ( first : T1 , second : T2 ) : T1 & T2 {
674
545
const result : T1 & T2 = < any > { } ;
675
- for ( const id in first ) {
676
- if ( hasOwnProperty . call ( first , id ) ) {
677
- ( result as any ) [ id ] = first [ id ] ;
678
- }
546
+ for ( const id in second ) if ( hasOwnProperty . call ( second , id ) ) {
547
+ ( result as any ) [ id ] = ( second as any ) [ id ] ;
679
548
}
680
- for ( const id in second ) {
681
- if ( hasOwnProperty . call ( second , id ) && ! hasOwnProperty . call ( result , id ) ) {
682
- ( result as any ) [ id ] = second [ id ] ;
683
- }
549
+ for ( const id in first ) if ( hasOwnProperty . call ( first , id ) ) {
550
+ ( result as any ) [ id ] = ( first as any ) [ id ] ;
684
551
}
685
552
return result ;
686
553
}
0 commit comments