fix let without assignment

This commit is contained in:
Dmitry Vasilev
2023-10-30 15:13:29 +08:00
parent 376799de84
commit 84ed01dbf2
2 changed files with 16 additions and 1 deletions

View File

@@ -1015,7 +1015,12 @@ const eval_statement = (s, scope, calls, context) => {
}
if(stmt.type == 'let' && s.type == 'identifier') {
const node = {...s, result: {ok: true}}
return {ok, children: [...children, node], scope, calls}
return {
ok,
children: [...children, node],
scope: {...scope, [s.value]: undefined},
calls
}
}
const {
ok: next_ok,

View File

@@ -329,6 +329,16 @@ export const tests = [
assert_equal(i.value_explorer.result.value, {y: 2, z: 3, q: 4})
}),
test('let variable not initialized bug', () => {
const code = `
let x
x /*label*/
`
const i = test_initial_state(code, code.indexOf('x /*label'))
assert_equal(i.value_explorer.result.ok, true)
assert_equal(i.value_explorer.result.value === undefined, true)
}),
test('else if', () => {
const code = `
let x