@@ -6,6 +6,7 @@ import { analyzeLibRef, isReactRef, LibRef } from "./lib.js";
66export type ComponentHead = {
77 superClassRef : LibRef ;
88 props : NodePath < TSType > | undefined ;
9+ propsEach : Map < string , NodePath < TSPropertySignature | TSMethodSignature > > ;
910 states : Map < string , NodePath < TSPropertySignature | TSMethodSignature > > ;
1011} ;
1112
@@ -35,36 +36,46 @@ export function analyzeHead(path: NodePath<ClassDeclaration>): ComponentHead | u
3536 }
3637 if ( superClassRef . name === "Component" || superClassRef . name === "PureComponent" ) {
3738 let props : NodePath < TSType > | undefined ;
38- const states = new Map < string , NodePath < TSPropertySignature | TSMethodSignature > > ( ) ;
39+ let propsEach : Map < string , NodePath < TSPropertySignature | TSMethodSignature > > | undefined = undefined ;
40+ let states : Map < string , NodePath < TSPropertySignature | TSMethodSignature > > | undefined = undefined ;
3941 const superTypeParameters = path . get ( "superTypeParameters" ) ;
4042 if ( superTypeParameters . isTSTypeParameterInstantiation ( ) ) {
4143 const params = superTypeParameters . get ( "params" ) ;
4244 if ( params . length > 0 ) {
4345 props = params [ 0 ] ;
46+ propsEach = decompose ( params [ 0 ] ! ) ;
4447 }
4548 if ( params . length > 1 ) {
4649 const stateParamPath = params [ 1 ] ! ;
47- const statePath = resolveAlias ( stateParamPath ) ;
48- const members =
49- statePath . isTSTypeLiteral ( )
50- ? statePath . get ( "members" )
51- : statePath . isTSInterfaceBody ( )
52- ? statePath . get ( "body" )
53- : undefined ;
54- if ( members ) {
55- for ( const member of members ) {
56- if ( member . isTSPropertySignature ( ) || member . isTSMethodSignature ( ) ) {
57- const name = memberName ( member . node ) ;
58- if ( name != null ) {
59- states . set ( name , member ) ;
60- }
61- }
62- }
50+ states = decompose ( stateParamPath ) ;
51+ }
52+ }
53+ propsEach ??= new Map ( ) ;
54+ states ??= new Map ( ) ;
55+ return { superClassRef, props, propsEach, states } ;
56+ }
57+ }
58+
59+ function decompose ( path : NodePath < TSType > ) : Map < string , NodePath < TSPropertySignature | TSMethodSignature > > {
60+ const aliasPath = resolveAlias ( path ) ;
61+ const members =
62+ aliasPath . isTSTypeLiteral ( )
63+ ? aliasPath . get ( "members" )
64+ : aliasPath . isTSInterfaceBody ( )
65+ ? aliasPath . get ( "body" )
66+ : undefined ;
67+ const decomposed = new Map < string , NodePath < TSPropertySignature | TSMethodSignature > > ( ) ;
68+ if ( members ) {
69+ for ( const member of members ) {
70+ if ( member . isTSPropertySignature ( ) || member . isTSMethodSignature ( ) ) {
71+ const name = memberName ( member . node ) ;
72+ if ( name != null ) {
73+ decomposed . set ( name , member ) ;
6374 }
6475 }
6576 }
66- return { superClassRef, props, states } ;
6777 }
78+ return decomposed ;
6879}
6980
7081function resolveAlias ( path : NodePath < TSType > ) : NodePath < TSType | TSInterfaceBody > {
0 commit comments