(sourceFile, program, cancellationToken)
| 144694 | (function (ts) { |
| 144695 | var visitedNestedConvertibleFunctions = new ts.Map(); |
| 144696 | function computeSuggestionDiagnostics(sourceFile, program, cancellationToken) { |
| 144697 | program.getSemanticDiagnostics(sourceFile, cancellationToken); |
| 144698 | var diags = []; |
| 144699 | var checker = program.getTypeChecker(); |
| 144700 | var isCommonJSFile = sourceFile.impliedNodeFormat === ts.ModuleKind.CommonJS || ts.fileExtensionIsOneOf(sourceFile.fileName, [".cts" /* Extension.Cts */, ".cjs" /* Extension.Cjs */]); |
| 144701 | if (!isCommonJSFile && |
| 144702 | sourceFile.commonJsModuleIndicator && |
| 144703 | (ts.programContainsEsModules(program) || ts.compilerOptionsIndicateEsModules(program.getCompilerOptions())) && |
| 144704 | containsTopLevelCommonjs(sourceFile)) { |
| 144705 | diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES_module)); |
| 144706 | } |
| 144707 | var isJsFile = ts.isSourceFileJS(sourceFile); |
| 144708 | visitedNestedConvertibleFunctions.clear(); |
| 144709 | check(sourceFile); |
| 144710 | if (ts.getAllowSyntheticDefaultImports(program.getCompilerOptions())) { |
| 144711 | for (var _i = 0, _a = sourceFile.imports; _i < _a.length; _i++) { |
| 144712 | var moduleSpecifier = _a[_i]; |
| 144713 | var importNode = ts.importFromModuleSpecifier(moduleSpecifier); |
| 144714 | var name = importNameForConvertToDefaultImport(importNode); |
| 144715 | if (!name) |
| 144716 | continue; |
| 144717 | var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text, ts.getModeForUsageLocation(sourceFile, moduleSpecifier)); |
| 144718 | var resolvedFile = module_1 && program.getSourceFile(module_1.resolvedFileName); |
| 144719 | if (resolvedFile && resolvedFile.externalModuleIndicator && resolvedFile.externalModuleIndicator !== true && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) { |
| 144720 | diags.push(ts.createDiagnosticForNode(name, ts.Diagnostics.Import_may_be_converted_to_a_default_import)); |
| 144721 | } |
| 144722 | } |
| 144723 | } |
| 144724 | ts.addRange(diags, sourceFile.bindSuggestionDiagnostics); |
| 144725 | ts.addRange(diags, program.getSuggestionDiagnostics(sourceFile, cancellationToken)); |
| 144726 | return diags.sort(function (d1, d2) { return d1.start - d2.start; }); |
| 144727 | function check(node) { |
| 144728 | if (isJsFile) { |
| 144729 | if (canBeConvertedToClass(node, checker)) { |
| 144730 | diags.push(ts.createDiagnosticForNode(ts.isVariableDeclaration(node.parent) ? node.parent.name : node, ts.Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration)); |
| 144731 | } |
| 144732 | } |
| 144733 | else { |
| 144734 | if (ts.isVariableStatement(node) && |
| 144735 | node.parent === sourceFile && |
| 144736 | node.declarationList.flags & 2 /* NodeFlags.Const */ && |
| 144737 | node.declarationList.declarations.length === 1) { |
| 144738 | var init = node.declarationList.declarations[0].initializer; |
| 144739 | if (init && ts.isRequireCall(init, /*checkArgumentIsStringLiteralLike*/ true)) { |
| 144740 | diags.push(ts.createDiagnosticForNode(init, ts.Diagnostics.require_call_may_be_converted_to_an_import)); |
| 144741 | } |
| 144742 | } |
| 144743 | if (ts.codefix.parameterShouldGetTypeFromJSDoc(node)) { |
| 144744 | diags.push(ts.createDiagnosticForNode(node.name || node, ts.Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types)); |
| 144745 | } |
| 144746 | } |
| 144747 | if (canBeConvertedToAsync(node)) { |
| 144748 | addConvertToAsyncFunctionDiagnostics(node, checker, diags); |
| 144749 | } |
| 144750 | node.forEachChild(check); |
| 144751 | } |
| 144752 | } |
| 144753 | ts.computeSuggestionDiagnostics = computeSuggestionDiagnostics; |
nothing calls this directly
no test coverage detected