@@ -424,11 +424,16 @@ namespace ts {
424424
425425 export function some < T > ( array : T [ ] , predicate ?: ( value : T ) => boolean ) : boolean {
426426 if ( array ) {
427- for ( const v of array ) {
428- if ( ! predicate || predicate ( v ) ) {
429- return true ;
427+ if ( predicate ) {
428+ for ( const v of array ) {
429+ if ( predicate ( v ) ) {
430+ return true ;
431+ }
430432 }
431433 }
434+ else {
435+ return array . length > 0 ;
436+ }
432437 }
433438 return false ;
434439 }
@@ -485,21 +490,35 @@ namespace ts {
485490 return result ;
486491 }
487492
493+ /**
494+ * Appends a value to an array, returning the array.
495+ *
496+ * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
497+ * is created if `value` was appended.
498+ * @param value The value to append to the array. If `value` is `undefined`, nothing is
499+ * appended.
500+ */
488501 export function append < T > ( to : T [ ] | undefined , value : T | undefined ) : T [ ] | undefined {
489502 if ( value === undefined ) return to ;
490503 if ( to === undefined ) to = [ ] ;
491504 to . push ( value ) ;
492505 return to ;
493506 }
494507
495- export function addRange < T > ( to : T [ ] , from : T [ ] ) : void {
496- if ( to && from ) {
497- for ( const v of from ) {
498- if ( v !== undefined ) {
499- to . push ( v ) ;
500- }
501- }
508+ /**
509+ * Appends a range of value to an array, returning the array.
510+ *
511+ * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
512+ * is created if `value` was appended.
513+ * @param from The values to append to the array. If `from` is `undefined`, nothing is
514+ * appended. If an element of `from` is `undefined`, that element is not appended.
515+ */
516+ export function addRange < T > ( to : T [ ] | undefined , from : T [ ] | undefined ) : T [ ] | undefined {
517+ if ( from === undefined ) return to ;
518+ for ( const v of from ) {
519+ to = append ( to , v ) ;
502520 }
521+ return to ;
503522 }
504523
505524 export function rangeEquals < T > ( array1 : T [ ] , array2 : T [ ] , pos : number , end : number ) {
@@ -512,33 +531,43 @@ namespace ts {
512531 return true ;
513532 }
514533
534+ /**
535+ * Returns the first element of an array if non-empty, `undefined` otherwise.
536+ */
515537 export function firstOrUndefined < T > ( array : T [ ] ) : T {
516538 return array && array . length > 0
517539 ? array [ 0 ]
518540 : undefined ;
519541 }
520542
543+ /**
544+ * Returns the last element of an array if non-empty, `undefined` otherwise.
545+ */
546+ export function lastOrUndefined < T > ( array : T [ ] ) : T {
547+ return array && array . length > 0
548+ ? array [ array . length - 1 ]
549+ : undefined ;
550+ }
551+
552+ /**
553+ * Returns the only element of an array if it contains only one element, `undefined` otherwise.
554+ */
521555 export function singleOrUndefined < T > ( array : T [ ] ) : T {
522556 return array && array . length === 1
523557 ? array [ 0 ]
524558 : undefined ;
525559 }
526560
561+ /**
562+ * Returns the only element of an array if it contains only one element; otheriwse, returns the
563+ * array.
564+ */
527565 export function singleOrMany < T > ( array : T [ ] ) : T | T [ ] {
528566 return array && array . length === 1
529567 ? array [ 0 ]
530568 : array ;
531569 }
532570
533- /**
534- * Returns the last element of an array if non-empty, undefined otherwise.
535- */
536- export function lastOrUndefined < T > ( array : T [ ] ) : T {
537- return array && array . length > 0
538- ? array [ array . length - 1 ]
539- : undefined ;
540- }
541-
542571 /**
543572 * Performs a binary search, finding the index at which 'value' occurs in 'array'.
544573 * If no such index is found, returns the 2's-complement of first index at which
0 commit comments