Skip to content

Commit

Permalink
🐎 don't call inline inspections unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Jul 15, 2024
1 parent a43ddb9 commit 9a472c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/inspect/inspectors/inspectIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
ConsoleInspectOptions,
} from "../consoleInspect";
import { type ConsoleObject, consoleObject } from "../../core/consoleObject";
import spansLength from "../../utils/spansLength";
import indent from "../../utils/indent";
import isPrimitive from "../../utils/isPrimitive";
import ConsoleInspection from "../utils/ConsoleInspection";
import inspectInline from "./inspectInline";
import { inspectObject } from "./inspectObject";
import spansLength from "../../utils/spansLength";

export function inspectIterable(
iterable: Iterable<unknown>,
Expand All @@ -34,16 +34,22 @@ export function inspectIterable(
}

// wrap is "auto", try to fit on one line
const inspection = inspectIterableSingleLine(iterable, options, context);

const array = iterableArray(iterable);
if (
spansLength(inspection.spans) <= context.wrap &&
array.every(isPrimitive) &&
iterableExtraKeys(iterable).every((key) =>
isPrimitive(array[key as keyof typeof array]),
)
) {
return inspection;
const inspection = inspectIterableSingleLine(
iterable,
options,
context,
);
if (spansLength(inspection.spans) <= context.wrap) {
return inspection;
}
}

return inspectIterableMultiLine(iterable, options, context);
Expand Down
11 changes: 5 additions & 6 deletions src/inspect/inspectors/inspectObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ export function inspectObject(
}

// wrap is "auto", try to fit on one line
const inspection = inspectObjectSingleLine(object, options, context);
if (
hasOnlyPrimitives(object) &&
spansLength(inspection.spans) <= context.wrap
) {
return inspection;
if (hasOnlyPrimitives(object)) {
const inspection = inspectObjectSingleLine(object, options, context);
if (spansLength(inspection.spans) <= context.wrap) {
return inspection;
}
}

return inspectObjectMultiLine(object, options, context);
Expand Down

0 comments on commit 9a472c0

Please sign in to comment.