Skip to content

Commit

Permalink
Fix object literal enable multiple lines (josdejong#1328)
Browse files Browse the repository at this point in the history
* Allow object literal expression be multiple lines

* Add test for multiple lines object literal
  • Loading branch information
GHolk committed Dec 6, 2018
1 parent 0366c43 commit 66accc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/expression/parse.js
Expand Up @@ -1511,6 +1511,7 @@ function factory (type, config, load, typed) {
*/
function parseObject (state) {
if (state.token === '{') {
openParams(state)
let key

const properties = {}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/expression/parse.test.js
Expand Up @@ -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' })
})
Expand Down

0 comments on commit 66accc0

Please sign in to comment.