normalize.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const compare_1 = require("./compare");
  4. const range_tree_1 = require("./range-tree");
  5. /**
  6. * Normalizes a process coverage.
  7. *
  8. * Sorts the scripts alphabetically by `url`.
  9. * Reassigns script ids: the script at index `0` receives `"0"`, the script at
  10. * index `1` receives `"1"` etc.
  11. * This does not normalize the script coverages.
  12. *
  13. * @param processCov Process coverage to normalize.
  14. */
  15. function normalizeProcessCov(processCov) {
  16. processCov.result.sort(compare_1.compareScriptCovs);
  17. for (const [scriptId, scriptCov] of processCov.result.entries()) {
  18. scriptCov.scriptId = scriptId.toString(10);
  19. }
  20. }
  21. exports.normalizeProcessCov = normalizeProcessCov;
  22. /**
  23. * Normalizes a process coverage deeply.
  24. *
  25. * Normalizes the script coverages deeply, then normalizes the process coverage
  26. * itself.
  27. *
  28. * @param processCov Process coverage to normalize.
  29. */
  30. function deepNormalizeProcessCov(processCov) {
  31. for (const scriptCov of processCov.result) {
  32. deepNormalizeScriptCov(scriptCov);
  33. }
  34. normalizeProcessCov(processCov);
  35. }
  36. exports.deepNormalizeProcessCov = deepNormalizeProcessCov;
  37. /**
  38. * Normalizes a script coverage.
  39. *
  40. * Sorts the function by root range (pre-order sort).
  41. * This does not normalize the function coverages.
  42. *
  43. * @param scriptCov Script coverage to normalize.
  44. */
  45. function normalizeScriptCov(scriptCov) {
  46. scriptCov.functions.sort(compare_1.compareFunctionCovs);
  47. }
  48. exports.normalizeScriptCov = normalizeScriptCov;
  49. /**
  50. * Normalizes a script coverage deeply.
  51. *
  52. * Normalizes the function coverages deeply, then normalizes the script coverage
  53. * itself.
  54. *
  55. * @param scriptCov Script coverage to normalize.
  56. */
  57. function deepNormalizeScriptCov(scriptCov) {
  58. for (const funcCov of scriptCov.functions) {
  59. normalizeFunctionCov(funcCov);
  60. }
  61. normalizeScriptCov(scriptCov);
  62. }
  63. exports.deepNormalizeScriptCov = deepNormalizeScriptCov;
  64. /**
  65. * Normalizes a function coverage.
  66. *
  67. * Sorts the ranges (pre-order sort).
  68. * TODO: Tree-based normalization of the ranges.
  69. *
  70. * @param funcCov Function coverage to normalize.
  71. */
  72. function normalizeFunctionCov(funcCov) {
  73. funcCov.ranges.sort(compare_1.compareRangeCovs);
  74. const tree = range_tree_1.RangeTree.fromSortedRanges(funcCov.ranges);
  75. normalizeRangeTree(tree);
  76. funcCov.ranges = tree.toRanges();
  77. }
  78. exports.normalizeFunctionCov = normalizeFunctionCov;
  79. /**
  80. * @internal
  81. */
  82. function normalizeRangeTree(tree) {
  83. tree.normalize();
  84. }
  85. exports.normalizeRangeTree = normalizeRangeTree;
  86. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMvbm9ybWFsaXplLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsdUNBQXFGO0FBQ3JGLDZDQUF5QztBQUd6Qzs7Ozs7Ozs7O0dBU0c7QUFDSCxTQUFnQixtQkFBbUIsQ0FBQyxVQUFzQjtJQUN4RCxVQUFVLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQywyQkFBaUIsQ0FBQyxDQUFDO0lBQzFDLEtBQUssTUFBTSxDQUFDLFFBQVEsRUFBRSxTQUFTLENBQUMsSUFBSSxVQUFVLENBQUMsTUFBTSxDQUFDLE9BQU8sRUFBRSxFQUFFO1FBQy9ELFNBQVMsQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQztLQUM1QztBQUNILENBQUM7QUFMRCxrREFLQztBQUVEOzs7Ozs7O0dBT0c7QUFDSCxTQUFnQix1QkFBdUIsQ0FBQyxVQUFzQjtJQUM1RCxLQUFLLE1BQU0sU0FBUyxJQUFJLFVBQVUsQ0FBQyxNQUFNLEVBQUU7UU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