Skip to content
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

fix(inspect): ensure non-compact output when object literal has newline in entry text #18366

Merged
merged 3 commits into from
Mar 23, 2023
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: 2 additions & 2 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3261,8 +3261,8 @@ itest!(unhandled_rejection_dynamic_import2 {
});

itest!(nested_error {
args: "run run/nested_error.ts",
output: "run/nested_error.ts.out",
args: "run run/nested_error/main.ts",
output: "run/nested_error/main.ts.out",
Copy link
Member Author

Choose a reason for hiding this comment

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

I originally moved this file to increase the path length, but I kept it here as part of this PR because it's less cluttered.

exit_code: 1,
});

Expand Down
4 changes: 0 additions & 4 deletions cli/tests/testdata/run/nested_error.ts.out

This file was deleted.

4 changes: 4 additions & 0 deletions cli/tests/testdata/run/nested_error/main.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: Uncaught {
foo: Error
at file:///[WILDCARD]/main.ts:2:8
}
9 changes: 7 additions & 2 deletions ext/console/02_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,12 +1291,17 @@ function inspectRawObject(
inspectOptions.indentLevel--;

// Making sure color codes are ignored when calculating the total length
const entriesText = colors.stripColor(ArrayPrototypeJoin(entries, ""));
const totalLength = entries.length + inspectOptions.indentLevel +
colors.stripColor(ArrayPrototypeJoin(entries, "")).length;
entriesText.length;

if (entries.length === 0) {
baseString = "{}";
} else if (totalLength > LINE_BREAKING_LENGTH || !inspectOptions.compact) {
} else if (
totalLength > LINE_BREAKING_LENGTH ||
!inspectOptions.compact ||
StringPrototypeIncludes(entriesText, "\n")
) {
Copy link
Member Author

@dsherret dsherret Mar 22, 2023

Choose a reason for hiding this comment

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

I'm not sure how to write a test, but you can see here this is fixed:

> cargo run
Deno 1.31.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> Deno.inspect({ test: new Error() })
"{\n  test: Error\n    at <anonymous>:3:11\n}"
> close()
> deno
Deno 1.31.3+8bcffff
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> Deno.inspect({ test: new Error() })
"{ test: Error\n    at <anonymous>:3:11 }"

const entryIndent = StringPrototypeRepeat(
DEFAULT_INDENT,
inspectOptions.indentLevel + 1,
Expand Down