mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
fix
This commit is contained in:
13
src/eval.js
13
src/eval.js
@@ -447,7 +447,7 @@ export const eval_codestring = (codestring, scope) =>
|
|||||||
`
|
`
|
||||||
))(codestring, scope)
|
))(codestring, scope)
|
||||||
|
|
||||||
const get_args_scope = (fn_node, args) => {
|
const get_args_scope = (fn_node, args, closure) => {
|
||||||
const arg_names =
|
const arg_names =
|
||||||
collect_destructuring_identifiers(fn_node.function_args)
|
collect_destructuring_identifiers(fn_node.function_args)
|
||||||
.map(i => i.value)
|
.map(i => i.value)
|
||||||
@@ -464,7 +464,10 @@ const get_args_scope = (fn_node, args) => {
|
|||||||
*/
|
*/
|
||||||
const codestring = `(([${destructuring}]) => [${arg_names.join(',')}])(__args)`
|
const codestring = `(([${destructuring}]) => [${arg_names.join(',')}])(__args)`
|
||||||
|
|
||||||
const {ok, value, error} = eval_codestring(codestring, {__args: args})
|
const {ok, value, error} = eval_codestring(codestring, {
|
||||||
|
...closure,
|
||||||
|
__args: args,
|
||||||
|
})
|
||||||
|
|
||||||
if(!ok) {
|
if(!ok) {
|
||||||
// TODO show exact destructuring error
|
// TODO show exact destructuring error
|
||||||
@@ -1142,7 +1145,11 @@ export const eval_frame = (calltree_node, modules) => {
|
|||||||
} else {
|
} else {
|
||||||
// TODO default values for destructuring can be function calls
|
// TODO default values for destructuring can be function calls
|
||||||
|
|
||||||
const args_scope_result = get_args_scope(node, calltree_node.args)
|
const args_scope_result = get_args_scope(
|
||||||
|
node,
|
||||||
|
calltree_node.args,
|
||||||
|
calltree_node.fn.__closure
|
||||||
|
)
|
||||||
|
|
||||||
// TODO fine-grained destructuring error, only for identifiers that
|
// TODO fine-grained destructuring error, only for identifiers that
|
||||||
// failed destructuring
|
// failed destructuring
|
||||||
|
|||||||
18
test/test.js
18
test/test.js
@@ -820,6 +820,23 @@ export const tests = [
|
|||||||
assert_equal(frame.children[0].children[0].children[0].result.value, [1,2,3])
|
assert_equal(frame.children[0].children[0].children[0].result.value, [1,2,3])
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
test('eval_frame default arg', () => {
|
||||||
|
const code = `
|
||||||
|
const x = 1
|
||||||
|
function y(z = x) {
|
||||||
|
return z
|
||||||
|
}
|
||||||
|
y()
|
||||||
|
`
|
||||||
|
const tree = eval_tree(code)
|
||||||
|
const frame = eval_frame(tree.children[0])
|
||||||
|
assert_equal(
|
||||||
|
// value for z in return statement
|
||||||
|
frame.children[1].children[0].children[0].result.value,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
|
||||||
test('module not found', () => {
|
test('module not found', () => {
|
||||||
const parsed = parse_modules(
|
const parsed = parse_modules(
|
||||||
'a',
|
'a',
|
||||||
@@ -3174,6 +3191,7 @@ const y = x()`
|
|||||||
patch_builtin('random', null)
|
patch_builtin('random', null)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
test('record io cache discarded if args does not match', async () => {
|
test('record io cache discarded if args does not match', async () => {
|
||||||
// Patch fetch
|
// Patch fetch
|
||||||
patch_builtin('fetch', async () => 'first')
|
patch_builtin('fetch', async () => 'first')
|
||||||
|
|||||||
Reference in New Issue
Block a user