Skip to content

Commit

Permalink
fix: await inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Oct 1, 2021
1 parent 8289324 commit fd511ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/js/async/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

describe 'await', fn:
it 'compiles', fn:

expect
fink2js '
task1 = fn foo: -await foo
Expand All @@ -23,3 +22,14 @@ describe 'await', fn:
await ni
'
to_match_snapshot


it 'does not inline into func body', fn:
expect
fink2js '
task1 = fn foo:
bar = await foo
shrub fn ni:
ni + bar
'
to_match_snapshot
12 changes: 12 additions & 0 deletions src/js/async/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ export const task1 = task1_0,
task3 = task3_0,
a_gen = a_gen_0;"
`;

exports[`await does not inline into func body 1`] = `
"const task1_0 = async foo_0 => {
const bar_0 = await foo_0;
const result_1 = shrub(ni_0 => {
return ni_0 + bar_0;
});
return result_1;
};
export const task1 = task1_0;"
`;
2 changes: 1 addition & 1 deletion src/js/func/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ clean_args = fn args_id, args, body, ctx:

[fn_args, body, ctx]


# These are mostly ir transformations, should this be done as a prep step
split_args_body = fn [expr=false, ...exprs], args_id, ctx, args=[], body=[]:
match expr:
false:
Expand Down
5 changes: 5 additions & 0 deletions src/js/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ prepare_non_inlinable = fn [expr=false, ...exprs], ctx:
next_ctx = update_value res_id, {inline: false}, ctx
prepare_non_inlinable exprs, next_ctx

[{f: 'wt'}]:
[, [res_id]] = expr
next_ctx = update_value res_id, {inline: false}, ctx
prepare_non_inlinable exprs, next_ctx

[{f: 'str'}]:
[, [res_id]] = expr
next_ctx = update_value res_id, {tp: 'str'}, ctx
Expand Down

0 comments on commit fd511ba

Please sign in to comment.