aboutsummaryrefslogtreecommitdiff
path: root/node_modules/istanbul-lib-instrument/dist/visitor.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/istanbul-lib-instrument/dist/visitor.js')
-rw-r--r--node_modules/istanbul-lib-instrument/dist/visitor.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/node_modules/istanbul-lib-instrument/dist/visitor.js b/node_modules/istanbul-lib-instrument/dist/visitor.js
index c1308b24c..55a616848 100644
--- a/node_modules/istanbul-lib-instrument/dist/visitor.js
+++ b/node_modules/istanbul-lib-instrument/dist/visitor.js
@@ -8,6 +8,8 @@ var _createClass = function () { function defineProperties(target, props) { for
var _sourceCoverage = require('./source-coverage');
+var _constants = require('./constants');
+
var _crypto = require('crypto');
var _babelTemplate = require('babel-template');
@@ -18,8 +20,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-// function to use for creating hashes
-var SHA = 'sha1';
// istanbul ignore comment pattern
var COMMENT_RE = /^\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/;
// source map URL pattern
@@ -27,7 +27,7 @@ var SOURCE_MAP_RE = /[#@]\s*sourceMappingURL=(.*)\s*$/m;
// generate a variable name from hashing the supplied file path
function genVar(filename) {
- var hash = (0, _crypto.createHash)(SHA);
+ var hash = (0, _crypto.createHash)(_constants.SHA);
hash.update(filename);
return 'cov_' + parseInt(hash.digest('hex').substr(0, 12), 16).toString(36);
}
@@ -486,8 +486,8 @@ var coverageTemplate = (0, _babelTemplate2.default)('\n var COVERAGE_VAR = (f
* @param {string} [opts.coverageVariable=__coverage__] the global coverage variable name.
*/
function programVisitor(types) {
- var sourceFilePath = arguments.length <= 1 || arguments[1] === undefined ? 'unknown.js' : arguments[1];
- var opts = arguments.length <= 2 || arguments[2] === undefined ? { coverageVariable: '__coverage__' } : arguments[2];
+ var sourceFilePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknown.js';
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { coverageVariable: '__coverage__' };
var T = types;
var visitState = new VisitState(types, sourceFilePath);
@@ -498,8 +498,10 @@ function programVisitor(types) {
exit: function exit(path) {
visitState.cov.freeze();
var coverageData = visitState.cov.toJSON();
- var hash = (0, _crypto.createHash)(SHA).update(JSON.stringify(coverageData)).digest('hex');
+ coverageData[_constants.MAGIC_KEY] = _constants.MAGIC_VALUE;
+ var hash = (0, _crypto.createHash)(_constants.SHA).update(JSON.stringify(coverageData)).digest('hex');
var coverageNode = T.valueToNode(coverageData);
+ delete coverageData[_constants.MAGIC_KEY];
var cv = coverageTemplate({
GLOBAL_COVERAGE_VAR: T.stringLiteral(opts.coverageVariable),
COVERAGE_VAR: T.identifier(visitState.varName),
@@ -507,6 +509,7 @@ function programVisitor(types) {
INITIAL: coverageNode,
HASH: T.stringLiteral(hash)
});
+ cv._blockHoist = 3;
path.node.body.unshift(cv);
return {
fileCoverage: coverageData,