index.js
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fs = require('fs');
var _path = require('path');
var _istanbulLibInstrument = require('istanbul-lib-instrument');
var _objectAssign = require('object-assign');
var _objectAssign2 = _interopRequireDefault(_objectAssign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var testExclude = require('test-exclude');
var findUp = require('find-up');
function getRealpath(n) {
try {
return (0, _fs.realpathSync)(n) || n;
} catch (e) {
return n;
}
}
function makeShouldSkip() {
var exclude = void 0;
return function shouldSkip(file, opts) {
if (!exclude) {
var cwd = getRealpath(process.env.NYC_CWD || process.cwd());
exclude = testExclude((0, _objectAssign2.default)({ cwd: cwd }, Object.keys(opts).length > 0 ? opts : {
configKey: 'nyc',
configPath: (0, _path.dirname)(findUp.sync('package.json', { cwd: cwd }))
}));
}
return !exclude.shouldInstrument(file);
};
}
function makeVisitor(_ref) {
var t = _ref.types;
var shouldSkip = makeShouldSkip();
return {
visitor: {
Program: {
enter: function enter(path) {
this.__dv__ = null;
var realPath = getRealpath(this.file.opts.filename);
if (shouldSkip(realPath, this.opts)) {
return;
}
var inputSourceMap = this.opts.inputSourceMap;
if (this.opts.useInlineSourceMaps !== false) {
inputSourceMap = inputSourceMap || this.file.opts.inputSourceMap;
}
this.__dv__ = (0, _istanbulLibInstrument.programVisitor)(t, realPath, {
coverageVariable: '__coverage__',
inputSourceMap: inputSourceMap
});
this.__dv__.enter(path);
},
exit: function exit(path) {
if (!this.__dv__) {
return;
}
this.__dv__.exit(path);
}
}
}
};
}
exports.default = makeVisitor;