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

* Allow object literal expression be multiple lines

* Add test for multiple lines object literal
This commit is contained in:
Gold Holk 2018-12-07 02:37:57 +08:00 committed by Jos de Jong
parent 0366c439e9
commit 2032a9d126
2 changed files with 6 additions and 0 deletions

View File

@ -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)

View File

@ -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' })
})