Updating NPM dependencies
This commit is contained in:
138
node_modules/istanbul-lib-instrument/dist/instrumenter.js
generated
vendored
138
node_modules/istanbul-lib-instrument/dist/instrumenter.js
generated
vendored
@@ -3,46 +3,23 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaultOpts = defaultOpts;
|
||||
exports.default = void 0;
|
||||
|
||||
var parser = _interopRequireWildcard(require("@babel/parser"));
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
||||
|
||||
var _generator = _interopRequireDefault(require("@babel/generator"));
|
||||
var _schema = require("@istanbuljs/schema");
|
||||
|
||||
var _visitor = _interopRequireDefault(require("./visitor"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _readCoverage = _interopRequireDefault(require("./read-coverage"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/*
|
||||
Copyright 2012-2015, Yahoo Inc.
|
||||
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
||||
*/
|
||||
function defaultOpts() {
|
||||
return {
|
||||
coverageVariable: '__coverage__',
|
||||
coverageGlobalScope: 'this',
|
||||
coverageGlobalScopeFunc: true,
|
||||
preserveComments: false,
|
||||
compact: true,
|
||||
esModules: false,
|
||||
autoWrap: false,
|
||||
produceSourceMap: false,
|
||||
ignoreClassMethods: [],
|
||||
sourceMapUrlCallback: null,
|
||||
debug: false,
|
||||
|
||||
/* babel parser plugins are to be enabled when the feature is stage 3 and
|
||||
* implemented in a released version of node.js */
|
||||
plugins: ['asyncGenerators', 'bigInt', 'classProperties', 'classPrivateProperties', 'dynamicImport', 'importMeta', 'objectRestSpread', 'optionalCatchBinding', 'flow', 'jsx']
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Instrumenter is the public API for the instrument library.
|
||||
* It is typically used for ES5 code. For ES6 code that you
|
||||
@@ -59,36 +36,16 @@ function defaultOpts() {
|
||||
* @param {Function} [opts.sourceMapUrlCallback=null] a callback function that is called when a source map URL
|
||||
* is found in the original code. This function is called with the source file name and the source map URL.
|
||||
* @param {boolean} [opts.debug=false] - turn debugging on
|
||||
* @param {array} [opts.plugins=['asyncGenerators','dynamicImport','objectRestSpread','optionalCatchBinding','flow','jsx']] - set plugins
|
||||
* @param {array} [opts.parserPlugins] - set babel parser plugins, see @istanbuljs/schema for defaults.
|
||||
*/
|
||||
|
||||
|
||||
class Instrumenter {
|
||||
constructor(opts = defaultOpts()) {
|
||||
this.opts = this.normalizeOpts(opts);
|
||||
constructor(opts = {}) {
|
||||
this.opts = { ..._schema.defaults.instrumenter,
|
||||
...opts
|
||||
};
|
||||
this.fileCoverage = null;
|
||||
this.sourceMap = null;
|
||||
}
|
||||
/**
|
||||
* normalize options passed in and assign defaults.
|
||||
* @param opts
|
||||
* @private
|
||||
*/
|
||||
|
||||
|
||||
normalizeOpts(opts) {
|
||||
const normalize = (name, defaultValue) => {
|
||||
if (!opts.hasOwnProperty(name)) {
|
||||
opts[name] = defaultValue;
|
||||
}
|
||||
};
|
||||
|
||||
const defOpts = defaultOpts();
|
||||
Object.keys(defOpts).forEach(k => {
|
||||
normalize(k, defOpts[k]);
|
||||
});
|
||||
return opts;
|
||||
}
|
||||
/**
|
||||
* instrument the supplied code and track coverage against the supplied
|
||||
* filename. It throws if invalid code is passed to it. ES5 and ES6 syntax
|
||||
@@ -110,38 +67,59 @@ class Instrumenter {
|
||||
}
|
||||
|
||||
filename = filename || String(new Date().getTime()) + '.js';
|
||||
const opts = this.opts;
|
||||
const ast = parser.parse(code, {
|
||||
allowReturnOutsideFunction: opts.autoWrap,
|
||||
sourceType: opts.esModules ? 'module' : 'script',
|
||||
plugins: opts.plugins
|
||||
});
|
||||
const ee = (0, _visitor.default)(t, filename, {
|
||||
coverageVariable: opts.coverageVariable,
|
||||
coverageGlobalScope: opts.coverageGlobalScope,
|
||||
coverageGlobalScopeFunc: opts.coverageGlobalScopeFunc,
|
||||
ignoreClassMethods: opts.ignoreClassMethods,
|
||||
inputSourceMap
|
||||
});
|
||||
const {
|
||||
opts
|
||||
} = this;
|
||||
let output = {};
|
||||
const visitor = {
|
||||
Program: {
|
||||
enter: ee.enter,
|
||||
|
||||
exit(path) {
|
||||
output = ee.exit(path);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
(0, _traverse.default)(ast, visitor);
|
||||
const generateOptions = {
|
||||
const babelOpts = {
|
||||
configFile: false,
|
||||
babelrc: false,
|
||||
ast: true,
|
||||
filename: filename || String(new Date().getTime()) + '.js',
|
||||
inputSourceMap,
|
||||
sourceMaps: opts.produceSourceMap,
|
||||
compact: opts.compact,
|
||||
comments: opts.preserveComments,
|
||||
sourceMaps: opts.produceSourceMap,
|
||||
sourceFileName: filename
|
||||
parserOpts: {
|
||||
allowReturnOutsideFunction: opts.autoWrap,
|
||||
sourceType: opts.esModules ? 'module' : 'script',
|
||||
plugins: opts.parserPlugins
|
||||
},
|
||||
plugins: [[({
|
||||
types
|
||||
}) => {
|
||||
const ee = (0, _visitor.default)(types, filename, {
|
||||
coverageVariable: opts.coverageVariable,
|
||||
coverageGlobalScope: opts.coverageGlobalScope,
|
||||
coverageGlobalScopeFunc: opts.coverageGlobalScopeFunc,
|
||||
ignoreClassMethods: opts.ignoreClassMethods,
|
||||
inputSourceMap
|
||||
});
|
||||
return {
|
||||
visitor: {
|
||||
Program: {
|
||||
enter: ee.enter,
|
||||
|
||||
exit(path) {
|
||||
output = ee.exit(path);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}]]
|
||||
};
|
||||
const codeMap = (0, _generator.default)(ast, generateOptions, code);
|
||||
const codeMap = (0, _core.transformSync)(code, babelOpts);
|
||||
|
||||
if (!output || !output.fileCoverage) {
|
||||
const initialCoverage = (0, _readCoverage.default)(codeMap.ast) ||
|
||||
/* istanbul ignore next: paranoid check */
|
||||
{};
|
||||
this.fileCoverage = initialCoverage.coverageData;
|
||||
this.sourceMap = inputSourceMap;
|
||||
return code;
|
||||
}
|
||||
|
||||
this.fileCoverage = output.fileCoverage;
|
||||
this.sourceMap = codeMap.map;
|
||||
const cb = this.opts.sourceMapUrlCallback;
|
||||
|
||||
Reference in New Issue
Block a user