Skip to content

fix: perch scan stopped on a function inside a constructor that uses this - #359

Merged
jbrown9513 merged 1 commit into
mainfrom
fix/bases-prototype-keys
Oct 11, 2026
Merged

jbrown9513 merged 1 commit into
mainfrom
fix/bases-prototype-keys

Conversation

@jbrown9513

Copy link
Copy Markdown
Contributor

perch scan stopped with function is not iterable (cannot read property Symbol(Symbol.iterator)) on a file like this:

export class Tenant extends Store {
  constructor() {
    super();
    const columns = table => this.sql.exec(table);
    columns('usage');
  }
}

To find where this.sql is assigned, the graph looks up the bases of the class around the caller. For columns, it takes the name of the method around it, constructor, as that class. A file's record keeps each class's bases in a plain object, so bases['constructor'] returned Object's own constructor, a function, and iterating it threw. A method named toString, valueOf or any other name on Object did the same. It needs a class with a base in the file, so the record has bases at all. 0.4.2 has the bug.

All six lookups of a class's bases in src/graph.js now go through basesOf, which reads only the record's own keys. Building the object without a prototype would not be enough: records parsed in a child process come back through JSON.

A new test in test/bindings.test.js covers the constructor and the toString cases. It fails with the TypeError without the change. npm run check passes: lint, typecheck and 671 tests.

Users don't need to change anything.

Closes #358

🤖 Generated with Claude Code

…this

A file's record keeps each class's bases in a plain object, and the graph looked them up by name. For a named function inside a constructor, the name it looks up is the method around it, constructor, which finds Object's own constructor and stopped the scan with "function is not iterable". toString, valueOf and the other names on Object did the same. Every lookup of a class's bases now reads only the record's own keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@perchcode-bot

perchcode-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Perch Scan: no issues in 88 methods at 1677472.

See the scan

@jbrown9513
jbrown9513 merged commit dacd98f into main Oct 11, 2026
6 checks passed
@jbrown9513
jbrown9513 deleted the fix/bases-prototype-keys branch October 11, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perch scan stops with "function is not iterable" on a function inside a constructor that uses this

1 participant