-
Notifications
You must be signed in to change notification settings - Fork 907
Port TS#63043: Implement walkBindingPattern for declaration emit of destructured parameter properties #2751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1430,7 +1430,7 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl | |
| parameterProperties = append(parameterProperties, updated) | ||
| } else { | ||
| // Pattern - this is currently an error, but we emit declarations for it somewhat correctly | ||
| // !!! is this worth reimplementing? We never made it not-an-error | ||
| parameterProperties = append(parameterProperties, tx.walkBindingPattern(param.Name().AsBindingPattern(), param)...) | ||
| } | ||
| } | ||
| tx.state.getSymbolAccessibilityDiagnostic = oldDiag | ||
|
|
@@ -1542,6 +1542,27 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl | |
| ) | ||
| } | ||
|
|
||
| func (tx *DeclarationTransformer) walkBindingPattern(pattern *ast.BindingPattern, param *ast.Node) []*ast.Node { | ||
| var elems []*ast.Node | ||
| 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)...) | ||
| continue | ||
| } | ||
| elems = append(elems, tx.Factory().NewPropertyDeclaration( | ||
| tx.ensureModifiers(param), | ||
| elem.Name(), | ||
| nil, /*questionOrExclamationToken*/ | ||
| tx.ensureType(elem, false), | ||
| nil, /*initializer*/ | ||
| )) | ||
|
Comment on lines
+1547
to
+1561
|
||
| } | ||
| return elems | ||
| } | ||
|
|
||
| func (tx *DeclarationTransformer) transformVariableStatement(input *ast.VariableStatement) *ast.Node { | ||
| visible := false | ||
| for _, decl := range input.DeclarationList.AsVariableDeclarationList().Declarations.Nodes { | ||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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
IsBindingPatternbranch is supposed to continue. I'm pretty sure that this code will crash in the new compiler:I've opened up microsoft/TypeScript#63153
There was a problem hiding this comment.
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
continuestatement in theIsBindingPatternbranch.There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the
continuestatement in598ba830. ThewalkBindingPatternnow recurses into nested binding patterns and skips emitting aPropertyDeclarationfor the pattern itself, matching the fix in TS#63154.