From 54ee6d5714fb7dd307466cc02c9647ddac0aa398 Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Wed, 24 Jul 2024 13:47:49 +0800 Subject: [PATCH] fix: add typeArguments to CallExpression --- src/def/typescript.ts | 3 +++ src/gen/builders.ts | 2 ++ src/gen/kinds.ts | 2 +- src/gen/namedTypes.ts | 14 +++++++------- src/gen/visitor.ts | 8 ++++---- src/test/typescript.ts | 14 ++++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/def/typescript.ts b/src/def/typescript.ts index 3375ac3d..fdf12745 100644 --- a/src/def/typescript.ts +++ b/src/def/typescript.ts @@ -522,6 +522,9 @@ export default function (fork: Fork) { def("TSDeclareMethod"), TSTypeMember )]); + + def("CallExpression") + .bases("TSHasOptionalTypeParameterInstantiation"); }; maybeSetModuleExports(() => module); diff --git a/src/gen/builders.ts b/src/gen/builders.ts index 2db1b429..9e7a7fee 100644 --- a/src/gen/builders.ts +++ b/src/gen/builders.ts @@ -598,6 +598,7 @@ export interface CallExpressionBuilder { loc?: K.SourceLocationKind | null; optional?: boolean; typeArguments?: null | K.TypeParameterInstantiationKind; + typeParameters?: K.TSTypeParameterInstantiationKind | null; } ): namedTypes.CallExpression; } @@ -1206,6 +1207,7 @@ export interface OptionalCallExpressionBuilder { loc?: K.SourceLocationKind | null; optional?: boolean; typeArguments?: null | K.TypeParameterInstantiationKind; + typeParameters?: K.TSTypeParameterInstantiationKind | null; } ): namedTypes.OptionalCallExpression; } diff --git a/src/gen/kinds.ts b/src/gen/kinds.ts index da2d4a58..d2faefbd 100644 --- a/src/gen/kinds.ts +++ b/src/gen/kinds.ts @@ -51,6 +51,7 @@ export type UpdateExpressionKind = namedTypes.UpdateExpression; export type LogicalExpressionKind = namedTypes.LogicalExpression; export type ConditionalExpressionKind = namedTypes.ConditionalExpression; export type NewExpressionKind = namedTypes.NewExpression; +export type TSHasOptionalTypeParameterInstantiationKind = namedTypes.CallExpression | namedTypes.OptionalCallExpression | namedTypes.TSExpressionWithTypeArguments | namedTypes.TSTypeReference | namedTypes.TSImportType | namedTypes.TSInstantiationExpression; export type CallExpressionKind = namedTypes.CallExpression | namedTypes.OptionalCallExpression; export type RestElementKind = namedTypes.RestElement; export type TypeAnnotationKind = namedTypes.TypeAnnotation; @@ -126,7 +127,6 @@ export type TypeParameterInstantiationKind = namedTypes.TypeParameterInstantiati export type TSTypeParameterInstantiationKind = namedTypes.TSTypeParameterInstantiation; export type ClassImplementsKind = namedTypes.ClassImplements; export type TSTypeKind = namedTypes.TSExpressionWithTypeArguments | namedTypes.TSTypeReference | namedTypes.TSAnyKeyword | namedTypes.TSBigIntKeyword | namedTypes.TSBooleanKeyword | namedTypes.TSNeverKeyword | namedTypes.TSNullKeyword | namedTypes.TSNumberKeyword | namedTypes.TSObjectKeyword | namedTypes.TSStringKeyword | namedTypes.TSSymbolKeyword | namedTypes.TSUndefinedKeyword | namedTypes.TSUnknownKeyword | namedTypes.TSVoidKeyword | namedTypes.TSIntrinsicKeyword | namedTypes.TSThisType | namedTypes.TSArrayType | namedTypes.TSLiteralType | namedTypes.TSUnionType | namedTypes.TSIntersectionType | namedTypes.TSConditionalType | namedTypes.TSInferType | namedTypes.TSParenthesizedType | namedTypes.TSFunctionType | namedTypes.TSConstructorType | namedTypes.TSMappedType | namedTypes.TSTupleType | namedTypes.TSNamedTupleMember | namedTypes.TSRestType | namedTypes.TSOptionalType | namedTypes.TSIndexedAccessType | namedTypes.TSTypeOperator | namedTypes.TSTypePredicate | namedTypes.TSTypeQuery | namedTypes.TSImportType | namedTypes.TSTypeLiteral; -export type TSHasOptionalTypeParameterInstantiationKind = namedTypes.TSExpressionWithTypeArguments | namedTypes.TSTypeReference | namedTypes.TSImportType | namedTypes.TSInstantiationExpression; export type TSExpressionWithTypeArgumentsKind = namedTypes.TSExpressionWithTypeArguments; export type FlowKind = namedTypes.AnyTypeAnnotation | namedTypes.EmptyTypeAnnotation | namedTypes.MixedTypeAnnotation | namedTypes.VoidTypeAnnotation | namedTypes.SymbolTypeAnnotation | namedTypes.NumberTypeAnnotation | namedTypes.BigIntTypeAnnotation | namedTypes.NumberLiteralTypeAnnotation | namedTypes.NumericLiteralTypeAnnotation | namedTypes.BigIntLiteralTypeAnnotation | namedTypes.StringTypeAnnotation | namedTypes.StringLiteralTypeAnnotation | namedTypes.BooleanTypeAnnotation | namedTypes.BooleanLiteralTypeAnnotation | namedTypes.NullableTypeAnnotation | namedTypes.NullLiteralTypeAnnotation | namedTypes.NullTypeAnnotation | namedTypes.ThisTypeAnnotation | namedTypes.ExistsTypeAnnotation | namedTypes.ExistentialTypeParam | namedTypes.FunctionTypeAnnotation | namedTypes.ArrayTypeAnnotation | namedTypes.ObjectTypeAnnotation | namedTypes.GenericTypeAnnotation | namedTypes.MemberTypeAnnotation | namedTypes.IndexedAccessType | namedTypes.OptionalIndexedAccessType | namedTypes.UnionTypeAnnotation | namedTypes.IntersectionTypeAnnotation | namedTypes.TypeofTypeAnnotation | namedTypes.TypeParameter | namedTypes.InterfaceTypeAnnotation | namedTypes.TupleTypeAnnotation | namedTypes.InferredPredicate | namedTypes.DeclaredPredicate; export type FlowTypeKind = namedTypes.AnyTypeAnnotation | namedTypes.EmptyTypeAnnotation | namedTypes.MixedTypeAnnotation | namedTypes.VoidTypeAnnotation | namedTypes.SymbolTypeAnnotation | namedTypes.NumberTypeAnnotation | namedTypes.BigIntTypeAnnotation | namedTypes.NumberLiteralTypeAnnotation | namedTypes.NumericLiteralTypeAnnotation | namedTypes.BigIntLiteralTypeAnnotation | namedTypes.StringTypeAnnotation | namedTypes.StringLiteralTypeAnnotation | namedTypes.BooleanTypeAnnotation | namedTypes.BooleanLiteralTypeAnnotation | namedTypes.NullableTypeAnnotation | namedTypes.NullLiteralTypeAnnotation | namedTypes.NullTypeAnnotation | namedTypes.ThisTypeAnnotation | namedTypes.ExistsTypeAnnotation | namedTypes.ExistentialTypeParam | namedTypes.FunctionTypeAnnotation | namedTypes.ArrayTypeAnnotation | namedTypes.ObjectTypeAnnotation | namedTypes.GenericTypeAnnotation | namedTypes.MemberTypeAnnotation | namedTypes.IndexedAccessType | namedTypes.OptionalIndexedAccessType | namedTypes.UnionTypeAnnotation | namedTypes.IntersectionTypeAnnotation | namedTypes.TypeofTypeAnnotation | namedTypes.TypeParameter | namedTypes.InterfaceTypeAnnotation | namedTypes.TupleTypeAnnotation; diff --git a/src/gen/namedTypes.ts b/src/gen/namedTypes.ts index b4edc8aa..cb29dfb2 100644 --- a/src/gen/namedTypes.ts +++ b/src/gen/namedTypes.ts @@ -300,7 +300,11 @@ export namespace namedTypes { typeArguments?: null | K.TypeParameterInstantiationKind; } - export interface CallExpression extends Omit, Omit { + export interface TSHasOptionalTypeParameterInstantiation { + typeParameters?: K.TSTypeParameterInstantiationKind | null; + } + + export interface CallExpression extends Omit, Omit, TSHasOptionalTypeParameterInstantiation { type: "CallExpression"; callee: K.ExpressionKind; arguments: (K.ExpressionKind | K.SpreadElementKind)[]; @@ -751,10 +755,6 @@ export namespace namedTypes { export interface TSType extends Node {} - export interface TSHasOptionalTypeParameterInstantiation { - typeParameters?: K.TSTypeParameterInstantiationKind | null; - } - export interface TSExpressionWithTypeArguments extends Omit, TSHasOptionalTypeParameterInstantiation { type: "TSExpressionWithTypeArguments"; expression: K.IdentifierKind | K.TSQualifiedNameKind; @@ -1778,6 +1778,7 @@ export namespace namedTypes { export let LogicalExpression: Type; export let ConditionalExpression: Type; export let NewExpression: Type; + export let TSHasOptionalTypeParameterInstantiation: Type; export let CallExpression: Type; export let RestElement: Type; export let TypeAnnotation: Type; @@ -1853,7 +1854,6 @@ export namespace namedTypes { export let TSTypeParameterInstantiation: Type; export let ClassImplements: Type; export let TSType: Type; - export let TSHasOptionalTypeParameterInstantiation: Type; export let TSExpressionWithTypeArguments: Type; export let Flow: Type; export let FlowType: Type; @@ -2074,6 +2074,7 @@ export interface NamedTypes { LogicalExpression: Type; ConditionalExpression: Type; NewExpression: Type; + TSHasOptionalTypeParameterInstantiation: Type; CallExpression: Type; RestElement: Type; TypeAnnotation: Type; @@ -2149,7 +2150,6 @@ export interface NamedTypes { TSTypeParameterInstantiation: Type; ClassImplements: Type; TSType: Type; - TSHasOptionalTypeParameterInstantiation: Type; TSExpressionWithTypeArguments: Type; Flow: Type; FlowType: Type; diff --git a/src/gen/visitor.ts b/src/gen/visitor.ts index 9c92f7c7..0e090a33 100644 --- a/src/gen/visitor.ts +++ b/src/gen/visitor.ts @@ -55,6 +55,10 @@ export interface Visitor { visitLogicalExpression?(this: Context & M, path: NodePath): any; visitConditionalExpression?(this: Context & M, path: NodePath): any; visitNewExpression?(this: Context & M, path: NodePath): any; + visitTSHasOptionalTypeParameterInstantiation?( + this: Context & M, + path: NodePath + ): any; visitCallExpression?(this: Context & M, path: NodePath): any; visitRestElement?(this: Context & M, path: NodePath): any; visitTypeAnnotation?(this: Context & M, path: NodePath): any; @@ -130,10 +134,6 @@ export interface Visitor { visitTSTypeParameterInstantiation?(this: Context & M, path: NodePath): any; visitClassImplements?(this: Context & M, path: NodePath): any; visitTSType?(this: Context & M, path: NodePath): any; - visitTSHasOptionalTypeParameterInstantiation?( - this: Context & M, - path: NodePath - ): any; visitTSExpressionWithTypeArguments?( this: Context & M, path: NodePath diff --git a/src/test/typescript.ts b/src/test/typescript.ts index c201f8fa..5fff0fbb 100644 --- a/src/test/typescript.ts +++ b/src/test/typescript.ts @@ -413,5 +413,19 @@ glob("**/*.ts", { } }); }); + + it("visits type parameters of call expressions", function () { + const program = babelParse([ + "fn(808)", + ].join("\n"), { + plugins: ["typescript"] + }); + + assertVisited(program, { + visitTSTypeParameterInstantiation(path) { + this.traverse(path); + } + }); + }); }); });