Skip to content

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

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

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
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review November 20, 2026 20:34
Copilot AI balanced review requested due to automatic review settings November 20, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

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

3 participants