@@ -15,7 +15,11 @@ export const transformerFactory = (
1515 return ( context ) => ( rootNode ) => {
1616 globalContext = context ;
1717 const visitor = ( node : ts . Node ) : ts . Node => {
18- //1. find `const ModuleName = new Container();`
18+ // Find container initialization
19+ // 1. const container = new Container();
20+ // 2. const container = (new Container()).register();
21+
22+ // case 1
1923 if (
2024 ts . isVariableStatement ( node ) &&
2125 node . declarationList . declarations . length === 1
@@ -58,6 +62,45 @@ export const transformerFactory = (
5862 }
5963 }
6064 }
65+
66+ // case 2
67+ if (
68+ ts . isCallExpression ( node ) &&
69+ ts . isPropertyAccessExpression ( node . expression )
70+ ) {
71+ // dig into expression to find the identifier
72+ let expressionChildren = node . expression . getChildren ( ) ;
73+ while ( ! ts . isIdentifier ( expressionChildren [ 0 ] ) ) {
74+ if ( ts . isParenthesizedExpression ( expressionChildren [ 0 ] ) ) {
75+ // (new Container()).register()
76+ if ( ts . isNewExpression ( expressionChildren [ 0 ] . expression ) ) {
77+ const containerNode =
78+ expressionChildren [ 0 ] . expression . getChildren ( ) [ 1 ] ;
79+ handleContainer (
80+ rootNode ,
81+ containerNode ,
82+ globalTypeChecker . getSymbolAtLocation ( containerNode ) ! ,
83+ program ,
84+ transformList
85+ ) ;
86+ }
87+ }
88+ if ( ts . isNewExpression ( expressionChildren [ 0 ] ) ) {
89+ const containerNode = expressionChildren [ 0 ] . getChildren ( ) [ 1 ] ;
90+ handleContainer (
91+ rootNode ,
92+ containerNode ,
93+ globalTypeChecker . getSymbolAtLocation ( containerNode ) ! ,
94+ program ,
95+ transformList
96+ ) ;
97+ }
98+ expressionChildren = expressionChildren [ 0 ] . getChildren ( ) ;
99+ if ( expressionChildren . length <= 2 ) {
100+ break ;
101+ }
102+ }
103+ }
61104 return ts . visitEachChild ( node , visitor , context ) ;
62105 } ;
63106
0 commit comments