summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/dts/lib.deno.ns.d.ts14
-rw-r--r--cli/tests/unit/console_test.ts14
2 files changed, 22 insertions, 6 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index da016db8a..e83858586 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -2193,14 +2193,14 @@ declare namespace Deno {
* console.log(obj); // prints same value as objAsString, e.g. { a: 10, b: "hello" }
* ```
*
- * You can also register custom inspect functions, via the `customInspect` Deno
- * symbol on objects, to control and customize the output.
+ * You can also register custom inspect functions, via the symbol `Symbol.for("Deno.customInspect")`,
+ * on objects, to control and customize the output.
*
* ```ts
* class A {
* x = 10;
* y = "hello";
- * [Deno.customInspect](): string {
+ * [Symbol.for("Deno.customInspect")](): string {
* return "x=" + this.x + ", y=" + this.y;
* }
* }
@@ -2388,9 +2388,13 @@ declare namespace Deno {
*/
export const args: string[];
- /** A symbol which can be used as a key for a custom method which will be
+ /**
+ * @deprecated A symbol which can be used as a key for a custom method which will be
* called when `Deno.inspect()` is called, or when the object is logged to
- * the console. */
+ * the console.
+ *
+ * This symbol is deprecated since 1.9. Use `Symbol.for("Deno.customInspect")` instead.
+ */
export const customInspect: unique symbol;
/** The URL of the entrypoint module entered from the command-line. */
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 8013da152..edb1b245f 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -17,7 +17,7 @@ import {
} from "./test_util.ts";
import { stripColor } from "../../../test_util/std/fmt/colors.ts";
-const customInspect = Deno.customInspect;
+const customInspect = Symbol.for("Deno.customInspect");
const {
Console,
cssToAnsi: cssToAnsi_,
@@ -879,6 +879,18 @@ unitTest(function consoleTestWithCustomInspector(): void {
assertEquals(stringify(new A()), "b");
});
+unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void {
+ class A {
+ [customInspect](
+ inspect: (v: unknown, opts?: Deno.InspectOptions) => string,
+ ): string {
+ return "b " + inspect({ c: 1 });
+ }
+ }
+
+ assertEquals(stringify(new A()), "b { c: 1 }");
+});
+
unitTest(function consoleTestWithCustomInspectorError(): void {
class A {
[customInspect](): never {