Skip to content

Read p5.strands callback params and body from the AST - #9188

Merged
perminder-17 merged 3 commits into
processing:mainfrom
tsumon:fix/9180-strands-arrow-params
Sep 20, 2026
Merged

perminder-17 merged 3 commits into
processing:mainfrom
tsumon:fix/9180-strands-arrow-params

Conversation

@tsumon

@tsumon tsumon commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Resolves #9180

Changes:

buildStrandsCallback used a regex on escodegen output that required a parenthesized parameter list. escodegen prints a single arrow parameter without parentheses, so param => { ... } (and (param) => { ... } after codegen) threw Could not parse p5.strands function!.

The callback source is wrapped in parentheses before parsing, so the function is the program's single expression. This change reads params and body from that AST node instead of the regex.

Added a regression test that passes the unparenthesized arrow form as source text so the case does not depend on how the test file itself is transformed.

function(param) {}, () => {}, and ({ p }) => {} still go through the same callback path.

AI usage:

I used an AI assistant to explore the transpiler, draft the AST extraction, and add the regression test. I reviewed every line. The approach follows the discussion on #9180: add a failing test first, then read params and body from the AST because that regex has been brittle.

PR Checklist

  • npm run lint passes on the two changed files
  • Inline reference is included / updated
  • Unit tests are included / updated

tsumon and others added 2 commits September 17, 2026 09:19
escodegen drops parentheses on a single arrow parameter, so the old regex
failed on param => { ... }. Use the parsed function node instead.

Fixes processing#9180
@p5-bot

p5-bot Bot commented Sep 20, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: 941e748

Previous deployments

This is an automated message.

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for your work on this @tsumon

@perminder-17
perminder-17 merged commit 1f127ca into processing:main Sep 20, 2026
4 checks passed
@perminder-17

Copy link
Copy Markdown
Collaborator

@all-contributors please add @tsumon for code

@allcontributors

Copy link
Copy Markdown
Contributor

@perminder-17

I've put up a pull request to add @tsumon! 🎉

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.

[p5.js 2.0+ Bug Report]: strands breaking on arrow functions with parameters

2 participants