Permalink
Browse files

Fix object literal enable multiple lines (#1328) (#1349)

* Allow object literal expression be multiple lines

* Add test for multiple lines object literal
  • Loading branch information...
GHolk authored and josdejong committed Dec 6, 2018
1 parent 0366c43 commit 2032a9d1268c9900a3cb12e02079f50f49a607c2
Showing with 6 additions and 0 deletions.
  1. +2 −0 src/expression/parse.js
  2. +4 −0 test/expression/parse.test.js
@@ -1511,6 +1511,7 @@ function factory (type, config, load, typed) {
*/
function parseObject (state) {
if (state.token === '{') {
openParams(state)
let key
const properties = {}
@@ -1545,6 +1546,7 @@ function factory (type, config, load, typed) {
if (state.token !== '}') {
throw createSyntaxError(state, 'Comma , or bracket } expected after object value')
}
closeParams(state)
getToken(state)
let node = new ObjectNode(properties)
@@ -815,6 +815,10 @@ describe('parse', function () {
assert.deepStrictEqual(parseAndEval('{}'), {})
})
it('should spread a object over multiple lines', function () {
assert.deepStrictEqual(parseAndEval('{\na:2+3,\nb:"foo"\n}'), { a: 5, b: 'foo' })
})
it('should create an object with quoted keys', function () {
assert.deepStrictEqual(parseAndEval('{"a":2+3,"b":"foo"}'), { a: 5, b: 'foo' })
})

0 comments on commit 2032a9d

Please sign in to comment.