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AC;QACtC,IAAI,KAAK,KAAK,QAAQ,CAAC,OAAO,EAAE;YAC5B,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAChC;IACL,CAAC;CACJ;AA9BD,sCA8BC;AAKD,MAAa,cAAe,SAAQ,MAAM;IAWtC,YAAY,QAAkB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IASM,GAAG,CAAC,OAAe,EAAE,QAAkB,QAAQ,CAAC,IAAI,EAAE,OAAiB;QAC1E,IAAI,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE;YAC1B,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;SACxB;QAED,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACJ;AA9BD,wCA8BC","sourcesContent":["import * as ts from 'typescript';\nimport * as Util from 'util';\n\n/**\n * List of known log levels. Used to specify the urgency of a log message.\n */\nexport enum LogLevel {\n Verbose,\n Info,\n Warn,\n Error,\n Success\n}\n\n/**\n * A logger that will not produce any output.\n *\n * This logger also serves as the base class of other loggers as it implements\n * all the required utility functions.\n */\nexport class Logger {\n /**\n * How many error messages have been logged?\n */\n errorCount = 0;\n\n /**\n * Has an error been raised through the log method?\n */\n public hasErrors(): boolean {\n return this.errorCount > 0;\n }\n\n /**\n * Reset the error counter.\n */\n public resetErrors() {\n this.errorCount = 0;\n }\n\n /**\n * Log the given message.\n *\n * @param text The message that should be logged.\n * @param args The arguments that should be printed into the given message.\n */\n public write(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Info);\n }\n\n /**\n * Log the given message with a trailing whitespace.\n *\n * @param text The message that should be logged.\n * @param args The arguments that should be printed into the given message.\n */\n public writeln(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Info, true);\n }\n\n /**\n * Log the given success message.\n *\n * @param text The message that should be logged.\n * @param args The arguments that should be printed into the given message.\n */\n public success(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Success);\n }\n\n /**\n * Log the given verbose message.\n *\n * @param text The message that should be logged.\n * @param args The arguments that should be printed into the given message.\n */\n public verbose(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Verbose);\n }\n\n /**\n * Log the given warning.\n *\n * @param text The warning that should be logged.\n * @param args The arguments that should be printed into the given warning.\n */\n public warn(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Warn);\n }\n\n /**\n * Log the given error.\n *\n * @param text The error that should be logged.\n * @param args The arguments that should be printed into the given error.\n */\n public error(text: string, ...args: string[]) {\n this.log(Util.format.apply(this, arguments), LogLevel.Error);\n }\n\n /**\n * Print a log message.\n *\n * @param message The message itself.\n * @param level The urgency of the log message.\n * @param newLine Should the logger print a trailing whitespace?\n */\n public log(message: string, level: LogLevel = LogLevel.Info, newLine?: boolean) {\n if (level === LogLevel.Error) {\n this.errorCount += 1;\n }\n }\n\n /**\n * Print the given TypeScript log messages.\n *\n * @param diagnostics The TypeScript messages that should be logged.\n */\n public diagnostics(diagnostics: ReadonlyArray<ts.Diagnostic>) {\n diagnostics.forEach((diagnostic) => {\n this.diagnostic(diagnostic);\n });\n }\n\n /**\n * Print the given TypeScript log message.\n *\n * @param diagnostic The TypeScript message that should be logged.\n */\n public diagnostic(diagnostic: ts.Diagnostic) {\n let output: string;\n if (diagnostic.file) {\n output = diagnostic.file.fileName;\n output += '(' + ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start || 0).line + ')';\n output += ts.sys.newLine + ' ' + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine);\n } else {\n output = ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine);\n }\n\n switch (diagnostic.category) {\n case ts.DiagnosticCategory.Error:\n this.log(output, LogLevel.Error);\n break;\n case ts.DiagnosticCategory.Warning:\n this.log(output, LogLevel.Warn);\n break;\n case ts.DiagnosticCategory.Message:\n this.log(output, LogLevel.Info);\n }\n }\n}\n\n/**\n * A logger that outputs all messages to the console.\n */\nexport class ConsoleLogger extends Logger {\n /**\n * Print a log message.\n *\n * @param message The message itself.\n * @param level The urgency of the log message.\n * @param newLine Should the logger print a trailing whitespace?\n */\n public log(message: string, level: LogLevel = LogLevel.Info, newLine?: boolean) {\n if (level === LogLevel.Error) {\n this.errorCount += 1;\n }\n\n let output = '';\n if (level === LogLevel.Error) {\n output += 'Error: ';\n }\n if (level === LogLevel.Warn) {\n output += 'Warning: ';\n }\n output += message;\n\n if (newLine || level === LogLevel.Success) {\n ts.sys.write(ts.sys.newLine);\n }\n ts.sys.write(output + ts.sys.newLine);\n if (level === LogLevel.Success) {\n ts.sys.write(ts.sys.newLine);\n }\n }\n}\n\n/**\n * A logger that calls a callback function.\n */\nexport class CallbackLogger extends Logger {\n /**\n * This loggers callback function\n */\n callback: Function;\n\n /**\n * Create a new CallbackLogger instance.\n *\n * @param callback The callback that should be used to log messages.\n */\n constructor(callback: Function) {\n super();\n this.callback = callback;\n }\n\n /**\n * Print a log message.\n *\n * @param message The message itself.\n * @param level The urgency of the log message.\n * @param newLine Should the logger print a trailing whitespace?\n */\n public log(message: string, level: LogLevel = LogLevel.Info, newLine?: boolean) {\n if (level === LogLevel.Error) {\n this.errorCount += 1;\n }\n\n this.callback(message, level, newLine);\n }\n}\n"]}
\No newline at end of file