clone.js 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * Creates a deep copy of a process coverage.
  5. *
  6. * @param processCov Process coverage to clone.
  7. * @return Cloned process coverage.
  8. */
  9. function cloneProcessCov(processCov) {
  10. const result = [];
  11. for (const scriptCov of processCov.result) {
  12. result.push(cloneScriptCov(scriptCov));
  13. }
  14. return {
  15. result,
  16. };
  17. }
  18. exports.cloneProcessCov = cloneProcessCov;
  19. /**
  20. * Creates a deep copy of a script coverage.
  21. *
  22. * @param scriptCov Script coverage to clone.
  23. * @return Cloned script coverage.
  24. */
  25. function cloneScriptCov(scriptCov) {
  26. const functions = [];
  27. for (const functionCov of scriptCov.functions) {
  28. functions.push(cloneFunctionCov(functionCov));
  29. }
  30. return {
  31. scriptId: scriptCov.scriptId,
  32. url: scriptCov.url,
  33. functions,
  34. };
  35. }
  36. exports.cloneScriptCov = cloneScriptCov;
  37. /**
  38. * Creates a deep copy of a function coverage.
  39. *
  40. * @param functionCov Function coverage to clone.
  41. * @return Cloned function coverage.
  42. */
  43. function cloneFunctionCov(functionCov) {
  44. const ranges = [];
  45. for (const rangeCov of functionCov.ranges) {
  46. ranges.push(cloneRangeCov(rangeCov));
  47. }
  48. return {
  49. functionName: functionCov.functionName,
  50. ranges,
  51. isBlockCoverage: functionCov.isBlockCoverage,
  52. };
  53. }
  54. exports.cloneFunctionCov = cloneFunctionCov;
  55. /**
  56. * Creates a deep copy of a function coverage.
  57. *
  58. * @param rangeCov Range coverage to clone.
  59. * @return Cloned range coverage.
  60. */
  61. function cloneRangeCov(rangeCov) {
  62. return {
  63. startOffset: rangeCov.startOffset,
  64. endOffset: rangeCov.endOffset,
  65. count: rangeCov.count,
  66. };
  67. }
  68. exports.cloneRangeCov = cloneRangeCov;
  69. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2Vz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