Repository navigation
[p5.js 2.0+ Bug Report]: strands breaking on arrow functions with parameters #9180
Description
Activity
Hi maintainers, I would like to work on this issue if a contributor PR would be welcome.
My current understanding is that the strands callback handling assumes a parenthesized parameter list. JavaScript permits a single arrow-function parameter without parentheses (
param => { ... }), and the transpiled form can therefore bypass the current parameter/body extraction, while destructuring (({ p }) => { ... }) retains parentheses and still works.I would first add regression coverage for the failing single-parameter arrow form and the working destructuring form, then make the smallest parser/transpiler change that handles both forms without changing existing callback behavior. I am using AI assistance for repository exploration; I will review and understand every line and disclose that assistance in any PR.
Could you confirm the preferred implementation direction and whether you would welcome a PR for this issue?
Reacted by kitHi @tsumon, the approach of first adding a test to verify it fails and then adding a fix makes sense to me. Feel free to go ahead with a PR and to ask any questions you have along the way here to build up your understanding.
As far as changes go, that regex has been pretty brittle, possibly we can replace it with something that uses the AST.
Update: the fix is implemented in #9188. It adds regression coverage for a single-parameter arrow callback without parentheses and replaces the brittle regex extraction with the parsed AST node, while preserving the existing function/arrow callback paths. Oxlint passes on both changed files. The local Chromium runner currently fails while importing the WebGL test file with Unexpected identifier highp, before collecting tests, so I have left the regression test in the PR for CI and maintainer review.
- added a commit that references this issue
on Sep 20, 2026
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsCompleted
Most appropriate sub-area of p5.js?
p5.js version
2.3.2
Web browser and version
All
Operating system
All
Steps to reproduce this
If you are using instance mode, you have to pass in a second parameter to p5.strands containing whatever outside context you need in the shader. This gets passed back into the function you pass in, so you add an argument to your function to collect the data from the outside world. However, this currently throws an error, I assume because a regex doesn't handle
param => { ... }correctly.Live: https://editor.p5js.org/davepagurek/sketches/k64e4h1LA
Notably, this works if you:
function(param) { ... }({ p }) => { ... }in the example above.I believe we have tests that do some of the above, but I guess not this particular case.