Repository navigation
Keep renamed reserved-word expando locals private in declaration emit - #65606
Draft
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
Draft
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@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.
For expando hosts with reserved-word members, declaration emit exported the generated local from the second reserved-word member onward. Consumers could then type-check
decl._b, which isundefinedat runtime.export declare namespace decl { var _a: number; export { _a as default }; - export var _b: number; + var _b: number; export { _b as class }; }Cause
transformExpandoAssignmentadds members one at a time. Once the namespace already contains anexport { … }, its members are no longer exported implicitly, so each later variable gets an explicitexport. That modifier was also applied to renamed locals, which should only be reachable through their alias.The same path leaks the first renamed local when an earlier member is an identifier alias (
decl.x = someIdentemitsexport { someIdent as x }first).Change
exportonly if the namespace already contains anexport { … }and its local name equals its exported name. Renamed locals stay private.export { … }per member rather than 6.0's single combined statement. The set of exported names now matches 6.0.Tests
declarationEmitExpandoReservedWordMembers.ts. It covers function andconstarrow hosts, reserved-word members mixed with ordinary ones, and a host whose first member is an identifier alias.nullPropertyNameandjsDeclarationsFunctionKeywordPropExhaustive, which had recorded the leakedexport var _xlines.