1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(url): properly indent when inspecting URLs (#14867)

This commit updates the custom inspect function for URL objects
to pass the inspect options through so that the context is
propagated and the resulting indentation is correct.

Fixes: https://github.com/denoland/deno/issues/14171
This commit is contained in:
cjihrig 2022-06-14 19:25:58 -04:00 committed by Colin Ihrig
parent eadf943e59
commit b2109a12aa
4 changed files with 57 additions and 2 deletions

View file

@ -2704,3 +2704,8 @@ itest!(error_name_non_string {
output: "error_name_non_string.js.out",
exit_code: 1,
});
itest!(custom_inspect_url {
args: "run custom_inspect_url.js",
output: "custom_inspect_url.js.out",
});

View file

@ -0,0 +1,3 @@
console.log([new URL("https://example.com/path")]);
console.log({ url: new URL("https://example.com/path") });
console.log({ url: [new URL("https://example.com/path")] });

View file

@ -0,0 +1,47 @@
[
URL {
href: "https://example.com/path",
origin: "https://example.com",
protocol: "https:",
username: "",
password: "",
host: "example.com",
hostname: "example.com",
port: "",
pathname: "/path",
hash: "",
search: ""
}
]
{
url: URL {
href: "https://example.com/path",
origin: "https://example.com",
protocol: "https:",
username: "",
password: "",
host: "example.com",
hostname: "example.com",
port: "",
pathname: "/path",
hash: "",
search: ""
}
}
{
url: [
URL {
href: "https://example.com/path",
origin: "https://example.com",
protocol: "https:",
username: "",
password: "",
host: "example.com",
hostname: "example.com",
port: "",
pathname: "/path",
hash: "",
search: ""
}
]
}

View file

@ -322,7 +322,7 @@
this[_url] = opUrlParse(url, base);
}
[SymbolFor("Deno.privateCustomInspect")](inspect) {
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
const object = {
href: this.href,
origin: this.origin,
@ -336,7 +336,7 @@
hash: this.hash,
search: this.search,
};
return `${this.constructor.name} ${inspect(object)}`;
return `${this.constructor.name} ${inspect(object, inspectOptions)}`;
}
#updateSearchParams() {