not iterable error

This commit is contained in:
Dmitry Vasilev
2023-07-06 18:34:03 +03:00
parent 65bfacc180
commit 2f577d955d
6 changed files with 91 additions and 22 deletions

View File

@@ -837,6 +837,23 @@ export const tests = [
)
}),
test('array spread not iterable', () => {
assert_code_error(
`[...null]`,
new Error('null is not iterable'),
)
}),
test('args spread not iterable', () => {
assert_code_error(
`
function x() {}
x(...null)
`,
new Error('null is not iterable'),
)
}),
test('module not found', () => {
const parsed = parse_modules(
'a',
@@ -2336,6 +2353,20 @@ const y = x()`
assert_equal(s2.value_explorer.result.error.message, 'boom')
}),
test('move_cursor error in fn args bug', () => {
const code = `
function x() {}
x(null.foo)
`
const i = test_initial_state(code)
const m = COMMANDS.move_cursor(i, code.indexOf('x(null'))
assert_equal(
m.value_explorer.result.error,
new Error("Cannot read properties of null (reading 'foo')")
)
}),
test('frame follows cursor toplevel', () => {
const code = `
const x = () => {

View File

@@ -1,3 +1,4 @@
import {find_error_origin_node} from '../src/ast_utils.js'
import {parse, print_debug_node, load_modules} from '../src/parse_js.js'
import {eval_modules} from '../src/eval.js'
import {active_frame, pp_calltree} from '../src/calltree.js'
@@ -81,9 +82,8 @@ export const assert_code_evals_to = (codestring, expected) => {
export const assert_code_error = (codestring, error) => {
const state = test_initial_state(codestring)
const frame = active_frame(state)
const result = frame.children.at(-1).result
assert_equal(result.ok, false)
assert_equal(result.error, error)
assert_equal(frame.result.ok, false)
assert_equal(find_error_origin_node(frame).result.error, error)
}
export const assert_code_evals_to_async = async (codestring, expected) => {
@@ -168,9 +168,10 @@ export const test_deferred_calls_state = code => {
export const stringify = val =>
JSON.stringify(val, (key, value) => {
// TODO do not use instanceof because currently not implemented in parser
if(value?.constructor == Set){
if(value instanceof Set){
return [...value]
} else if(value instanceof Error) {
return {message: value.message}
} else {
return value
}