1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { ParseError } from '../parse_util';
|
---|
9 | import * as html from './ast';
|
---|
10 | // http://cldr.unicode.org/index/cldr-spec/plural-rules
|
---|
11 | const PLURAL_CASES = ['zero', 'one', 'two', 'few', 'many', 'other'];
|
---|
12 | /**
|
---|
13 | * Expands special forms into elements.
|
---|
14 | *
|
---|
15 | * For example,
|
---|
16 | *
|
---|
17 | * ```
|
---|
18 | * { messages.length, plural,
|
---|
19 | * =0 {zero}
|
---|
20 | * =1 {one}
|
---|
21 | * other {more than one}
|
---|
22 | * }
|
---|
23 | * ```
|
---|
24 | *
|
---|
25 | * will be expanded into
|
---|
26 | *
|
---|
27 | * ```
|
---|
28 | * <ng-container [ngPlural]="messages.length">
|
---|
29 | * <ng-template ngPluralCase="=0">zero</ng-template>
|
---|
30 | * <ng-template ngPluralCase="=1">one</ng-template>
|
---|
31 | * <ng-template ngPluralCase="other">more than one</ng-template>
|
---|
32 | * </ng-container>
|
---|
33 | * ```
|
---|
34 | */
|
---|
35 | export function expandNodes(nodes) {
|
---|
36 | const expander = new _Expander();
|
---|
37 | return new ExpansionResult(html.visitAll(expander, nodes), expander.isExpanded, expander.errors);
|
---|
38 | }
|
---|
39 | export class ExpansionResult {
|
---|
40 | constructor(nodes, expanded, errors) {
|
---|
41 | this.nodes = nodes;
|
---|
42 | this.expanded = expanded;
|
---|
43 | this.errors = errors;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | export class ExpansionError extends ParseError {
|
---|
47 | constructor(span, errorMsg) {
|
---|
48 | super(span, errorMsg);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | /**
|
---|
52 | * Expand expansion forms (plural, select) to directives
|
---|
53 | *
|
---|
54 | * @internal
|
---|
55 | */
|
---|
56 | class _Expander {
|
---|
57 | constructor() {
|
---|
58 | this.isExpanded = false;
|
---|
59 | this.errors = [];
|
---|
60 | }
|
---|
61 | visitElement(element, context) {
|
---|
62 | return new html.Element(element.name, element.attrs, html.visitAll(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
|
---|
63 | }
|
---|
64 | visitAttribute(attribute, context) {
|
---|
65 | return attribute;
|
---|
66 | }
|
---|
67 | visitText(text, context) {
|
---|
68 | return text;
|
---|
69 | }
|
---|
70 | visitComment(comment, context) {
|
---|
71 | return comment;
|
---|
72 | }
|
---|
73 | visitExpansion(icu, context) {
|
---|
74 | this.isExpanded = true;
|
---|
75 | return icu.type === 'plural' ? _expandPluralForm(icu, this.errors) :
|
---|
76 | _expandDefaultForm(icu, this.errors);
|
---|
77 | }
|
---|
78 | visitExpansionCase(icuCase, context) {
|
---|
79 | throw new Error('Should not be reached');
|
---|
80 | }
|
---|
81 | }
|
---|
82 | // Plural forms are expanded to `NgPlural` and `NgPluralCase`s
|
---|
83 | function _expandPluralForm(ast, errors) {
|
---|
84 | const children = ast.cases.map(c => {
|
---|
85 | if (PLURAL_CASES.indexOf(c.value) === -1 && !c.value.match(/^=\d+$/)) {
|
---|
86 | errors.push(new ExpansionError(c.valueSourceSpan, `Plural cases should be "=<number>" or one of ${PLURAL_CASES.join(', ')}`));
|
---|
87 | }
|
---|
88 | const expansionResult = expandNodes(c.expression);
|
---|
89 | errors.push(...expansionResult.errors);
|
---|
90 | return new html.Element(`ng-template`, [new html.Attribute('ngPluralCase', `${c.value}`, c.valueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
|
---|
91 | });
|
---|
92 | const switchAttr = new html.Attribute('[ngPlural]', ast.switchValue, ast.switchValueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */);
|
---|
93 | return new html.Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan);
|
---|
94 | }
|
---|
95 | // ICU messages (excluding plural form) are expanded to `NgSwitch` and `NgSwitchCase`s
|
---|
96 | function _expandDefaultForm(ast, errors) {
|
---|
97 | const children = ast.cases.map(c => {
|
---|
98 | const expansionResult = expandNodes(c.expression);
|
---|
99 | errors.push(...expansionResult.errors);
|
---|
100 | if (c.value === 'other') {
|
---|
101 | // other is the default case when no values match
|
---|
102 | return new html.Element(`ng-template`, [new html.Attribute('ngSwitchDefault', '', c.valueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
|
---|
103 | }
|
---|
104 | return new html.Element(`ng-template`, [new html.Attribute('ngSwitchCase', `${c.value}`, c.valueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
|
---|
105 | });
|
---|
106 | const switchAttr = new html.Attribute('[ngSwitch]', ast.switchValue, ast.switchValueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */);
|
---|
107 | return new html.Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan);
|
---|
108 | }
|
---|
109 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWN1X2FzdF9leHBhbmRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9tbF9wYXJzZXIvaWN1X2FzdF9leHBhbmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsVUFBVSxFQUFrQixNQUFNLGVBQWUsQ0FBQztBQUUxRCxP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