compare.mjs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Compares two script coverages.
  3. *
  4. * The result corresponds to the comparison of their `url` value (alphabetical sort).
  5. */
  6. export function compareScriptCovs(a, b) {
  7. if (a.url === b.url) {
  8. return 0;
  9. }
  10. else if (a.url < b.url) {
  11. return -1;
  12. }
  13. else {
  14. return 1;
  15. }
  16. }
  17. /**
  18. * Compares two function coverages.
  19. *
  20. * The result corresponds to the comparison of the root ranges.
  21. */
  22. export function compareFunctionCovs(a, b) {
  23. return compareRangeCovs(a.ranges[0], b.ranges[0]);
  24. }
  25. /**
  26. * Compares two range coverages.
  27. *
  28. * The ranges are first ordered by ascending `startOffset` and then by
  29. * descending `endOffset`.
  30. * This corresponds to a pre-order tree traversal.
  31. */
  32. export function compareRangeCovs(a, b) {
  33. if (a.startOffset !== b.startOffset) {
  34. return a.startOffset - b.startOffset;
  35. }
  36. else {
  37. return b.endOffset - a.endOffset;
  38. }
  39. }
  40. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMvY29tcGFyZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7OztHQUlHO0FBQ0gsTUFBTSxVQUFVLGlCQUFpQixDQUFDLENBQXNCLEVBQUUsQ0FBc0I7SUFDOUUsSUFBSSxDQUFDLENBQUMsR0FBRyxLQUFLLENBQUMsQ0FBQyxHQUFHLEVBQUU7UUFDbkIsT0FBTyxDQUFDLENBQUM7S0FDVjtTQUFNLElBQUksQ0FBQyxDQUFDLEdBQUcsR0FBRyxDQUFDLENBQUMsR0FBRyxFQUFFO1FBQ3hCLE9BQU8sQ0FBQyxDQUFDLENBQUM7S0FDWDtTQUFNO1FBQ0wsT0FBTyxDQUFDLENBQUM7S0FDVjtBQUNILENBQUM7QUFFRDs7OztHQUlHO0FBQ0gsTUFBTSxVQUFVLG1CQUFtQixDQUFDLENBQXdCLEVBQUUsQ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