Repository navigation
Keep renamed reserved-word expando locals private in declaration emit - #65606
Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
Open
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>
Ryan Cavanaugh (RyanCavanaugh)
marked this pull request as ready for review
November 20, 2026 20:34
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change that keeps renamed expando locals private in declaration output.
No open issues 🎉
What changed in this PR
Fixes #65605 by keeping generated locals for reserved-word expando properties private in declaration output, so consumers cannot access properties that do not exist at runtime.
Changes:
- Restricts explicit exports to locals whose names match their exported property names.
- Adds regression coverage for function and arrow hosts, mixed property names, and an identifier alias preceding reserved-word members.
- Updates declaration baselines to remove unintended local exports.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/declarationEmitExpandoReservedWordMembers.ts |
Adds targeted expando declaration regression cases. |
tsc/testdata/baselines/reference/conformance/nullPropertyName.js |
Removes leaked local exports from expected declarations. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsFunctionKeywordPropExhaustive(target=es2015).js |
Updates exhaustive keyword-property declaration expectations. |
tsc/testdata/baselines/reference/compiler/declarationEmitExpandoReservedWordMembers.types |
Records inferred types for the new cases. |
tsc/testdata/baselines/reference/compiler/declarationEmitExpandoReservedWordMembers.symbols |
Records symbol bindings for the new cases. |
tsc/testdata/baselines/reference/compiler/declarationEmitExpandoReservedWordMembers.js |
Records declarations with private locals and exported aliases. |
tsc/internal/transformers/declarations/transform.go |
Prevents renamed expando locals from receiving an export modifier. |
Review effort: Balanced
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.