fix(compiler): interpolation expressions report the correct offset (#12125)

This commit is contained in:
Chuck Jazdzewski
2016-10-06 15:22:10 -07:00
committed by Tobias Bosch
parent f4566f8128
commit d641c36a45
2 changed files with 52 additions and 14 deletions

View File

@ -8,7 +8,7 @@
import {ASTWithSource, BindingPipe, Interpolation, ParserError, TemplateBinding} from '@angular/compiler/src/expression_parser/ast';
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
import {Parser, TemplateBindingParseResult} from '@angular/compiler/src/expression_parser/parser';
import {Parser, SplitInterpolation, TemplateBindingParseResult} from '@angular/compiler/src/expression_parser/parser';
import {expect} from '@angular/platform-browser/testing/matchers';
import {isBlank, isPresent} from '../../src/facade/lang';
@ -39,6 +39,10 @@ export function main() {
return createParser().parseInterpolation(text, location);
}
function splitInterpolation(text: string, location: any = null): SplitInterpolation {
return createParser().splitInterpolation(text, location);
}
function parseSimpleBinding(text: string, location: any = null): ASTWithSource {
return createParser().parseSimpleBinding(text, location);
}
@ -539,5 +543,18 @@ export function main() {
it('should be able to recover from a missing selector in a array literal',
() => recover('[[a.], b, c]'));
});
describe('offsets', () => {
it('should retain the offsets of an interpolation', () => {
const interpolations = splitInterpolation('{{a}} {{b}} {{c}}');
expect(interpolations.offsets).toEqual([2, 9, 16]);
});
it('should retain the offsets into the expression AST of interpolations', () => {
const source = parseInterpolation('{{a}} {{b}} {{c}}');
const interpolation = source.ast as Interpolation;
expect(interpolation.expressions.map(e => e.span.start)).toEqual([2, 9, 16]);
});
});
});
}