swc-plugin-coverage-instrument
swc-plugin-coverage-instrument copied to clipboard
Functions in conditionals are not included in the coverage report
This is a minimal case for reproduction
let i = 0;
const t = true && {
renderFn: () => (
i++
),
}
t.renderFn();
babel result:
...
var i = (cov_1a1nkg2pc4().s[0]++, 0);
var t = (cov_1a1nkg2pc4().s[1]++, (cov_1a1nkg2pc4().b[0][0]++, true) && (cov_1a1nkg2pc4().b[0][1]++, {
renderFn: function renderFn() {
cov_1a1nkg2pc4().f[0]++; <<< HERE
cov_1a1nkg2pc4().s[2]++;
return i++;
}
}));
cov_1a1nkg2pc4().s[3]++;
t.renderFn();
...
this plugin result:
...
cov_1387234055988355335();
cov_1387234055988355335().s[1]++;
var t = (cov_1387234055988355335().b[0][0]++, true) && (cov_1387234055988355335().b[0][1]++, {
renderFn: function() {
return i++; <<< HERE
}
});
cov_1387234055988355335().s[2]++;
t.renderFn();
...
Similar to https://github.com/kwonoj/swc-plugin-coverage-instrument/issues/224#issuecomment-1666081083, I guess there's some missing coverage. Happy to accept PR.