From 2d03ce2c96baff3b5322cc6cf100c8542f4a3527 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Thu, 18 Nov 2021 13:07:20 +0100 Subject: [PATCH 1/2] fix(transform): disable cov for return statements --- src/js/call/call.fnk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/call/call.fnk b/src/js/call/call.fnk index 4bb8c10..2a6e7ea 100644 --- a/src/js/call/call.fnk +++ b/src/js/call/call.fnk @@ -94,7 +94,9 @@ transform_continue_with_cont = fn expr, ctx: res = get_js res_id, ctx match ret: {type: 'ReturnStatement'}: - js = with_loc res, returnStatement res + js = with_loc res, rec: + ...returnStatement res + leadingComments: [{type: 'CommentBlock', value: ' istanbul ignore next '}] [[js], ctx] else: exprs = list: From 37f0f5c4796085e197b21a8229eaaa0916e5672f Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Thu, 18 Nov 2021 14:16:08 +0100 Subject: [PATCH 2/2] fix(transform): disable cov for return statements having prev siblings --- src/generate.fnk | 11 ++++++++- src/js/async/init.test.fnk.snap | 11 +++++++++ src/js/call/call.fnk | 4 +--- src/js/call/call.test.fnk.snap | 30 +++++++++++++++++++++++++ src/js/call/pipe.test.fnk.snap | 7 ++++++ src/js/conditionals/match.test.fnk.snap | 4 ++++ src/js/func/init.test.fnk.snap | 13 +++++++++++ src/js/jsx/init.test.fnk.snap | 2 ++ 8 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/generate.fnk b/src/generate.fnk index 1e59e74..18f2143 100644 --- a/src/generate.fnk +++ b/src/generate.fnk @@ -2,7 +2,9 @@ babel_traverse = import '@babel/traverse' {default: traverse} = babel_traverse {transformFromAstSync} = import '@babel/core' -{try_catch} = import '@fink/js-interop/errors.fnk' +{try_catch} = import '@fink/js-interop/errors.js' +{set_props} = import '@fink/js-interop/reflect.js' +{undefined} = import '@fink/js-interop/nullish.js' {transform} = import './ir/transform.fnk' {init_ctx} = import './ir/init.fnk' @@ -33,6 +35,13 @@ transform_file = fn fink_ast, code, filename, {optimize: optim, ...options}: match error: false: traverse js_ast, rec: + ReturnStatement: fn path: + match path: + {key: ? > 0}: + set_props path.node, rec: + leadingComments: [{type: 'CommentBlock', value: ' istanbul ignore next '}] + undefined + AwaitExpression: {enter: transform_async} ...extras diff --git a/src/js/async/init.test.fnk.snap b/src/js/async/init.test.fnk.snap index 5ccebda..d34558f 100644 --- a/src/js/async/init.test.fnk.snap +++ b/src/js/async/init.test.fnk.snap @@ -3,17 +3,23 @@ exports[`await compiles 1`] = ` "const task1_0 = async foo_0 => { const right_0 = await foo_0; + + /* istanbul ignore next */ return -right_0; }; const task2_0 = async foo_1 => { const result_1 = await (foo_1 + 4); + + /* istanbul ignore next */ return result_1; }; const task3_0 = async foo_2 => { const futr_2 = foo_2(); const spam_0 = await futr_2; + + /* istanbul ignore next */ return bar + 123 + spam_0; }; @@ -24,9 +30,12 @@ const a_gen_0 = unfold(async hdm_0 => { if (shrub === spam) { const futr_3 = ni(curr_0); const result_6 = await futr_3; + + /* istanbul ignore next */ return result_6; } + /* istanbul ignore next */ return curr_0 + 1; }); export const task1 = task1_0, @@ -41,6 +50,8 @@ exports[`await does not inline into func body 1`] = ` const result_1 = shrub(ni_0 => { return ni_0 + bar_0; }); + + /* istanbul ignore next */ return result_1; }; diff --git a/src/js/call/call.fnk b/src/js/call/call.fnk index 2a6e7ea..4bb8c10 100644 --- a/src/js/call/call.fnk +++ b/src/js/call/call.fnk @@ -94,9 +94,7 @@ transform_continue_with_cont = fn expr, ctx: res = get_js res_id, ctx match ret: {type: 'ReturnStatement'}: - js = with_loc res, rec: - ...returnStatement res - leadingComments: [{type: 'CommentBlock', value: ' istanbul ignore next '}] + js = with_loc res, returnStatement res [[js], ctx] else: exprs = list: diff --git a/src/js/call/call.test.fnk.snap b/src/js/call/call.test.fnk.snap index e9f5068..797ccaa 100644 --- a/src/js/call/call.test.fnk.snap +++ b/src/js/call/call.test.fnk.snap @@ -22,11 +22,15 @@ export const call1 = call1_0, exports[`call compiles with partial arg 1`] = ` "const p1_0 = prtl_0 => { const pfn_0 = foo(prtl_0); + + /* istanbul ignore next */ return pfn_0; }; const p2_0 = prtl_1 => { const pfn_1 = foo(prtl_1, 123, prtl_1); + + /* istanbul ignore next */ return pfn_1; }; @@ -37,16 +41,22 @@ export const p1 = p1_0, exports[`call compiles with partial callee 1`] = ` "const p1_0 = prtl_0 => { const pfn_0 = prtl_0(123); + + /* istanbul ignore next */ return pfn_0; }; const p2_0 = prtl_1 => { const pfn_1 = prtl_1(bar, spam); + + /* istanbul ignore next */ return pfn_1; }; const p3_0 = prtl_2 => { const pfn_2 = prtl_2.bar(spam); + + /* istanbul ignore next */ return pfn_2; }; @@ -61,6 +71,8 @@ exports[`call compiles with partial exprs as args 1`] = ` }); const pa2_0 = filter(prtl_1 => { const right_1 = foo(prtl_1); + + /* istanbul ignore next */ return prtl_1 || right_1; }); const pa3_0 = filter(prtl_2 => { @@ -86,37 +98,51 @@ export const pa1 = pa1_0, exports[`call compiles with partial spread arg 1`] = ` "const p1_0 = prtl_0 => { const pfn_0 = foo(...prtl_0); + + /* istanbul ignore next */ return pfn_0; }; const p2_0 = prtl_1 => { const pfn_1 = foo(...prtl_1.bar); + + /* istanbul ignore next */ return pfn_1; }; const p3_0 = prtl_2 => { const pfn_2 = foo(...prtl_2.bar.spam); + + /* istanbul ignore next */ return pfn_2; }; const p4_0 = prtl_3 => { const sprd_3 = bar(prtl_3); const result_0 = foo(...sprd_3); + + /* istanbul ignore next */ return result_0; }; const p7_0 = prtl_4 => { const pfn_3 = prtl_4(123); + + /* istanbul ignore next */ return pfn_3; }; const p8_0 = prtl_5 => { const pfn_4 = prtl_5(bar, spam); + + /* istanbul ignore next */ return pfn_4; }; const p9_0 = prtl_6 => { const pfn_5 = prtl_6.bar(spam); + + /* istanbul ignore next */ return pfn_5; }; @@ -158,10 +184,14 @@ exports[`recursive functions compiles with self reference 1`] = ` /* istanbul ignore else */ if (cntr_0 === 1) { const items_1 = foo_0(cntr_0 - 1); + + /* istanbul ignore next */ return [...items_1]; } const items_0 = foo_0(cntr_0 - 1); + + /* istanbul ignore next */ return [cntr_0, ...items_0]; }; diff --git a/src/js/call/pipe.test.fnk.snap b/src/js/call/pipe.test.fnk.snap index c48ce70..55ea0f2 100644 --- a/src/js/call/pipe.test.fnk.snap +++ b/src/js/call/pipe.test.fnk.snap @@ -5,6 +5,8 @@ exports[`pipe compiles 1`] = ` const ppr_1 = (prtl_0 => { const pfn_2 = bar(prtl_0, 123); + + /* istanbul ignore next */ return pfn_2; })(ppr_0); @@ -12,6 +14,8 @@ const ppr_2 = spam(ppr_1); const ppr_3 = (prtl_1 => { const pfn_5 = prtl_1.spam(456); + + /* istanbul ignore next */ return pfn_5; })(ppr_2); @@ -42,9 +46,12 @@ exports[`pipe compiles 2`] = ` const ppr_1 = (prtl_0 => { const pfn_2 = prtl_0.shrub(123); + + /* istanbul ignore next */ return pfn_2; })(ppr_0); + /* istanbul ignore next */ return ppr_1; }); export const foo = foo_0;" diff --git a/src/js/conditionals/match.test.fnk.snap b/src/js/conditionals/match.test.fnk.snap index ff23fa2..2d2124d 100644 --- a/src/js/conditionals/match.test.fnk.snap +++ b/src/js/conditionals/match.test.fnk.snap @@ -137,6 +137,8 @@ exports[`match compiles nested match 1`] = ` } const result_1 = ret_1; + + /* istanbul ignore next */ return bar; } @@ -173,6 +175,8 @@ exports[`match handles scoping 1`] = ` /* istanbul ignore else */ if (foo_1 === spam) { const foo_2 = bar_0 * 2; + + /* istanbul ignore next */ return [foo_2, bar_0, foo_2]; } diff --git a/src/js/func/init.test.fnk.snap b/src/js/func/init.test.fnk.snap index aad6a3d..08ed3e6 100644 --- a/src/js/func/init.test.fnk.snap +++ b/src/js/func/init.test.fnk.snap @@ -5,6 +5,8 @@ exports[`func compiles defaults 1`] = ` const b_0 = undefined === hdm_0 ? 12 : hdm_0; const ni_0 = shrub(a_0, b_0); const result_1 = bar(b_0, ni_0); + + /* istanbul ignore next */ return result_1; }; @@ -149,6 +151,7 @@ exports[`func compiles spread 4`] = ` return [a_0, c_0, d_0]; } + /* istanbul ignore next */ return b_0; }; @@ -166,6 +169,7 @@ exports[`recursive functions compiles spread 1`] = ` continue fun_0; } + /* istanbul ignore next */ return b_0; } while (true); }; @@ -202,10 +206,14 @@ exports[`recursive functions compiles with self reference 1`] = ` /* istanbul ignore else */ if (cntr_0 === 1) { const items_1 = foo_0(cntr_0 - 1); + + /* istanbul ignore next */ return [...items_1]; } const items_0 = foo_0(cntr_0 - 1); + + /* istanbul ignore next */ return [cntr_0, ...items_0]; }; @@ -217,13 +225,18 @@ exports[`recursive functions compiles with self reference 2`] = ` const count_0 = start_0 => { const result_1 = _iterable_(() => { const item_0 = count_0(start_0 + 1); + + /* istanbul ignore next */ return [start_0 + 1, item_0]; }); + /* istanbul ignore next */ return result_1; }; const result_3 = count_0(0); + + /* istanbul ignore next */ return result_3; }; diff --git a/src/js/jsx/init.test.fnk.snap b/src/js/jsx/init.test.fnk.snap index f6c8b7b..f6d95e5 100644 --- a/src/js/jsx/init.test.fnk.snap +++ b/src/js/jsx/init.test.fnk.snap @@ -45,6 +45,8 @@ exports[`jsx compiles elem from rec 1`] = ` const { ...props_0 } = drec_0; const Foobar_0 = spam.Foobar; + + /* istanbul ignore next */ return ; };