(fixes, sourceFile, program, packageJsonImportFilter, host)
| 153443 | return ts.sort(fixes, function (a, b) { return ts.compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier, _toPath); }); |
| 153444 | } |
| 153445 | function getBestFix(fixes, sourceFile, program, packageJsonImportFilter, host) { |
| 153446 | if (!ts.some(fixes)) |
| 153447 | return; |
| 153448 | // These will always be placed first if available, and are better than other kinds |
| 153449 | if (fixes[0].kind === 0 /* ImportFixKind.UseNamespace */ || fixes[0].kind === 2 /* ImportFixKind.AddToExisting */) { |
| 153450 | return fixes[0]; |
| 153451 | } |
| 153452 | return fixes.reduce(function (best, fix) { |
| 153453 | // Takes true branch of conditional if `fix` is better than `best` |
| 153454 | return compareModuleSpecifiers(fix, best, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier, function (fileName) { return ts.toPath(fileName, host.getCurrentDirectory(), ts.hostGetCanonicalFileName(host)); }) === -1 /* Comparison.LessThan */ ? fix : best; |
| 153455 | }); |
| 153456 | } |
| 153457 | /** @returns `Comparison.LessThan` if `a` is better than `b`. */ |
| 153458 | function compareModuleSpecifiers(a, b, importingFile, program, allowsImportingSpecifier, toPath) { |
| 153459 | if (a.kind !== 0 /* ImportFixKind.UseNamespace */ && b.kind !== 0 /* ImportFixKind.UseNamespace */) { |
no test coverage detected