mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(cli/console): quote non-alphanumeric symbols (#7641)
This quotes and escapes symbol descriptions that contains characters outside of the basic alpha-numeric identifier range.
This commit is contained in:
parent
3ac9f1e209
commit
e1b61d6794
2 changed files with 28 additions and 2 deletions
|
@ -414,7 +414,7 @@
|
|||
case "undefined": // undefined is dim
|
||||
return dim(String(value));
|
||||
case "symbol": // Symbols are green
|
||||
return green(String(value));
|
||||
return green(maybeQuoteSymbol(value));
|
||||
case "bigint": // Bigints are yellow
|
||||
return yellow(`${value}n`);
|
||||
case "function": // Function string is cyan
|
||||
|
|
|
@ -102,6 +102,32 @@ unitTest(
|
|||
"foo\\n", "foo\\r",
|
||||
"foo\\t", "foo\\v",
|
||||
"foo\\x00"
|
||||
]`,
|
||||
);
|
||||
assertEquals(
|
||||
stringify(
|
||||
[
|
||||
Symbol(),
|
||||
Symbol(""),
|
||||
Symbol("foo\b"),
|
||||
Symbol("foo\f"),
|
||||
Symbol("foo\n"),
|
||||
Symbol("foo\r"),
|
||||
Symbol("foo\t"),
|
||||
Symbol("foo\v"),
|
||||
Symbol("foo\0"),
|
||||
],
|
||||
),
|
||||
`[
|
||||
Symbol(),
|
||||
Symbol(""),
|
||||
Symbol("foo\\b"),
|
||||
Symbol("foo\\f"),
|
||||
Symbol("foo\\n"),
|
||||
Symbol("foo\\r"),
|
||||
Symbol("foo\\t"),
|
||||
Symbol("foo\\v"),
|
||||
Symbol("foo\\x00")
|
||||
]`,
|
||||
);
|
||||
assertEquals(
|
||||
|
@ -247,7 +273,7 @@ unitTest(function consoleTestStringifyCircular(): void {
|
|||
);
|
||||
assertEquals(stringify(new WeakSet()), "WeakSet { [items unknown] }");
|
||||
assertEquals(stringify(new WeakMap()), "WeakMap { [items unknown] }");
|
||||
assertEquals(stringify(Symbol(1)), "Symbol(1)");
|
||||
assertEquals(stringify(Symbol(1)), `Symbol("1")`);
|
||||
assertEquals(stringify(null), "null");
|
||||
assertEquals(stringify(undefined), "undefined");
|
||||
assertEquals(stringify(new Extended()), "Extended { a: 1, b: 2 }");
|
||||
|
|
Loading…
Reference in a new issue