Skip to content

Commit

Permalink
fix: definition of TS function type params (#15867)
Browse files Browse the repository at this point in the history
Function type params can also be array or object patterns. They can NOT be assignment patterns.
  • Loading branch information
danez committed Aug 14, 2023
1 parent 444cea4 commit 9c5109b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
20 changes: 15 additions & 5 deletions packages/babel-types/src/ast-types/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1718,14 +1718,14 @@ export interface TSQualifiedName extends BaseNode {
export interface TSCallSignatureDeclaration extends BaseNode {
type: "TSCallSignatureDeclaration";
typeParameters?: TSTypeParameterDeclaration | null;
parameters: Array<Identifier | RestElement>;
parameters: Array<ArrayPattern | Identifier | ObjectPattern | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
}

export interface TSConstructSignatureDeclaration extends BaseNode {
type: "TSConstructSignatureDeclaration";
typeParameters?: TSTypeParameterDeclaration | null;
parameters: Array<Identifier | RestElement>;
parameters: Array<ArrayPattern | Identifier | ObjectPattern | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
}

Expand All @@ -1744,7 +1744,7 @@ export interface TSMethodSignature extends BaseNode {
type: "TSMethodSignature";
key: Expression;
typeParameters?: TSTypeParameterDeclaration | null;
parameters: Array<Identifier | RestElement>;
parameters: Array<ArrayPattern | Identifier | ObjectPattern | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
computed?: boolean;
kind: "method" | "get" | "set";
Expand Down Expand Up @@ -1818,14 +1818,14 @@ export interface TSThisType extends BaseNode {
export interface TSFunctionType extends BaseNode {
type: "TSFunctionType";
typeParameters?: TSTypeParameterDeclaration | null;
parameters: Array<Identifier | RestElement>;
parameters: Array<ArrayPattern | Identifier | ObjectPattern | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
}

export interface TSConstructorType extends BaseNode {
type: "TSConstructorType";
typeParameters?: TSTypeParameterDeclaration | null;
parameters: Array<Identifier | RestElement>;
parameters: Array<ArrayPattern | Identifier | ObjectPattern | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
abstract?: boolean | null;
}
Expand Down Expand Up @@ -2915,8 +2915,13 @@ export interface ParentMaps {
| ObjectMethod
| ObjectProperty
| RestElement
| TSCallSignatureDeclaration
| TSConstructSignatureDeclaration
| TSConstructorType
| TSDeclareFunction
| TSDeclareMethod
| TSFunctionType
| TSMethodSignature
| VariableDeclarator;
ArrayTypeAnnotation:
| ArrayTypeAnnotation
Expand Down Expand Up @@ -5626,8 +5631,13 @@ export interface ParentMaps {
| ObjectMethod
| ObjectProperty
| RestElement
| TSCallSignatureDeclaration
| TSConstructSignatureDeclaration
| TSConstructorType
| TSDeclareFunction
| TSDeclareMethod
| TSFunctionType
| TSMethodSignature
| VariableDeclarator;
ObjectProperty: ObjectExpression | ObjectPattern | RecordExpression;
ObjectTypeAnnotation:
Expand Down
20 changes: 15 additions & 5 deletions packages/babel-types/src/builders/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,9 @@ export function tsQualifiedName(
export { tsQualifiedName as tSQualifiedName };
export function tsCallSignatureDeclaration(
typeParameters: t.TSTypeParameterDeclaration | null | undefined = null,
parameters: Array<t.Identifier | t.RestElement>,
parameters: Array<
t.ArrayPattern | t.Identifier | t.ObjectPattern | t.RestElement
>,
typeAnnotation: t.TSTypeAnnotation | null = null,
): t.TSCallSignatureDeclaration {
return validateNode<t.TSCallSignatureDeclaration>({
Expand All @@ -1940,7 +1942,9 @@ export function tsCallSignatureDeclaration(
export { tsCallSignatureDeclaration as tSCallSignatureDeclaration };
export function tsConstructSignatureDeclaration(
typeParameters: t.TSTypeParameterDeclaration | null | undefined = null,
parameters: Array<t.Identifier | t.RestElement>,
parameters: Array<
t.ArrayPattern | t.Identifier | t.ObjectPattern | t.RestElement
>,
typeAnnotation: t.TSTypeAnnotation | null = null,
): t.TSConstructSignatureDeclaration {
return validateNode<t.TSConstructSignatureDeclaration>({
Expand Down Expand Up @@ -1968,7 +1972,9 @@ export { tsPropertySignature as tSPropertySignature };
export function tsMethodSignature(
key: t.Expression,
typeParameters: t.TSTypeParameterDeclaration | null | undefined = null,
parameters: Array<t.Identifier | t.RestElement>,
parameters: Array<
t.ArrayPattern | t.Identifier | t.ObjectPattern | t.RestElement
>,
typeAnnotation: t.TSTypeAnnotation | null = null,
): t.TSMethodSignature {
return validateNode<t.TSMethodSignature>({
Expand Down Expand Up @@ -2078,7 +2084,9 @@ export function tsThisType(): t.TSThisType {
export { tsThisType as tSThisType };
export function tsFunctionType(
typeParameters: t.TSTypeParameterDeclaration | null | undefined = null,
parameters: Array<t.Identifier | t.RestElement>,
parameters: Array<
t.ArrayPattern | t.Identifier | t.ObjectPattern | t.RestElement
>,
typeAnnotation: t.TSTypeAnnotation | null = null,
): t.TSFunctionType {
return validateNode<t.TSFunctionType>({
Expand All @@ -2091,7 +2099,9 @@ export function tsFunctionType(
export { tsFunctionType as tSFunctionType };
export function tsConstructorType(
typeParameters: t.TSTypeParameterDeclaration | null | undefined = null,
parameters: Array<t.Identifier | t.RestElement>,
parameters: Array<
t.ArrayPattern | t.Identifier | t.ObjectPattern | t.RestElement
>,
typeAnnotation: t.TSTypeAnnotation | null = null,
): t.TSConstructorType {
return validateNode<t.TSConstructorType>({
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/definitions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defineType("TSQualifiedName", {
const signatureDeclarationCommon = () => ({
typeParameters: validateOptionalType("TSTypeParameterDeclaration"),
[process.env.BABEL_8_BREAKING ? "params" : "parameters"]: validateArrayOfType(
["Identifier", "RestElement"],
["ArrayPattern", "Identifier", "ObjectPattern", "RestElement"],
),
[process.env.BABEL_8_BREAKING ? "returnType" : "typeAnnotation"]:
validateOptionalType("TSTypeAnnotation"),
Expand Down

0 comments on commit 9c5109b

Please sign in to comment.