Skip to content

Fix panic for rest properties in catch binding when targeting ES2017#3927

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-tsgo-panics-catch-binding
Open

Fix panic for rest properties in catch binding when targeting ES2017#3927
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-tsgo-panics-catch-binding

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

visitCatchClause in the object rest/spread transformer used a bitwise AND (Kind & KindSyntaxList != 0) to check the result of FlattenDestructuringBinding. Since KindSyntaxList (344) is not a power of 2, this incorrectly matched VariableDeclaration nodes, causing a type assertion panic on AsSyntaxList().

// panics with: interface conversion: ast.nodeData is *ast.VariableDeclaration, not *ast.SyntaxList
try {} catch ({ ...rest }) {}
  • Fix: Kind & KindSyntaxList != 0Kind == KindSyntaxList
  • Add regression test catchClauseRestProperties.ts

…k instead of bitmask for KindSyntaxList

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/80173b5b-79f5-4cae-90d2-f9f8d9bb5d1d

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsgo panics for rest properties in catch binding Fix panic for rest properties in catch binding when targeting ES2017 May 16, 2026
Copilot AI requested a review from jakebailey May 16, 2026 20:11
Copy link
Copy Markdown
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Oops, that's a typo

@jakebailey jakebailey marked this pull request as ready for review May 16, 2026 20:31
Copilot AI review requested due to automatic review settings May 16, 2026 20:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a panic in the object rest/spread transformer when flattening destructuring bindings in catch clauses by correcting an invalid bitwise kind check (which could misclassify a VariableDeclaration as a SyntaxList).

Changes:

  • Fix visitCatchClause to check visitedBindings.Kind == ast.KindSyntaxList instead of using Kind & KindSyntaxList != 0.
  • Add a regression compiler test covering catch ({ ...rest }) {} with @target: es2017.
  • Add new reference baselines for JS emit, types, symbols, and diagnostics for the new test.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/catchClauseRestProperties.ts Adds a regression test that previously triggered a panic in the transformer.
testdata/baselines/reference/compiler/catchClauseRestProperties.types Reference types baseline for the new test.
testdata/baselines/reference/compiler/catchClauseRestProperties.symbols Reference symbols baseline for the new test.
testdata/baselines/reference/compiler/catchClauseRestProperties.js Reference JS emit baseline verifying object-rest downleveling in catch binding.
testdata/baselines/reference/compiler/catchClauseRestProperties.errors.txt Reference diagnostics baseline ensuring compilation reports the expected error without panicking.
internal/transformers/estransforms/objectrestspread.go Fixes the kind check to avoid calling AsSyntaxList() on non-SyntaxList nodes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsgo panics for rest properties in catch binding when targeting ES2017

3 participants