Skip to content

Commit

Permalink
fix: name of function is now preserved or named exports (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw authored and bcoe committed Aug 23, 2017
1 parent 8c2ef39 commit 2ce8974
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/istanbul-lib-instrument/src/visitor.js
Expand Up @@ -154,7 +154,9 @@ class VisitState {
// make an attempt to hoist the statement counter, so that
// function names are maintained.
const parent = path.parentPath.parentPath;
if (parent && (T.isProgram(parent.parentPath) || T.isBlockStatement(parent.parentPath))) {
if (parent && T.isExportNamedDeclaration(parent.parentPath)) {
parent.parentPath.insertBefore(T.expressionStatement(increment));
} else if (parent && (T.isProgram(parent.parentPath) || T.isBlockStatement(parent.parentPath))) {
parent.insertBefore(T.expressionStatement(
increment
));
Expand Down
9 changes: 9 additions & 0 deletions packages/istanbul-lib-instrument/test/varia.test.js
Expand Up @@ -47,6 +47,15 @@ describe('varia', function () {
assert.ok(code.match(/\/* hello */));
});

it('preserves function names for named export arrow functions', function () {
/* https://github.com/istanbuljs/babel-plugin-istanbul/issues/125 */
var v = verifier.create('export const func = () => true;', { generateOnly: true }, { esModules: true }),
code;
assert.ok(!v.err);
code = v.getGeneratedCode();
assert.ok(code.match(/cov_(.+)\.s\[\d+\]\+\+;export const func=\(\)=>/));
});

it('returns last coverage object', function (cb) {
var instrumenter = new Instrumenter({coverageVariable: '__testing_coverage__'}),
generated,
Expand Down

0 comments on commit 2ce8974

Please sign in to comment.