@@ -35,16 +35,16 @@ export function main() {
3535 return new Parser ( new Lexer ( ) , reflector ) ;
3636 }
3737
38- function parseAction ( text ) {
39- return createParser ( ) . parseAction ( text ) . ast ;
38+ function parseAction ( text , location = null ) {
39+ return createParser ( ) . parseAction ( text , location ) ;
4040 }
4141
42- function parseBinding ( text ) {
43- return createParser ( ) . parseBinding ( text ) . ast ;
42+ function parseBinding ( text , location = null ) {
43+ return createParser ( ) . parseBinding ( text , location ) ;
4444 }
4545
46- function parseTemplateBindings ( text ) {
47- return createParser ( ) . parseTemplateBindings ( text ) ;
46+ function parseTemplateBindings ( text , location = null ) {
47+ return createParser ( ) . parseTemplateBindings ( text , location ) ;
4848 }
4949
5050 function expectEval ( text , passedInContext = null ) {
@@ -340,7 +340,7 @@ export function main() {
340340
341341 it ( 'should pass exceptions' , ( ) => {
342342 expect ( ( ) => {
343- createParser ( ) . parseAction ( 'a()' ) . ast . eval ( td ( ( ) => { throw new BaseException ( "boo to you" ) } ) ) ;
343+ parseAction ( 'a()' ) . eval ( td ( ( ) => { throw new BaseException ( "boo to you" ) } ) ) ;
344344 } ) . toThrowError ( 'boo to you' ) ;
345345 } ) ;
346346
@@ -352,20 +352,24 @@ export function main() {
352352 } ) ;
353353
354354 it ( 'should store the source in the result' , ( ) => {
355- expect ( createParser ( ) . parseAction ( 'someExpr' ) . source ) . toBe ( 'someExpr' ) ;
355+ expect ( parseAction ( 'someExpr' ) . source ) . toBe ( 'someExpr' ) ;
356+ } ) ;
357+
358+ it ( 'should store the passed-in location' , ( ) => {
359+ expect ( parseAction ( 'someExpr' , 'location' ) . location ) . toBe ( 'location' ) ;
356360 } ) ;
357361 } ) ;
358362
359363 describe ( "parseBinding" , ( ) => {
360364 describe ( "formatters" , ( ) => {
361365 it ( "should parse formatters" , ( ) => {
362- var exp = parseBinding ( "'Foo'|uppercase" ) ;
366+ var exp = parseBinding ( "'Foo'|uppercase" ) . ast ;
363367 expect ( exp ) . toBeAnInstanceOf ( Formatter ) ;
364368 expect ( exp . name ) . toEqual ( "uppercase" ) ;
365369 } ) ;
366370
367371 it ( "should parse formatters with args" , ( ) => {
368- var exp = parseBinding ( "1|increment:2" ) ;
372+ var exp = parseBinding ( "1|increment:2" ) . ast ;
369373 expect ( exp ) . toBeAnInstanceOf ( Formatter ) ;
370374 expect ( exp . name ) . toEqual ( "increment" ) ;
371375 expect ( exp . args [ 0 ] ) . toBeAnInstanceOf ( LiteralPrimitive ) ;
@@ -380,7 +384,11 @@ export function main() {
380384 } ) ;
381385
382386 it ( 'should store the source in the result' , ( ) => {
383- expect ( createParser ( ) . parseBinding ( 'someExpr' ) . source ) . toBe ( 'someExpr' ) ;
387+ expect ( parseBinding ( 'someExpr' ) . source ) . toBe ( 'someExpr' ) ;
388+ } ) ;
389+
390+ it ( 'should store the passed-in location' , ( ) => {
391+ expect ( parseBinding ( 'someExpr' , 'location' ) . location ) . toBe ( 'location' ) ;
384392 } ) ;
385393
386394 it ( 'should throw on chain expressions' , ( ) => {
@@ -409,7 +417,7 @@ export function main() {
409417
410418 function exprAsts ( templateBindings ) {
411419 return ListWrapper . map ( templateBindings ,
412- ( binding ) => isPresent ( binding . expression ) ? binding . expression . ast : null ) ;
420+ ( binding ) => isPresent ( binding . expression ) ? binding . expression : null ) ;
413421 }
414422
415423 it ( 'should parse an empty string' , ( ) => {
@@ -482,6 +490,11 @@ export function main() {
482490 expect ( bindings [ 0 ] . expression . source ) . toEqual ( '1' ) ;
483491 expect ( bindings [ 1 ] . expression . source ) . toEqual ( '2' ) ;
484492 } ) ;
493+
494+ it ( 'should store the passed-in location' , ( ) => {
495+ var bindings = parseTemplateBindings ( "a 1,b 2" , 'location' ) ;
496+ expect ( bindings [ 0 ] . expression . location ) . toEqual ( 'location' ) ;
497+ } ) ;
485498 } ) ;
486499 } ) ;
487500}
0 commit comments