/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { ParseError } from '../parse_util'; import * as html from './ast'; // http://cldr.unicode.org/index/cldr-spec/plural-rules const PLURAL_CASES = ['zero', 'one', 'two', 'few', 'many', 'other']; /** * Expands special forms into elements. * * For example, * * ``` * { messages.length, plural, * =0 {zero} * =1 {one} * other {more than one} * } * ``` * * will be expanded into * * ``` * * zero * one * more than one * * ``` */ export function expandNodes(nodes) { const expander = new _Expander(); return new ExpansionResult(html.visitAll(expander, nodes), expander.isExpanded, expander.errors); } export class ExpansionResult { constructor(nodes, expanded, errors) { this.nodes = nodes; this.expanded = expanded; this.errors = errors; } } export class ExpansionError extends ParseError { constructor(span, errorMsg) { super(span, errorMsg); } } /** * Expand expansion forms (plural, select) to directives * * @internal */ class _Expander { constructor() { this.isExpanded = false; this.errors = []; } visitElement(element, context) { return new html.Element(element.name, element.attrs, html.visitAll(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan); } visitAttribute(attribute, context) { return attribute; } visitText(text, context) { return text; } visitComment(comment, context) { return comment; } visitExpansion(icu, context) { this.isExpanded = true; return icu.type === 'plural' ? _expandPluralForm(icu, this.errors) : _expandDefaultForm(icu, this.errors); } visitExpansionCase(icuCase, context) { throw new Error('Should not be reached'); } visitBlockGroup(group, context) { return new html.BlockGroup(html.visitAll(this, group.blocks), group.sourceSpan, group.startSourceSpan, group.endSourceSpan); } visitBlock(block, context) { return new html.Block(block.name, block.parameters, html.visitAll(this, block.children), block.sourceSpan, block.startSourceSpan); } visitBlockParameter(parameter, context) { return parameter; } } // Plural forms are expanded to `NgPlural` and `NgPluralCase`s function _expandPluralForm(ast, errors) { const children = ast.cases.map(c => { if (PLURAL_CASES.indexOf(c.value) === -1 && !c.value.match(/^=\d+$/)) { errors.push(new ExpansionError(c.valueSourceSpan, `Plural cases should be "=" or one of ${PLURAL_CASES.join(', ')}`)); } const expansionResult = expandNodes(c.expression); errors.push(...expansionResult.errors); 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); }); const switchAttr = new html.Attribute('[ngPlural]', ast.switchValue, ast.switchValueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */); return new html.Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan); } // ICU messages (excluding plural form) are expanded to `NgSwitch` and `NgSwitchCase`s function _expandDefaultForm(ast, errors) { const children = ast.cases.map(c => { const expansionResult = expandNodes(c.expression); errors.push(...expansionResult.errors); if (c.value === 'other') { // other is the default case when no values match 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); } 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); }); const switchAttr = new html.Attribute('[ngSwitch]', ast.switchValue, ast.switchValueSourceSpan, undefined /* keySpan */, undefined /* valueSpan */, undefined /* valueTokens */, undefined /* i18n */); return new html.Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWN1X2FzdF9leHBhbmRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9tbF9wYXJzZXIvaWN1X2FzdF9leHBhb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