diff --git a/src/ng/parse.js b/src/ng/parse.js index bd3aa048df44..885dc50afab9 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(':'); diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 466be755d523..38fce3f78793 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -460,6 +460,8 @@ describe('parser', function() { expect(scope.$eval("[1, 2]").length).toEqual(2); expect(scope.$eval("[1, 2]")[0]).toEqual(1); expect(scope.$eval("[1, 2]")[1]).toEqual(2); + expect(scope.$eval("[1, 2,]")[1]).toEqual(2); + expect(scope.$eval("[1, 2,]").length).toEqual(2); }); it('should evaluate array access', function() { @@ -474,6 +476,9 @@ describe('parser', function() { expect(toJson(scope.$eval("{a:'b'}"))).toEqual('{"a":"b"}'); expect(toJson(scope.$eval("{'a':'b'}"))).toEqual('{"a":"b"}'); expect(toJson(scope.$eval("{\"a\":'b'}"))).toEqual('{"a":"b"}'); + expect(toJson(scope.$eval("{a:'b',}"))).toEqual('{"a":"b"}'); + expect(toJson(scope.$eval("{'a':'b',}"))).toEqual('{"a":"b"}'); + expect(toJson(scope.$eval("{\"a\":'b',}"))).toEqual('{"a":"b"}'); }); it('should evaluate object access', function() {