@@ -61,6 +61,7 @@ process.argv.slice(2).forEach((file) => {
6161
6262 // Scan for exports.
6363 const exported = { constructors : [ ] , identifiers : [ ] } ;
64+ const indirect = { } ;
6465 program . forEach ( ( statement ) => {
6566 if ( statement . type === 'ExpressionStatement' ) {
6667 const expr = statement . expression ;
@@ -69,35 +70,52 @@ process.argv.slice(2).forEach((file) => {
6970 let lhs = expr . left ;
7071 if ( expr . left . object . type === 'MemberExpression' ) lhs = lhs . object ;
7172 if ( lhs . type !== 'MemberExpression' ) return ;
72- if ( lhs . object . name !== 'module' ) return ;
73- if ( lhs . property . name !== 'exports' ) return ;
74-
75- let rhs = expr . right ;
76- while ( rhs . type === 'AssignmentExpression' ) rhs = rhs . right ;
77-
78- if ( rhs . type === 'NewExpression' ) {
79- exported . constructors . push ( rhs . callee . name ) ;
80- } else if ( rhs . type === 'ObjectExpression' ) {
81- rhs . properties . forEach ( ( property ) => {
82- if ( property . value . type === 'Identifier' ) {
83- exported . identifiers . push ( property . value . name ) ;
84- if ( / ^ [ A - Z ] / . test ( property . value . name [ 0 ] ) ) {
85- exported . constructors . push ( property . value . name ) ;
86- }
73+ if ( lhs . object . name === 'exports' ) {
74+ const name = lhs . property . name ;
75+ if ( expr . right . type === 'FunctionExpression' ) {
76+ definition [ `${ basename } .${ name } ` ] =
77+ `${ link } #L${ statement . loc . start . line } ` ;
78+ } else if ( expr . right . type === 'Identifier' ) {
79+ if ( expr . right . name === name ) {
80+ indirect [ name ] = `${ basename } .${ name } ` ;
8781 }
88- } ) ;
89- } else if ( rhs . type === 'Identifier' ) {
90- exported . identifiers . push ( rhs . name ) ;
82+ } else {
83+ exported . identifiers . push ( name ) ;
84+ }
85+ } else if ( lhs . object . name === 'module' ) {
86+ if ( lhs . property . name !== 'exports' ) return ;
87+
88+ let rhs = expr . right ;
89+ while ( rhs . type === 'AssignmentExpression' ) rhs = rhs . right ;
90+
91+ if ( rhs . type === 'NewExpression' ) {
92+ exported . constructors . push ( rhs . callee . name ) ;
93+ } else if ( rhs . type === 'ObjectExpression' ) {
94+ rhs . properties . forEach ( ( property ) => {
95+ if ( property . value . type === 'Identifier' ) {
96+ exported . identifiers . push ( property . value . name ) ;
97+ if ( / ^ [ A - Z ] / . test ( property . value . name [ 0 ] ) ) {
98+ exported . constructors . push ( property . value . name ) ;
99+ }
100+ }
101+ } ) ;
102+ } else if ( rhs . type === 'Identifier' ) {
103+ exported . identifiers . push ( rhs . name ) ;
104+ }
91105 }
92106 } else if ( statement . type === 'VariableDeclaration' ) {
93107 for ( const decl of statement . declarations ) {
94108 let init = decl . init ;
95109 while ( init && init . type === 'AssignmentExpression' ) init = init . left ;
96110 if ( ! init || init . type !== 'MemberExpression' ) continue ;
97- if ( init . object . name !== 'module' ) continue ;
98- if ( init . property . name !== 'exports' ) continue ;
99- exported . constructors . push ( decl . id . name ) ;
100- definition [ decl . id . name ] = `${ link } #L${ statement . loc . start . line } ` ;
111+ if ( init . object . name === 'exports' ) {
112+ definition [ `${ basename } .${ init . property . name } ` ] =
113+ `${ link } #L${ statement . loc . start . line } ` ;
114+ } else if ( init . object . name === 'module' ) {
115+ if ( init . property . name !== 'exports' ) continue ;
116+ exported . constructors . push ( decl . id . name ) ;
117+ definition [ decl . id . name ] = `${ link } #L${ statement . loc . start . line } ` ;
118+ }
101119 }
102120 }
103121 } ) ;
@@ -107,10 +125,8 @@ process.argv.slice(2).forEach((file) => {
107125 // ClassName.foo = ...;
108126 // ClassName.prototype.foo = ...;
109127 // function Identifier(...) {...};
110- // class Foo {...}
128+ // class Foo {...};
111129 //
112- const indirect = { } ;
113-
114130 program . forEach ( ( statement ) => {
115131 if ( statement . type === 'ExpressionStatement' ) {
116132 const expr = statement . expression ;
0 commit comments