Skip to content

Commit

Permalink
fix: update instrument, account for lack of arrow expression (#119) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tswaters authored and bcoe committed Feb 13, 2018
1 parent 968152e commit 0968206
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/istanbul-lib-instrument/src/visitor.js
Expand Up @@ -343,9 +343,11 @@ function parenthesizedExpressionProp(prop) {
function convertArrowExpression(path) {
const n = path.node;
const T = this.types;
if (n.expression) {
if (!T.isBlockStatement(n.body)) {
const bloc = n.body.loc;
n.expression = false;
if (n.expression === true) {
n.expression = false;
}
n.body = T.blockStatement([
T.returnStatement(
n.body
Expand Down
42 changes: 42 additions & 0 deletions packages/istanbul-lib-instrument/test/specs/arrow-fn.yaml
Expand Up @@ -19,6 +19,27 @@ tests:
statements: {'0': 1, '1': 1, '2': 0}
functions: {'0': 0}

---
name: es6 arrow function expression - multiple args
guard: isArrowFnAvailable
code: |
var input = args
output = input.reduce((memo, item) => memo + item, 0)
tests:
- name: function called
args: [1, 2, 3, 4]
out: 10
lines: {'1': 1, '2': 4}
statements: {'0': 1, '1': 1, '2': 4}
functions: {'0': 4}

- name: function not called
args: []
out: 0
lines: {'1': 1, '2': 1}
statements: {'0': 1, '1': 1, '2': 0}
functions: {'0': 0}

---
name: es6 arrow function block
guard: isArrowFnAvailable
Expand All @@ -40,6 +61,27 @@ tests:
statements: {'0': 1, '1': 1, '2': 0}
functions: {'0': 0}

---
name: es6 arrow function block - multiple args
guard: isArrowFnAvailable
code: |
var input = args
output = input.reduce((memo, item) => { return memo + item }, 0)
tests:
- name: function called
args: [1, 2, 3, 4]
out: 10
lines: {'1': 1, '2': 4}
statements: {'0': 1, '1': 1, '2': 4}
functions: {'0': 4}

- name: function not called
args: []
out: 0
lines: {'1': 1, '2': 1}
statements: {'0': 1, '1': 1, '2': 0}
functions: {'0': 0}

---
name: complex arrow fn
guard: isArrowFnAvailable
Expand Down

0 comments on commit 0968206

Please sign in to comment.