@@ -37,23 +37,8 @@ namespace ts {
3737
3838 function check ( node : Node ) {
3939 if ( isJsFile ) {
40- switch ( node . kind ) {
41- case SyntaxKind . FunctionExpression :
42- const decl = getDeclarationOfExpando ( node ) ;
43- if ( decl ) {
44- const symbol = decl . symbol ;
45- if ( symbol && ( symbol . exports && symbol . exports . size || symbol . members && symbol . members . size ) ) {
46- diags . push ( createDiagnosticForNode ( isVariableDeclaration ( node . parent ) ? node . parent . name : node , Diagnostics . This_constructor_function_may_be_converted_to_a_class_declaration ) ) ;
47- break ;
48- }
49- }
50- // falls through if no diagnostic was created
51- case SyntaxKind . FunctionDeclaration :
52- const symbol = node . symbol ;
53- if ( symbol . members && ( symbol . members . size > 0 ) ) {
54- diags . push ( createDiagnosticForNode ( isVariableDeclaration ( node . parent ) ? node . parent . name : node , Diagnostics . This_constructor_function_may_be_converted_to_a_class_declaration ) ) ;
55- }
56- break ;
40+ if ( canBeConvertedToClass ( node ) ) {
41+ diags . push ( createDiagnosticForNode ( isVariableDeclaration ( node . parent ) ? node . parent . name : node , Diagnostics . This_constructor_function_may_be_converted_to_a_class_declaration ) ) ;
5742 }
5843 }
5944 else {
@@ -193,4 +178,22 @@ namespace ts {
193178 function getKeyFromNode ( exp : FunctionLikeDeclaration ) {
194179 return `${ exp . pos . toString ( ) } :${ exp . end . toString ( ) } ` ;
195180 }
181+
182+ function canBeConvertedToClass ( node : Node ) : boolean {
183+ if ( node . kind === SyntaxKind . FunctionExpression ) {
184+ if ( isVariableDeclaration ( node . parent ) && node . symbol . members ?. size ) {
185+ return true ;
186+ }
187+
188+ const decl = getDeclarationOfExpando ( node ) ;
189+ const symbol = decl ?. symbol ;
190+ return ! ! ( symbol && ( symbol . exports ?. size || symbol . members ?. size ) ) ;
191+ }
192+
193+ if ( node . kind === SyntaxKind . FunctionDeclaration ) {
194+ return ! ! node . symbol . members ?. size ;
195+ }
196+
197+ return false ;
198+ }
196199}
0 commit comments