1
1
import { Comparer , Comparison , EqualityComparer , MapLike , Push , SortedArray , SortedReadonlyArray } from "./corePublic" ;
2
- import { Debug } from "./debug" ;
2
+ // import { Debug } from "./debug";
3
3
import { __String , CharacterCodes , Queue , TextSpan , UnderscoreEscapedMap } from "./types" ;
4
4
5
5
/** @internal */
@@ -122,7 +122,7 @@ export function reduceLeftIterator<T, U>(iterator: Iterator<T> | undefined, f: (
122
122
/** @internal */
123
123
export function zipWith < T , U , V > ( arrayA : readonly T [ ] , arrayB : readonly U [ ] , callback : ( a : T , b : U , index : number ) => V ) : V [ ] {
124
124
const result : V [ ] = [ ] ;
125
- Debug . assertEqual ( arrayA . length , arrayB . length ) ;
125
+ // Debug.assertEqual(arrayA.length, arrayB.length);
126
126
for ( let i = 0 ; i < arrayA . length ; i ++ ) {
127
127
result . push ( callback ( arrayA [ i ] , arrayB [ i ] , i ) ) ;
128
128
}
@@ -131,7 +131,7 @@ export function zipWith<T, U, V>(arrayA: readonly T[], arrayB: readonly U[], cal
131
131
132
132
/** @internal */
133
133
export function zipToIterator < T , U > ( arrayA : readonly T [ ] , arrayB : readonly U [ ] ) : Iterator < [ T , U ] > {
134
- Debug . assertEqual ( arrayA . length , arrayB . length ) ;
134
+ // Debug.assertEqual(arrayA.length, arrayB.length);
135
135
let i = 0 ;
136
136
return {
137
137
next ( ) {
@@ -146,7 +146,7 @@ export function zipToIterator<T, U>(arrayA: readonly T[], arrayB: readonly U[]):
146
146
147
147
/** @internal */
148
148
export function zipToMap < K , V > ( keys : readonly K [ ] , values : readonly V [ ] ) : Map < K , V > {
149
- Debug . assert ( keys . length === values . length ) ;
149
+ // Debug.assert(keys.length === values.length);
150
150
const map = new Map < K , V > ( ) ;
151
151
for ( let i = 0 ; i < keys . length ; ++ i ) {
152
152
map . set ( keys [ i ] , values [ i ] ) ;
@@ -266,7 +266,8 @@ export function findMap<T, U>(array: readonly T[], callback: (element: T, index:
266
266
return result ;
267
267
}
268
268
}
269
- return Debug . fail ( ) ;
269
+ // return Debug.fail();
270
+ throw new Error ( ) ;
270
271
}
271
272
272
273
/** @internal */
@@ -884,7 +885,8 @@ function deduplicateSorted<T>(array: SortedReadonlyArray<T>, comparer: EqualityC
884
885
885
886
case Comparison . LessThan :
886
887
// If `array` is sorted, `next` should **never** be less than `last`.
887
- return Debug . fail ( "Array is unsorted." ) ;
888
+ // return Debug.fail("Array is unsorted.");
889
+ throw new Error ( "Array is unsorted." ) ;
888
890
}
889
891
890
892
deduplicated . push ( last = next ) ;
@@ -1005,14 +1007,14 @@ export function relativeComplement<T>(arrayA: T[] | undefined, arrayB: T[] | und
1005
1007
loopB: for ( let offsetA = 0 , offsetB = 0 ; offsetB < arrayB . length ; offsetB ++ ) {
1006
1008
if ( offsetB > 0 ) {
1007
1009
// Ensure `arrayB` is properly sorted.
1008
- Debug . assertGreaterThanOrEqual ( comparer ( arrayB [ offsetB ] , arrayB [ offsetB - 1 ] ) , Comparison . EqualTo ) ;
1010
+ // Debug.assertGreaterThanOrEqual(comparer(arrayB[offsetB], arrayB[offsetB - 1]), Comparison.EqualTo);
1009
1011
}
1010
1012
1011
1013
loopA: for ( const startA = offsetA ; offsetA < arrayA . length ; offsetA ++ ) {
1012
1014
if ( offsetA > startA ) {
1013
1015
// Ensure `arrayA` is properly sorted. We only need to perform this check if
1014
1016
// `offsetA` has changed since we entered the loop.
1015
- Debug . assertGreaterThanOrEqual ( comparer ( arrayA [ offsetA ] , arrayA [ offsetA - 1 ] ) , Comparison . EqualTo ) ;
1017
+ // Debug.assertGreaterThanOrEqual(comparer(arrayA[offsetA], arrayA[offsetA - 1]), Comparison.EqualTo);
1016
1018
}
1017
1019
1018
1020
switch ( comparer ( arrayB [ offsetB ] , arrayA [ offsetA ] ) ) {
@@ -1259,7 +1261,7 @@ export function firstOrUndefined<T>(array: readonly T[] | undefined): T | undefi
1259
1261
1260
1262
/** @internal */
1261
1263
export function first < T > ( array : readonly T [ ] ) : T {
1262
- Debug . assert ( array . length !== 0 ) ;
1264
+ // Debug.assert(array.length !== 0);
1263
1265
return array [ 0 ] ;
1264
1266
}
1265
1267
@@ -1274,7 +1276,7 @@ export function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefin
1274
1276
1275
1277
/** @internal */
1276
1278
export function last < T > ( array : readonly T [ ] ) : T {
1277
- Debug . assert ( array . length !== 0 ) ;
1279
+ // Debug.assert(array.length !== 0);
1278
1280
return array [ array . length - 1 ] ;
1279
1281
}
1280
1282
@@ -1295,7 +1297,12 @@ export function singleOrUndefined<T>(array: readonly T[] | undefined): T | undef
1295
1297
* @internal
1296
1298
*/
1297
1299
export function single < T > ( array : readonly T [ ] ) : T {
1298
- return Debug . checkDefined ( singleOrUndefined ( array ) ) ;
1300
+ // return Debug.checkDefined(singleOrUndefined(array));
1301
+ const result = singleOrUndefined ( array ) ;
1302
+ if ( result === undefined ) {
1303
+ throw new Error ( ) ;
1304
+ }
1305
+ return result ;
1299
1306
}
1300
1307
1301
1308
/**
@@ -1991,8 +1998,8 @@ export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined
1991
1998
/** @internal */
1992
1999
export function cast < TOut extends TIn , TIn = any > ( value : TIn | undefined , test : ( value : TIn ) => value is TOut ) : TOut {
1993
2000
if ( value !== undefined && test ( value ) ) return value ;
1994
-
1995
- return Debug . fail ( `Invalid cast. The supplied value ${ value } did not pass the test '${ Debug . getFunctionName ( test ) } '.` ) ;
2001
+ throw new Error ( `Invalid cast. The supplied value ${ value } did not pass the test` ) ;
2002
+ // return Debug.fail(`Invalid cast. The supplied value ${value} did not pass the test '${Debug.getFunctionName(test)}'.`);
1996
2003
}
1997
2004
1998
2005
/**
@@ -2478,7 +2485,7 @@ export function getSpellingSuggestion<T>(name: string, candidates: T[], getName:
2478
2485
continue ;
2479
2486
}
2480
2487
2481
- Debug . assert ( distance < bestDistance ) ; // Else `levenshteinWithMax` should return undefined
2488
+ // Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
2482
2489
bestDistance = distance ;
2483
2490
bestCandidate = candidate ;
2484
2491
}
@@ -2692,7 +2699,7 @@ export function patternText({ prefix, suffix }: Pattern): string {
2692
2699
* @internal
2693
2700
*/
2694
2701
export function matchedText ( pattern : Pattern , candidate : string ) : string {
2695
- Debug . assert ( isPatternMatch ( pattern , candidate ) ) ;
2702
+ // Debug.assert(isPatternMatch(pattern, candidate));
2696
2703
return candidate . substring ( pattern . prefix . length , candidate . length - pattern . suffix . length ) ;
2697
2704
}
2698
2705
0 commit comments