99import { Lexer as ExpressionLexer } from '../expression_parser/lexer' ;
1010import { Parser as ExpressionParser } from '../expression_parser/parser' ;
1111import * as html from '../ml_parser/ast' ;
12+ import { InterpolationConfig } from '../ml_parser/defaults' ;
1213import { getHtmlTagDefinition } from '../ml_parser/html_tags' ;
13- import { InterpolationConfig } from '../ml_parser/interpolation_config' ;
1414import { InterpolatedAttributeToken , InterpolatedTextToken , TokenType } from '../ml_parser/tokens' ;
1515import { ParseSourceSpan } from '../parse_util' ;
1616
@@ -29,9 +29,9 @@ export interface I18nMessageFactory {
2929/**
3030 * Returns a function converting html nodes to an i18n Message given an interpolationConfig
3131 */
32- export function createI18nMessageFactory ( interpolationConfig : InterpolationConfig ) :
33- I18nMessageFactory {
34- const visitor = new _I18nVisitor ( _expParser , interpolationConfig ) ;
32+ export function createI18nMessageFactory (
33+ interpolationConfig : InterpolationConfig , containerBlocks : Set < string > ) : I18nMessageFactory {
34+ const visitor = new _I18nVisitor ( _expParser , interpolationConfig , containerBlocks ) ;
3535 return ( nodes , meaning , description , customId , visitNodeFn ) =>
3636 visitor . toI18nMessage ( nodes , meaning , description , customId , visitNodeFn ) ;
3737}
@@ -52,7 +52,9 @@ function noopVisitNodeFn(_html: html.Node, i18n: i18n.Node): i18n.Node {
5252class _I18nVisitor implements html . Visitor {
5353 constructor (
5454 private _expressionParser : ExpressionParser ,
55- private _interpolationConfig : InterpolationConfig ) { }
55+ private _interpolationConfig : InterpolationConfig ,
56+ private _containerBlocks : Set < string > ,
57+ ) { }
5658
5759 public toI18nMessage (
5860 nodes : html . Node [ ] , meaning = '' , description = '' , customId = '' ,
@@ -164,11 +166,35 @@ class _I18nVisitor implements html.Visitor {
164166
165167 visitBlock ( block : html . Block , context : I18nMessageVisitorContext ) {
166168 const children = html . visitAll ( this , block . children , context ) ;
167- const node = new i18n . Container ( children , block . sourceSpan ) ;
169+
170+ if ( this . _containerBlocks . has ( block . name ) ) {
171+ return new i18n . Container ( children , block . sourceSpan ) ;
172+ }
173+
174+ const parameters = block . parameters . map ( param => param . expression ) ;
175+ const startPhName =
176+ context . placeholderRegistry . getStartBlockPlaceholderName ( block . name , parameters ) ;
177+ const closePhName = context . placeholderRegistry . getCloseBlockPlaceholderName ( block . name ) ;
178+
179+ context . placeholderToContent [ startPhName ] = {
180+ text : block . startSourceSpan . toString ( ) ,
181+ sourceSpan : block . startSourceSpan ,
182+ } ;
183+
184+ context . placeholderToContent [ closePhName ] = {
185+ text : block . endSourceSpan ? block . endSourceSpan . toString ( ) : '}' ,
186+ sourceSpan : block . endSourceSpan ?? block . sourceSpan ,
187+ } ;
188+
189+ const node = new i18n . BlockPlaceholder (
190+ block . name , parameters , startPhName , closePhName , children , block . sourceSpan ,
191+ block . startSourceSpan , block . endSourceSpan ) ;
168192 return context . visitNodeFn ( block , node ) ;
169193 }
170194
171- visitBlockParameter ( _parameter : html . BlockParameter , _context : I18nMessageVisitorContext ) { }
195+ visitBlockParameter ( _parameter : html . BlockParameter , _context : I18nMessageVisitorContext ) {
196+ throw new Error ( 'Unreachable code' ) ;
197+ }
172198
173199 /**
174200 * Convert, text and interpolated tokens up into text and placeholder pieces.
0 commit comments