challenge-algorithms-v2.0-u.../node_modules/@bcoe/v8-coverage/dist/lib/normalize.js

88 lines
7.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const compare_1 = require("./compare");
const range_tree_1 = require("./range-tree");
/**
* Normalizes a process coverage.
*
* Sorts the scripts alphabetically by `url`.
* Reassigns script ids: the script at index `0` receives `"0"`, the script at
* index `1` receives `"1"` etc.
* This does not normalize the script coverages.
*
* @param processCov Process coverage to normalize.
*/
function normalizeProcessCov(processCov) {
processCov.result.sort(compare_1.compareScriptCovs);
for (const [scriptId, scriptCov] of processCov.result.entries()) {
scriptCov.scriptId = scriptId.toString(10);
}
}
exports.normalizeProcessCov = normalizeProcessCov;
/**
* Normalizes a process coverage deeply.
*
* Normalizes the script coverages deeply, then normalizes the process coverage
* itself.
*
* @param processCov Process coverage to normalize.
*/
function deepNormalizeProcessCov(processCov) {
for (const scriptCov of processCov.result) {
deepNormalizeScriptCov(scriptCov);
}
normalizeProcessCov(processCov);
}
exports.deepNormalizeProcessCov = deepNormalizeProcessCov;
/**
* Normalizes a script coverage.
*
* Sorts the function by root range (pre-order sort).
* This does not normalize the function coverages.
*
* @param scriptCov Script coverage to normalize.
*/
function normalizeScriptCov(scriptCov) {
scriptCov.functions.sort(compare_1.compareFunctionCovs);
}
exports.normalizeScriptCov = normalizeScriptCov;
/**
* Normalizes a script coverage deeply.
*
* Normalizes the function coverages deeply, then normalizes the script coverage
* itself.
*
* @param scriptCov Script coverage to normalize.
*/
function deepNormalizeScriptCov(scriptCov) {
for (const funcCov of scriptCov.functions) {
normalizeFunctionCov(funcCov);
}
normalizeScriptCov(scriptCov);
}
exports.deepNormalizeScriptCov = deepNormalizeScriptCov;
/**
* Normalizes a function coverage.
*
* Sorts the ranges (pre-order sort).
* TODO: Tree-based normalization of the ranges.
*
* @param funcCov Function coverage to normalize.
*/
function normalizeFunctionCov(funcCov) {
funcCov.ranges.sort(compare_1.compareRangeCovs);
const tree = range_tree_1.RangeTree.fromSortedRanges(funcCov.ranges);
normalizeRangeTree(tree);
funcCov.ranges = tree.toRanges();
}
exports.normalizeFunctionCov = normalizeFunctionCov;
/**
* @internal
*/
function normalizeRangeTree(tree) {
tree.normalize();
}
exports.normalizeRangeTree = normalizeRangeTree;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMvbm9ybWFsaXplLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsdUNBQXFGO0FBQ3JGLDZDQUF5QztBQUd6Qzs7Ozs7Ozs7O0dBU0c7QUFDSCxTQUFnQixtQkFBbUIsQ0FBQyxVQUFzQjtJQUN4RCxVQUFVLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQywyQkFBaUIsQ0FBQyxDQUFDO0lBQzFDLEtBQUssTUFBTSxDQUFDLFFBQVEsRUFBRSxTQUFTLENBQUMsSUFBSSxVQUFVLENBQUMsTUFBTSxDQUFDLE9BQU8sRUFBRSxFQUFFO1FBQy9ELFNBQVMsQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQztLQUM1QztBQUNILENBQUM7QUFMRCxrREFLQztBQUVEOzs7Ozs7O0dBT0c7QUFDSCxTQUFnQix1QkFBdUIsQ0FBQyxVQUFzQjtJQUM1RCxLQUFLLE1BQU0sU0FBUyxJQUFJLFVBQVUsQ0FBQyxNQUFNLEVBQUU7UUFDekMsc0JBQXNCLENBQUMsU0FBUyxDQUFDLENBQUM7S0FDbkM7SUFDRCxtQkFBbUIsQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUNsQyxDQUFDO0FBTEQsMERBS0M7QUFFRDs7Ozs7OztHQU9HO0FBQ0gsU0FBZ0Isa0JBQWtCLENBQUMsU0FBb0I7SUFDckQsU0FBUyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsNkJBQW1CLENBQUMsQ0FBQztBQUNoRC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