Skip to content

Instantly share code, notes, and snippets.

@gotwarlost
Last active June 21, 2016 11:24
Show Gist options
  • Save gotwarlost/e203dff7e14bb8234fb8c48db5a61d7a to your computer and use it in GitHub Desktop.
Save gotwarlost/e203dff7e14bb8234fb8c48db5a61d7a to your computer and use it in GitHub Desktop.
import {realpathSync} from 'fs';
import {programVisitor} from 'istanbul-lib-instrument';
function getRealpath(n) {
try {
return realpathSync(n) || n
} catch (e) {
return n
}
}
function shouldSkip(file) {
return false;
}
function makeVisitor({types: t}) {
return {
visitor: {
Program: {
enter(path) {
this.__dv__ = null;
const realPath = getRealpath(this.file.opts.filename);
if (shouldSkip(realPath)) {
return;
}
this.__dv__ = programVisitor(t, realPath);
this.__dv__.enter(path);
},
exit(path) {
if (!this.__dv__) {
return;
}
this.__dv__.exit(path);
}
}
}
};
}
export default makeVisitor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment