Skip to content

Convert patterns in object rest bindings to assignment targets - #65493

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/rest-binding-targets
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/rest-binding-targets

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

An object rest binding with a nested pattern, as in export const { ...{ object } } = source, is a syntax error, but emit runs anyway. CommonJS export emit turns the declaration into an assignment and left the nested binding pattern as a spread assignment's expression, so the printer panicked before emit could finish with the diagnostic.

Caught in an audit.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 00:17
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 14, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 14, 2026

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 block the targeted fix for malformed nested object-rest bindings during CommonJS export emission.

No open issues 🎉

What changed in this PR

Prevents a printer panic in the native TypeScript compiler when malformed nested object rest bindings reach CommonJS export emit, while preserving the syntax diagnostic.

Changes:

  • Converts object rest binding names into assignment targets before creating spread assignments.
  • Adds a regression test for ES2018 and ESNext.
  • Records expected JavaScript, diagnostics, types, and symbols for both targets.
File Description
tsc/​testdata/​tests/​cases/​compiler/​commonjsExportNestedRestBinding.ts Adds the malformed nested rest regression case.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=esnext).types Records ESNext type information.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=esnext).symbols Records ESNext symbol information.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=esnext).js Records ESNext emit without a printer panic.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=esnext).errors.txt Preserves the ESNext syntax diagnostic.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=es2018).types Records ES2018 type information.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=es2018).symbols Records ES2018 symbol information.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=es2018).js Records ES2018 emit without a printer panic.
tsc/​testdata/​baselines/​reference/​compiler/​commonjsExportNestedRestBinding(target=es2018).errors.txt Preserves the ES2018 syntax diagnostic.
tsc/​internal/​transformers/​utilities.go Converts nested rest binding patterns into assignment targets.

Review effort: Balanced

An object rest binding with a nested pattern, as in
export const { ...{ object } } = source, is a syntax error, but emit
runs anyway. CommonJS export emit turns the declaration into an
assignment and left the nested binding pattern as a spread
assignment's expression, so the printer panicked before emit could
finish with the diagnostic.
@jakebailey
Jake Bailey (jakebailey) force-pushed the compiler-fixes/rest-binding-targets branch from 75fe9c0 to 4d03e45 Compare November 18, 2026 02:48
@jakebailey Jake Bailey (jakebailey) changed the title Convert nested rest bindings to assignment targets Convert patterns in object rest bindings to assignment targets Nov 18, 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

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants