From 3cb9b438516c3a1b745a62f2a8ef4ad622b867b9 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 29 Apr 2020 09:10:40 +0100 Subject: [PATCH] refactor(localize): hide merging diagnostics messages behind a method (#36792) This commit introduces `Diagnostics.merge(other)` which will take the messages from `other` and append them to the messages of `this`. The translation loader is updated to use this new method. PR Close #36792 --- packages/localize/src/tools/src/diagnostics.ts | 3 +++ .../src/translate/translation_files/translation_loader.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/localize/src/tools/src/diagnostics.ts b/packages/localize/src/tools/src/diagnostics.ts index 695374f1f9..7e3ef838db 100644 --- a/packages/localize/src/tools/src/diagnostics.ts +++ b/packages/localize/src/tools/src/diagnostics.ts @@ -31,6 +31,9 @@ export class Diagnostics { error(message: string) { this.messages.push({type: 'error', message}); } + merge(other: Diagnostics) { + this.messages.push(...other.messages); + } formatDiagnostics(message: string): string { const errors = this.messages!.filter(d => d.type === 'error').map(d => ' - ' + d.message); const warnings = this.messages!.filter(d => d.type === 'warning').map(d => ' - ' + d.message); diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts b/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts index a0abd83781..58e51b7c47 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts @@ -64,7 +64,7 @@ export class TranslationLoader { // If we were passed a diagnostics object then copy the messages over to it. if (this.diagnostics) { - this.diagnostics.messages.push(...diagnostics.messages); + this.diagnostics.merge(diagnostics); } return {locale, translations, diagnostics};