Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esnext-coverage-analytics

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esnext-coverage-analytics - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

94

dist/codec.js

@@ -6,10 +6,14 @@ 'use strict';

});
exports.encode = encode;
exports.encodeAll = encodeAll;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.encodeLocation = encodeLocation;
exports.decodeLocation = decodeLocation;
exports.encodeToken = encodeToken;
exports.decodeToken = decodeToken;
exports.decode = decode;
exports.decodeAll = decodeAll;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var tagMapping = ['statement', // 0
var locationTagMapping = ['statement', // 0
'expression', // 1

@@ -25,2 +29,9 @@ 'function', // 2

var tokenTypeMapping = ['keyword', // 0
'comment', // 1
'name', // 2
'string', // 3
'other' // 4
];
/**

@@ -31,3 +42,3 @@ * Encodes a decoded coverage location.

*/
function encode(_ref) {
function encodeLocation(_ref) {
var _ref$count = _ref.count,

@@ -39,3 +50,3 @@ count = _ref$count === undefined ? 0 : _ref$count,

return [count, loc.start.column, loc.start.line, loc.end.column, loc.end.line].concat(_toConsumableArray(tags.map(function (tag) {
return tagMapping.indexOf(tag);
return locationTagMapping.indexOf(tag);
})));

@@ -45,21 +56,8 @@ }

/**
* Encodes a list of decoded coverage locations.
* @param {Array<Object>} locations - List of decoded locations.
* @return {Array<Array>} List of encoded locations.
*/
function encodeAll(locations) {
return locations.map(function (location, index) {
var encodedLocation = encode(location);
encodedLocation.id = index;
return encodedLocation;
});
}
/**
* Decodes an encoded coverage location.
* @param {Array<Number>} location - Encoded location.
* @param {Number} index - Index of location used as location id.
* @return {Array<Number>} Encoded location.
* @return {Array<Number>} Decoded location.
*/
function decode(location, index) {
function decodeLocation(location, index) {
return {

@@ -73,3 +71,3 @@ id: index,

tags: location.slice(5).map(function (tagId) {
return tagMapping[tagId];
return locationTagMapping[tagId];
})

@@ -80,8 +78,52 @@ };

/**
* Encodes a simplified token.
* @param {Object} token - Simplified token.
* @return {Array<Number>} Encoded token.
*/
function encodeToken(_ref2) {
var type = _ref2.type,
loc = _ref2.loc;
return [loc.start.column, loc.start.line, loc.end.column, loc.end.line, tokenTypeMapping.indexOf(type)];
}
/**
* Decodes an encoded simplified token.
* @param {Array<Number>} token - Encoded token.
* @return {Object} Decoded token.
*/
function decodeToken(_ref3) {
var _ref4 = _slicedToArray(_ref3, 5),
startColumn = _ref4[0],
startLine = _ref4[1],
endColumn = _ref4[2],
endLine = _ref4[3],
typeId = _ref4[4];
return {
type: tokenTypeMapping[typeId],
loc: {
start: { column: startColumn, line: startLine },
end: { column: endColumn, line: endLine }
}
};
}
/**
* Decodes a list of encoded coverage locations.
* @param {Array<Array>} locations - List of encoded locations.
* @return {Array<Object>} List of decoded locations.
* @param {Array<Array>} coverage - Encoded coverage.
* @return {Object} Decoded coverage.
*/
function decodeAll(locations) {
return locations.map(decode);
function decode(_ref5) {
var _ref6 = _slicedToArray(_ref5, 3),
_ref6$ = _ref6[0],
locations = _ref6$ === undefined ? [] : _ref6$,
_ref6$2 = _ref6[1],
tokens = _ref6$2 === undefined ? [] : _ref6$2,
_ref6$3 = _ref6[2],
stack = _ref6$3 === undefined ? [] : _ref6$3;
locations = locations.map(decodeLocation);
tokens = tokens.map(decodeToken);
return { locations: locations, tokens: tokens, stack: stack };
}

@@ -20,7 +20,7 @@ 'use strict';

*
* @param {Array<Array>} locations – Encoded coverage data locations.
* @param {Array<Array>} coverage – Encoded coverage data.
* @param {Array} rules – List of rules.
* @returns {Object} New coverage data.
*/
function filter(locations, rules) {
function filter(coverage, rules) {
var map = {};

@@ -38,3 +38,3 @@ var index = {};

return (0, _codec.decodeAll)(locations).filter(function (location) {
return (0, _codec.decode)(coverage).locations.filter(function (location) {
var tags = location.tags;

@@ -41,0 +41,0 @@

@@ -25,9 +25,9 @@ 'use strict';

* Compute line coverage given a list of instrumented locations.
* @param {Array<Array>} locations – Encoded coverage data locations.
* @param {Array<Array>} coverage – Encoded coverage data.
* @returns {Array} Array of line data.
*/
function lines(locations) {
function lines(coverage) {
var lineExecCount = {};
(0, _codec.decodeAll)(locations).filter(isLine).forEach(function (entry) {
(0, _codec.decode)(coverage).locations.filter(isLine).forEach(function (entry) {
var line = entry.loc.start.line;

@@ -43,4 +43,4 @@ if (Object.hasOwnProperty.call(lineExecCount, line)) {

var count = lineExecCount[line];
return { line, count };
return { line: line, count: count };
});
}

@@ -9,3 +9,3 @@ "use strict";

* Compute coverage metrics from the given locations.
* @param {Array<Array>} locations – Encoded coverage data locations.
* @param {Array<Array>} locations – Decoded coverage data locations.
* @return {Object} Metrics.

@@ -19,3 +19,3 @@ */

}, 0);
return { covered, total };
return { covered: covered, total: total };
}

@@ -12,7 +12,7 @@ 'use strict';

* Generate a tag index from coverage data.
* @param {Array<Array>} locations – Encoded coverage data locations.
* @param {Array<Array>} coverage – Encoded coverage data.
* @param {Array} [tagsToSelect] – List of tags to get data for.
* @returns {Object} Locations grouped by tag.
*/
function coverageByTag(locations, tagsToSelect) {
function coverageByTag(coverage, tagsToSelect) {
var tagIndex = {};

@@ -24,3 +24,3 @@ if (tagsToSelect) {

}
(0, _codec.decodeAll)(locations).forEach(function (location) {
(0, _codec.decode)(coverage).locations.forEach(function (location) {
location.tags.forEach(function (tag) {

@@ -27,0 +27,0 @@ if (Object.hasOwnProperty.call(tagIndex, tag)) {

{
"name": "esnext-coverage-analytics",
"version": "0.0.5",
"version": "0.0.6",
"description": "Analytics package for esnext-coverage",

@@ -28,6 +28,7 @@ "main": "dist/index.js",

"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-env": "^1.1.1",
"babel-cli": "^6.24.1",
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
"babel-preset-env": "^1.4.0",
"chai": "^3.5.0",
"eslint": "^3.12.1",
"eslint": "^3.19.0",
"eslint-config-meetic": "^4.0.0",

@@ -34,0 +35,0 @@ "mocha": "^3.2.0"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc