@@ -11,53 +11,12 @@ import {
11
11
FlowLabel ,
12
12
FlowNode ,
13
13
FlowSwitchClause ,
14
- getEffectiveModifierFlagsNoCache ,
15
- getEmitFlags ,
16
14
getOwnKeys ,
17
- getParseTreeNode ,
18
15
getSourceFileOfNode ,
19
16
getSourceTextOfNodeFromSourceFile ,
20
17
hasProperty ,
21
- idText ,
22
18
IntrinsicType ,
23
- isArrayTypeNode ,
24
- isBigIntLiteral ,
25
- isCallSignatureDeclaration ,
26
- isConditionalTypeNode ,
27
- isConstructorDeclaration ,
28
- isConstructorTypeNode ,
29
- isConstructSignatureDeclaration ,
30
19
isDefaultClause ,
31
- isFunctionTypeNode ,
32
- isGeneratedIdentifier ,
33
- isGetAccessorDeclaration ,
34
- isIdentifier ,
35
- isImportTypeNode ,
36
- isIndexedAccessTypeNode ,
37
- isIndexSignatureDeclaration ,
38
- isInferTypeNode ,
39
- isIntersectionTypeNode ,
40
- isLiteralTypeNode ,
41
- isMappedTypeNode ,
42
- isNamedTupleMember ,
43
- isNumericLiteral ,
44
- isOptionalTypeNode ,
45
- isParameter ,
46
- isParenthesizedTypeNode ,
47
- isParseTreeNode ,
48
- isPrivateIdentifier ,
49
- isRestTypeNode ,
50
- isSetAccessorDeclaration ,
51
- isStringLiteral ,
52
- isThisTypeNode ,
53
- isTupleTypeNode ,
54
- isTypeLiteralNode ,
55
- isTypeOperatorNode ,
56
- isTypeParameterDeclaration ,
57
- isTypePredicateNode ,
58
- isTypeQueryNode ,
59
- isTypeReferenceNode ,
60
- isUnionTypeNode ,
61
20
LiteralType ,
62
21
map ,
63
22
MatchingKeys ,
@@ -67,7 +26,6 @@ import {
67
26
NodeArray ,
68
27
NodeCheckFlags ,
69
28
NodeFlags ,
70
- nodeIsSynthesized ,
71
29
noop ,
72
30
objectAllocator ,
73
31
ObjectFlags ,
@@ -362,8 +320,7 @@ export namespace Debug {
362
320
* This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and
363
321
* as a result can reduce the number of unnecessary casts.
364
322
*/
365
- export function type < T > ( value : unknown ) : asserts value is T ;
366
- export function type ( _value : unknown ) { }
323
+ export function type < T > ( value : unknown ) : asserts value is T { }
367
324
368
325
export function getFunctionName ( func : AnyFunction ) {
369
326
if ( typeof func !== "function" ) {
@@ -607,6 +564,16 @@ export namespace Debug {
607
564
}
608
565
}
609
566
567
+ const debugInfoRegistrations : ( ( ) => void ) [ ] = [ ] ;
568
+ export function registerDebugInfo ( cb : ( ) => void ) {
569
+ if ( isDebugInfoEnabled ) {
570
+ cb ( ) ;
571
+ }
572
+ else {
573
+ debugInfoRegistrations . push ( cb ) ;
574
+ }
575
+ }
576
+
610
577
/**
611
578
* Injects debug information into frequently used types.
612
579
*/
@@ -615,8 +582,6 @@ export namespace Debug {
615
582
616
583
// avoid recomputing
617
584
const weakTypeTextMap = new WeakMap < Type , string > ( ) ;
618
- const weakNodeTextMap = new WeakMap < Node , string > ( ) ;
619
-
620
585
// Add additional properties in debug mode to assist with debugging.
621
586
Object . defineProperties ( objectAllocator . getSymbolConstructor ( ) . prototype , {
622
587
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
@@ -702,106 +667,10 @@ export namespace Debug {
702
667
} ,
703
668
} ) ;
704
669
705
- const nodeConstructors = [
706
- objectAllocator . getNodeConstructor ( ) ,
707
- objectAllocator . getIdentifierConstructor ( ) ,
708
- objectAllocator . getTokenConstructor ( ) ,
709
- objectAllocator . getSourceFileConstructor ( ) ,
710
- ] ;
711
-
712
- for ( const ctor of nodeConstructors ) {
713
- if ( ! hasProperty ( ctor . prototype , "__debugKind" ) ) {
714
- Object . defineProperties ( ctor . prototype , {
715
- // for use with vscode-js-debug's new customDescriptionGenerator in launch.json
716
- __tsDebuggerDisplay : {
717
- value ( this : Node ) {
718
- const nodeHeader = isGeneratedIdentifier ( this ) ? "GeneratedIdentifier" :
719
- isIdentifier ( this ) ? `Identifier '${ idText ( this ) } '` :
720
- isPrivateIdentifier ( this ) ? `PrivateIdentifier '${ idText ( this ) } '` :
721
- isStringLiteral ( this ) ? `StringLiteral ${ JSON . stringify ( this . text . length < 10 ? this . text : this . text . slice ( 10 ) + "..." ) } ` :
722
- isNumericLiteral ( this ) ? `NumericLiteral ${ this . text } ` :
723
- isBigIntLiteral ( this ) ? `BigIntLiteral ${ this . text } n` :
724
- isTypeParameterDeclaration ( this ) ? "TypeParameterDeclaration" :
725
- isParameter ( this ) ? "ParameterDeclaration" :
726
- isConstructorDeclaration ( this ) ? "ConstructorDeclaration" :
727
- isGetAccessorDeclaration ( this ) ? "GetAccessorDeclaration" :
728
- isSetAccessorDeclaration ( this ) ? "SetAccessorDeclaration" :
729
- isCallSignatureDeclaration ( this ) ? "CallSignatureDeclaration" :
730
- isConstructSignatureDeclaration ( this ) ? "ConstructSignatureDeclaration" :
731
- isIndexSignatureDeclaration ( this ) ? "IndexSignatureDeclaration" :
732
- isTypePredicateNode ( this ) ? "TypePredicateNode" :
733
- isTypeReferenceNode ( this ) ? "TypeReferenceNode" :
734
- isFunctionTypeNode ( this ) ? "FunctionTypeNode" :
735
- isConstructorTypeNode ( this ) ? "ConstructorTypeNode" :
736
- isTypeQueryNode ( this ) ? "TypeQueryNode" :
737
- isTypeLiteralNode ( this ) ? "TypeLiteralNode" :
738
- isArrayTypeNode ( this ) ? "ArrayTypeNode" :
739
- isTupleTypeNode ( this ) ? "TupleTypeNode" :
740
- isOptionalTypeNode ( this ) ? "OptionalTypeNode" :
741
- isRestTypeNode ( this ) ? "RestTypeNode" :
742
- isUnionTypeNode ( this ) ? "UnionTypeNode" :
743
- isIntersectionTypeNode ( this ) ? "IntersectionTypeNode" :
744
- isConditionalTypeNode ( this ) ? "ConditionalTypeNode" :
745
- isInferTypeNode ( this ) ? "InferTypeNode" :
746
- isParenthesizedTypeNode ( this ) ? "ParenthesizedTypeNode" :
747
- isThisTypeNode ( this ) ? "ThisTypeNode" :
748
- isTypeOperatorNode ( this ) ? "TypeOperatorNode" :
749
- isIndexedAccessTypeNode ( this ) ? "IndexedAccessTypeNode" :
750
- isMappedTypeNode ( this ) ? "MappedTypeNode" :
751
- isLiteralTypeNode ( this ) ? "LiteralTypeNode" :
752
- isNamedTupleMember ( this ) ? "NamedTupleMember" :
753
- isImportTypeNode ( this ) ? "ImportTypeNode" :
754
- formatSyntaxKind ( this . kind ) ;
755
- return `${ nodeHeader } ${ this . flags ? ` (${ formatNodeFlags ( this . flags ) } )` : "" } ` ;
756
- } ,
757
- } ,
758
- __debugKind : {
759
- get ( this : Node ) {
760
- return formatSyntaxKind ( this . kind ) ;
761
- } ,
762
- } ,
763
- __debugNodeFlags : {
764
- get ( this : Node ) {
765
- return formatNodeFlags ( this . flags ) ;
766
- } ,
767
- } ,
768
- __debugModifierFlags : {
769
- get ( this : Node ) {
770
- return formatModifierFlags ( getEffectiveModifierFlagsNoCache ( this ) ) ;
771
- } ,
772
- } ,
773
- __debugTransformFlags : {
774
- get ( this : Node ) {
775
- return formatTransformFlags ( this . transformFlags ) ;
776
- } ,
777
- } ,
778
- __debugIsParseTreeNode : {
779
- get ( this : Node ) {
780
- return isParseTreeNode ( this ) ;
781
- } ,
782
- } ,
783
- __debugEmitFlags : {
784
- get ( this : Node ) {
785
- return formatEmitFlags ( getEmitFlags ( this ) ) ;
786
- } ,
787
- } ,
788
- __debugGetText : {
789
- value ( this : Node , includeTrivia ?: boolean ) {
790
- if ( nodeIsSynthesized ( this ) ) return "" ;
791
- // avoid recomputing
792
- let text = weakNodeTextMap . get ( this ) ;
793
- if ( text === undefined ) {
794
- const parseNode = getParseTreeNode ( this ) ;
795
- const sourceFile = parseNode && getSourceFileOfNode ( parseNode ) ;
796
- text = sourceFile ? getSourceTextOfNodeFromSourceFile ( sourceFile , parseNode , includeTrivia ) : "" ;
797
- weakNodeTextMap . set ( this , text ) ;
798
- }
799
- return text ;
800
- } ,
801
- } ,
802
- } ) ;
803
- }
670
+ for ( const cb of debugInfoRegistrations ) {
671
+ cb ( ) ;
804
672
}
673
+ debugInfoRegistrations . length = 0 ;
805
674
806
675
isDebugInfoEnabled = true ;
807
676
}
0 commit comments