fix(cli/console): enclose symbol keys in brackets (#7642)

This encloses symbol keys when used in objects with brackets (e.g
[Symbol("Symbol.iterator")]).
This commit is contained in:
Casper Beyer 2020-09-23 19:58:28 +08:00 committed by GitHub
parent 29dd62b08c
commit d68fb81342
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 13 deletions

View file

@ -747,7 +747,7 @@
} }
for (const key of symbolKeys) { for (const key of symbolKeys) {
entries.push( entries.push(
`${maybeQuoteSymbol(key)}: ${ `[${maybeQuoteSymbol(key)}]: ${
inspectValueWithQuotes( inspectValueWithQuotes(
value[key], value[key],
ctx, ctx,

View file

@ -1 +1 @@
Module { isMod4: true, Symbol(Symbol.toStringTag): "Module" } Module { isMod4: true, [Symbol(Symbol.toStringTag)]: "Module" }

View file

@ -1 +1 @@
Module { isMod4: true, Symbol(Symbol.toStringTag): "Module" } Module { isMod4: true, [Symbol(Symbol.toStringTag)]: "Module" }

View file

@ -1 +1 @@
Module { Symbol(Symbol.toStringTag): "Module" } Module { [Symbol(Symbol.toStringTag)]: "Module" }

View file

@ -121,11 +121,11 @@ unitTest(
}, },
), ),
`{ `{
Symbol("foo\\b"): 'Symbol("foo\\n\")', [Symbol("foo\\b")]: 'Symbol("foo\\n\")',
Symbol("bar\\n"): 'Symbol("bar\\n\")', [Symbol("bar\\n")]: 'Symbol("bar\\n\")',
Symbol("bar\\r"): 'Symbol("bar\\r\")', [Symbol("bar\\r")]: 'Symbol("bar\\r\")',
Symbol("baz\\t"): 'Symbol("baz\\t\")', [Symbol("baz\\t")]: 'Symbol("baz\\t\")',
Symbol("qux\\x00"): 'Symbol(\"qux\\x00")' [Symbol("qux\\x00")]: 'Symbol(\"qux\\x00")'
}`, }`,
); );
assertEquals( assertEquals(
@ -277,7 +277,10 @@ unitTest(function consoleTestStringifyCircular(): void {
"{ a: { b: { c: { d: [Set] } } } }", "{ a: { b: { c: { d: [Set] } } } }",
); );
assertEquals(stringify(nestedObj), nestedObjExpected); assertEquals(stringify(nestedObj), nestedObjExpected);
assertEquals(stringify(JSON), 'JSON { Symbol(Symbol.toStringTag): "JSON" }'); assertEquals(
stringify(JSON),
'JSON { [Symbol(Symbol.toStringTag)]: "JSON" }',
);
assertEquals( assertEquals(
stringify(console), stringify(console),
`{ `{
@ -301,12 +304,12 @@ unitTest(function consoleTestStringifyCircular(): void {
clear: [Function: clear], clear: [Function: clear],
trace: [Function: trace], trace: [Function: trace],
indentLevel: 0, indentLevel: 0,
Symbol(isConsoleInstance): true [Symbol(isConsoleInstance)]: true
}`, }`,
); );
assertEquals( assertEquals(
stringify({ str: 1, [Symbol.for("sym")]: 2, [Symbol.toStringTag]: "TAG" }), stringify({ str: 1, [Symbol.for("sym")]: 2, [Symbol.toStringTag]: "TAG" }),
'TAG { str: 1, Symbol(sym): 2, Symbol(Symbol.toStringTag): "TAG" }', 'TAG { str: 1, [Symbol(sym)]: 2, [Symbol(Symbol.toStringTag)]: "TAG" }',
); );
// test inspect is working the same // test inspect is working the same
assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected); assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected);
@ -798,7 +801,7 @@ unitTest(function consoleTestWithCustomInspectorError(): void {
assertEquals(stringify(new B({ a: "a" })), "a"); assertEquals(stringify(new B({ a: "a" })), "a");
assertEquals( assertEquals(
stringify(B.prototype), stringify(B.prototype),
"{ Symbol(Deno.customInspect): [Function: [Deno.customInspect]] }", "{ [Symbol(Deno.customInspect)]: [Function: [Deno.customInspect]] }",
); );
}); });