Repository navigation
[12.x] Fix shadowed JS names colliding with $ identifiers - #9463
Open
illusionalsagacity wants to merge 1 commit into
Open
illusionalsagacity wants to merge 1 commit into
illusionalsagacity wants to merge 1 commit into
Conversation
Backport of rescript-lang#8778 to 12.x. Track printed names in Ext_pp_scope so a suffix like x$1 is never reused for an identifier that already contains $, and reserve the raw JS names a program refers to, so a renamed local like x$2 can't capture an external with that name. Differs from master only in using 12.x's Map_string, Map_int and Set_string (data-first, where master uses the stdlib Map and Set), and in keeping Ext_pp_scope.print, which 12.x still has, adapted to the new scope type. Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
This branch has not been deployed
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.
Backport of #8778 to 12.x. It is a prerequisite for the backport of #9417 (branch
fix-for-loop-closure-12.x), whose later commits build on the raw JS names thatExt_pp_scopereserves here.Problem
A shadowed variable is printed with a
$Nsuffix, but identifiers may themselves contain$, so a suffixed name likex$1could equal another identifier's name. A suffixed local could also capture a raw JS name the module refers to, such as a@valglobal namedy$1.Before (a syntax error:
x$1is declared twice;y$1reads the local, not the global):After:
Fix
As on master:
Ext_pp_scopetracks every printed name in scope and picks the first$Nsuffix that is not in use.Js_dump_programreserves the raw JS names a program refers to, so that no suffixed name equals one of them.Differences from master:
Ext_pp_scopeuses 12.x'sMap_string,Map_intandSet_string, which take the map or set first; master uses the stdlibMapandSet(Use the stdlib Set for the compiler's sets #8789, Use the stdlib Map for the compiler's maps #8790).Ext_pp_scope.print(master removed it in Remove dead code and stale docs in compiler/ext, common, depends and ml #8699). It is kept, adapted to the new scope type.Tests
tests/tests/src/shadow_dollar_test.resis master's: parameters and bindings namedx$1next to shadowedx, in nested functions, and raw JS namesy$1,z$2andw$1next to shadowed locals at the toplevel and in a function. Its.mjsis the same as on master. Built with 12.x before this change, the module is a syntax error. No other module intests/testschanges output.No later change on master fixes a regression from #8778. The later commits of #9417 build on it, and are backported in
fix-for-loop-closure-12.x.Investigated by Claude.