Skip to content

Enable debug info when running tests #16310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ namespace ts {
}
}

if (ts.Debug.isDebugging) {
ts.Debug.enableDebugInfo();
}

if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
ts.sys.tryEnableSourceMapsForHost();
}
Expand Down
76 changes: 47 additions & 29 deletions src/compiler/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1517,35 +1517,7 @@ namespace ts {
}

export namespace Debug {
if (isDebugging) {
// Add additional properties in debug mode to assist with debugging.
Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, {
"__debugFlags": { get(this: Symbol) { return formatSymbolFlags(this.flags); } }
});

Object.defineProperties(objectAllocator.getTypeConstructor().prototype, {
"__debugFlags": { get(this: Type) { return formatTypeFlags(this.flags); } },
"__debugObjectFlags": { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((<ObjectType>this).objectFlags) : ""; } },
"__debugTypeToString": { value(this: Type) { return this.checker.typeToString(this); } },
});

for (const ctor of [objectAllocator.getNodeConstructor(), objectAllocator.getIdentifierConstructor(), objectAllocator.getTokenConstructor(), objectAllocator.getSourceFileConstructor()]) {
if (!ctor.prototype.hasOwnProperty("__debugKind")) {
Object.defineProperties(ctor.prototype, {
"__debugKind": { get(this: Node) { return formatSyntaxKind(this.kind); } },
"__debugModifierFlags": { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } },
"__debugTransformFlags": { get(this: Node) { return formatTransformFlags(this.transformFlags); } },
"__debugEmitFlags": { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } },
"__debugGetText": { value(this: Node, includeTrivia?: boolean) {
if (nodeIsSynthesized(this)) return "";
const parseNode = getParseTreeNode(this);
const sourceFile = parseNode && getSourceFileOfNode(parseNode);
return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : "";
} }
});
}
}
}
let isDebugInfoEnabled = false;

export const failBadSyntaxKind = shouldAssert(AssertionLevel.Normal)
? (node: Node, message?: string): void => fail(
Expand Down Expand Up @@ -1592,5 +1564,51 @@ namespace ts {
() => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`,
assertMissingNode)
: noop;

/**
* Injects debug information into frequently used types.
*/
export function enableDebugInfo() {
if (isDebugInfoEnabled) return;

// Add additional properties in debug mode to assist with debugging.
Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, {
"__debugFlags": { get(this: Symbol) { return formatSymbolFlags(this.flags); } }
});

Object.defineProperties(objectAllocator.getTypeConstructor().prototype, {
"__debugFlags": { get(this: Type) { return formatTypeFlags(this.flags); } },
"__debugObjectFlags": { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((<ObjectType>this).objectFlags) : ""; } },
"__debugTypeToString": { value(this: Type) { return this.checker.typeToString(this); } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not this be a getter too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. typeToString performs type checking, which could result in caching resolutions/types/etc. This can be problematic when you are in the middle of debugging a resolution.

Its available as a method as there are cases where you would like to get a view of type while debugging and typeToString is not available as it is not in the environment record of the closure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just wounder how slow it would be to do this on every type when you are debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance impact so far has been fairly small, as far as my own experience has been, as it only matters when the debugger is paused as that is the only time the watch window performs expression evaluation.

});

const nodeConstructors = [
objectAllocator.getNodeConstructor(),
objectAllocator.getIdentifierConstructor(),
objectAllocator.getTokenConstructor(),
objectAllocator.getSourceFileConstructor()
];

for (const ctor of nodeConstructors) {
if (!ctor.prototype.hasOwnProperty("__debugKind")) {
Object.defineProperties(ctor.prototype, {
"__debugKind": { get(this: Node) { return formatSyntaxKind(this.kind); } },
"__debugModifierFlags": { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } },
"__debugTransformFlags": { get(this: Node) { return formatTransformFlags(this.transformFlags); } },
"__debugEmitFlags": { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } },
"__debugGetText": {
value(this: Node, includeTrivia?: boolean) {
if (nodeIsSynthesized(this)) return "";
const parseNode = getParseTreeNode(this);
const sourceFile = parseNode && getSourceFileOfNode(parseNode);
return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : "";
}
}
});
}
}

isDebugInfoEnabled = true;
}
}
}
4 changes: 4 additions & 0 deletions src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ if (taskConfigsFolder) {
}
}
else {
if (ts.Debug.isDebugging) {
ts.Debug.enableDebugInfo();
}

runTests(runners);
}
if (!runUnitTests) {
Expand Down