Skip to content

Commit f7e767f

Browse files
trotylmhevery
authored andcommitted
feat(compiler): allow trailing comma in array literal (#22277)
Allows `[1, 2, ]` syntax in angular expressions. closes #20773 PR Close #22277
1 parent 015bdb3 commit f7e767f

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/compiler/src/expression_parser/parser.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,14 @@ export class _ParseAST {
820820

821821
parseExpressionList(terminator: number): AST[] {
822822
const result: AST[] = [];
823-
if (!this.next.isCharacter(terminator)) {
824-
do {
823+
824+
do {
825+
if (!this.next.isCharacter(terminator)) {
825826
result.push(this.parsePipe());
826-
} while (this.consumeOptionalCharacter(chars.$COMMA));
827-
}
827+
} else {
828+
break;
829+
}
830+
} while (this.consumeOptionalCharacter(chars.$COMMA));
828831
return result;
829832
}
830833

‎packages/compiler/test/expression_parser/parser_spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('parser', () => {
106106
checkAction('[]');
107107
checkAction('[].length');
108108
checkAction('[1, 2].length');
109+
checkAction('[1, 2,]', '[1, 2]');
109110
});
110111

111112
it('should parse map', () => {

0 commit comments

Comments
 (0)