Repository navigation
JS: clean up reused undeclared variables when scopes close - #133
Merged
tdewolff merged 1 commit intoOct 18, 2026
Merged
Conversation
Defer indexed declaration cleanup until scope close, including global scopes. Preserve outer references and argument-use offsets. Add scope regression checks and strengthen the timing guard.
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.
Fixes #132.
Keep the indexed
Declarepath cheap by reusing the variable and setting its declaration kind without removing itsUndeclaredentry or shifting indices. When the scope closes,HoistUndeclaredremoves entries that also belong to that scope'sDeclaredlist in one pass, then rebuilds the index once if needed. It also adjusts theNumArgUsesoffset when removing entries before it.The cleanup checks variable identity against the scope's declarations. Testing only
Decl != NoDeclwould also remove references to variables declared in enclosing scopes, such as thebin{var b}. Those references must remain inUndeclared.Module and inline parsing now close the global scope too.
HoistUndeclaredcleans that scope without trying to hoist into a parent.Validation:
js.Varrecords across 2,605 real JavaScript programs, totaling 16,310,585 bytes, against v2.8.16. Every file parsed successfully. Names, declaration kinds, use counts and links all match, with zero differences.go test ./...passes.go vet ./...reports the same two findings as unchanged v2.8.18:binary.go:512, theWriteBytesignature, andjs/ast.go:76, unreachable code inAST.JSON.