@@ -57,6 +57,10 @@ class ParseException extends BaseException {
5757 }
5858}
5959
60+ export class SplitInterpolation {
61+ constructor ( public strings : string [ ] , public expressions : string [ ] ) { }
62+ }
63+
6064@Injectable ( )
6165export class Parser {
6266 /** @internal */
@@ -118,6 +122,21 @@ export class Parser {
118122 }
119123
120124 parseInterpolation ( input : string , location : any ) : ASTWithSource {
125+ let split = this . splitInterpolation ( input , location ) ;
126+ if ( split == null ) return null ;
127+
128+ let expressions = [ ] ;
129+
130+ for ( let i = 0 ; i < split . expressions . length ; ++ i ) {
131+ var tokens = this . _lexer . tokenize ( split . expressions [ i ] ) ;
132+ var ast = new _ParseAST ( input , location , tokens , this . _reflector , false ) . parseChain ( ) ;
133+ expressions . push ( ast ) ;
134+ }
135+
136+ return new ASTWithSource ( new Interpolation ( split . strings , expressions ) , input , location ) ;
137+ }
138+
139+ splitInterpolation ( input : string , location : string ) : SplitInterpolation {
121140 var parts = StringWrapper . split ( input , INTERPOLATION_REGEXP ) ;
122141 if ( parts . length <= 1 ) {
123142 return null ;
@@ -131,16 +150,14 @@ export class Parser {
131150 // fixed string
132151 strings . push ( part ) ;
133152 } else if ( part . trim ( ) . length > 0 ) {
134- var tokens = this . _lexer . tokenize ( part ) ;
135- var ast = new _ParseAST ( input , location , tokens , this . _reflector , false ) . parseChain ( ) ;
136- expressions . push ( ast ) ;
153+ expressions . push ( part ) ;
137154 } else {
138155 throw new ParseException ( 'Blank expressions are not allowed in interpolated strings' , input ,
139156 `at column ${ this . _findInterpolationErrorColumn ( parts , i ) } in` ,
140157 location ) ;
141158 }
142159 }
143- return new ASTWithSource ( new Interpolation ( strings , expressions ) , input , location ) ;
160+ return new SplitInterpolation ( strings , expressions ) ;
144161 }
145162
146163 wrapLiteralPrimitive ( input : string , location : any ) : ASTWithSource {
0 commit comments