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

@@ -145,20 +145,30 @@ export const find_node = (node, pred) => {
)
}
// TODO refactor, have explicit information if node is error origin, without
// guessing. See also color.js
// TODO check if return result is null and throw early
export const find_error_origin_node = node =>
find_node(
// TODO do not go inside function_expr
node,
n => n.result != null && !n.result.ok && (
n.result.error != null
||
// In case if throw null or throw undefined
n.type == 'throw'
||
// await can also throw null
n.type == 'unary' && n.operator == 'await'
// or function call throwing null or undefined
||
n.type == 'function_call'
// node has no error, but its children also have no error, so this node
// is error origin
n.children.find(c => find_error_origin_node(c) != null) == null
&&
(
// In case if throw null or throw undefined
n.type == 'throw'
||
// await can also throw null
n.type == 'unary' && n.operator == 'await'
// or function call throwing null or undefined
||
n.type == 'function_call'
)
)
)