From 6b049c74ccc9ee19688bb9bbe504c300e61776dc Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski Date: Wed, 21 Aug 2013 11:25:04 +0200 Subject: feat($parse): support trailing commas in object & array literals Per ECMAScript 5.1 specification trailing commas are allowed in object and array literals. All modern browsers as well as IE>8 support this syntax. This commit adds support for such syntax to Angular expressions. --- src/ng/parse.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ng/parse.js') diff --git a/src/ng/parse.js b/src/ng/parse.js index bd3aa048..885dc50a 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -785,6 +785,10 @@ Parser.prototype = { var allConstant = true; if (this.peekToken().text !== ']') { do { + if (this.peek(']')) { + // Support trailing commas per ES5.1. + break; + } var elementFn = this.expression(); elementFns.push(elementFn); if (!elementFn.constant) { @@ -811,6 +815,10 @@ Parser.prototype = { var allConstant = true; if (this.peekToken().text !== '}') { do { + if (this.peek('}')) { + // Support trailing commas per ES5.1. + break; + } var token = this.expect(), key = token.string || token.text; this.consume(':'); -- cgit v1.2.3