(pretty: boolean, logger: Logger)
| 5 | type Logger = Pick<Console, 'log' | 'info' | 'warn' | 'error'>; |
| 6 | |
| 7 | export function createDiagnosticReporter(pretty: boolean, logger: Logger): ts.DiagnosticReporter { |
| 8 | const host: ts.FormatDiagnosticsHost = { |
| 9 | getCurrentDirectory: () => ts.sys.getCurrentDirectory(), |
| 10 | getNewLine: () => ts.sys.newLine, |
| 11 | getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase() |
| 12 | }; |
| 13 | |
| 14 | const mapping: Record<ts.DiagnosticCategory, keyof Logger> = { |
| 15 | [ts.DiagnosticCategory.Warning]: 'warn', |
| 16 | [ts.DiagnosticCategory.Error]: 'error', |
| 17 | [ts.DiagnosticCategory.Message]: 'info', |
| 18 | [ts.DiagnosticCategory.Suggestion]: 'log' |
| 19 | }; |
| 20 | |
| 21 | if (!pretty) { |
| 22 | return diagnostic => logger[mapping[diagnostic.category]](ts.formatDiagnostic(diagnostic, host)); |
| 23 | } |
| 24 | |
| 25 | return diagnostic => { |
| 26 | logger[mapping[diagnostic.category]]( |
| 27 | ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + host.getNewLine() |
| 28 | ); |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | export function symbolFromNode(checker: ts.TypeChecker, node: ts.Node) { |
| 33 | return ((node as any).symbol as ts.Symbol | undefined) || checker.getSymbolAtLocation(node); |
no outgoing calls
no test coverage detected