Skip to content

Commit

Permalink
Merge pull request #137 from fink-lang/fix-cov
Browse files Browse the repository at this point in the history
fix(transform): disable cov for return statements
  • Loading branch information
kollhof authored Nov 18, 2021
2 parents 888b232 + 37f0f5c commit d23274d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/generate.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/js/async/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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,
Expand All @@ -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;
};
Expand Down
30 changes: 30 additions & 0 deletions src/js/call/call.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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 => {
Expand All @@ -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;
};
Expand Down Expand Up @@ -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];
};
Expand Down
7 changes: 7 additions & 0 deletions src/js/call/pipe.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ exports[`pipe compiles 1`] = `
const ppr_1 = (prtl_0 => {
const pfn_2 = bar(prtl_0, 123);
/* istanbul ignore next */
return pfn_2;
})(ppr_0);
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);
Expand Down Expand Up @@ -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;"
Expand Down
4 changes: 4 additions & 0 deletions src/js/conditionals/match.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ exports[`match compiles nested match 1`] = `
}
const result_1 = ret_1;
/* istanbul ignore next */
return bar;
}
Expand Down Expand Up @@ -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];
}
Expand Down
13 changes: 13 additions & 0 deletions src/js/func/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -149,6 +151,7 @@ exports[`func compiles spread 4`] = `
return [a_0, c_0, d_0];
}
/* istanbul ignore next */
return b_0;
};
Expand All @@ -166,6 +169,7 @@ exports[`recursive functions compiles spread 1`] = `
continue fun_0;
}
/* istanbul ignore next */
return b_0;
} while (true);
};
Expand Down Expand Up @@ -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];
};
Expand All @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions src/js/jsx/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foobar_0 {...props_0} />;
};
Expand Down

0 comments on commit d23274d

Please sign in to comment.