fix value explorer for destructuring

This commit is contained in:
Dmitry Vasilev
2023-12-30 17:27:59 +08:00
parent 212179b788
commit acd24fe5b7
4 changed files with 22 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import {update_children} from './parse_js.js'
import {map_accum, map_find, map_object, stringify, findLast} from './utils.js' import {map_accum, map_find, map_object, stringify, findLast} from './utils.js'
import {is_eq, find_error_origin_node} from './ast_utils.js' import {is_eq, find_error_origin_node} from './ast_utils.js'
import {find_node, find_leaf, ancestry_inc} from './ast_utils.js' import {find_node, find_leaf, ancestry_inc} from './ast_utils.js'
@@ -147,7 +148,7 @@ export const add_frame = (
let frame let frame
frame = state.frames?.[active_calltree_node.id] frame = state.frames?.[active_calltree_node.id]
if(frame == null) { if(frame == null) {
frame = eval_frame(active_calltree_node, state.modules) frame = update_children(eval_frame(active_calltree_node, state.modules))
const execution_paths = active_calltree_node.toplevel const execution_paths = active_calltree_node.toplevel
? null ? null
: get_execution_paths(frame) : get_execution_paths(frame)

View File

@@ -1029,7 +1029,10 @@ const eval_decl_pair = (s, eval_cxt, frame_cxt) => {
} }
}) })
), ),
n => n.result == null n =>
// TODO this should set result for default values in destructuring
// Currently not implemented
n.result == null
? {...n, result: {ok}} ? {...n, result: {ok}}
: n : n
) )

View File

@@ -1561,7 +1561,7 @@ const update_children_not_rec = (node, children = node.children) => {
} }
} }
const update_children = node => { export const update_children = node => {
if(Array.isArray(node)) { if(Array.isArray(node)) {
return node.map(update_children) return node.map(update_children)
} else { } else {

View File

@@ -873,9 +873,15 @@ export const tests = [
const frame = active_frame(i) const frame = active_frame(i)
assert_equal( assert_equal(
// value for z in return statement // value for z in return statement
frame.children[1].children[0].children[0].result.value, find_node(frame.children[1], n => n.value == 'z').result.value,
1 1
) )
// TODO not implemented
//assert_equal(
// // value for x in arguments
// find_node(frame.children[0], n => n.value == 'x').result.value,
// 1
//)
}), }),
test('array spread not iterable', () => { test('array spread not iterable', () => {
@@ -2653,6 +2659,12 @@ const y = x()`
}) })
}), }),
test('move_cursor destructuring default', () => {
const code = `const [x = 1, y] = [undefined, 2]`
const s = test_initial_state(code)
assert_equal(s.value_explorer.result.value, {x: 1, y: 2})
}),
test('move_cursor after type toplevel', () => { test('move_cursor after type toplevel', () => {
const code = `1` const code = `1`
const s1 = test_initial_state(code) const s1 = test_initial_state(code)