mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
chore(ext/console): inspect anonymous function as [Function (anonymous)]
(#18283)
This PR changes the inspect result of anonymous functions from `[Function]` to `[Function (anonymous)]`. This behavior is aligned to `util.inspect` of Node.js.
This commit is contained in:
parent
4c34a2f2df
commit
896d7f02cb
@ -1,28 +1,44 @@
|
||||
Node esm importing node cjs
|
||||
===========================
|
||||
{ default: [Function], named: [Function], MyClass: [Class: MyClass] }
|
||||
{ default: [Function], named: [Function] }
|
||||
{
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [Class: MyClass]
|
||||
}
|
||||
{ default: [Function (anonymous)], named: [Function (anonymous)] }
|
||||
Module {
|
||||
MyClass: [Class: MyClass],
|
||||
__esModule: true,
|
||||
default: { default: [Function], named: [Function], MyClass: [Class: MyClass] },
|
||||
named: [Function]
|
||||
default: {
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [Class: MyClass]
|
||||
},
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
Module {
|
||||
__esModule: true,
|
||||
default: { default: [Function], named: [Function] },
|
||||
named: [Function]
|
||||
default: { default: [Function (anonymous)], named: [Function (anonymous)] },
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
===========================
|
||||
static method
|
||||
Deno esm importing node cjs
|
||||
===========================
|
||||
{ default: [Function], named: [Function], MyClass: [Class: MyClass] }
|
||||
{
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [Class: MyClass]
|
||||
}
|
||||
Module {
|
||||
MyClass: [Class: MyClass],
|
||||
__esModule: true,
|
||||
default: { default: [Function], named: [Function], MyClass: [Class: MyClass] },
|
||||
named: [Function]
|
||||
default: {
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [Class: MyClass]
|
||||
},
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
===========================
|
||||
Deno esm importing node esm
|
||||
|
@ -1,2 +1,2 @@
|
||||
[WILDCARD]
|
||||
[Function]
|
||||
[Function (anonymous)]
|
||||
|
@ -1,9 +1,13 @@
|
||||
[WILDCARD]package.json file found at '[WILDCARD]with_package_json[WILDCARD]package.json'
|
||||
[WILDCARD]
|
||||
ok
|
||||
[Chalk] {
|
||||
constructor: [Function],
|
||||
[Chalk (anonymous)] {
|
||||
constructor: [Function (anonymous)],
|
||||
Instance: [Class: ChalkClass],
|
||||
supportsColor: false,
|
||||
stderr: [Chalk] { constructor: [Function], Instance: [Class: ChalkClass], supportsColor: false }
|
||||
stderr: [Chalk (anonymous)] {
|
||||
constructor: [Function (anonymous)],
|
||||
Instance: [Class: ChalkClass],
|
||||
supportsColor: false
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ Deno.test(function consoleTestStringifyCircular() {
|
||||
nu: null,
|
||||
arrowFunc: [Function: arrowFunc],
|
||||
extendedClass: Extended { a: 1, b: 2 },
|
||||
nFunc: [Function],
|
||||
nFunc: [Function (anonymous)],
|
||||
extendedCstr: [Class: Extended],
|
||||
o: {
|
||||
num: 2,
|
||||
@ -395,7 +395,13 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() {
|
||||
assertEquals(
|
||||
stringify({ f }),
|
||||
`{
|
||||
f: [Function: f] { x: [Function], y: 3, z: [Function], b: [Function: bar], a: Map {} }
|
||||
f: [Function: f] {
|
||||
x: [Function (anonymous)],
|
||||
y: 3,
|
||||
z: [Function (anonymous)],
|
||||
b: [Function: bar],
|
||||
a: Map {}
|
||||
}
|
||||
}`,
|
||||
);
|
||||
|
||||
@ -407,9 +413,9 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() {
|
||||
stringify({ f }),
|
||||
`{
|
||||
f: <ref *1> [Function: f] {
|
||||
x: [Function],
|
||||
x: [Function (anonymous)],
|
||||
y: 3,
|
||||
z: [Function],
|
||||
z: [Function (anonymous)],
|
||||
b: [Function: bar],
|
||||
a: Map {},
|
||||
s: [Circular *1],
|
||||
@ -2168,3 +2174,21 @@ Deno.test(function inspectQuotesOverride() {
|
||||
`"'foo'"`,
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test(function inspectAnonymousFunctions() {
|
||||
assertEquals(Deno.inspect(() => {}), "[Function (anonymous)]");
|
||||
assertEquals(Deno.inspect(function () {}), "[Function (anonymous)]");
|
||||
assertEquals(Deno.inspect(async () => {}), "[AsyncFunction (anonymous)]");
|
||||
assertEquals(
|
||||
Deno.inspect(async function () {}),
|
||||
"[AsyncFunction (anonymous)]",
|
||||
);
|
||||
assertEquals(
|
||||
Deno.inspect(function* () {}),
|
||||
"[GeneratorFunction (anonymous)]",
|
||||
);
|
||||
assertEquals(
|
||||
Deno.inspect(async function* () {}),
|
||||
"[AsyncGeneratorFunction (anonymous)]",
|
||||
);
|
||||
});
|
||||
|
@ -390,7 +390,7 @@ function inspectFunction(value, inspectOptions) {
|
||||
// from MDN spec
|
||||
return cyan(`${refStr}[${cstrName}: ${value.name}]`) + suffix;
|
||||
}
|
||||
return cyan(`${refStr}[${cstrName}]`) + suffix;
|
||||
return cyan(`${refStr}[${cstrName} (anonymous)]`) + suffix;
|
||||
}
|
||||
|
||||
function inspectIterable(
|
||||
|
Loading…
Reference in New Issue
Block a user