code: function compareScopes(a, b, compareNext) {
      if (a.scope === b.scope) return compareNext(a, b);
  
      // if `scope` comparison returns `0` (equal), we'll use the secondary
      // comparer (which might also have a secondary comparer).
      function next(c) {
          return c === 0 // || c === null
              ? compareNext ? compareNext(a, b) : c
              : c;
      }
  
      // compareBy returns either -1, 0, 1 or null. If null is returned,
      // neither of a and b has the specified scope, so we move on to test
      // the next scope.
  
      // possible scope values: undefined, global, static, instance, inner
      let c;
      c = compareBy('scope', undefined, a, b); // module scopes are undefined
      if (c !== null) return next(c);
      c = compareBy('scope', 'global', a, b);
      if (c !== null) return next(c);
      c = compareBy('scope', 'static', a, b);
      if (c !== null) return next(c);
      c = compareBy('scope', 'instance', a, b);
      if (c !== null) return next(c);
      c = compareBy('scope', 'inner', a, b);
      return next(c);
  }
docs: const aLevels = utils.getLevels(a); const bLevels = utils.getLevels(b); if (aLevels > bLevels) return 1; if (aLevels < bLevels) return -1; return compareNext ? compareNext(a, b) : 0; }