feature-node: match methods by the class of the value, not by name #26
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/feature-node-method-receivers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
The Node pack matched methods by name across a whole module. A name that fails on one class was reported on any value from that module:
fs.createReadStream(p).read()was reported as if it wereFileHandle#read.open,stream,content, ...) were reported on anything anode:zlibchain returns, e.g.createGzip().pipe(dest).open().To limit the damage, the generator dropped every name used twice in a module, which also lost real failures:
zip.get(),zip.close(),zip.add(),zipBuffer.get(),gunzip.toArray().How it works now
Pack format (
safe-ts.json, generated byinventory.ts --write-pack). New per-module fields:classes: per class, its failingstatics(ZipFile.open()),methods(zip.get()) andextends("node:stream Transform"). A class is listed when it or a base has failing members.creates: callable → the class of its (awaited) result. Keys can befn,ns.fn,Class.static,Class#methodornew Alias. Example:ZipFile.open→ ZipFile,ZipFile#get→ ZipEntry,createGzip→ Gzip,fs.promises.open→ FileHandle.instances: exported values of a class (performance).methods(name-only, unchanged meaning) now only holds members that belong to no class (fs.promises.readFile).node-api.json has two new sections:
extends: each class's nearest base. Written from the running Node byinventory.ts --write-extends. The manifest test checks it is current.node inventory.tssays when it changed.creates: hand-written. I checked every entry by calling it on Node 26.13. The manifest test checks that each one names a mapped callable and an existing class, and checks exported instances at runtime.Checker (
features.rs,analyze.rs,project.rs):Get/Call/Newsteps, also across files).FeatureSet::lookup_methodresolves that path to a class throughcreates/instances.methods, as before. Other packs (zod, vue-router) use onlymethodsand behave as before.new X()is now followed as an origin (before,newvalues had none). For other packs, that means name-onlymethodsand automatic mode can now apply to values made withnewfrom a package.safe-ts coverageuses the same lookup.Counts: 189 functions as before. Methods went from 231 name-only to 35 name-only plus 215 class members (212 methods, 3 statics).
Collisions in other modules
Same module. I checked every name main matched by name alone against every other class in the same module, inherited methods included (now possible with
extends). One real collision: node:fsread. It rejects onDir/FileHandle, butReadStream#read(from Readable) never fails. Fixed by this PR and covered by a fixture.Across chains. These names were matched on any value from their module, including values that leave the module through a chain (
pipe, user objects built from module values):open,get,run,all,exec,prepare,iteratewriteread/writestartpostpostMessagefinal/signrequestdecoderesolvemeasurequestion/commitopen/stream/content/toBufferThey are all class members now, so they only match receivers of that class.
Coverage kept. Every class method main matched by name is still reachable: through
new, acreatesfactory, or aninstancesexport (performance,createRequire()).Tests
New fixture
crates/safe_ts_core/tests/fixtures/node_classes:.on()/.write()/.end(),createHash().update().digest(),fs.createReadStream(p).read(), andcreateGzip().pipe(destination).open().ZipFile.open/openSync,zip.get/getSync/close,entry.content/contentSync,zipBuffer.get(), a ZipFile opened in another file,gunzip.toArray()(through Readable),open()→handle.read(),fs.promises.open()→.read(),signer.sign(),performance.measure(),createRequire(...).resolve().Against main's checker and pack, this fixture fails with 2 false positives and 5 misses.
Manifest tests (
npm run test:std) have two new checks: bases match the running Node, andcreatesis consistent.Commands run:
cargo nextest run: 104 passednpm run test:std: 132 passed (incl. 4 manifest tests)npm run test:vite: passesnpm run test:docs: passes (new checked bad/good example indocs/guide/libraries.md)npm run typecheck: passesLeft out / uncertain
new ZipBuffer(bytes)can throw, but no constructor is reported yet (as the pack already said). The fixture notes it.createsis hand-written, so a factory missing from it leaves its values classless. That gives fewer reports, not wrong ones. Values that only arrive through callbacks or events (ServerResponse, server-sideTLSSocket) have no origin, as before.unsafeAsync(() => ...)fix on a call whose receiver containsawait(await (await zip.get(n)).content()) produces anawaitinside a non-async arrow. The fixture splits those lines.🤖 Generated with Claude Code