src/optimizer/transforms/char-class-classranges-merge-transform.js
function sortCharClass(a, b) {
  const aValue = getSortValue(a);
  const bValue = getSortValue(b);

  if (aValue === bValue) {
    // We want ClassRange before Char
    // [bb-d] -> [b-db]
    if (a.type === 'ClassRange' && b.type !== 'ClassRange') {
      return -1;
    }
    if (b.type === 'ClassRange' && a.type !== 'ClassRange') {
      return 1;
    }
    if (a.type === 'ClassRange' && b.type === 'ClassRange') {
      return getSortValue(a.to) - getSortValue(b.to);
    }
    if (
      (isMeta(a) && isMeta(b)) ||
      (isControl(a) && isControl(b))
    ) {
      return a.value < b.value ? -1 : 1;
    }
  }
  return aValue - bValue;
}
function sortCharClass(a, b) {
  const aValue = getSortValue(a);
  const bValue = getSortValue(b);

  if (aValue === bValue) {
    // We want ClassRange before Char
    // [bb-d] -> [b-db]
    if (a.type === 'ClassRange' && b.type !== 'ClassRange') {
      return -1;
    }
    if (b.type === 'ClassRange' && a.type !== 'ClassRange') {
      return 1;
    }
    if (a.type === 'ClassRange' && b.type === 'ClassRange') {
      return getSortValue(a.to) - getSortValue(b.to);
    }
    if (
      (isMeta(a) && isMeta(b)) ||
      (isControl(a) && isControl(b))
    ) {
      return a.value < b.value ? -1 : 1;
    }
  }
  return aValue - bValue;
}
Sorts expressions in char class in the following order:
- meta chars, ordered alphabetically by value
- chars (except `control` kind) and class ranges, ordered alphabetically (`from` char is used for class ranges)
- if ambiguous, class range comes before char
- if ambiguous between two class ranges, orders alphabetically by `to` char
- control chars, ordered alphabetically by value
@param {Object} a - Left Char or ClassRange node
@param {Object} b - Right Char or ClassRange node
@returns {number}