mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
run with find_call
This commit is contained in:
30
src/eval.js
30
src/eval.js
@@ -359,6 +359,33 @@ export const eval_modules = (
|
||||
}
|
||||
}
|
||||
|
||||
const run_and_find_call = (location) => {
|
||||
searched_location = location
|
||||
|
||||
const run_result = run()
|
||||
|
||||
const after_run = ({calltree, modules, logs}) => {
|
||||
searched_location = null
|
||||
const call = found_call
|
||||
found_call = null
|
||||
|
||||
return {
|
||||
calltree,
|
||||
modules,
|
||||
logs,
|
||||
call,
|
||||
}
|
||||
}
|
||||
|
||||
// Support to paths, one for async 'run', and one for sync, to avoid
|
||||
// refactoring code (mostly test code) to always async
|
||||
if(run_result instanceof Promise) {
|
||||
return run_result.then(after_run)
|
||||
} else {
|
||||
return after_run(run_result)
|
||||
}
|
||||
}
|
||||
|
||||
const find_call = (location, deferred_calls) => {
|
||||
searched_location = location
|
||||
let is_found_deferred_call = false
|
||||
@@ -667,6 +694,7 @@ export const eval_modules = (
|
||||
|
||||
return {
|
||||
run,
|
||||
run_and_find_call,
|
||||
expand_calltree_node,
|
||||
find_call,
|
||||
}
|
||||
@@ -725,7 +753,7 @@ export const eval_modules = (
|
||||
|
||||
const result = location == null
|
||||
? actions.run()
|
||||
: calltree_actions.find_call(location)
|
||||
: actions.run_and_find_call(location)
|
||||
|
||||
const make_result = result => ({
|
||||
modules: result.modules,
|
||||
|
||||
24
test/test.js
24
test/test.js
@@ -2858,19 +2858,29 @@ const y = x()`
|
||||
)
|
||||
}),
|
||||
|
||||
/*
|
||||
// TODO
|
||||
test('async/await move_cursor', async () => {
|
||||
test('async/await edit', async () => {
|
||||
const code = `
|
||||
const f = async () => {
|
||||
console.log('f')
|
||||
}
|
||||
|
||||
}
|
||||
await f()
|
||||
`
|
||||
const i = await test_initial_state_async(code)
|
||||
const cursor = COMMANDS.move_cursor(i, code.indexOf('console'))
|
||||
const code2 = `
|
||||
const f = async () => {
|
||||
1
|
||||
}
|
||||
await f()
|
||||
`
|
||||
const {state: after_edit} = COMMANDS.input(i, code2, code2.indexOf('1'))
|
||||
const result = await after_edit.eval_modules_state.promise
|
||||
const after_edit_finished = COMMANDS.eval_modules_finished(
|
||||
after_edit,
|
||||
result,
|
||||
after_edit.eval_modules_state.node,
|
||||
after_edit.eval_modules_state.toplevel
|
||||
)
|
||||
assert_equal(after_edit_finished.active_calltree_node.fn.name, 'f')
|
||||
}),
|
||||
*/
|
||||
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user