value explorer for Sets and Maps

This commit is contained in:
Dmitry Vasilev
2023-08-01 00:05:04 +03:00
parent 93dc56c08d
commit 6ffc971dda
3 changed files with 23 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
// TODO paging for large arrays/objects
// TODO maps, sets
// TODO show Errors in red
// TODO fns as clickable links (jump to definition), both for header and for
// content

View File

@@ -40,6 +40,12 @@ export const displayed_entries = object => {
)
} else if(Array.isArray(object)) {
return object.map((v, i) => [i, v])
} else if(object[Symbol.toStringTag] == 'Set') {
// TODO display set as list without keys as indexes, because Set in JS are
// not ordered and it would be incorrect to imply ordering
return [...object.values()].map((entry, i) => [i, entry])
} else if(object[Symbol.toStringTag] == 'Map') {
return [...object.entries()]
} else if(typeof(object.toJSON) == 'function') {
const result = toJSON_safe(object)
if(result == object) {
@@ -139,7 +145,7 @@ const header_object = object => {
return `${k}: ${value}`
})
.join(', ')
return `${prefix} {${inner}}`
return `${prefix}{${inner}}`
}
export const header = (object, no_toJSON = false) => {

View File

@@ -2,6 +2,7 @@ import {find_leaf, ancestry, find_node} from '../src/ast_utils.js'
import {print_debug_node} from '../src/parse_js.js'
import {eval_frame, eval_modules} from '../src/eval.js'
import {COMMANDS} from '../src/cmd.js'
import {header} from '../src/value_explorer_utils.js'
import {
root_calltree_node,
active_frame,
@@ -3454,5 +3455,19 @@ const y = x()`
0
)
assert_equal(second.state.logs.logs.length, 1)
})
}),
test('value_explorer Set', () => {
assert_equal(
header(new Set(['foo', 'bar'])),
'Set {0: "foo", 1: "bar"}'
)
}),
test('value_explorer Map', () => {
assert_equal(
header(new Map([['foo', 'bar'], ['baz', 'qux']])),
'Map {foo: "bar", baz: "qux"}'
)
}),
]