Generate a substitution for the class or id selector

@param token Token
@param substitutionPattern string
@param substitutions {{string: string[]}}
@returns {string}
552782
function generateSubstitution(token, substitutionPattern, substitutions) {
  var substitution = substitutionPattern.replace(/{([^}]+)}/ig, (all, group)=> {
    switch (group) {
      case 'namespace':
        return token.namespace;
      case 'name':
        return token.className;
      case 'random':
        return 'r' + Math.random().toString(36).substring(7);
      case 'hash':
        return 'h' + (token.hash + 0.0).toString(36);
      case 'unique':
        return 'u' + (++uniqueCounter);
    }
  });

  substitutions[token.className] = [];
  substitutions[token.className].push(substitution);
  return substitution;
}
370453
private Collection<TokenPattern> getOrCreatePatterns(final String patternCode) {
        // first try the cheapest get(..) method
        final Collection<TokenPattern> patterns = _patterns.get(patternCode);
        if (patterns != null) {
            return patterns;
        }

        // then try the concurrent version which requires a collection
        final Collection<TokenPattern> newPatterns = new ArrayList<>(3);
        final Collection<TokenPattern> existingPatterns = _patterns.putIfAbsent(patternCode, newPatterns);
        if (existingPatterns == null) {
            return newPatterns;
        }
        return existingPatterns;
    }
163518
String getPattern() {
        final StringBuilder result = new StringBuilder();

        if (myPrefix != null) {
            result.append(myPrefix);
        }
        if (mySuffixes != null) {
            result.append("*");
            for (final Literal sub : mySuffixes) {
                result.append(sub);
                result.append("*");
            }
        }
        if (myPostfix != null) {
            result.append(myPostfix);
        }
        return result.toString();
    }
1104556
public PatternTokenBuilder csToken(String token) {
    this.token = Objects.requireNonNull(token);
    caseSensitive = true;
    return this;
  }
275322
function getTypeFromArrayBindingPattern(pattern, includePatternInType, reportErrors) {
            var elements = pattern.elements;
            if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
                return languageVersion >= 2 /* ES6 */ ? createIterableType(anyType) : anyArrayType;
            }
            // If the pattern has at least one element, and no rest element, then it should imply a tuple type.
            var elementTypes = ts.map(elements, function (e) { return e.kind === 193 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors); });
            var result = createTupleType(elementTypes);
            if (includePatternInType) {
                result = cloneTypeReference(result);
                result.pattern = pattern;
            }
            return result;
        }
1167657
public final List<SequenceLabel> getSequencesFromSpans(final String[] tokens,
      final Span[] seqSpans) {
    final List<SequenceLabel> sequences = new ArrayList<SequenceLabel>();
    for (final Span seqSpan : seqSpans) {
      final String seqString = seqSpan.getCoveredText(tokens);
      final String seqType = seqSpan.getType();
      final SequenceLabel sequence = this.sequenceFactory
          .createSequence(seqString, seqType, seqSpan);
      sequences.add(sequence);
    }
    return sequences;
  }
912557
public Expression2 substitute(int index, Expression2 newExpression) {
    Preconditions.checkArgument(index < size);
    if (index == 0) {
      return newExpression;
    } else {
      int[] parts = findSubexpression(index);
      
      Expression2 substituted = subexpressions.get(parts[0]).substitute(parts[1], newExpression);
      List<Expression2> newSubexpressions = Lists.newArrayList(subexpressions);
      newSubexpressions.set(parts[0], substituted);
      return Expression2.nested(newSubexpressions);
    }
  }
455113
private void addTokens(final Token curToken, final List<Token> tokens) {
    if (curToken.tokenLength() != 0) {
      if (this.unTokenizable) {
        tokens.add(curToken);
      } else if (!this.unTokenizable) {
        if (!replacement.matcher(curToken.getTokenValue()).matches()) {
          tokens.add(curToken);
        }
      }
    }
  }
487702
function tokensId(tokens, prepend) {
    if (!prepend) return null;

    return _.reduce(tokens, function(prev, token) {
        var tokId = [
            token.index,
            token.offset,
            token.value
        ].join('-');

        return [prev, tokId].join(':');
    }, prepend);
}
590633
function make_regex(tokens) {
	var str = tokens.reduce(function (res, token, index) {
			var is_last = (index == (tokens.length - 1));
			var before_multi = (index === (tokens.length - 2)) && (last(tokens).type == "multi");
			return res + ((is_last || before_multi) ? token.last : token.piece);
		},
		"");
	return new RegExp("^" + str + "$");
}
985227
function(selector) {
        var token = {},     // one token per simple selector (left selector holds combinator)
            tokens = [],    // array of tokens
            id,             // unique id for the simple selector (if found)
            found = false,  // whether or not any matches were found this pass
            patterns = Y.Selector._patterns,
            match;          // the regex match

        selector = Y.Selector._replaceShorthand(selector); // convert ID and CLASS shortcuts to attributes

        /*
            Search for selector patterns, store, and strip them from the selector string
            until no patterns match (invalid selector) or we run out of chars.

            Multiple attributes and pseudos are allowed, in any order.
            for example:
                'form:first-child[type=button]:not(button)[lang|=en]'
        */
        do {
            found = false; // reset after full pass
            for (var re in patterns) {
                if (YAHOO.lang.hasOwnProperty(patterns, re)) {
                    if (re != 'tag' && re != 'combinator') { // only one allowed
                        token[re] = token[re] || [];
                    }
                    if ( (match = patterns[re].exec(selector)) ) { // note assignment
                        found = true;
                        if (re != 'tag' && re != 'combinator') { // only one allowed
                            // capture ID for fast path to element
                            if (re === 'attributes' && match[1] === 'id') {
                                token.id = match[3];
                            }

                            token[re].push(match.slice(1));
                        } else { // single selector (tag, combinator)
                            token[re] = match[1];
                        }
                        selector = selector.replace(match[0], ''); // strip current match from selector
                        if (re === 'combinator' || !selector.length) { // next token or done
                            token.attributes = Y.Selector._fixAttributes(token.attributes);
                            token.pseudos = token.pseudos || [];
                            token.tag = token.tag ? token.tag.toUpperCase() : '*';
                            tokens.push(token);

                            token = { // prep next token
                                previous: token
                            };
                        }
                    }
                }
            }
        } while (found);

        return tokens;
    }
1201791
public static Map<String, Object> convertMutationTokenToMap(MutationToken mutationToken) {
    Map<String, Object> result = null;
    if (mutationToken != null) {
      result = new HashMap<String, Object>();
      result.put("vbucketID", mutationToken.vbucketID());
      result.put("vbucketUUID", mutationToken.vbucketUUID());
      result.put("sequenceNumber", mutationToken.sequenceNumber());
      result.put("bucket", mutationToken.bucket());
    }
    return result;
  }
797439
function attemptReplacePatterns(token, replacements, measureThreshold) {
  var replacement = null;

  for(var i = 0; i < replacements.length; i++) {
    if(!measureThreshold || measure(attemptReplace(token, replacements[i][0], '')) > measureThreshold)
      replacement = attemptReplace(token, replacements[i][0], replacements[i][1]);

    if(replacement)
      break;
  }

  return replacement;
}
387731
@Override
	public String substituteProps(String str, SubstitutionTransformer transformer) {
		if (str == null) {
			return null;
		}
		StringBuffer buf = new StringBuffer();
		Matcher matcher = pattern.matcher(str);
		while ( matcher.find() ) {
			String propName = matcher.group(1);
			String propValue = getPropValue(propName);
			if (propValue != null) {
				if (transformer != null) {
					propValue = transformer.transform(propName, propValue);
				}
				matcher.appendReplacement(
						buf,
						propValue
						.replace("\\", "\\\\") //$NON-NLS-1$ //$NON-NLS-2$
						.replace("$", "\\$")  //$NON-NLS-1$ //$NON-NLS-2$
						);
			} else {
				matcher.appendReplacement(buf, "\\${"+propName+"}"); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
		matcher.appendTail(buf);
		return buf.toString();
	}
1200592
private void replaceArrayPattern(
      NodeTraversal t, Node arrayPattern, Node rhs, Node parent, Node nodeToDetach) {

    if (rewriteMode == ObjectDestructuringRewriteMode.REWRITE_OBJECT_REST) {
      if (patternNestingStack.isEmpty() || !patternNestingStack.peekLast().hasNestedObjectRest) {
        return;
      }
    }

    String tempVarName = getTempVariableName();
    Node makeIteratorCall = astFactory.createJSCompMakeIteratorCall(rhs.detach(), t.getScope());
    Node tempVarModel = astFactory.createName(tempVarName, makeIteratorCall.getJSType());
    Node tempDecl = IR.var(tempVarModel.cloneNode(), makeIteratorCall);
    tempDecl.useSourceInfoIfMissingFromForTree(arrayPattern);
    nodeToDetach.getParent().addChildBefore(tempDecl, nodeToDetach);

    for (Node child = arrayPattern.getFirstChild(), next; child != null; child = next) {
      next = child.getNext();
      if (child.isEmpty()) {
        // Just call the next() method to advance the iterator, but throw away the value.
        Node nextCall =
            IR.exprResult(
                astFactory.createCall(astFactory.createGetProp(tempVarModel.cloneNode(), "next")));
        nextCall.useSourceInfoIfMissingFromForTree(child);
        nodeToDetach.getParent().addChildBefore(nextCall, nodeToDetach);
        continue;
      }

      Node newLHS;
      Node newRHS;
      if (child.isDefaultValue()) {
        //   [x = defaultValue] = rhs;
        // becomes
        //   var temp0 = $jscomp.makeIterator(rhs);
        //   var temp1 = temp.next().value
        //   x = (temp1 === undefined) ? defaultValue : temp1;
        String nextVarName = getTempVariableName();
        // `temp.next().value`
        Node nextCallDotValue =
            astFactory.createGetProp(
                astFactory.createCall(astFactory.createGetProp(tempVarModel.cloneNode(), "next")),
                "value");
        JSType nextVarType = nextCallDotValue.getJSType();
        // `var temp1 = temp.next().value`
        Node var = IR.var(astFactory.createName(nextVarName, nextVarType), nextCallDotValue);
        var.useSourceInfoIfMissingFromForTree(child);
        nodeToDetach.getParent().addChildBefore(var, nodeToDetach);

        // `x`
        newLHS = child.getFirstChild().detach();
        // `(temp1 === undefined) ? defaultValue : temp1;
        newRHS =
            defaultValueHook(
                astFactory.createName(nextVarName, nextVarType), child.getLastChild().detach());
      } else if (child.isRest()) {
        //   [...x] = rhs;
        // becomes
        //   var temp = $jscomp.makeIterator(rhs);
        //   x = $jscomp.arrayFromIterator(temp);
        newLHS = child.getFirstChild().detach();
        newRHS =
            astFactory.createJscompArrayFromIteratorCall(tempVarModel.cloneNode(), t.getScope());
      } else {
        // LHS is just a name (or a nested pattern).
        //   var [x] = rhs;
        // becomes
        //   var temp = $jscomp.makeIterator(rhs);
        //   var x = temp.next().value;
        newLHS = child.detach();
        newRHS =
            astFactory.createGetProp(
                astFactory.createCall(astFactory.createGetProp(tempVarModel.cloneNode(), "next")),
                "value");
      }
      Node newNode;
      if (parent.isAssign()) {
        Node assignment = astFactory.createAssign(newLHS, newRHS);
        newNode = IR.exprResult(assignment);
      } else {
        newNode = IR.declaration(newLHS, newRHS, parent.getToken());
      }
      newNode.useSourceInfoIfMissingFromForTree(arrayPattern);

      nodeToDetach.getParent().addChildBefore(newNode, nodeToDetach);
      // Explicitly visit the LHS of the new node since it may be a nested
      // destructuring pattern.
      visit(t, newLHS, newLHS.getParent());
    }

    nodeToDetach.detach();
    t.reportCodeChange();
  }
60318
private void parseLiteral(String token) {
        Matcher m = Pattern.compile(String.format(ESCAPED_LITERAL_PATTERN_TEMPLATE, escapeCharacter)).matcher(token);
        while (m.find()) {
            cleanedToken = trimSpecialCharacters(m.group(1));
            if (tokenHasContent()) {
                mergedTokens.add(new LiteralToken(cleanedToken));
            }
        }
    }
1137999
function createRegExpForIgnorePatterns(normalizedOptions) {
    Object.keys(normalizedOptions).forEach(key => {
        const ignorePatternStr = normalizedOptions[key].ignorePattern;

        if (ignorePatternStr) {
            const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`, "u");

            normalizedOptions[key].ignorePatternRegExp = regExp;
        }
    });
}