@@ -48,6 +48,13 @@ var _implicitReceiver = new ImplicitReceiver();
48
48
// TODO(tbosch): Cannot make this const/final right now because of the transpiler...
49
49
var INTERPOLATION_REGEXP = / \{ \{ ( .* ?) \} \} / g;
50
50
51
+ class ParseException extends BaseException {
52
+ constructor ( message : string , input : string , errLocation : string , ctxLocation ?: any ) {
53
+ super ( `Parser Error: ${ message } ${ errLocation } [${ input } ] in ${ ctxLocation } ` , null , null ,
54
+ ctxLocation ) ;
55
+ }
56
+ }
57
+
51
58
@Injectable ( )
52
59
export class Parser {
53
60
_reflector : Reflector ;
@@ -88,14 +95,21 @@ export class Parser {
88
95
var expressions = [ ] ;
89
96
90
97
for ( var i = 0 ; i < parts . length ; i ++ ) {
91
- var part = parts [ i ] ;
98
+ var part : string = parts [ i ] ;
92
99
if ( i % 2 === 0 ) {
93
100
// fixed string
94
101
strings . push ( part ) ;
95
- } else {
102
+ } else if ( part . trim ( ) . length > 0 ) {
96
103
var tokens = this . _lexer . tokenize ( part ) ;
97
104
var ast = new _ParseAST ( input , location , tokens , this . _reflector , false ) . parseChain ( ) ;
98
105
expressions . push ( ast ) ;
106
+ } else {
107
+ var errLocation = '' ;
108
+ for ( var j = 0 ; j < i ; j ++ ) {
109
+ errLocation += j % 2 === 0 ? parts [ j ] : `{{${ parts [ j ] } }}` ;
110
+ }
111
+ throw new ParseException ( 'Blank expressions are not allowed in interpolated strings' , input ,
112
+ `at column ${ errLocation . length } in` , location ) ;
99
113
}
100
114
}
101
115
return new ASTWithSource ( new Interpolation ( strings , expressions ) , input , location ) ;
@@ -596,8 +610,7 @@ export class _ParseAST {
596
610
var location = ( index < this . tokens . length ) ? `at column ${ this . tokens [ index ] . index + 1 } in` :
597
611
`at the end of the expression` ;
598
612
599
- throw new BaseException (
600
- `Parser Error: ${ message } ${ location } [${ this . input } ] in ${ this . location } ` ) ;
613
+ throw new ParseException ( message , this . input , location , this . location ) ;
601
614
}
602
615
}
603
616
0 commit comments