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
This commit is contained in:
Pete Bacon Darwin 2020-04-29 09:10:40 +01:00 committed by Alex Rickabaugh
parent bf0c520f2e
commit 3cb9b43851
2 changed files with 4 additions and 1 deletions

View File

@ -31,6 +31,9 @@ export class Diagnostics {
error(message: string) { error(message: string) {
this.messages.push({type: 'error', message}); this.messages.push({type: 'error', message});
} }
merge(other: Diagnostics) {
this.messages.push(...other.messages);
}
formatDiagnostics(message: string): string { formatDiagnostics(message: string): string {
const errors = this.messages!.filter(d => d.type === 'error').map(d => ' - ' + d.message); 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); const warnings = this.messages!.filter(d => d.type === 'warning').map(d => ' - ' + d.message);

View File

@ -64,7 +64,7 @@ export class TranslationLoader {
// If we were passed a diagnostics object then copy the messages over to it. // If we were passed a diagnostics object then copy the messages over to it.
if (this.diagnostics) { if (this.diagnostics) {
this.diagnostics.messages.push(...diagnostics.messages); this.diagnostics.merge(diagnostics);
} }
return {locale, translations, diagnostics}; return {locale, translations, diagnostics};