Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x | import type {CheckpointFn, IMeta} from '@feasibleone/blong/types';
/**
* Records a checkpoint in the $meta.checkpoints array.
* Uses `this` binding — works correctly when called as
* $meta.checkpoint?.('name', data) with optional chaining.
*/
const checkpoint: CheckpointFn = function (this: IMeta, name: string, data?: unknown): void {
(this.checkpoints ??= []).push({
name,
data,
timestamp: Date.now(),
});
};
/**
* Attaches the checkpoint function to $meta if not already present.
* The function uses `this` to record into the $meta it's called on.
*/
export function attachCheckpoint($meta: IMeta): void {
$meta.checkpoint ??= checkpoint;
}
/**
* Returns an attachCheckpoint function when checkpoint mode is enabled,
* or undefined for production (zero overhead via optional chaining).
*/
export function createAttachCheckpoint(
mode: 'test' | 'debug' | 'production',
): ((meta: IMeta) => void) | undefined {
return mode === 'production' ? undefined : attachCheckpoint;
}
|