import * as t from "@babel/types" ; export const GenericTypeAnnotation = { exit ( path , state ) { const { id : typeName , typeParameters } = path . node ; if ( typeName . name in UnqualifiedReactTypeNameMap ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( UnqualifiedReactTypeNameMap [ typeName . name ] ) ) , typeParameters && typeParameters . params . length > 0 ? typeParameters : null ) ; } if ( typeName . name === "React$Node" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "ReactNode" ) ) ) ; } if ( typeName . name === "React$Element" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "ReactElement" ) ) , t . tsTypeParameterInstantiation ( [ t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "ComponentProps" ) ) , t . tsTypeParameterInstantiation ( [ typeParameters . params [ 0 ] ] ) ) , typeParameters . params [ 0 ] , ] ) ) ; } if ( typeName . name === "React$Component" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "Component" ) ) , typeParameters ) ; } if ( typeName . name === "React$ComponentType" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "ComponentType" ) ) , typeParameters ) ; } if ( typeName . name === "React$Context" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "Context" ) ) , typeParameters ) ; } if ( typeName . name === "React$Ref" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "Ref" ) ) , typeParameters ) ; } if ( typeName . name === "React$StatelessFunctionalComponent" ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "FC" ) ) , typeParameters ) ; } if ( t . isTSQualifiedName ( typeName ) ) { const { left , right } = typeName ; if ( t . isIdentifier ( left , { name : "React" } ) && t . isIdentifier ( right , { name : "ElementConfig" } ) ) { return t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "JSX" ) , t . identifier ( "LibraryManagedAttributes" ) ) , t . tsTypeParameterInstantiation ( [ typeParameters . params [ 0 ] , t . tsTypeReference ( t . tsQualifiedName ( t . identifier ( "React" ) , t . identifier ( "ComponentProps" ) ) , t . tsTypeParameterInstantiation ( [ typeParameters . params [ 0 ] ] ) ) , ] ) ) ; } } } } ; const UnqualifiedReactTypeNameMap = { SyntheticEvent : "SyntheticEvent" , SyntheticAnimationEvent : "AnimationEvent" , SyntheticClipboardEvent : "ClipboardEvent" , SyntheticCompositionEvent : "CompositionEvent" , SyntheticInputEvent : "SyntheticEvent" , SyntheticUIEvent : "UIEvent" , SyntheticFocusEvent : "FocusEvent" , SyntheticKeyboardEvent : "KeyboardEvent" , SyntheticMouseEvent : "MouseEvent" , SyntheticDragEvent : "DragEvent" , SyntheticWheelEvent : "WheelEvent" , SyntheticPointerEvent : "PointerEvent" , SyntheticTouchEvent : "TouchEvent" , SyntheticTransitionEvent : "TransitionEvent" , React$ElementType : "ElementType" , } ; export const QualifiedTypeIdentifier = { exit ( path , state ) { const { qualification , id } = path . node ; const left = qualification ; const right = id ; if ( left . name === "React" && right . name in QualifiedReactTypeNameMap ) { return t . tsQualifiedName ( left , t . identifier ( QualifiedReactTypeNameMap [ right . name ] ) ) ; } } } ; const QualifiedReactTypeNameMap = { Node : "ReactNode" , Text : "ReactText" , Child : "ReactChild" , Children : "ReactChildren" , Element : "ReactElement" , Fragment : "ReactFragment" , Portal : "ReactPortal" , NodeArray : "ReactNodeArray" , } ;