Refactor closure capture analysis and remove collectCapturedNames #3
+7,078
−1,713
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.
Replaces the collectCapturedNames function with a unified scanNodeForCaptures that supports both local and name modes for closure variable capture analysis. Updates all relevant call sites and improves handling of various node kinds, making closure capture logic more robust and maintainable. Also updates test WAT files to reflect changes in closure environment global naming.
Refactor closure function creation logic
Removed unused parameters and redundant local set in array rest parameter initialization. Simplified compileClosureFunctionCreation by removing the staticOffset argument, as it is no longer used.
Ensure that default values of function parameters are scanned for variable captures before parameter names are added to the inner function scope. This fixes issues where closures in default parameter expressions could not capture outer variables. Adds new tests for closures in default parameter values.
Replaces all occurrences of the closure environment global variable from '$$~lib/__closure_env' to '$~lib/__closure_env' in the compiler source and test files. This change ensures consistency in global naming and avoids the use of double dollar signs.
Extended closure variable capture logic in the compiler to handle while, do-while, for, for-of, switch, try/catch/finally, and various expression nodes. Updated test cases to cover closure captures in these new contexts, ensuring correct environment handling and variable scoping for closures in complex control flow and expression scenarios.