Skip to content

Commit b325790

Browse files
authored
Merge pull request #16310 from Microsoft/enableDebugInfo
Enable debug info when running tests
2 parents b94c513 + 4c65be8 commit b325790

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

src/compiler/tsc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ namespace ts {
662662
}
663663
}
664664

665+
if (ts.Debug.isDebugging) {
666+
ts.Debug.enableDebugInfo();
667+
}
668+
665669
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
666670
ts.sys.tryEnableSourceMapsForHost();
667671
}

src/compiler/visitor.ts

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/harness/runner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ if (taskConfigsFolder) {
222222
}
223223
}
224224
else {
225+
if (ts.Debug.isDebugging) {
226+
ts.Debug.enableDebugInfo();
227+
}
228+
225229
runTests(runners);
226230
}
227231
if (!runUnitTests) {

0 commit comments

Comments
 (0)