Skip to content

Commit

Permalink
🐛 setting ii.defaults can use stale options
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Dec 20, 2024
1 parent f6d9111 commit 31c9951
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/inspect/ii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface InspectInspect {

function createInspectInspect(options: ConsoleInspectOptions): InspectInspect {
const fn = (...args: unknown[]) => {
return inspectInspect(options, ...args);
return inspectInspect(fn, ...args);
};
fn.defaults = options;
fn.depth = (depth: number) => createInspectInspect({ ...options, depth });
Expand All @@ -29,16 +29,16 @@ function createInspectInspect(options: ConsoleInspectOptions): InspectInspect {
}

function inspectInspect<T>(
options: ConsoleInspectOptions,
self: InspectInspect,
value: T,
...args: unknown[]
): T;
function inspectInspect(
options: ConsoleInspectOptions,
self: InspectInspect,
...args: unknown[]
): unknown;
function inspectInspect(
options: ConsoleInspectOptions,
self: InspectInspect,
...args: unknown[]
): unknown {
if (args.length === 0) {
Expand All @@ -48,7 +48,7 @@ function inspectInspect(
const hasPromise = args.some((arg) => arg instanceof Promise);
if (hasPromise) {
Promise.all(args).then((values) => {
return inspectInspect(options, ...values);
return inspectInspect(self, ...values);
});
} else {
if (hasWebContext()) {
Expand All @@ -61,7 +61,7 @@ function inspectInspect(
first = false;
spans.push(
...consoleInspect(value, {
...options,
...self.defaults,
print: false,
}),
);
Expand Down
12 changes: 6 additions & 6 deletions src/inspect/tt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ export interface TableTable {

function createTableTable(options: ConsoleTableOptions): TableTable {
const fn = (...args: unknown[]) => {
return tableTable(options, ...args);
return tableTable(fn, ...args);
};
fn.defaults = options;
return fn as TableTable;
}

function tableTable<T>(
options: ConsoleTableOptions,
self: TableTable,
value: T,
...args: unknown[]
): T;
function tableTable(options: ConsoleTableOptions, ...args: unknown[]): unknown;
function tableTable(options: ConsoleTableOptions, ...args: unknown[]): unknown {
function tableTable(self: TableTable, ...args: unknown[]): unknown;
function tableTable(self: TableTable, ...args: unknown[]): unknown {
if (args.length === 0) {
return undefined;
}

const hasPromise = args.some((arg) => arg instanceof Promise);
if (hasPromise) {
Promise.all(args).then((values) => {
return tableTable(options, ...values);
return tableTable(self, ...values);
});
} else {
if (hasWebContext()) {
Expand All @@ -51,7 +51,7 @@ function tableTable(options: ConsoleTableOptions, ...args: unknown[]): unknown {
...consoleTable(
isPrimitive(value) ? [value] : (value as {}),
{
...options,
...self.defaults,
print: false,
},
),
Expand Down

0 comments on commit 31c9951

Please sign in to comment.