Updating NPM dependencies
This commit is contained in:
66
node_modules/istanbul-lib-instrument/dist/visitor.js
generated
vendored
66
node_modules/istanbul-lib-instrument/dist/visitor.js
generated
vendored
@@ -7,16 +7,14 @@ exports.default = void 0;
|
||||
|
||||
var _crypto = require("crypto");
|
||||
|
||||
var _template = _interopRequireDefault(require("@babel/template"));
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var _schema = require("@istanbuljs/schema");
|
||||
|
||||
var _sourceCoverage = require("./source-coverage");
|
||||
|
||||
var _constants = require("./constants");
|
||||
|
||||
var _instrumenter = require("./instrumenter");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// pattern for istanbul to ignore a section
|
||||
const COMMENT_RE = /^\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/; // pattern for istanbul to ignore the whole file
|
||||
|
||||
@@ -171,7 +169,7 @@ class VisitState {
|
||||
const T = this.types;
|
||||
const wrap = index !== null ? // If `index` present, turn `x` into `x[index]`.
|
||||
x => T.memberExpression(x, T.numericLiteral(index), true) : x => x;
|
||||
return T.updateExpression('++', wrap(T.memberExpression(T.memberExpression(T.identifier(this.varName), T.identifier(type)), T.numericLiteral(id), true)));
|
||||
return T.updateExpression('++', wrap(T.memberExpression(T.memberExpression(T.callExpression(T.identifier(this.varName), []), T.identifier(type)), T.numericLiteral(id), true)));
|
||||
}
|
||||
|
||||
insertCounter(path, increment) {
|
||||
@@ -308,7 +306,7 @@ class VisitState {
|
||||
|
||||
function entries(...enter) {
|
||||
// the enter function
|
||||
const wrappedEntry = function wrappedEntry(path, node) {
|
||||
const wrappedEntry = function (path, node) {
|
||||
this.onEnter(path);
|
||||
|
||||
if (this.shouldIgnore(path)) {
|
||||
@@ -320,7 +318,7 @@ function entries(...enter) {
|
||||
});
|
||||
};
|
||||
|
||||
const exit = function exit(path, node) {
|
||||
const exit = function (path, node) {
|
||||
this.onExit(path, node);
|
||||
};
|
||||
|
||||
@@ -364,6 +362,8 @@ function makeBlock(path) {
|
||||
if (!path.isBlockStatement()) {
|
||||
path.replaceWith(T.blockStatement([path.node]));
|
||||
path.node.loc = path.node.body[0].loc;
|
||||
path.node.body[0].leadingComments = path.node.leadingComments;
|
||||
path.node.leadingComments = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,31 +528,42 @@ const codeVisitor = {
|
||||
ConditionalExpression: entries(coverTernary),
|
||||
LogicalExpression: entries(coverLogicalExpression)
|
||||
};
|
||||
const globalTemplateAlteredFunction = (0, _template.default)(`
|
||||
const globalTemplateAlteredFunction = (0, _core.template)(`
|
||||
var Function = (function(){}).constructor;
|
||||
var global = (new Function(GLOBAL_COVERAGE_SCOPE))();
|
||||
`);
|
||||
const globalTemplateFunction = (0, _template.default)(`
|
||||
const globalTemplateFunction = (0, _core.template)(`
|
||||
var global = (new Function(GLOBAL_COVERAGE_SCOPE))();
|
||||
`);
|
||||
const globalTemplateVariable = (0, _template.default)(`
|
||||
const globalTemplateVariable = (0, _core.template)(`
|
||||
var global = GLOBAL_COVERAGE_SCOPE;
|
||||
`); // the template to insert at the top of the program.
|
||||
|
||||
const coverageTemplate = (0, _template.default)(`
|
||||
var COVERAGE_VAR = (function () {
|
||||
const coverageTemplate = (0, _core.template)(`
|
||||
function COVERAGE_FUNCTION () {
|
||||
var path = PATH;
|
||||
var hash = HASH;
|
||||
GLOBAL_COVERAGE_TEMPLATE
|
||||
var gcv = GLOBAL_COVERAGE_VAR;
|
||||
var coverageData = INITIAL;
|
||||
var coverage = global[gcv] || (global[gcv] = {});
|
||||
if (coverage[path] && coverage[path].hash === hash) {
|
||||
return coverage[path];
|
||||
if (!coverage[path] || coverage[path].hash !== hash) {
|
||||
coverage[path] = coverageData;
|
||||
}
|
||||
return coverage[path] = coverageData;
|
||||
})();
|
||||
`); // the rewire plugin (and potentially other babel middleware)
|
||||
|
||||
var actualCoverage = coverage[path];
|
||||
{
|
||||
// @ts-ignore
|
||||
COVERAGE_FUNCTION = function () {
|
||||
return actualCoverage;
|
||||
}
|
||||
}
|
||||
|
||||
return actualCoverage;
|
||||
}
|
||||
`, {
|
||||
preserveComments: true
|
||||
}); // the rewire plugin (and potentially other babel middleware)
|
||||
// may cause files to be instrumented twice, see:
|
||||
// https://github.com/istanbuljs/babel-plugin-istanbul/issues/94
|
||||
// we should only instrument code for coverage the first time
|
||||
@@ -565,10 +576,6 @@ function alreadyInstrumented(path, visitState) {
|
||||
function shouldIgnoreFile(programNode) {
|
||||
return programNode.parent && programNode.parent.comments.some(c => COMMENT_FILE_RE.test(c.value));
|
||||
}
|
||||
|
||||
const defaultProgramVisitorOpts = {
|
||||
inputSourceMap: undefined
|
||||
};
|
||||
/**
|
||||
* programVisitor is a `babel` adaptor for instrumentation.
|
||||
* It returns an object with two methods `enter` and `exit`.
|
||||
@@ -593,10 +600,12 @@ const defaultProgramVisitorOpts = {
|
||||
* original code.
|
||||
*/
|
||||
|
||||
function programVisitor(types, sourceFilePath = 'unknown.js', opts = defaultProgramVisitorOpts) {
|
||||
const T = types; // This sets some unused options but ensures all required options are initialized
|
||||
|
||||
opts = Object.assign({}, (0, _instrumenter.defaultOpts)(), defaultProgramVisitorOpts, opts);
|
||||
function programVisitor(types, sourceFilePath = 'unknown.js', opts = {}) {
|
||||
const T = types;
|
||||
opts = { ..._schema.defaults.instrumentVisitor,
|
||||
...opts
|
||||
};
|
||||
const visitState = new VisitState(types, sourceFilePath, opts.inputSourceMap, opts.ignoreClassMethods);
|
||||
return {
|
||||
enter(path) {
|
||||
@@ -653,12 +662,13 @@ function programVisitor(types, sourceFilePath = 'unknown.js', opts = defaultProg
|
||||
const cv = coverageTemplate({
|
||||
GLOBAL_COVERAGE_VAR: T.stringLiteral(opts.coverageVariable),
|
||||
GLOBAL_COVERAGE_TEMPLATE: gvTemplate,
|
||||
COVERAGE_VAR: T.identifier(visitState.varName),
|
||||
COVERAGE_FUNCTION: T.identifier(visitState.varName),
|
||||
PATH: T.stringLiteral(sourceFilePath),
|
||||
INITIAL: coverageNode,
|
||||
HASH: T.stringLiteral(hash)
|
||||
});
|
||||
cv._blockHoist = 5;
|
||||
}); // explicitly call this.varName to ensure coverage is always initialized
|
||||
|
||||
path.node.body.unshift(T.expressionStatement(T.callExpression(T.identifier(visitState.varName), [])));
|
||||
path.node.body.unshift(cv);
|
||||
return {
|
||||
fileCoverage: coverageData,
|
||||
|
||||
Reference in New Issue
Block a user