Skip to content

Port TS#63043: Implement walkBindingPattern for declaration emit of destructured parameter properties#2751

Merged
DanielRosenwasser merged 3 commits intomainfrom
copilot/fix-transform-crash-destructured-property
Feb 18, 2026
Merged

Port TS#63043: Implement walkBindingPattern for declaration emit of destructured parameter properties#2751
DanielRosenwasser merged 3 commits intomainfrom
copilot/fix-transform-crash-destructured-property

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

  • Fetch and analyze TypeScript PR #63043 ("Fix transform crash with destructured parameter property")
  • Verify runtime transform crash fix already ported (IsIdentifier checks in runtimesyntax.go)
  • Implement walkBindingPattern in declarations/transform.go for declaration emit of destructured parameter properties
  • Build passes
  • All tests pass (full test suite)
  • Both .js.diff files eliminated (baselines now match TypeScript reference)
  • Port TS#63154: Add continue after recursing into nested binding patterns to prevent crash with e.g. constructor(public [[x]]: any[])
  • Code review completed
  • Security scan completed (no issues)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Implement walkBindingPattern in declaration emit to properly emit
property declarations for destructured parameter properties. While
parameter properties with binding patterns are an error (TS1187),
the declaration emitter should still emit them correctly.

The runtime transform crash fix was already ported (IsIdentifier
checks in runtimesyntax.go). This change ports the remaining
declaration emit behavior to match TypeScript.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix transform crash with destructured parameter property Port TS#63043: Implement walkBindingPattern for declaration emit of destructured parameter properties Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 00:50
@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 00:59
Copilot AI review requested due to automatic review settings February 11, 2026 00:59
Copy link
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

Ports TypeScript PR microsoft/TypeScript#63043 into the Go declaration transformer so .d.ts emit includes class property declarations for destructured parameter properties, aligning tsgo’s output with upstream TypeScript baselines.

Changes:

  • Implemented walkBindingPattern in the declarations transformer and wired it into transformClassDeclaration for parameter properties with binding patterns.
  • Updated reference baselines to include the emitted property declarations and removed now-unnecessary .js.diff divergence files.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/transformers/declarations/transform.go Adds walkBindingPattern and uses it to emit PropertyDeclarations for destructured parameter properties during .d.ts emit.
testdata/baselines/reference/submodule/compiler/declarationEmitDestructuringParameterProperties.js Baseline update showing emitted x/y/z properties in generated .d.ts.
testdata/baselines/reference/submodule/compiler/declarationEmitDestructuringParameterProperties2.js Baseline update showing emitted x/y/z properties in generated .d.ts.
testdata/baselines/reference/submodule/compiler/declarationEmitDestructuringParameterProperties.js.diff Removes accepted-diff file since output now matches reference behavior.
testdata/baselines/reference/submodule/compiler/declarationEmitDestructuringParameterProperties2.js.diff Removes accepted-diff file since output now matches reference behavior.

Comment on lines +1547 to +1560
for _, elem := range pattern.Elements.Nodes {
if ast.IsOmittedExpression(elem) {
continue
}
if ast.IsBindingPattern(elem.Name()) {
elems = append(elems, tx.walkBindingPattern(elem.Name().AsBindingPattern(), param)...)
}
elems = append(elems, tx.Factory().NewPropertyDeclaration(
tx.ensureModifiers(param),
elem.Name(),
nil, /*questionOrExclamationToken*/
tx.ensureType(elem, false),
nil, /*initializer*/
))
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

walkBindingPattern unconditionally calls ast.IsBindingPattern(elem.Name()) and then emits a PropertyDeclaration with elem.Name().

  • In array binding patterns, the parser represents elisions (leading ,) as BindingElement nodes with name == nil (see BindingElement.name comment). In that case elem.Name() is nil and ast.IsBindingPattern(nil) will panic.
  • For nested destructuring (e.g. { a: { b } }), elem.Name() can be a BindingPattern. Emitting a PropertyDeclaration with a binding pattern name will later panic in the printer (emitPropertyName only handles identifiers/literals/computed/private identifiers).

Consider: (1) skip elements with elem.Name() == nil, and (2) when elem.Name() is a binding pattern, recurse and continue (only emit a property when the binding name is an identifier/property-name node).

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

I guess Copilot caught the same thing I called out but I didn't see the comment.

@jakebailey
Copy link
Member

It's sort of debatable whether or not this is a good behavior or not. This is a type error we somehow still produce a decent declaration file for.

Comment on lines +1551 to +1556
if ast.IsBindingPattern(elem.Name()) {
elems = append(elems, tx.walkBindingPattern(elem.Name().AsBindingPattern(), param)...)
}
elems = append(elems, tx.Factory().NewPropertyDeclaration(
tx.ensureModifiers(param),
elem.Name(),
Copy link
Member

Choose a reason for hiding this comment

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

There's a bug in the original code and the port - I assume the IsBindingPattern branch is supposed to continue. I'm pretty sure that this code will crash in the new compiler:

export class C {
  constructor(public [[x]]: any[]) {}
}

I've opened up microsoft/TypeScript#63153

Copy link
Member

Choose a reason for hiding this comment

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

PR is at microsoft/TypeScript#63154

Pretty sure no test is required for this (we'll get one after we update the submodule), but basically we need a continue statement in the IsBindingPattern branch.

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Read microsoft/TypeScript#63154 and port it to this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the continue statement in 598ba830. The walkBindingPattern now recurses into nested binding patterns and skips emitting a PropertyDeclaration for the pattern itself, matching the fix in TS#63154.

When walkBindingPattern encounters a nested binding pattern, it should
recurse and continue to the next element, not fall through to also emit
a PropertyDeclaration with the binding pattern as a name (which would
crash in the printer).

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Feb 18, 2026
Merged via the queue into main with commit f4cb73b Feb 18, 2026
20 checks passed
@DanielRosenwasser DanielRosenwasser deleted the copilot/fix-transform-crash-destructured-property branch February 18, 2026 01:16
Copilot AI added a commit that referenced this pull request Feb 25, 2026
…estructured parameter properties (#2751)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
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.

4 participants