From fd511ba46ce29d792e0464194b004877ed750546 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Fri, 1 Oct 2021 06:37:58 +0200 Subject: [PATCH] fix: await inlining --- src/js/async/init.test.fnk | 12 +++++++++++- src/js/async/init.test.fnk.snap | 12 ++++++++++++ src/js/func/init.fnk | 2 +- src/js/init.fnk | 5 +++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/js/async/init.test.fnk b/src/js/async/init.test.fnk index 04dffec..a7ddb64 100644 --- a/src/js/async/init.test.fnk +++ b/src/js/async/init.test.fnk @@ -4,7 +4,6 @@ describe 'await', fn: it 'compiles', fn: - expect fink2js ' task1 = fn foo: -await foo @@ -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 diff --git a/src/js/async/init.test.fnk.snap b/src/js/async/init.test.fnk.snap index 8afe73e..47e4589 100644 --- a/src/js/async/init.test.fnk.snap +++ b/src/js/async/init.test.fnk.snap @@ -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;" +`; diff --git a/src/js/func/init.fnk b/src/js/func/init.fnk index d9b1588..b40e3f7 100644 --- a/src/js/func/init.fnk +++ b/src/js/func/init.fnk @@ -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: diff --git a/src/js/init.fnk b/src/js/init.fnk index 056f1b0..9e8c782 100644 --- a/src/js/init.fnk +++ b/src/js/init.fnk @@ -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