11/* @internal */
22namespace ts {
3- export function computeSuggestionDiagnostics ( sourceFile : SourceFile , program : Program ) : DiagnosticWithLocation [ ] {
4- program . getSemanticDiagnostics ( sourceFile ) ;
5- const checker = program . getDiagnosticsProducingTypeChecker ( ) ;
3+ export function computeSuggestionDiagnostics ( sourceFile : SourceFile , program : Program , cancellationToken : CancellationToken ) : DiagnosticWithLocation [ ] {
4+ program . getSemanticDiagnostics ( sourceFile , cancellationToken ) ;
65 const diags : DiagnosticWithLocation [ ] = [ ] ;
76
87 if ( sourceFile . commonJsModuleIndicator &&
@@ -23,6 +22,18 @@ namespace ts {
2322 }
2423 }
2524 break ;
25+ case SyntaxKind . VariableStatement :
26+ if ( ! isJsFile && node . parent === sourceFile ) {
27+ const statement = node as VariableStatement ;
28+ if ( statement . declarationList . flags & NodeFlags . Const &&
29+ statement . declarationList . declarations . length === 1 ) {
30+ const init = statement . declarationList . declarations [ 0 ] . initializer ;
31+ if ( init && isRequireCall ( init , /*checkArgumentIsStringLiteralLike*/ true ) ) {
32+ diags . push ( createDiagnosticForNode ( init , Diagnostics . require_call_may_be_converted_to_an_import ) ) ;
33+ }
34+ }
35+ }
36+ break ;
2637 }
2738
2839 if ( ! isJsFile && codefix . parameterShouldGetTypeFromJSDoc ( node ) ) {
@@ -33,19 +44,6 @@ namespace ts {
3344 }
3445 check ( sourceFile ) ;
3546
36- if ( ! isJsFile ) {
37- for ( const statement of sourceFile . statements ) {
38- if ( isVariableStatement ( statement ) &&
39- statement . declarationList . flags & NodeFlags . Const &&
40- statement . declarationList . declarations . length === 1 ) {
41- const init = statement . declarationList . declarations [ 0 ] . initializer ;
42- if ( init && isRequireCall ( init , /*checkArgumentIsStringLiteralLike*/ true ) ) {
43- diags . push ( createDiagnosticForNode ( init , Diagnostics . require_call_may_be_converted_to_an_import ) ) ;
44- }
45- }
46- }
47- }
48-
4947 if ( getAllowSyntheticDefaultImports ( program . getCompilerOptions ( ) ) ) {
5048 for ( const moduleSpecifier of sourceFile . imports ) {
5149 const importNode = importFromModuleSpecifier ( moduleSpecifier ) ;
@@ -60,7 +58,8 @@ namespace ts {
6058 }
6159
6260 addRange ( diags , sourceFile . bindSuggestionDiagnostics ) ;
63- return diags . concat ( checker . getSuggestionDiagnostics ( sourceFile ) ) . sort ( ( d1 , d2 ) => d1 . start - d2 . start ) ;
61+ addRange ( diags , program . getSuggestionDiagnostics ( sourceFile , cancellationToken ) ) ;
62+ return diags . sort ( ( d1 , d2 ) => d1 . start - d2 . start ) ;
6463 }
6564
6665 // convertToEs6Module only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
0 commit comments