mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
`rmSync?.(…)`: an imported node:fs function has a call lowering but no value form, so lowering the guarded callee failed with "library functions as values". The checker types the callee never-nullish, so the guard can never short-circuit and the step is the plain call. When the callee is never-nullish (any/unknown excluded) and has no value lowering, mark the call's `?.` node chainHandled and re-dispatch the plain call; it reports its own diagnostics when it has no lowering either. Also drops the unused isSafeToDiscard import left behind in optional-chains.ts. Corpus: tests/corpus/optional-call-library-function.ts (Node vs native, byte-identical). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1019 B
TypeScript
28 lines
1019 B
TypeScript
// `f?.(…)` where the checker types the callee never-nullish: an imported
|
|
// node:fs function has no value form at all (only a call), and the guard
|
|
// can never short-circuit, so the step is the plain call. The present
|
|
// target is created and removed; the force-missing target stays silent,
|
|
// exactly as the plain call.
|
|
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
const base = mkdtempSync(join(tmpdir(), "scriptc-optcall-"));
|
|
const dir = join(base, "nested");
|
|
|
|
rmSync?.(dir, { force: true, recursive: true });
|
|
mkdirSync(dir, { recursive: true });
|
|
console.log("created");
|
|
|
|
rmSync?.(dir, { force: true, recursive: true });
|
|
console.log("removed");
|
|
|
|
rmSync?.(join(base, "missing"), { force: true, recursive: true });
|
|
console.log("missing ok");
|
|
|
|
// The plain spelling of the same import keeps compiling unchanged.
|
|
rmSync(dir, { force: true, recursive: true });
|
|
console.log("plain ok");
|
|
|
|
rmSync?.(base, { force: true, recursive: true });
|