mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix bug
This commit is contained in:
21
src/eval.js
21
src/eval.js
@@ -72,8 +72,8 @@ const codegen_function_expr = (node, cxt) => {
|
|||||||
|
|
||||||
const call = (node.is_async ? 'async ' : '') + `(${args}) => ` + (
|
const call = (node.is_async ? 'async ' : '') + `(${args}) => ` + (
|
||||||
(node.body.type == 'do')
|
(node.body.type == 'do')
|
||||||
? '{' + do_codegen(node.body) + '}'
|
? '{ let __obj, __fn; ' + do_codegen(node.body) + '}'
|
||||||
: '(' + do_codegen(node.body) + ')'
|
: '{ let __obj, __fn; return ' + do_codegen(node.body) + '}'
|
||||||
)
|
)
|
||||||
|
|
||||||
const argscount = node
|
const argscount = node
|
||||||
@@ -103,18 +103,17 @@ const codegen_function_call = (node, cxt) => {
|
|||||||
|
|
||||||
let call
|
let call
|
||||||
if(node.fn.type == 'member_access') {
|
if(node.fn.type == 'member_access') {
|
||||||
// Wrap to IIFE to create scope to calculate obj.
|
|
||||||
// We cant do `codegen(obj)[prop].bind(codegen(obj))` because codegen(obj)
|
|
||||||
// can be expr we dont want to eval twice
|
|
||||||
|
|
||||||
const op = node.fn.is_optional_chaining ? '?.' : ''
|
const op = node.fn.is_optional_chaining ? '?.' : ''
|
||||||
|
|
||||||
// TODO gensym __obj, __fn
|
// TODO gensym __obj, __fn
|
||||||
return `((() => {
|
// We cant do `codegen(obj)[prop].bind(codegen(obj))` because codegen(obj)
|
||||||
const __obj = ${do_codegen(node.fn.object)};
|
// can be expr we dont want to eval twice. Use comma operator to perform
|
||||||
const __fn = __obj${op}[${do_codegen(node.fn.property)}]
|
// assignments in expression context
|
||||||
return trace_call(__fn, __obj, ${args})
|
return `(
|
||||||
})())`
|
__obj = ${do_codegen(node.fn.object)},
|
||||||
|
__fn = __obj${op}[${do_codegen(node.fn.property)}],
|
||||||
|
trace_call(__fn, __obj, ${args})
|
||||||
|
)`
|
||||||
} else {
|
} else {
|
||||||
return `trace_call(${do_codegen(node.fn)}, null, ${args})`
|
return `trace_call(${do_codegen(node.fn)}, null, ${args})`
|
||||||
}
|
}
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -2912,5 +2912,22 @@ const y = x()`
|
|||||||
const {state: after_move} = await COMMANDS.move_cursor(i, code.indexOf('1'))
|
const {state: after_move} = await COMMANDS.move_cursor(i, code.indexOf('1'))
|
||||||
assert_equal(after_move.active_calltree_node.fn.name, 'f')
|
assert_equal(after_move.active_calltree_node.fn.name, 'f')
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
test('async/await await argument bug', async () => {
|
||||||
|
await assert_code_evals_to_async(
|
||||||
|
`
|
||||||
|
Object.assign({}, await {foo: 1})
|
||||||
|
`,
|
||||||
|
{foo: 1}
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
|
||||||
|
/*
|
||||||
|
test('async/await move_cursor bug', async () => {
|
||||||
|
const i = await test_initial_state_async(`
|
||||||
|
await new Promise(resolve => globalThis.setTimeout(resolve, 1))
|
||||||
|
`)
|
||||||
|
}),
|
||||||
|
*/
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user