Fix panic for rest properties in catch binding when targeting ES2017#3927
Open
Copilot wants to merge 2 commits into
Open
Fix panic for rest properties in catch binding when targeting ES2017#3927Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…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
Contributor
There was a problem hiding this comment.
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
visitCatchClauseto checkvisitedBindings.Kind == ast.KindSyntaxListinstead of usingKind & 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. |
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.
visitCatchClausein the object rest/spread transformer used a bitwise AND (Kind & KindSyntaxList != 0) to check the result ofFlattenDestructuringBinding. SinceKindSyntaxList(344) is not a power of 2, this incorrectly matchedVariableDeclarationnodes, causing a type assertion panic onAsSyntaxList().Kind & KindSyntaxList != 0→Kind == KindSyntaxListcatchClauseRestProperties.ts