UNPKG

@clawject/di

Version:

<p align="center"> <a href="https://clawject.com/" target="_blank"><img src="https://clawject.com/img/logo.svg" align="center" alt="Clawject Logo" width="120" height="120" /></a> </p>

38 lines (37 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorsReporter = void 0; const DiagnosticsBuilder_1 = require("@clawject/core/ts-diagnostics/DiagnosticsBuilder"); const Context_1 = require("@clawject/core/compilation-context/Context"); const lodash_1 = require("lodash"); class ErrorsReporter { reportErrors(cb) { const errors = this.getErrorsAndClear(); errors.forEach(it => { cb(it); }); } getErrorsAndClear() { const errors = Array.from(Context_1.Context.errors); Context_1.Context.clearMessages(); const diagnostics = this.getDiagnostics(errors); return diagnostics.map(it => this.transformDiagnostic(it)); } getDiagnostics(messages) { return (0, lodash_1.compact)(messages.map(it => DiagnosticsBuilder_1.DiagnosticsBuilder.compilationMessageToDiagnostic(it))); } transformDiagnostic(diagnostic) { const loc = diagnostic.file?.getLineAndCharacterOfPosition(diagnostic.start ?? 0); return { plugin: 'clawject-unplugin', message: DiagnosticsBuilder_1.DiagnosticsBuilder.diagnosticsToString([diagnostic]), pluginCode: diagnostic.code, loc: loc ? { file: diagnostic.file?.fileName, line: loc.line + 1, column: loc.character, } : undefined }; } } exports.ErrorsReporter = ErrorsReporter;