4
4
AssertionLevel ,
5
5
BigIntLiteralType ,
6
6
CheckMode ,
7
+ Comparer ,
7
8
compareValues ,
8
9
EmitFlags ,
9
10
every ,
@@ -356,15 +357,6 @@ export namespace Debug {
356
357
}
357
358
}
358
359
359
- /**
360
- * Asserts the symbol is defined and is of the right kind (originating in TSC or sample DTE depending o the test that is currently being run)
361
- * The default implementation just asserts the symbol is not null
362
- * In tests it is overridden to ensure we don't accidentally use TSC symbols in DTE
363
- */
364
- // eslint-disable-next-line prefer-const
365
- export let assertSymbolValid = ( symbol : Symbol ) => {
366
- assert ( symbol , "Symbol not defined" ) ;
367
- } ;
368
360
/**
369
361
* Asserts a value has the specified type in typespace only (does not perform a runtime assertion).
370
362
* This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and
@@ -395,18 +387,18 @@ export namespace Debug {
395
387
* Formats an enum value as a string for debugging and debug assertions.
396
388
*/
397
389
export function formatEnum ( value = 0 , enumObject : any , isFlags ?: boolean ) {
398
- const members = getEnumMembers ( enumObject ) ;
390
+ const members = getEnumMembers ( enumObject , isFlags ) ;
399
391
if ( value === 0 ) {
400
392
return members . length > 0 && members [ 0 ] [ 0 ] === 0 ? members [ 0 ] [ 1 ] : "0" ;
401
393
}
402
394
if ( isFlags ) {
403
395
const result : string [ ] = [ ] ;
404
396
let remainingFlags = value ;
405
397
for ( const [ enumValue , enumName ] of members ) {
406
- if ( enumValue > value ) {
398
+ if ( enumValue > remainingFlags ) {
407
399
break ;
408
400
}
409
- if ( enumValue !== 0 && enumValue & value ) {
401
+ if ( enumValue !== 0 && enumValue & remainingFlags ) {
410
402
result . push ( enumName ) ;
411
403
remainingFlags &= ~ enumValue ;
412
404
}
@@ -427,7 +419,7 @@ export namespace Debug {
427
419
428
420
const enumMemberCache = new Map < any , SortedReadonlyArray < [ number , string ] > > ( ) ;
429
421
430
- function getEnumMembers ( enumObject : any ) {
422
+ function getEnumMembers ( enumObject : any , isFlags ?: boolean ) {
431
423
// Assuming enum objects do not change at runtime, we can cache the enum members list
432
424
// to reuse later. This saves us from reconstructing this each and every time we call
433
425
// a formatting function (which can be expensive for large enums like SyntaxKind).
@@ -444,7 +436,10 @@ export namespace Debug {
444
436
}
445
437
}
446
438
447
- const sorted = stableSort < [ number , string ] > ( result , ( x , y ) => compareValues ( x [ 0 ] , y [ 0 ] ) ) ;
439
+ const comparer : Comparer < [ number , string ] > = isFlags ?
440
+ ( x , y ) => compareValues ( x [ 0 ] >>> 0 , y [ 0 ] >>> 0 ) :
441
+ ( x , y ) => compareValues ( x [ 0 ] , y [ 0 ] ) ;
442
+ const sorted = stableSort ( result , comparer ) ;
448
443
enumMemberCache . set ( enumObject , sorted ) ;
449
444
return sorted ;
450
445
}
0 commit comments