refactor(compiler): iteratively parse interpolations (#38977)

This patch refactors the interpolation parser to do so iteratively
rather than using a regex. Doing so prepares us for supporting granular
recovery on poorly-formed interpolations, for example when an
interpolation does not terminate (`{{ 1 + 2`) or is not terminated
properly (`{{ 1 + 2 {{ 2 + 3 }}`).

Part of #38596

PR Close #38977
This commit is contained in:
ayazhafiz
2020-09-24 11:22:12 -05:00
committed by Joey Perrott
parent f50313f54d
commit 6791cd79af
2 changed files with 70 additions and 28 deletions

View File

@ -728,6 +728,13 @@ describe('parser', () => {
expect(parseInterpolation('nothing')).toBe(null);
});
it('should not parse malformed interpolations as strings', () => {
const ast = parseInterpolation('{{a}} {{example}<!--->}')!.ast as Interpolation;
expect(ast.strings).toEqual(['', ' {{example}<!--->}']);
expect(ast.expressions.length).toEqual(1);
expect(ast.expressions[0].name).toEqual('a');
});
it('should parse no prefix/suffix interpolation', () => {
const ast = parseInterpolation('{{a}}')!.ast as Interpolation;
expect(ast.strings).toEqual(['', '']);