fix bug with function decls

This commit is contained in:
Dmitry Vasilev
2023-06-10 20:17:04 +03:00
parent 280d41f153
commit b774063b79
2 changed files with 21 additions and 1 deletions

View File

@@ -70,7 +70,7 @@ const codegen_function_expr = (node, node_cxt) => {
const decl = node.is_arrow
? `(${args}) => `
: `function ${node.name}(${args})`
: `function(${args})`
const call = (node.is_async ? 'async ' : '') + decl + (
// TODO gensym __obj, __fn

View File

@@ -1227,6 +1227,26 @@ export const tests = [
)
}),
test('function decl', () => {
const code = `
function fib(n) {
if(n == 0 || n == 1) {
return n
} else {
return fib(n - 1) + fib(n - 2)
}
}
fib(6)
`
const i = test_initial_state(code)
const s = COMMANDS.calltree.arrow_right(COMMANDS.calltree.arrow_down(
COMMANDS.calltree.arrow_right(COMMANDS.calltree.arrow_down(i))
))
const s2 = COMMANDS.calltree.arrow_down(s)
assert_equal(s2.active_calltree_node.value, 5)
}),
/*
TODO use before assignment
test('no use before assignment', () => {