mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
Reading the name of a function stored in a const followed const aliases to
the definition, but stopped at destructuring: `const { cwd } = process`
gave the binding's name instead of Node's "wrappedCwd". A member
destructured from the process global or a builtin module's namespace now
gives the module table's name for it.
An anonymous function wrapped in parentheses (`const f = (function () {})`)
answered an empty name. As in Node, it takes the name of the binding or
property it initializes through the parentheses.
A builtin read as a property (`util.debuglog.name`) answered the name its
shared adapter was first created under, so after `util.debug` it answered
"debug". The name now comes from the property and the module table, and
util.debug's value is named "debuglog", as in Node.
21 lines
806 B
JavaScript
21 lines
806 B
JavaScript
// The name of a function value read through a const binding: a builtin
|
|
// keeps Node's name (including when destructured), an anonymous function or
|
|
// arrow takes the binding's name through parentheses, and an alias of a
|
|
// named function keeps the function's name.
|
|
import * as path from "node:path";
|
|
import * as processModule from "node:process";
|
|
|
|
const { cwd } = process;
|
|
const { cwd: renamed } = processModule;
|
|
const join = path.join;
|
|
const parenthesized = (function () {});
|
|
const arrow = (() => 0);
|
|
const nested = ((function () {}));
|
|
function named() {}
|
|
const alias = named;
|
|
const aliasOfAlias = alias;
|
|
console.log(cwd.name, renamed.name, join.name);
|
|
console.log(parenthesized.name, arrow.name, nested.name);
|
|
console.log(alias.name, aliasOfAlias.name);
|
|
console.log(cwd === process.cwd, typeof cwd());
|