@@ -268,13 +268,33 @@ namespace ts {
268268 if ( array ) {
269269 result = [ ] ;
270270 for ( let i = 0 ; i < array . length ; i ++ ) {
271- const v = array [ i ] ;
272- result . push ( f ( v , i ) ) ;
271+ result . push ( f ( array [ i ] , i ) ) ;
273272 }
274273 }
275274 return result ;
276275 }
277276
277+ // Maps from T to T and avoids allocation if all elements map to themselves
278+ export function sameMap < T > ( array : T [ ] , f : ( x : T , i : number ) => T ) : T [ ] {
279+ let result : T [ ] ;
280+ if ( array ) {
281+ for ( let i = 0 ; i < array . length ; i ++ ) {
282+ if ( result ) {
283+ result . push ( f ( array [ i ] , i ) ) ;
284+ }
285+ else {
286+ const item = array [ i ] ;
287+ const mapped = f ( item , i ) ;
288+ if ( item !== mapped ) {
289+ result = array . slice ( 0 , i ) ;
290+ result . push ( mapped ) ;
291+ }
292+ }
293+ }
294+ }
295+ return result || array ;
296+ }
297+
278298 /**
279299 * Flattens an array containing a mix of array or non-array elements.
280300 *
@@ -402,6 +422,17 @@ namespace ts {
402422 return result ;
403423 }
404424
425+ export function some < T > ( array : T [ ] , predicate ?: ( value : T ) => boolean ) : boolean {
426+ if ( array ) {
427+ for ( const v of array ) {
428+ if ( ! predicate || predicate ( v ) ) {
429+ return true ;
430+ }
431+ }
432+ }
433+ return false ;
434+ }
435+
405436 export function concatenate < T > ( array1 : T [ ] , array2 : T [ ] ) : T [ ] {
406437 if ( ! array2 || ! array2 . length ) return array1 ;
407438 if ( ! array1 || ! array1 . length ) return array2 ;
@@ -1181,7 +1212,7 @@ namespace ts {
11811212
11821213 /**
11831214 * Returns the path except for its basename. Eg:
1184- *
1215+ *
11851216 * /path/to/file.ext -> /path/to
11861217 */
11871218 export function getDirectoryPath ( path : Path ) : Path ;
@@ -1207,7 +1238,7 @@ namespace ts {
12071238 export function getEmitModuleKind ( compilerOptions : CompilerOptions ) {
12081239 return typeof compilerOptions . module === "number" ?
12091240 compilerOptions . module :
1210- getEmitScriptTarget ( compilerOptions ) === ScriptTarget . ES6 ? ModuleKind . ES6 : ModuleKind . CommonJS ;
1241+ getEmitScriptTarget ( compilerOptions ) >= ScriptTarget . ES2015 ? ModuleKind . ES2015 : ModuleKind . CommonJS ;
12111242 }
12121243
12131244 /* @internal */
0 commit comments