mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* Allow object literal expression be multiple lines * Add test for multiple lines object literal
This commit is contained in:
parent
0366c439e9
commit
2032a9d126
@ -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' })
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user