Skip to content

Fix inline anonymous functions causing a parsing error in p5.strands callbacks #7956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

nking07049925
Copy link

@nking07049925 nking07049925 commented Jul 7, 2025

Resolves #7955

Changes:

WebGL ShaderGenerator.js

  • Wraps function source string in round brackets to prevent issues with acorn parsing top level function statements

Unit Tests

  • Adds a unit test to p5.Shader for an anonymous function being passed into the shader

Screenshots of the change

Example from the issue running locally with no errors
image

PR Checklist

  • npm run lint passes
  • Unit tests are included / updated

Copy link

welcome bot commented Jul 7, 2025

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for adding this, and the test as well! Just one minor comment about leaving some context for the change behind.

@@ -19,7 +19,7 @@ function shadergenerator(p5, fn) {
if (shaderModifier instanceof Function) {
let generatorFunction;
if (options.parser) {
const sourceString = shaderModifier.toString()
const sourceString = `(${shaderModifier.toString()})`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind adding a comment here to explain to other contributors why the brackets are necessary?

Copy link
Author

Choose a reason for hiding this comment

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

Would something like this work?

// #7955 Wrap function declaration code in brackets so anonymous functions are not top level statements, which causes an error in acorn when parsing

Copy link
Contributor

Choose a reason for hiding this comment

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

looks great, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

Nice! I will be able to make a commit later today

@davepagurek davepagurek merged commit e4ad5ee into processing:dev-2.0 Jul 9, 2025
2 checks passed
@davepagurek
Copy link
Contributor

@all-contributors please add @nking07049925 for code

Copy link
Contributor

@davepagurek

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

@nking07049925 nking07049925 deleted the 7955_strands_AnonymousFunctionCallbackFix branch July 11, 2025 17:53
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.

2 participants