1
0
Fork 0
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:
Casper Beyer 2020-09-24 02:10:35 +08:00 committed by GitHub
parent 3ac9f1e209
commit e1b61d6794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -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

View file

@ -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 }");