feat(compiler): recover expression parsing in more malformed pipe cases (#39437)

This commit handles the following cases:
- incomplete pipes in a pipe chain
- incomplete arguments in a pipe chain
- incomplete arguments provided to a pipe
- nested pipes

The idea is to unconditionally recover on the presence of a pipe, which
should be okay because expression parsing can be independently between
pipes.

PR Close #39437
This commit is contained in:
ayazhafiz
2020-10-26 17:40:26 -05:00
committed by Joey Perrott
parent 8d324ec314
commit e3365724f2
2 changed files with 65 additions and 17 deletions
@@ -393,9 +393,52 @@ describe('parser', () => {
checkBinding('a | b:(c | d)', '(a | b:(c | d))');
});
it('should parse incomplete pipes', () => {
checkBinding('a | b | ', '((a | b) | )');
expectBindingError('a | b | ', 'Unexpected end of input, expected identifier or keyword');
describe('should parse incomplete pipes', () => {
const cases: Array<[string, string, string, string]> = [
[
'should parse missing pipe names: end',
'a | b | ',
'((a | b) | )',
'Unexpected end of input, expected identifier or keyword',
],
[
'should parse missing pipe names: middle',
'a | | b',
'((a | ) | b)',
'Unexpected token |, expected identifier or keyword',
],
[
'should parse missing pipe names: start',
' | a | b',
'(( | a) | b)',
'Unexpected token |',
],
[
'should parse missing pipe args: end',
'a | b | c: ',
'((a | b) | c:)',
'Unexpected end of expression',
],
[
'should parse missing pipe args: middle',
'a | b: | c',
'((a | b:) | c)',
'Unexpected token |',
],
[
'should parse incomplete pipe args',
'a | b: (a | ) + | c',
'((a | b:(a | ) + ) | c)',
'Unexpected token |',
],
];
for (const [name, input, output, err] of cases) {
it(name, () => {
checkBinding(input, output);
expectBindingError(input, err);
});
}
});
it('should only allow identifier or keyword as formatter names', () => {