feat(compiler): do not parse xtb messages not needed by angular (#14111)
fixes #14046 PR Close #14111
This commit is contained in:

committed by
Miško Hevery

parent
20b454cbc9
commit
f7fba74c58
@ -9,8 +9,10 @@
|
||||
import {escapeRegExp} from '@angular/core/src/facade/lang';
|
||||
|
||||
import {serializeNodes} from '../../../src/i18n/digest';
|
||||
import * as i18n from '../../../src/i18n/i18n_ast';
|
||||
import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
|
||||
|
||||
export function main(): void {
|
||||
describe('XTB serializer', () => {
|
||||
const serializer = new Xtb();
|
||||
@ -100,6 +102,25 @@ export function main(): void {
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
it('should be able to parse non-angular xtb files without error', () => {
|
||||
const XTB = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<translationbundle>
|
||||
<translation id="angular">is great</translation>
|
||||
<translation id="non angular">is <invalid>less</invalid> great</translation>
|
||||
</translationbundle>`;
|
||||
|
||||
// Invalid messages should not cause the parser to throw
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]};
|
||||
expect(() => { i18nNodesByMsgId = serializer.load(XTB, 'url'); }).not.toThrow();
|
||||
|
||||
expect(Object.keys(i18nNodesByMsgId).length).toEqual(2);
|
||||
expect(serializeNodes(i18nNodesByMsgId['angular']).join('')).toEqual('is great');
|
||||
// Messages that contain unsupported feature should throw on access
|
||||
expect(() => {
|
||||
const read = i18nNodesByMsgId['non angular'];
|
||||
}).toThrowError(/xtb parse errors/);
|
||||
});
|
||||
|
||||
it('should throw on nested <translationbundle>', () => {
|
||||
const XTB =
|
||||
'<translationbundle><translationbundle></translationbundle></translationbundle>';
|
||||
|
Reference in New Issue
Block a user