mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
`const proc = globalThis.process` lowers to alias plumbing: the declaration emits no storage and no code, because member and call reads resolve through the global it names. A read that needs the VALUE therefore failed at the use with the generic "binding form with no lowering", which names neither the declaration nor the cause. Register every stdlib-global snapshot declaration (TypeScript sources only, matching the elision) and report the cause at the declaration (SC2020), naming the global and, when it has a short spelling, the type the program asked the compiler to hold. The use site keeps the inherited-blocker cascade (SC2004) instead of the generic text. An unread snapshot stays elided: reading a global has no side effects, so dropping an unread `const p = process` is observationally identical to Node, and refusing it would break programs that compile harmlessly today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
// process basics: platform, argv shape/identity/mutation, cwd. The
|
|
// argv[0]/argv[1] VALUES differ between Node and scriptc (documented
|
|
// divergence — positions and length match), so only shape and identity
|
|
// properties print; cwd itself prints because both sides run in one cwd.
|
|
const platform = process.platform;
|
|
console.log(platform === "darwin" || platform === "linux" || platform === "win32");
|
|
console.log(platform.length > 0, platform === process.platform);
|
|
|
|
// One stable interned array, exactly like Node's process.argv.
|
|
console.log(process.argv === process.argv);
|
|
const argv = process.argv;
|
|
console.log(argv === process.argv);
|
|
console.log(argv.length); // [runtime, program] — 2 on both sides
|
|
console.log(argv[0].length > 0, argv[1].length > 0);
|
|
// Mutations persist across reads (it is ONE array, not a fresh copy).
|
|
argv.push("extra");
|
|
console.log(process.argv.length, process.argv[2] === "extra");
|
|
process.argv.pop();
|
|
console.log(argv.length);
|
|
|
|
// argv through ordinary array machinery.
|
|
let nonEmpty = 0;
|
|
for (const a of process.argv) {
|
|
if (a.length > 0) {
|
|
nonEmpty = nonEmpty + 1;
|
|
}
|
|
}
|
|
console.log(nonEmpty === process.argv.length);
|
|
|
|
// cwd: a fresh string per call, equal by content, absolute.
|
|
const cwd = process.cwd();
|
|
console.log(cwd);
|
|
console.log(cwd === process.cwd(), cwd.startsWith("/"));
|
|
|
|
// A stdlib-global snapshot (`const proc = globalThis.process`) lowers to
|
|
// alias plumbing — no storage, no code — and reads through it resolve to
|
|
// the global itself.
|
|
const proc = globalThis.process;
|
|
console.log(proc.pid === process.pid, proc.platform === process.platform);
|
|
console.log(proc.argv === process.argv);
|