Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*/
))
}
return elems
}

func (tx *DeclarationTransformer) transformVariableStatement(input *ast.VariableStatement) *ast.Node {
visible := false
for _, decl := range input.DeclarationList.AsVariableDeclarationList().Declarations.Nodes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class C3 {

//// [declarationEmitDestructuringParameterProperties.d.ts]
declare class C1 {
x: string;
y: string;
z: string;
constructor([x, y, z]: string[]);
}
type TupleType1 = [string, number, boolean];
declare class C2 {
x: string;
y: number;
z: boolean;
constructor([x, y, z]: TupleType1);
}
type ObjType1 = {
Expand All @@ -48,5 +54,8 @@ type ObjType1 = {
z: boolean;
};
declare class C3 {
x: number;
y: string;
z: boolean;
constructor({ x, y, z }: ObjType1);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class C3 {

//// [declarationEmitDestructuringParameterProperties2.d.ts]
declare class C1 {
x: string;
y: string;
z: string;
constructor([x, y, z]: string[]);
}
type TupleType1 = [string, number, boolean];
declare class C2 {
x: string;
y: number;
z: boolean;
constructor([x, y, z]: TupleType1);
}
type ObjType1 = {
Expand All @@ -48,5 +54,8 @@ type ObjType1 = {
z: boolean;
};
declare class C3 {
x: number;
y: string;
z: boolean;
constructor({ x, y, z }: ObjType1);
}

This file was deleted.