function tokenIndexOfUnescaped(stream, searchValue) {
    // comparing to the alternative of stream.current().match(searchValueRegex),
    // this implementation avoids a substring creation and regex match
    const searchEndIdxExclusive = stream.pos;
    const tokenStartIdx = stream.start;
    let searchStartIdx = stream.start;
    while (searchStartIdx < searchEndIdxExclusive) {
      const candidate = stream.string.indexOf(searchValue, searchStartIdx);
      if (candidate < 0 || candidate >= searchEndIdxExclusive) {
        return -1;
      }
      // ensure it's not an escaped one
      if (candidate === tokenStartIdx // candidate is the start of the token, it is not escaped
      || !tokenIsCharEscaped(stream, candidate)) {
        // case find a match
        return candidate - tokenStartIdx;
      }
      // else case an escaped ${, continue to search
      searchStartIdx = candidate + searchValue.length;
    }
    return -1; // reach beyond token boundary
  }
Return the index of searchValue within the current token, i.e., stream.current(),
excluding those prefixed with escape. E.g., if searchValue is "${", it will ignore
those string with the pattern of "\${", as the dollar sign is escaped.

The returned index is relative to the token, rather than the entire stream.