Reading what was generated
Reading a helper a model wrote
It looks pure, returns the right shape, and changes something it was never given. · 12 minutes
A generated helper rarely has a syntax problem. It has a model problem: it was written by something that knows what idiomatic code looks like and has no view of the heap. The bug is almost always a value that two places share without either of them saying so.
So read it the way the machine runs it. For every object it touches, ask where that object came from — the arguments, a fresh literal, or something that already existed before the call.
const BASE = { scopes: [] }; function grant(user, s) { const next = { ...BASE, ...user }; next.scopes.push(s); return next; } — after grant(a, 'read') and grant(b, 'write'), what is BASE.scopes.length?