Skip to content

Commit

Permalink
fix(compiler): handle trailing comma in object literal (#49535)
Browse files Browse the repository at this point in the history
Fixes that the compiler wasn't parsing an object literal with a trailing comma correctly.

Fixes #49534.

PR Close #49535
  • Loading branch information
crisbeto authored and atscott committed Mar 23, 2023
1 parent a844435 commit c3cff35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/compiler/src/expression_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ export class _ParseAST {
values.push(new PropertyRead(
span, sourceSpan, sourceSpan, new ImplicitReceiver(span, sourceSpan), key));
}
} while (this.consumeOptionalCharacter(chars.$COMMA));
} while (this.consumeOptionalCharacter(chars.$COMMA) &&
!this.next.isCharacter(chars.$RBRACE));
this.rbracesExpected--;
this.expectCharacter(chars.$RBRACE);
}
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/test/expression_parser/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('parser', () => {
checkAction('{}');
checkAction('{a: 1, "b": 2}[2]');
checkAction('{}["a"]');
checkAction('{a: 1, b: 2,}', '{a: 1, b: 2}');
});

it('should only allow identifier, string, or keyword as map key', () => {
Expand Down

0 comments on commit c3cff35

Please sign in to comment.