Use stricter types for tracing event arguments (#41217)
* Use stricter types for tracing event arguments In local development, I've routinely passed the wrong local and ended up having JSON.stringify throw. * Make the type recursive Courtesy of @rbuckton * Fix lint error
This commit is contained in:
parent
03877260f8
commit
4c8418ee19
|
@ -17,6 +17,11 @@ namespace ts.tracing {
|
|||
let legendPath: string | undefined;
|
||||
const legend: TraceRecord[] = [];
|
||||
|
||||
// The actual constraint is that JSON.stringify be able to serialize it without throwing.
|
||||
interface Args {
|
||||
[key: string]: string | number | boolean | null | undefined | Args | readonly (string | number | boolean | null | undefined | Args)[];
|
||||
};
|
||||
|
||||
/** Starts tracing for the given project (unless the `fs` module is unavailable). */
|
||||
export function startTracing(tracingMode: Mode, traceDir: string, configFilePath?: string) {
|
||||
Debug.assert(!traceFd, "Tracing already started");
|
||||
|
@ -108,12 +113,12 @@ namespace ts.tracing {
|
|||
Session = "session",
|
||||
}
|
||||
|
||||
export function instant(phase: Phase, name: string, args?: object) {
|
||||
export function instant(phase: Phase, name: string, args?: Args) {
|
||||
if (!traceFd) return;
|
||||
writeEvent("I", phase, name, args, `"s":"g"`);
|
||||
}
|
||||
|
||||
const eventStack: { phase: Phase, name: string, args?: object, time: number, separateBeginAndEnd: boolean }[] = [];
|
||||
const eventStack: { phase: Phase, name: string, args?: Args, time: number, separateBeginAndEnd: boolean }[] = [];
|
||||
|
||||
/**
|
||||
* @param separateBeginAndEnd - used for special cases where we need the trace point even if the event
|
||||
|
@ -121,7 +126,7 @@ namespace ts.tracing {
|
|||
* In the future we might implement an exit handler to dump unfinished events which would deprecate
|
||||
* these operations.
|
||||
*/
|
||||
export function push(phase: Phase, name: string, args?: object, separateBeginAndEnd = false) {
|
||||
export function push(phase: Phase, name: string, args?: Args, separateBeginAndEnd = false) {
|
||||
if (!traceFd) return;
|
||||
if (separateBeginAndEnd) {
|
||||
writeEvent("B", phase, name, args);
|
||||
|
@ -152,7 +157,7 @@ namespace ts.tracing {
|
|||
}
|
||||
}
|
||||
|
||||
function writeEvent(eventType: string, phase: Phase, name: string, args: object | undefined, extras?: string,
|
||||
function writeEvent(eventType: string, phase: Phase, name: string, args: Args | undefined, extras?: string,
|
||||
time: number = 1000 * timestamp()) {
|
||||
Debug.assert(traceFd);
|
||||
Debug.assert(fs);
|
||||
|
|
Loading…
Reference in a new issue