mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(compiler): remove container blocks config
Removes the ability to specify container blocks when creating an i18n parser. We were only passing in `switch` and it likely won't change.
This commit is contained in:
parent
7ddf4a6b07
commit
b6c141bf8b
6 changed files with 2 additions and 20 deletions
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import * as html from '../ml_parser/ast';
|
||||
import {DEFAULT_CONTAINER_BLOCKS} from '../ml_parser/defaults';
|
||||
import {ParseTreeResult} from '../ml_parser/parser';
|
||||
import {TokenType} from '../ml_parser/tokens';
|
||||
import {ParseError} from '../parse_util';
|
||||
|
|
@ -285,7 +284,6 @@ class _Visitor implements html.Visitor {
|
|||
this._messages = [];
|
||||
this._inImplicitNode = false;
|
||||
this._createI18nMessage = createI18nMessageFactory(
|
||||
DEFAULT_CONTAINER_BLOCKS,
|
||||
// When dropping significant whitespace we need to retain whitespace tokens or
|
||||
// else we won't be able to reuse source spans because empty tokens would be
|
||||
// removed and cause a mismatch.
|
||||
|
|
|
|||
|
|
@ -41,16 +41,10 @@ export interface I18nMessageFactory {
|
|||
* Returns a function converting html nodes to an i18n Message
|
||||
*/
|
||||
export function createI18nMessageFactory(
|
||||
containerBlocks: Set<string>,
|
||||
retainEmptyTokens: boolean,
|
||||
preserveExpressionWhitespace: boolean,
|
||||
): I18nMessageFactory {
|
||||
const visitor = new _I18nVisitor(
|
||||
_expParser,
|
||||
containerBlocks,
|
||||
retainEmptyTokens,
|
||||
preserveExpressionWhitespace,
|
||||
);
|
||||
const visitor = new _I18nVisitor(_expParser, retainEmptyTokens, preserveExpressionWhitespace);
|
||||
return (nodes, meaning, description, customId, visitNodeFn) =>
|
||||
visitor.toI18nMessage(nodes, meaning, description, customId, visitNodeFn);
|
||||
}
|
||||
|
|
@ -71,7 +65,6 @@ function noopVisitNodeFn(_html: html.Node, i18n: i18n.Node): i18n.Node {
|
|||
class _I18nVisitor implements html.Visitor {
|
||||
constructor(
|
||||
private _expressionParser: ExpressionParser,
|
||||
private _containerBlocks: Set<string>,
|
||||
private readonly _retainEmptyTokens: boolean,
|
||||
private readonly _preserveExpressionWhitespace: boolean,
|
||||
) {}
|
||||
|
|
@ -183,7 +176,7 @@ class _I18nVisitor implements html.Visitor {
|
|||
visitBlock(block: html.Block, context: I18nMessageVisitorContext) {
|
||||
const children = html.visitAll(this, block.children, context);
|
||||
|
||||
if (this._containerBlocks.has(block.name)) {
|
||||
if (block.name === 'switch') {
|
||||
return new i18n.Container(children, block.sourceSpan);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,5 +31,3 @@ export const DEFAULT_INTERPOLATION_CONFIG: InterpolationConfig = new Interpolati
|
|||
'{{',
|
||||
'}}',
|
||||
);
|
||||
|
||||
export const DEFAULT_CONTAINER_BLOCKS = new Set(['switch']);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import {computeDecimalDigest, computeDigest, decimalDigest} from '../../../i18n/
|
|||
import * as i18n from '../../../i18n/i18n_ast';
|
||||
import {createI18nMessageFactory, VisitNodeFn} from '../../../i18n/i18n_parser';
|
||||
import * as html from '../../../ml_parser/ast';
|
||||
import {DEFAULT_CONTAINER_BLOCKS} from '../../../ml_parser/defaults';
|
||||
import {ParseTreeResult} from '../../../ml_parser/parser';
|
||||
import * as o from '../../../output/output_ast';
|
||||
import {isTrustedTypesSink} from '../../../schema/trusted_types_sinks';
|
||||
|
|
@ -63,7 +62,6 @@ export class I18nMetaVisitor implements html.Visitor {
|
|||
constructor(
|
||||
private keepI18nAttrs = false,
|
||||
private enableI18nLegacyMessageIdFormat = false,
|
||||
private containerBlocks: Set<string> = DEFAULT_CONTAINER_BLOCKS,
|
||||
private readonly preserveSignificantWhitespace: boolean = true,
|
||||
|
||||
// When dropping significant whitespace we need to retain empty tokens or
|
||||
|
|
@ -82,7 +80,6 @@ export class I18nMetaVisitor implements html.Visitor {
|
|||
): i18n.Message {
|
||||
const {meaning, description, customId} = this._parseMetadata(meta);
|
||||
const createI18nMessage = createI18nMessageFactory(
|
||||
this.containerBlocks,
|
||||
this.retainEmptyTokens,
|
||||
/* preserveExpressionWhitespace */ this.preserveSignificantWhitespace,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -189,7 +189,6 @@ export function parseTemplate(
|
|||
const i18nMetaVisitor = new I18nMetaVisitor(
|
||||
/* keepI18nAttrs */ !preserveWhitespaces,
|
||||
enableI18nLegacyMessageIdFormat,
|
||||
/* containerBlocks */ undefined,
|
||||
options.preserveSignificantWhitespace,
|
||||
retainEmptyTokens,
|
||||
);
|
||||
|
|
@ -246,7 +245,6 @@ export function parseTemplate(
|
|||
new I18nMetaVisitor(
|
||||
/* keepI18nAttrs */ false,
|
||||
/* enableI18nLegacyMessageIdFormat */ undefined,
|
||||
/* containerBlocks */ undefined,
|
||||
/* preserveSignificantWhitespace */ true,
|
||||
retainEmptyTokens,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@
|
|||
|
||||
import {createI18nMessageFactory} from '../../src/i18n/i18n_parser';
|
||||
import {Node} from '../../src/ml_parser/ast';
|
||||
import {DEFAULT_CONTAINER_BLOCKS} from '../../src/ml_parser/defaults';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
|
||||
describe('Message', () => {
|
||||
const messageFactory = createI18nMessageFactory(
|
||||
DEFAULT_CONTAINER_BLOCKS,
|
||||
/* retainEmptyTokens */ false,
|
||||
/* preserveExpressionWhitespace */ true,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue