feat(ICU): enable ICU extraction even when when in is not used
BREAKING CHANGES: "{" is used a a delimiter for ICU messages then it could not be used in text nodes. "{" should be escaped as "{{ '{' }}" Before: <span>some { valid } text</span> After: <span>some { invalid } text<span> <!-- throw parse error --> <span>some {{ '{' }} valid } text</span>
This commit is contained in:
@ -6,12 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {HtmlAttrAst, HtmlElementAst, HtmlTextAst} from '@angular/compiler/src/html_ast';
|
||||
import {HtmlParser} from '@angular/compiler/src/html_parser';
|
||||
import {ExpansionResult, expandNodes} from '@angular/compiler/src/i18n/expander';
|
||||
import {ParseError} from '@angular/compiler/src/parse_util';
|
||||
import {humanizeNodes} from '@angular/compiler/test/html_ast_spec_utils';
|
||||
import {ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
|
||||
import {ddescribe, describe, expect, iit, it} from '../../core/testing/testing_internal';
|
||||
import {ExpansionResult, expandNodes} from '../src/expander';
|
||||
import {HtmlAttrAst, HtmlElementAst, HtmlTextAst} from '../src/html_ast';
|
||||
import {HtmlParser} from '../src/html_parser';
|
||||
import {ParseError} from '../src/parse_util';
|
||||
|
||||
import {humanizeNodes} from './html_ast_spec_utils';
|
||||
|
||||
export function main() {
|
||||
describe('Expander', () => {
|
@ -30,8 +30,6 @@ var MOCK_SCHEMA_REGISTRY = [{
|
||||
useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})
|
||||
}];
|
||||
|
||||
let zeConsole = console;
|
||||
|
||||
export function main() {
|
||||
var ngIf: CompileDirectiveMetadata;
|
||||
var parse:
|
||||
@ -864,19 +862,18 @@ There is no directive with "exportAs" set to "dirA" ("<div [ERROR ->]#a="dirA"><
|
||||
});
|
||||
|
||||
it('should report duplicate reference names', () => {
|
||||
expect(() => parse('<div #a></div><div #a></div>', []))
.toThrowError(
|
||||
`Template parse errors:
|
||||
expect(() => parse('<div #a></div><div #a></div>', []))
|
||||
.toThrowError(`Template parse errors:
|
||||
Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>"): TestComp@0:19`);
|
||||
|
||||
});
|
||||
|
||||
it(
|
||||
'should not throw error when there is same reference name in different templates',
|
||||
() => {
|
||||
expect(() => parse('<div #a><template #a><span>OK</span></template></div>', []))
|
||||
.not.toThrowError();
|
||||
it('should not throw error when there is same reference name in different templates',
|
||||
() => {
|
||||
expect(() => parse('<div #a><template #a><span>OK</span></template></div>', []))
|
||||
.not.toThrowError();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should assign references with empty value to components', () => {
|
||||
var dirA = CompileDirectiveMetadata.create({
|
||||
@ -1506,6 +1503,38 @@ The pipe 'test' could not be found ("[ERROR ->]{{a | test}}"): TestComp@0:0`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ICU messages', () => {
|
||||
it('should expand plural messages', () => {
|
||||
const shortForm = '{ count, plural, =0 {small} many {big} }';
|
||||
const expandedForm = '<ng-container [ngPlural]="count">' +
|
||||
'<template ngPluralCase="=0">small</template>' +
|
||||
'<template ngPluralCase="many">big</template>' +
|
||||
'</ng-container>';
|
||||
|
||||
expect(humanizeTplAst(parse(shortForm, []))).toEqual(humanizeTplAst(parse(expandedForm, [
|
||||
])));
|
||||
});
|
||||
|
||||
it('should expand other messages', () => {
|
||||
const shortForm = '{ sex, gender, =f {foo} other {bar} }';
|
||||
const expandedForm = '<ng-container [ngSwitch]="sex">' +
|
||||
'<template ngSwitchCase="=f">foo</template>' +
|
||||
'<template ngSwitchCase="other">bar</template>' +
|
||||
'</ng-container>';
|
||||
|
||||
expect(humanizeTplAst(parse(shortForm, []))).toEqual(humanizeTplAst(parse(expandedForm, [
|
||||
])));
|
||||
});
|
||||
|
||||
it('should be possible to escape ICU messages', () => {
|
||||
const escapedForm = 'escaped {{ "{" }} }';
|
||||
|
||||
expect(humanizeTplAst(parse(escapedForm, []))).toEqual([
|
||||
[BoundTextAst, 'escaped {{ "{" }} }'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user