processing / processing/p5.js-web-editor
Bug: Loop protection generates invalid JS from do while loop with standalone comment
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 1.7k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 8
Description
p5.js version
No response
What is your operating system?
Windows
Web browser and version
Edge 148.0.3967.83
Actual Behavior
When transforming a do-while loop with a standalone comment, the infinite loop guard erroneously treats the while (...); as if it were the start of a standalone while loop.
Expected Behavior
The loop guard should not be treating the while statement after a do while loop as standalone and should not add an infinite loop detector.
Steps to reproduce
Steps:
- Make a project, whether its saves or not or version doesn't matter.
- Paste in the following snippet into anywhere, it can be setup, draw, or even outside any function
- Press run (also crashes in the full view)
Snippet:
do{
// Hello this is a comment and this comment is very important to this bug
}while (false);
Link is here
Transformed code
The code that actually runs according to inspect is here:
{;loopProtect.protect({ line: 7, reset: true }); do{;if (loopProtect.protect({ line: 7 })) break;
}{;loopProtect.protect({ line: 9, reset: true }); while (false){if (loopProtect.protect({ line: 9 })) break;;}}
When the bug occurs
This bug only occurs in a do while loop. When the do statement has no comment, the bug does not occur. A inline comment does not trigger this. Both single and multi-line comments trigger this. This does not happen when the loop has // noprotect. EDIT: This also can trigger when code is within the do clause as long as the comment is standalone.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the linked p5.js Editor sketch using the provided do-while snippet with a standalone comment, then inspect the transformed code shown in the report. The fix is complete when this case produces valid JavaScript without treating the post-do while while statement as a standalone loop or adding an infinite-loop detector.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100