@@ -11,53 +11,12 @@ import {
1111 FlowLabel ,
1212 FlowNode ,
1313 FlowSwitchClause ,
14- getEffectiveModifierFlagsNoCache ,
15- getEmitFlags ,
1614 getOwnKeys ,
17- getParseTreeNode ,
1815 getSourceFileOfNode ,
1916 getSourceTextOfNodeFromSourceFile ,
2017 hasProperty ,
21- idText ,
2218 IntrinsicType ,
23- isArrayTypeNode ,
24- isBigIntLiteral ,
25- isCallSignatureDeclaration ,
26- isConditionalTypeNode ,
27- isConstructorDeclaration ,
28- isConstructorTypeNode ,
29- isConstructSignatureDeclaration ,
3019 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 ,
6120 LiteralType ,
6221 map ,
6322 MatchingKeys ,
@@ -67,7 +26,6 @@ import {
6726 NodeArray ,
6827 NodeCheckFlags ,
6928 NodeFlags ,
70- nodeIsSynthesized ,
7129 noop ,
7230 objectAllocator ,
7331 ObjectFlags ,
@@ -362,8 +320,7 @@ export namespace Debug {
362320 * This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and
363321 * as a result can reduce the number of unnecessary casts.
364322 */
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 { }
367324
368325 export function getFunctionName ( func : AnyFunction ) {
369326 if ( typeof func !== "function" ) {
@@ -607,6 +564,16 @@ export namespace Debug {
607564 }
608565 }
609566
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+
610577 /**
611578 * Injects debug information into frequently used types.
612579 */
@@ -615,8 +582,6 @@ export namespace Debug {
615582
616583 // avoid recomputing
617584 const weakTypeTextMap = new WeakMap < Type , string > ( ) ;
618- const weakNodeTextMap = new WeakMap < Node , string > ( ) ;
619-
620585 // Add additional properties in debug mode to assist with debugging.
621586 Object . defineProperties ( objectAllocator . getSymbolConstructor ( ) . prototype , {
622587 // for use with vscode-js-debug's new customDescriptionGenerator in launch.json
@@ -702,106 +667,10 @@ export namespace Debug {
702667 } ,
703668 } ) ;
704669
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 ( ) ;
804672 }
673+ debugInfoRegistrations . length = 0 ;
805674
806675 isDebugInfoEnabled = true ;
807676 }
0 commit comments