mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
value explorer for Sets and Maps
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
// TODO paging for large arrays/objects
|
// TODO paging for large arrays/objects
|
||||||
// TODO maps, sets
|
|
||||||
// TODO show Errors in red
|
// TODO show Errors in red
|
||||||
// TODO fns as clickable links (jump to definition), both for header and for
|
// TODO fns as clickable links (jump to definition), both for header and for
|
||||||
// content
|
// content
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ export const displayed_entries = object => {
|
|||||||
)
|
)
|
||||||
} else if(Array.isArray(object)) {
|
} else if(Array.isArray(object)) {
|
||||||
return object.map((v, i) => [i, v])
|
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') {
|
} else if(typeof(object.toJSON) == 'function') {
|
||||||
const result = toJSON_safe(object)
|
const result = toJSON_safe(object)
|
||||||
if(result == object) {
|
if(result == object) {
|
||||||
@@ -139,7 +145,7 @@ const header_object = object => {
|
|||||||
return `${k}: ${value}`
|
return `${k}: ${value}`
|
||||||
})
|
})
|
||||||
.join(', ')
|
.join(', ')
|
||||||
return `${prefix} {${inner}}`
|
return `${prefix}{${inner}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const header = (object, no_toJSON = false) => {
|
export const header = (object, no_toJSON = false) => {
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -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 {print_debug_node} from '../src/parse_js.js'
|
||||||
import {eval_frame, eval_modules} from '../src/eval.js'
|
import {eval_frame, eval_modules} from '../src/eval.js'
|
||||||
import {COMMANDS} from '../src/cmd.js'
|
import {COMMANDS} from '../src/cmd.js'
|
||||||
|
import {header} from '../src/value_explorer_utils.js'
|
||||||
import {
|
import {
|
||||||
root_calltree_node,
|
root_calltree_node,
|
||||||
active_frame,
|
active_frame,
|
||||||
@@ -3454,5 +3455,19 @@ const y = x()`
|
|||||||
0
|
0
|
||||||
)
|
)
|
||||||
assert_equal(second.state.logs.logs.length, 1)
|
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"}'
|
||||||
|
)
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user