Skip to content

Keep renamed reserved-word expando locals private in declaration emit - #65606

Draft
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
mainfrom
copilot/fix-declaration-emit-reserved-words
Draft

Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
mainfrom
copilot/fix-declaration-emit-reserved-words

Conversation

@RyanCavanaugh

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

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 is undefined at runtime.

export function decl() {}
decl.default = 1;
decl.class = 2;
 export declare namespace decl {
     var _a: number;
     export { _a as default };
-    export var _b: number;
+    var _b: number;
     export { _b as class };
 }

Cause

transformExpandoAssignment adds members one at a time. Once the namespace already contains an export { … }, its members are no longer exported implicitly, so each later variable gets an explicit export. 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 = someIdent emits export { someIdent as x } first).

Change

  • A variable gets export only if the namespace already contains an export { … } and its local name equals its exported name. Renamed locals stay private.
  • Aliases are still emitted as one export { … } per member rather than 6.0's single combined statement. The set of exported names now matches 6.0.

Tests

  • New: declarationEmitExpandoReservedWordMembers.ts. It covers function and const arrow hosts, reserved-word members mixed with ordinary ones, and a host whose first member is an identifier alias.
  • Updated baselines: nullPropertyName and jsDeclarationsFunctionKeywordPropExhaustive, which had recorded the leaked export var _x lines.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Nov 20, 2026
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) changed the title [WIP] Fix declaration emit for reserved-word expando members Keep renamed reserved-word expando locals private in declaration emit Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declaration emit exports the renamed locals of reserved-word expando members after the first one

2 participants