Skip to content

Commit

Permalink
feat: add support for optional catch binding (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 31, 2018
1 parent 53f6710 commit 088dd9f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/istanbul-lib-instrument/src/instrumenter.js
Expand Up @@ -87,6 +87,7 @@ class Instrumenter {
'asyncGenerators',
'dynamicImport',
'objectRestSpread',
'optionalCatchBinding',
'flow',
'jsx'
]
Expand Down
1 change: 1 addition & 0 deletions packages/istanbul-lib-instrument/src/read-coverage.js
Expand Up @@ -18,6 +18,7 @@ export default function readInitialCoverage (code) {
'asyncGenerators',
'dynamicImport',
'objectRestSpread',
'optionalCatchBinding',
'flow',
'jsx'
]
Expand Down
26 changes: 26 additions & 0 deletions packages/istanbul-lib-instrument/test/specs/try.yaml
Expand Up @@ -23,3 +23,29 @@ tests:
lines: {'1': 1, '2': 1, '3': 0, '5': 1, '7': 1}
branches: {'0': [1, 0]}
statements: {'0': 1, '1': 1, '2': 1, '3': 0, '4': 1, '5': 1}
---
name: optional catch binding
guard: isOptionalCatchBindingAvailable
code: |
try {
if (args[0] === "X") { throw "foo"; }
output = args[0];
} catch {
output="Y";
} finally {
output += 1;
}
tests:
- name: happy path
args: [1]
out: 2
lines: {'1': 1, '2': 1, '3': 1, '5': 0, '7': 1}
branches: {'0': [0, 1]}
statements: {'0': 1, '1': 1, '2': 0, '3': 1, '4': 0, '5': 1}

- name: sad path
args: [X]
out: Y1
lines: {'1': 1, '2': 1, '3': 0, '5': 1, '7': 1}
branches: {'0': [1, 0]}
statements: {'0': 1, '1': 1, '2': 1, '3': 0, '4': 1, '5': 1}
4 changes: 4 additions & 0 deletions packages/istanbul-lib-instrument/test/util/guards.js
Expand Up @@ -42,6 +42,10 @@ export function isObjectFreezeAvailable() {
}
}

export function isOptionalCatchBindingAvailable () {
return tryThis('try {} catch {}');
}

export function isImportAvailable() {
return tryThis('import fs from "fs"', 'import', true);
}
Expand Down

0 comments on commit 088dd9f

Please sign in to comment.