code: function is_ternary_op() {
      var level = 0,
        colon_count = 0,
        i;
          
      for (i = output.length - 1; i >= 0; i -= 1) {
        switch (output[i]) {
        case ':':
          if (level === 0) {
            colon_count += 1;
          }
          break;
          
        case '?':
          if (level === 0) {
            if (colon_count === 0) {
              return true;
            } else {
              colon_count -= 1;
            }
          }
          break;
          
        case '{':
          if (level === 0) {
            return false;
          }
          level -= 1;
          break;
          
        case '(':
        case '[':
          level -= 1;
          break;
          
        case ')':
        case ']':
        case '}':
          level += 1;
          break;
        }
      }
    }
docs: Walk backwards from the colon to find a '?' (colon is part of a ternary op) or a '{' (colon is part of a class literal).  Along the way, keep track of the blocks and expressions we pass so we only trigger on those chars in our own level, and keep track of the colons so we only trigger on the matching '?'.