fix: nested loop protection without braces causing ReferenceError: _LP is not defined#4184
Open
dsaicharan072-cmyk wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe the bug
When users run sketch files with nested loops that do not use braces (e.g.,
for (...) for (...) stmt), the preprocessor generates loop protection checks using_LP[idx]variables. However, because the inner loop is not a direct child of anyBlockStatement, the preprocessor was silently dropping thevar _LP0 = Date.now()variable declaration. This resulted inReferenceError: _LP0 is not definedwhen executing the code in the preview.Solution
In
jsPreprocess.js:directParent(the immediate parent loop or statement) incollectLoopsToProtect.injectProtection, whenparentBlock.body.indexOf(loop) === -1, check if it's nested directly underdirectParentwithout braces.BlockStatementcontaining both the prepended variable declaration and the loop itself.no-continuerule) by restructuring the loops collection conditional logic.Tests
forloops andwhileloops without braces inside other loops.