@@ -1517,35 +1517,7 @@ namespace ts {
15171517 }
15181518
15191519 export namespace Debug {
1520- if ( isDebugging ) {
1521- // Add additional properties in debug mode to assist with debugging.
1522- Object . defineProperties ( objectAllocator . getSymbolConstructor ( ) . prototype , {
1523- "__debugFlags" : { get ( this : Symbol ) { return formatSymbolFlags ( this . flags ) ; } }
1524- } ) ;
1525-
1526- Object . defineProperties ( objectAllocator . getTypeConstructor ( ) . prototype , {
1527- "__debugFlags" : { get ( this : Type ) { return formatTypeFlags ( this . flags ) ; } } ,
1528- "__debugObjectFlags" : { get ( this : Type ) { return this . flags & TypeFlags . Object ? formatObjectFlags ( ( < ObjectType > this ) . objectFlags ) : "" ; } } ,
1529- "__debugTypeToString" : { value ( this : Type ) { return this . checker . typeToString ( this ) ; } } ,
1530- } ) ;
1531-
1532- for ( const ctor of [ objectAllocator . getNodeConstructor ( ) , objectAllocator . getIdentifierConstructor ( ) , objectAllocator . getTokenConstructor ( ) , objectAllocator . getSourceFileConstructor ( ) ] ) {
1533- if ( ! ctor . prototype . hasOwnProperty ( "__debugKind" ) ) {
1534- Object . defineProperties ( ctor . prototype , {
1535- "__debugKind" : { get ( this : Node ) { return formatSyntaxKind ( this . kind ) ; } } ,
1536- "__debugModifierFlags" : { get ( this : Node ) { return formatModifierFlags ( getModifierFlagsNoCache ( this ) ) ; } } ,
1537- "__debugTransformFlags" : { get ( this : Node ) { return formatTransformFlags ( this . transformFlags ) ; } } ,
1538- "__debugEmitFlags" : { get ( this : Node ) { return formatEmitFlags ( getEmitFlags ( this ) ) ; } } ,
1539- "__debugGetText" : { value ( this : Node , includeTrivia ?: boolean ) {
1540- if ( nodeIsSynthesized ( this ) ) return "" ;
1541- const parseNode = getParseTreeNode ( this ) ;
1542- const sourceFile = parseNode && getSourceFileOfNode ( parseNode ) ;
1543- return sourceFile ? getSourceTextOfNodeFromSourceFile ( sourceFile , parseNode , includeTrivia ) : "" ;
1544- } }
1545- } ) ;
1546- }
1547- }
1548- }
1520+ let isDebugInfoEnabled = false ;
15491521
15501522 export const failBadSyntaxKind = shouldAssert ( AssertionLevel . Normal )
15511523 ? ( node : Node , message ?: string ) : void => fail (
@@ -1592,5 +1564,51 @@ namespace ts {
15921564 ( ) => `Node ${ formatSyntaxKind ( node . kind ) } was unexpected'.` ,
15931565 assertMissingNode )
15941566 : noop ;
1567+
1568+ /**
1569+ * Injects debug information into frequently used types.
1570+ */
1571+ export function enableDebugInfo ( ) {
1572+ if ( isDebugInfoEnabled ) return ;
1573+
1574+ // Add additional properties in debug mode to assist with debugging.
1575+ Object . defineProperties ( objectAllocator . getSymbolConstructor ( ) . prototype , {
1576+ "__debugFlags" : { get ( this : Symbol ) { return formatSymbolFlags ( this . flags ) ; } }
1577+ } ) ;
1578+
1579+ Object . defineProperties ( objectAllocator . getTypeConstructor ( ) . prototype , {
1580+ "__debugFlags" : { get ( this : Type ) { return formatTypeFlags ( this . flags ) ; } } ,
1581+ "__debugObjectFlags" : { get ( this : Type ) { return this . flags & TypeFlags . Object ? formatObjectFlags ( ( < ObjectType > this ) . objectFlags ) : "" ; } } ,
1582+ "__debugTypeToString" : { value ( this : Type ) { return this . checker . typeToString ( this ) ; } } ,
1583+ } ) ;
1584+
1585+ const nodeConstructors = [
1586+ objectAllocator . getNodeConstructor ( ) ,
1587+ objectAllocator . getIdentifierConstructor ( ) ,
1588+ objectAllocator . getTokenConstructor ( ) ,
1589+ objectAllocator . getSourceFileConstructor ( )
1590+ ] ;
1591+
1592+ for ( const ctor of nodeConstructors ) {
1593+ if ( ! ctor . prototype . hasOwnProperty ( "__debugKind" ) ) {
1594+ Object . defineProperties ( ctor . prototype , {
1595+ "__debugKind" : { get ( this : Node ) { return formatSyntaxKind ( this . kind ) ; } } ,
1596+ "__debugModifierFlags" : { get ( this : Node ) { return formatModifierFlags ( getModifierFlagsNoCache ( this ) ) ; } } ,
1597+ "__debugTransformFlags" : { get ( this : Node ) { return formatTransformFlags ( this . transformFlags ) ; } } ,
1598+ "__debugEmitFlags" : { get ( this : Node ) { return formatEmitFlags ( getEmitFlags ( this ) ) ; } } ,
1599+ "__debugGetText" : {
1600+ value ( this : Node , includeTrivia ?: boolean ) {
1601+ if ( nodeIsSynthesized ( this ) ) return "" ;
1602+ const parseNode = getParseTreeNode ( this ) ;
1603+ const sourceFile = parseNode && getSourceFileOfNode ( parseNode ) ;
1604+ return sourceFile ? getSourceTextOfNodeFromSourceFile ( sourceFile , parseNode , includeTrivia ) : "" ;
1605+ }
1606+ }
1607+ } ) ;
1608+ }
1609+ }
1610+
1611+ isDebugInfoEnabled = true ;
1612+ }
15951613 }
15961614}
0 commit comments