MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / createDiagnosticReporter

Function createDiagnosticReporter

packages/tooling/src/typescript.ts:7–30  ·  view source on GitHub ↗
(pretty: boolean, logger: Logger)

Source from the content-addressed store, hash-verified

5type Logger = Pick<Console, 'log' | 'info' | 'warn' | 'error'>;
6
7export 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
32export function symbolFromNode(checker: ts.TypeChecker, node: ts.Node) {
33 return ((node as any).symbol as ts.Symbol | undefined) || checker.getSymbolAtLocation(node);

Callers 2

TranspilerBase.tsFile · 0.90
createApiDtsFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected