File tree 4 files changed +32
-24
lines changed
4 files changed +32
-24
lines changed Original file line number Diff line number Diff line change @@ -4406,7 +4406,7 @@ namespace ts {
4406
4406
type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
4407
4407
}
4408
4408
else {
4409
- Debug.fail("Unhandled declaration kind! " + (ts as any).SyntaxKind[ declaration.kind] );
4409
+ Debug.fail("Unhandled declaration kind! " + Debug.showSyntaxKind( declaration) );
4410
4410
}
4411
4411
4412
4412
if (!popTypeResolution()) {
@@ -20682,7 +20682,7 @@ namespace ts {
20682
20682
case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591
20683
20683
return DeclarationSpaces.ExportValue;
20684
20684
default:
20685
- Debug.fail((ts as any).SyntaxKind[d.kind] );
20685
+ Debug.fail(Debug.showSyntaxKind(d) );
20686
20686
}
20687
20687
}
20688
20688
}
Original file line number Diff line number Diff line change @@ -1466,7 +1466,7 @@ namespace ts {
1466
1466
if ( value !== undefined && test ( value ) ) return value ;
1467
1467
1468
1468
if ( value && typeof ( value as any ) . kind === "number" ) {
1469
- Debug . fail ( `Invalid cast. The supplied ${ ( ts as any ) . SyntaxKind [ ( value as any ) . kind ] } did not pass the test '${ Debug . getFunctionName ( test ) } '.` ) ;
1469
+ Debug . fail ( `Invalid cast. The supplied ${ Debug . showSyntaxKind ( value as any as Node ) } did not pass the test '${ Debug . getFunctionName ( test ) } '.` ) ;
1470
1470
}
1471
1471
else {
1472
1472
Debug . fail ( `Invalid cast. The supplied value did not pass the test '${ Debug . getFunctionName ( test ) } '.` ) ;
@@ -2925,6 +2925,25 @@ namespace ts {
2925
2925
return match ? match [ 1 ] : "" ;
2926
2926
}
2927
2927
}
2928
+
2929
+ export function showSymbol ( symbol : Symbol ) : string {
2930
+ return `{ flags: ${ showFlags ( symbol . flags , ( ts as any ) . SymbolFlags ) } ; declarations: ${ map ( symbol . declarations , showSyntaxKind ) } }` ;
2931
+ }
2932
+
2933
+ function showFlags ( flags : number , flagsEnum : { [ flag : number ] : string } ) : string {
2934
+ const out = [ ] ;
2935
+ for ( let pow = 0 ; pow <= 30 ; pow ++ ) {
2936
+ const n = 1 << pow ;
2937
+ if ( flags & n ) {
2938
+ out . push ( flagsEnum [ n ] ) ;
2939
+ }
2940
+ }
2941
+ return out . join ( "|" ) ;
2942
+ }
2943
+
2944
+ export function showSyntaxKind ( node : Node ) : string {
2945
+ return ( ts as any ) . SyntaxKind [ node . kind ] ;
2946
+ }
2928
2947
}
2929
2948
2930
2949
/** Remove an item from an array, moving everything to its right one space left. */
Original file line number Diff line number Diff line change @@ -416,10 +416,16 @@ namespace ts.FindAllReferences.Core {
416
416
}
417
417
418
418
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
419
- return firstDefined ( symbol . declarations , decl =>
420
- isTypeLiteralNode ( decl . parent ) && isUnionTypeNode ( decl . parent . parent )
419
+ return firstDefined ( symbol . declarations , decl => {
420
+ if ( ! decl . parent ) {
421
+ // Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
422
+ Debug . assert ( decl . kind === SyntaxKind . SourceFile ) ;
423
+ Debug . fail ( `Unexpected symbol at ${ Debug . showSyntaxKind ( node ) } : ${ Debug . showSymbol ( symbol ) } ` ) ;
424
+ }
425
+ return isTypeLiteralNode ( decl . parent ) && isUnionTypeNode ( decl . parent . parent )
421
426
? checker . getPropertyOfType ( checker . getTypeFromTypeNode ( decl . parent . parent ) , symbol . name )
422
- : undefined ) || symbol ;
427
+ : undefined ;
428
+ } ) || symbol ;
423
429
}
424
430
425
431
/**
Original file line number Diff line number Diff line change @@ -517,29 +517,12 @@ namespace ts.FindAllReferences {
517
517
const sym = useLhsSymbol ? checker . getSymbolAtLocation ( cast ( node . left , isPropertyAccessExpression ) . name ) : symbol ;
518
518
// Better detection for GH#20803
519
519
if ( sym && ! ( checker . getMergedSymbol ( sym . parent ) . flags & SymbolFlags . Module ) ) {
520
- Debug . fail ( `Special property assignment kind does not have a module as its parent. Assignment is ${ showSymbol ( sym ) } , parent is ${ showSymbol ( sym . parent ) } ` ) ;
520
+ Debug . fail ( `Special property assignment kind does not have a module as its parent. Assignment is ${ Debug . showSymbol ( sym ) } , parent is ${ Debug . showSymbol ( sym . parent ) } ` ) ;
521
521
}
522
522
return sym && exportInfo ( sym , kind ) ;
523
523
}
524
524
}
525
525
526
- function showSymbol ( s : Symbol ) : string {
527
- const decls = s . declarations . map ( d => ( ts as any ) . SyntaxKind [ d . kind ] ) . join ( "," ) ;
528
- const flags = showFlags ( s . flags , ( ts as any ) . SymbolFlags ) ;
529
- return `{ declarations: ${ decls } , flags: ${ flags } }` ;
530
- }
531
-
532
- function showFlags ( f : number , flags : any ) {
533
- const out = [ ] ;
534
- for ( let pow = 0 ; pow <= 30 ; pow ++ ) {
535
- const n = 1 << pow ;
536
- if ( f & n ) {
537
- out . push ( flags [ n ] ) ;
538
- }
539
- }
540
- return out . join ( "|" ) ;
541
- }
542
-
543
526
function getImport ( ) : ImportedSymbol | undefined {
544
527
const isImport = isNodeImport ( node ) ;
545
528
if ( ! isImport ) return undefined ;
You can’t perform that action at this time.
0 commit comments