istanbul-lib-instrument
Advanced tools
Comparing version 4.0.0-alpha.0 to 4.0.0-alpha.1
@@ -6,2 +6,32 @@ # Change Log | ||
# [4.0.0-alpha.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-instrument@4.0.0-alpha.0...istanbul-lib-instrument@4.0.0-alpha.1) (2019-10-06) | ||
### Bug Fixes | ||
* Eliminate babel hoisting of the coverage variable ([#481](https://github.com/istanbuljs/istanbuljs/issues/481)) ([8dfbcba](https://github.com/istanbuljs/istanbuljs/commit/8dfbcba)), closes [#92](https://github.com/istanbuljs/istanbuljs/issues/92) | ||
* Honor ignore hints in chained if statements ([#469](https://github.com/istanbuljs/istanbuljs/issues/469)) ([a629770](https://github.com/istanbuljs/istanbuljs/commit/a629770)), closes [#468](https://github.com/istanbuljs/istanbuljs/issues/468) | ||
* Populate lastFileCoverage for already instrumented files ([#470](https://github.com/istanbuljs/istanbuljs/issues/470)) ([ea6d779](https://github.com/istanbuljs/istanbuljs/commit/ea6d779)), closes [istanbuljs/nyc#594](https://github.com/istanbuljs/nyc/issues/594) | ||
### Features | ||
* Use @istanbuljs/schema to pull defaults ([#485](https://github.com/istanbuljs/istanbuljs/issues/485)) ([87e27f3](https://github.com/istanbuljs/istanbuljs/commit/87e27f3)), closes [#460](https://github.com/istanbuljs/istanbuljs/issues/460) | ||
### BREAKING CHANGES | ||
* The defaults for `autoWrap`, `preserveComments`, | ||
`esModules` and `produceSourceMap` are now true. This applies only to | ||
the stand-alone instrumenter, the visitor does not use these options. | ||
* The `flow` and `jsx` parser plugins are no longer | ||
enabled by default. This applies only to the stand-alone instrumenter, | ||
the visitor does not use this option. | ||
* The `plugins` option of the stand-alone instrumenter | ||
has been renamed to `parserPlugins` to match nyc. | ||
# [4.0.0-alpha.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-instrument@3.3.0...istanbul-lib-instrument@4.0.0-alpha.0) (2019-06-19) | ||
@@ -8,0 +38,0 @@ |
@@ -7,8 +7,2 @@ "use strict"; | ||
exports.createInstrumenter = createInstrumenter; | ||
Object.defineProperty(exports, "defaultOpts", { | ||
enumerable: true, | ||
get: function () { | ||
return _instrumenter.defaultOpts; | ||
} | ||
}); | ||
Object.defineProperty(exports, "programVisitor", { | ||
@@ -26,5 +20,8 @@ enumerable: true, | ||
}); | ||
exports.defaultOpts = void 0; | ||
var _instrumenter = _interopRequireWildcard(require("./instrumenter")); | ||
var _schema = require("@istanbuljs/schema"); | ||
var _instrumenter = _interopRequireDefault(require("./instrumenter")); | ||
var _visitor = _interopRequireDefault(require("./visitor")); | ||
@@ -36,4 +33,2 @@ | ||
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; } } | ||
/** | ||
@@ -47,2 +42,5 @@ * createInstrumenter creates a new instrumenter with the | ||
return new _instrumenter.default(opts); | ||
} | ||
} | ||
const defaultOpts = _schema.defaults.instrumenter; | ||
exports.defaultOpts = defaultOpts; |
@@ -6,3 +6,2 @@ "use strict"; | ||
}); | ||
exports.defaultOpts = defaultOpts; | ||
exports.default = void 0; | ||
@@ -18,8 +17,14 @@ | ||
var _schema = require("@istanbuljs/schema"); | ||
var _visitor = _interopRequireDefault(require("./visitor")); | ||
var _readCoverage = _interopRequireDefault(require("./read-coverage")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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 _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/* | ||
@@ -29,21 +34,3 @@ Copyright 2012-2015, Yahoo Inc. | ||
*/ | ||
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'] | ||
}; | ||
} | ||
/** | ||
@@ -65,9 +52,7 @@ * Instrumenter is the public API for the instrument library. | ||
* @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 = {}) { | ||
this.opts = { ...defaultOpts(), | ||
this.opts = { ..._schema.defaults.instrumenter, | ||
...opts | ||
@@ -103,3 +88,3 @@ }; | ||
sourceType: opts.esModules ? 'module' : 'script', | ||
plugins: opts.plugins | ||
plugins: opts.parserPlugins | ||
}); | ||
@@ -132,3 +117,12 @@ const ee = (0, _visitor.default)(t, filename, { | ||
const codeMap = (0, _generator.default)(ast, generateOptions, code); | ||
this.fileCoverage = output.fileCoverage; | ||
if (output && output.fileCoverage) { | ||
this.fileCoverage = output.fileCoverage; | ||
} else { | ||
const initialCoverage = (0, _readCoverage.default)(ast) || | ||
/* istanbul ignore next: paranoid check */ | ||
{}; | ||
this.fileCoverage = initialCoverage.coverageData; | ||
} | ||
this.sourceMap = codeMap.map; | ||
@@ -135,0 +129,0 @@ const cb = this.opts.sourceMapUrlCallback; |
@@ -14,11 +14,18 @@ "use strict"; | ||
var _schema = require("@istanbuljs/schema"); | ||
var _constants = require("./constants"); | ||
var _instrumenter = require("./instrumenter"); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
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 _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function readInitialCoverage(code) { | ||
function getAst(code) { | ||
if (typeof code === 'object' && typeof code.type === 'string') { | ||
// Assume code is already a babel ast. | ||
return code; | ||
} | ||
if (typeof code !== 'string') { | ||
@@ -29,3 +36,3 @@ throw new Error('Code must be a string'); | ||
const ast = (0, _parser.parse)(code, { | ||
return (0, _parser.parse)(code, { | ||
allowImportExportEverywhere: true, | ||
@@ -35,4 +42,8 @@ allowReturnOutsideFunction: true, | ||
sourceType: 'script', | ||
plugins: (0, _instrumenter.defaultOpts)().plugins | ||
plugins: _schema.defaults.instrumenter.parserPlugins | ||
}); | ||
} | ||
function readInitialCoverage(code) { | ||
const ast = getAst(code); | ||
let covScope; | ||
@@ -83,3 +94,4 @@ (0, _traverse.default)(ast, { | ||
delete result.coverageData[_constants.MAGIC_KEY]; | ||
delete result.coverageData.hash; | ||
return result; | ||
} |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _schema = require("@istanbuljs/schema"); | ||
var _sourceCoverage = require("./source-coverage"); | ||
@@ -17,4 +19,2 @@ | ||
var _instrumenter = require("./instrumenter"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -40,2 +40,3 @@ | ||
this.varName = genVar(sourceFilePath); | ||
this.varCalled = false; | ||
this.attrs = {}; | ||
@@ -177,3 +178,4 @@ this.nextIgnore = null; | ||
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))); | ||
this.varCalled = true; | ||
return T.updateExpression('++', wrap(T.memberExpression(T.memberExpression(T.callExpression(T.identifier(this.varName), []), T.identifier(type)), T.numericLiteral(id), true))); | ||
} | ||
@@ -371,2 +373,4 @@ | ||
path.node.loc = path.node.body[0].loc; | ||
path.node.body[0].leadingComments = path.node.leadingComments; | ||
path.node.leadingComments = undefined; | ||
} | ||
@@ -548,3 +552,3 @@ } | ||
const coverageTemplate = (0, _template.default)(` | ||
var COVERAGE_VAR = (function () { | ||
function COVERAGE_FUNCTION () { | ||
var path = PATH; | ||
@@ -556,7 +560,13 @@ var hash = HASH; | ||
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; | ||
})(); | ||
var actualCoverage = coverage[path]; | ||
COVERAGE_FUNCTION = function () { | ||
return actualCoverage; | ||
} | ||
return actualCoverage; | ||
} | ||
`); // the rewire plugin (and potentially other babel middleware) | ||
@@ -575,6 +585,2 @@ // may cause files to be instrumented twice, see: | ||
} | ||
const defaultProgramVisitorOpts = { | ||
inputSourceMap: undefined | ||
}; | ||
/** | ||
@@ -604,7 +610,6 @@ * programVisitor is a `babel` adaptor for instrumentation. | ||
function programVisitor(types, sourceFilePath = 'unknown.js', opts = defaultProgramVisitorOpts) { | ||
const T = types; // This sets some unused options but ensures all required options are initialized | ||
opts = { ...(0, _instrumenter.defaultOpts)(), | ||
...defaultProgramVisitorOpts, | ||
function programVisitor(types, sourceFilePath = 'unknown.js', opts = {}) { | ||
const T = types; | ||
opts = { ..._schema.defaults.instrumentVisitor, | ||
...opts | ||
@@ -668,8 +673,12 @@ }; | ||
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 if this file has no coverage | ||
if (!visitState.varCalled) { | ||
path.node.body.unshift(T.expressionStatement(T.callExpression(T.identifier(visitState.varName), []))); | ||
} | ||
path.node.body.unshift(cv); | ||
@@ -676,0 +685,0 @@ return { |
{ | ||
"name": "istanbul-lib-instrument", | ||
"version": "4.0.0-alpha.0", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Core istanbul API for JS code coverage", | ||
@@ -16,21 +16,22 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>", | ||
"dependencies": { | ||
"@babel/generator": "^7.4.4", | ||
"@babel/parser": "^7.4.5", | ||
"@babel/template": "^7.4.4", | ||
"@babel/traverse": "^7.4.5", | ||
"@babel/types": "^7.4.4", | ||
"istanbul-lib-coverage": "^3.0.0-alpha.0", | ||
"semver": "^6.1.1" | ||
"@babel/generator": "^7.6.2", | ||
"@babel/parser": "^7.6.2", | ||
"@babel/template": "^7.6.0", | ||
"@babel/traverse": "^7.6.2", | ||
"@babel/types": "^7.6.1", | ||
"@istanbuljs/schema": "^0.1.0", | ||
"istanbul-lib-coverage": "^3.0.0-alpha.1", | ||
"semver": "^6.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"@babel/register": "^7.4.4", | ||
"@babel/cli": "^7.6.2", | ||
"@babel/core": "^7.6.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.6.0", | ||
"@babel/register": "^7.6.2", | ||
"chai": "^4.2.0", | ||
"clone": "^2.1.2", | ||
"debug": "^4.1.1", | ||
"documentation": "^11.0.1", | ||
"documentation": "^12.1.2", | ||
"js-yaml": "^3.13.1", | ||
"mocha": "^6.1.4", | ||
"mocha": "^6.2.1", | ||
"nopt": "^4.0.1", | ||
@@ -46,3 +47,4 @@ "nyc": "^14.1.1" | ||
"type": "git", | ||
"url": "git@github.com:istanbuljs/istanbuljs.git" | ||
"url": "git+ssh://git@github.com/istanbuljs/istanbuljs.git", | ||
"directory": "packages/istanbul-lib-instrument" | ||
}, | ||
@@ -58,3 +60,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "2e885073a9398806c9b8763dd39418398182ca34" | ||
"gitHead": "4d5e777a9bc4847d178ad31f379307124cdd1e4f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57817
917
8
+ Added@istanbuljs/schema@^0.1.0
+ Added@istanbuljs/schema@0.1.3(transitive)
Updated@babel/generator@^7.6.2
Updated@babel/parser@^7.6.2
Updated@babel/template@^7.6.0
Updated@babel/traverse@^7.6.2
Updated@babel/types@^7.6.1
Updatedsemver@^6.3.0