@@ -68,13 +68,13 @@ namespace ts {
68
68
}
69
69
70
70
// The global Map object. This may not be available, so we must test for it.
71
- declare const Map : { new < T > ( ) : Map < T > } | undefined ;
71
+ declare const Map : { new < T > ( ) : Map < T > } | undefined ;
72
72
// Internet Explorer's Map doesn't support iteration, so don't use it.
73
73
// tslint:disable-next-line no-in-operator variable-name
74
74
const MapCtr = typeof Map !== "undefined" && "entries" in Map . prototype ? Map : shimMap ( ) ;
75
75
76
76
// Keep the class inside a function so it doesn't get compiled if it's not used.
77
- function shimMap ( ) : { new < T > ( ) : Map < T > } {
77
+ function shimMap ( ) : { new < T > ( ) : Map < T > } {
78
78
79
79
class MapIterator < T , U extends ( string | T | [ string , T ] ) > {
80
80
private data : MapLike < T > ;
@@ -97,7 +97,7 @@ namespace ts {
97
97
}
98
98
}
99
99
100
- return class < T > implements Map < T > {
100
+ return class < T > implements Map < T > {
101
101
private data = createDictionaryObject < T > ( ) ;
102
102
public size = 0 ;
103
103
@@ -394,11 +394,13 @@ namespace ts {
394
394
return result ;
395
395
}
396
396
397
- export function mapIter < T , U > ( iter : Iterator < T > , mapFn : ( x : T ) => U ) : Iterator < U > {
398
- return { next } ;
399
- function next ( ) : { value : U , done : false } | { value : never , done : true } {
400
- const iterRes = iter . next ( ) ;
401
- return iterRes . done ? iterRes : { value : mapFn ( iterRes . value ) , done : false } ;
397
+
398
+ export function mapIterator < T , U > ( iter : Iterator < T > , mapFn : ( x : T ) => U ) : Iterator < U > {
399
+ return {
400
+ next ( ) {
401
+ const iterRes = iter . next ( ) ;
402
+ return iterRes . done ? iterRes : { value : mapFn ( iterRes . value ) , done : false } ;
403
+ }
402
404
}
403
405
}
404
406
@@ -936,6 +938,36 @@ namespace ts {
936
938
return array . slice ( ) . sort ( comparer ) ;
937
939
}
938
940
941
+ export function best < T > ( iter : Iterator < T > , isBetter : ( a : T , b : T ) => boolean ) : T | undefined {
942
+ const x = iter . next ( ) ;
943
+ if ( x . done ) {
944
+ return undefined ;
945
+ }
946
+ let best = x . value ;
947
+ while ( true ) {
948
+ const { value, done } = iter . next ( ) ;
949
+ if ( done ) {
950
+ return best ;
951
+ }
952
+ if ( isBetter ( value , best ) ) {
953
+ best = value ;
954
+ }
955
+ }
956
+ }
957
+
958
+ export function arrayIterator < T > ( array : ReadonlyArray < T > ) : Iterator < T > {
959
+ let i = 0 ;
960
+ return { next : ( ) => {
961
+ if ( i === array . length ) {
962
+ return { value : undefined as never , done : true } ;
963
+ }
964
+ else {
965
+ i ++ ;
966
+ return { value : array [ i - 1 ] , done : false } ;
967
+ }
968
+ } } ;
969
+ }
970
+
939
971
/**
940
972
* Stable sort of an array. Elements equal to each other maintain their relative position in the array.
941
973
*/
@@ -1241,10 +1273,12 @@ namespace ts {
1241
1273
return result ;
1242
1274
}
1243
1275
1244
- export function arrayToNumericMap < T > ( array : ReadonlyArray < T > , makeKey : ( value : T ) => number ) : T [ ] {
1245
- const result : T [ ] = [ ] ;
1276
+ export function arrayToNumericMap < T > ( array : ReadonlyArray < T > , makeKey : ( value : T ) => number ) : T [ ] ;
1277
+ export function arrayToNumericMap < T , V > ( array : ReadonlyArray < T > , makeKey : ( value : T ) => number , makeValue : ( value : T ) => V ) : V [ ] ;
1278
+ export function arrayToNumericMap < T , V > ( array : ReadonlyArray < T > , makeKey : ( value : T ) => number , makeValue ?: ( value : T ) => V ) : V [ ] {
1279
+ const result : V [ ] = [ ] ;
1246
1280
for ( const value of array ) {
1247
- result [ makeKey ( value ) ] = value ;
1281
+ result [ makeKey ( value ) ] = makeValue ? makeValue ( value ) : value as any as V ;
1248
1282
}
1249
1283
return result ;
1250
1284
}
@@ -1343,6 +1377,12 @@ namespace ts {
1343
1377
return Array . isArray ? Array . isArray ( value ) : value instanceof Array ;
1344
1378
}
1345
1379
1380
+ export function toArray < T > ( value : T | ReadonlyArray < T > ) : ReadonlyArray < T > ;
1381
+ export function toArray < T > ( value : T | T [ ] ) : T [ ] ;
1382
+ export function toArray < T > ( value : T | T [ ] ) : T [ ] {
1383
+ return isArray ( value ) ? value : [ value ] ;
1384
+ }
1385
+
1346
1386
/**
1347
1387
* Tests whether a value is string
1348
1388
*/
@@ -1942,7 +1982,7 @@ namespace ts {
1942
1982
: moduleKind === ModuleKind . System ;
1943
1983
}
1944
1984
1945
- export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict" ;
1985
+ export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | " alwaysStrict";
1946
1986
1947
1987
export function getStrictOptionValue ( compilerOptions : CompilerOptions , flag : StrictOptionName ) : boolean {
1948
1988
return compilerOptions [ flag ] === undefined ? compilerOptions . strict : compilerOptions [ flag ] ;
@@ -2052,7 +2092,7 @@ namespace ts {
2052
2092
}
2053
2093
}
2054
2094
2055
- export function getRelativePathToDirectoryOrUrl ( directoryPathOrUrl : string , relativeOrAbsolutePath : string , currentDirectory : string , getCanonicalFileName : ( fileName : string ) => string , isAbsolutePathAnUrl : boolean ) {
2095
+ export function getRelativePathToDirectoryOrUrl ( directoryPathOrUrl : string , relativeOrAbsolutePath : string , currentDirectory : string , getCanonicalFileName : GetCanonicalFileName , isAbsolutePathAnUrl : boolean ) {
2056
2096
const pathComponents = getNormalizedPathOrUrlComponents ( relativeOrAbsolutePath , currentDirectory ) ;
2057
2097
const directoryComponents = getNormalizedPathOrUrlComponents ( directoryPathOrUrl , currentDirectory ) ;
2058
2098
if ( directoryComponents . length > 1 && lastOrUndefined ( directoryComponents ) === "" ) {
@@ -2188,6 +2228,10 @@ namespace ts {
2188
2228
return expectedPos >= 0 && str . indexOf ( suffix , expectedPos ) === expectedPos ;
2189
2229
}
2190
2230
2231
+ export function removeSuffix ( str : string , suffix : string ) : string {
2232
+ return endsWith ( str , suffix ) ? str . slice ( 0 , str . length - suffix . length ) : str ;
2233
+ }
2234
+
2191
2235
export function stringContains ( str : string , substring : string ) : boolean {
2192
2236
return str . indexOf ( substring ) !== - 1 ;
2193
2237
}
@@ -2654,6 +2698,17 @@ namespace ts {
2654
2698
return < T > ( removeFileExtension ( path ) + newExtension ) ;
2655
2699
}
2656
2700
2701
+ /**
2702
+ * Takes a string like "jquery-min.4.2.3" and returns "jquery"
2703
+ */
2704
+ export function removeMinAndVersionNumbers ( fileName : string ) {
2705
+ // Match a "." or "-" followed by a version number or 'min' at the end of the name
2706
+ const trailingMinOrVersion = / [ . - ] ( ( m i n ) | ( \d + ( \. \d + ) * ) ) $ / ;
2707
+
2708
+ // The "min" or version may both be present, in either order, so try applying the above twice.
2709
+ return fileName . replace ( trailingMinOrVersion , "" ) . replace ( trailingMinOrVersion , "" ) ;
2710
+ }
2711
+
2657
2712
export interface ObjectAllocator {
2658
2713
getNodeConstructor ( ) : new ( kind : SyntaxKind , pos ?: number , end ?: number ) => Node ;
2659
2714
getTokenConstructor ( ) : new < TKind extends SyntaxKind > ( kind : TKind , pos ?: number , end ?: number ) => Token < TKind > ;
@@ -2716,6 +2771,12 @@ namespace ts {
2716
2771
VeryAggressive = 3 ,
2717
2772
}
2718
2773
2774
+ /**
2775
+ * Safer version of `Function` which should not be called.
2776
+ * Every function should be assignable to this, but this should not be assignable to every function.
2777
+ */
2778
+ export type AnyFunction = ( ...args : never [ ] ) => void ;
2779
+
2719
2780
export namespace Debug {
2720
2781
export let currentAssertionLevel = AssertionLevel . None ;
2721
2782
export let isDebugging = false ;
@@ -2724,7 +2785,7 @@ namespace ts {
2724
2785
return currentAssertionLevel >= level ;
2725
2786
}
2726
2787
2727
- export function assert ( expression : boolean , message ?: string , verboseDebugInfo ?: string | ( ( ) => string ) , stackCrawlMark ?: Function ) : void {
2788
+ export function assert ( expression : boolean , message ?: string , verboseDebugInfo ?: string | ( ( ) => string ) , stackCrawlMark ?: AnyFunction ) : void {
2728
2789
if ( ! expression ) {
2729
2790
if ( verboseDebugInfo ) {
2730
2791
message += "\r\nVerbose Debug Information: " + ( typeof verboseDebugInfo === "string" ? verboseDebugInfo : verboseDebugInfo ( ) ) ;
@@ -2758,7 +2819,7 @@ namespace ts {
2758
2819
}
2759
2820
}
2760
2821
2761
- export function fail ( message ?: string , stackCrawlMark ?: Function ) : never {
2822
+ export function fail ( message ?: string , stackCrawlMark ?: AnyFunction ) : never {
2762
2823
debugger ;
2763
2824
const e = new Error ( message ? `Debug Failure. ${ message } ` : "Debug Failure." ) ;
2764
2825
if ( ( < any > Error ) . captureStackTrace ) {
@@ -2767,11 +2828,11 @@ namespace ts {
2767
2828
throw e ;
2768
2829
}
2769
2830
2770
- export function assertNever ( member : never , message ?: string , stackCrawlMark ?: Function ) : never {
2831
+ export function assertNever ( member : never , message ?: string , stackCrawlMark ?: AnyFunction ) : never {
2771
2832
return fail ( message || `Illegal value: ${ member } ` , stackCrawlMark || assertNever ) ;
2772
2833
}
2773
2834
2774
- export function getFunctionName ( func : Function ) {
2835
+ export function getFunctionName ( func : AnyFunction ) {
2775
2836
if ( typeof func !== "function" ) {
2776
2837
return "" ;
2777
2838
}
@@ -2827,7 +2888,8 @@ namespace ts {
2827
2888
}
2828
2889
}
2829
2890
2830
- export function createGetCanonicalFileName ( useCaseSensitiveFileNames : boolean ) : ( fileName : string ) => string {
2891
+ export type GetCanonicalFileName = ( fileName : string ) => string ;
2892
+ export function createGetCanonicalFileName ( useCaseSensitiveFileNames : boolean ) : GetCanonicalFileName {
2831
2893
return useCaseSensitiveFileNames
2832
2894
? ( ( fileName ) => fileName )
2833
2895
: ( ( fileName ) => fileName . toLowerCase ( ) ) ;
@@ -2854,7 +2916,7 @@ namespace ts {
2854
2916
return findBestPatternMatch ( patterns , _ => _ , candidate ) ;
2855
2917
}
2856
2918
2857
- export function patternText ( { prefix, suffix} : Pattern ) : string {
2919
+ export function patternText ( { prefix, suffix } : Pattern ) : string {
2858
2920
return `${ prefix } *${ suffix } ` ;
2859
2921
}
2860
2922
@@ -2884,7 +2946,7 @@ namespace ts {
2884
2946
return matchedValue ;
2885
2947
}
2886
2948
2887
- function isPatternMatch ( { prefix, suffix} : Pattern , candidate : string ) {
2949
+ function isPatternMatch ( { prefix, suffix } : Pattern , candidate : string ) {
2888
2950
return candidate . length >= prefix . length + suffix . length &&
2889
2951
startsWith ( candidate , prefix ) &&
2890
2952
endsWith ( candidate , suffix ) ;
0 commit comments