@@ -22,16 +22,14 @@ import {
2222 partition ,
2323 Part ,
2424 stringifyNodes ,
25- meaning ,
26- getPhNameFromBinding ,
27- dedupePhName
25+ meaning
2826} from './shared' ;
2927
3028const _I18N_ATTR = "i18n" ;
3129const _PLACEHOLDER_ELEMENT = "ph" ;
3230const _NAME_ATTR = "name" ;
3331const _I18N_ATTR_PREFIX = "i18n-" ;
34- let _PLACEHOLDER_EXPANDED_REGEXP = RegExpWrapper . create ( `\\<ph(\\s)+name=("(\\w )+")\\>\\<\\/ph\\>` ) ;
32+ let _PLACEHOLDER_EXPANDED_REGEXP = RegExpWrapper . create ( `\\<ph(\\s)+name=("(\\d )+")\\>\\<\\/ph\\>` ) ;
3533
3634/**
3735 * Creates an i18n-ed version of the parsed template.
@@ -315,31 +313,19 @@ export class I18nHtmlParser implements HtmlParser {
315313
316314 private _replacePlaceholdersWithExpressions ( message : string , exps : string [ ] ,
317315 sourceSpan : ParseSourceSpan ) : string {
318- let expMap = this . _buildExprMap ( exps ) ;
319316 return RegExpWrapper . replaceAll ( _PLACEHOLDER_EXPANDED_REGEXP , message , ( match ) => {
320317 let nameWithQuotes = match [ 2 ] ;
321318 let name = nameWithQuotes . substring ( 1 , nameWithQuotes . length - 1 ) ;
322- return this . _convertIntoExpression ( name , expMap , sourceSpan ) ;
319+ let index = NumberWrapper . parseInt ( name , 10 ) ;
320+ return this . _convertIntoExpression ( index , exps , sourceSpan ) ;
323321 } ) ;
324322 }
325323
326- private _buildExprMap ( exps : string [ ] ) : Map < string , string > {
327- let expMap = new Map < string , string > ( ) ;
328- let usedNames = new Map < string , number > ( ) ;
329-
330- for ( var i = 0 ; i < exps . length ; i ++ ) {
331- let phName = getPhNameFromBinding ( exps [ i ] , i ) ;
332- expMap . set ( dedupePhName ( usedNames , phName ) , exps [ i ] ) ;
333- }
334- return expMap ;
335- }
336-
337- private _convertIntoExpression ( name : string , expMap : Map < string , string > ,
338- sourceSpan : ParseSourceSpan ) {
339- if ( expMap . has ( name ) ) {
340- return `{{${ expMap . get ( name ) } }}` ;
324+ private _convertIntoExpression ( index : number , exps : string [ ] , sourceSpan : ParseSourceSpan ) {
325+ if ( index >= 0 && index < exps . length ) {
326+ return `{{${ exps [ index ] } }}` ;
341327 } else {
342- throw new I18nError ( sourceSpan , `Invalid interpolation name '${ name } '` ) ;
328+ throw new I18nError ( sourceSpan , `Invalid interpolation index '${ index } '` ) ;
343329 }
344330 }
345331}
@@ -361,4 +347,4 @@ class _CreateNodeMapping implements HtmlAstVisitor {
361347 }
362348
363349 visitComment ( ast : HtmlCommentAst , context : any ) : any { return "" ; }
364- }
350+ }
0 commit comments