-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add detection for outside variable references in p5.strands uniforms #8195
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
Open
Aayushdev18
wants to merge
3
commits into
processing:main
Choose a base branch
from
Aayushdev18:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll want to go with a different approach than manually trying to make a list of variable names to exclude. A user could create a variable named anything they want, so we need something more robust to capture that. The test code in the issue was just an example.
We may need to detect variable declarations in the transpilation phase (https://github.com/processing/p5.js/blob/dev-2.0/src/strands/strands_transpiler.js) and then see if there are references to variables not included in that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @davepagurek for the feedback! You're absolutely right - checking for hardcoded variable names isn't robust. I've removed that implementation.
Following your suggestion, I need to implement this during the transpilation phase in strands_transpiler.js. The approach should:
Could you provide some guidance on how to best integrate this with the existing transpiler? Should I add a new callback to the ASTCallbacks object, or would it be better to analyze the AST separately before/after transpilation?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since nothing actually needs to be rewritten, this could be a new phase (maybe run before actual transpilation), but feel free to reuse a lot of the structure of the transpiler, since acorn will be a valuable tool in detecting these. You can use AST Explorer and change the AST to Acorn in the header to see how Acorn parses code, which can help you figure out what structures to look for when detecting declarations.
This is also the kind of thing that would really benefit from unit tests so we can see what's covered.