Skip to content

Commit

Permalink
fix: function declaration assignment now retains function name (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze authored and bcoe committed Dec 27, 2016
1 parent 52b94d2 commit 2d781da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/visitor.js
Expand Up @@ -189,6 +189,12 @@ class VisitState {
end: { line: n.loc.start.line, column: n.loc.start.column + 1 }
};
}
if (!n.id) {
const decl = path.find(node => node.isVariableDeclarator());
if (decl) {
n.id = decl.get('id').node;
}
}
const name = path.node.id ? path.node.id.name : path.node.name;
const index = this.cov.newFunction(name, dloc, path.node.body.loc);
const increment = this.increase('f', index, null);
Expand Down
12 changes: 12 additions & 0 deletions test/specs/functions.yaml
Expand Up @@ -95,3 +95,15 @@ tests:
branches: {'0': [0, 1]}
functions: {'0': 1, '1': 1}
statements: {'0': 1, '1': 1, '2': 1 }

---
name: function declaration assignment name
code: |
const foo = function() {}
output = foo.name;
tests:
- name: properly sets function name
out: 'foo'
lines: {'1': 1, '2': 1}
functions: {'0': 0}
statements: {'0': 1, '1': 1}

0 comments on commit 2d781da

Please sign in to comment.