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:
@ -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(['', '']);
|
||||
|
Reference in New Issue
Block a user