src/language-js/embed.js
function replacePlaceholders(quasisDoc, expressionDocs) {
  if (!expressionDocs || !expressionDocs.length) {
    return quasisDoc;
  }

  const expressions = expressionDocs.slice();
  let replaceCounter = 0;
  const newDoc = mapDoc(quasisDoc, doc => {
    if (!doc || !doc.parts || !doc.parts.length) {
      return doc;
    }
    let parts = doc.parts;
    const atIndex = parts.indexOf("@");
    const placeholderIndex = atIndex + 1;
    if (
      atIndex > -1 &&
      typeof parts[placeholderIndex] === "string" &&
      parts[placeholderIndex].startsWith("prettier-placeholder")
    ) {
      // If placeholder is split, join it
      const at = parts[atIndex];
      const placeholder = parts[placeholderIndex];
      const rest = parts.slice(placeholderIndex + 1);
      parts = parts
        .slice(0, atIndex)
        .concat([at + placeholder])
        .concat(rest);
    }
    const atPlaceholderIndex = parts.findIndex(
      part =>
        typeof part === "string" && part.startsWith("@prettier-placeholder")
    );
    if (atPlaceholderIndex > -1) {
      const placeholder = parts[atPlaceholderIndex];
      const rest = parts.slice(atPlaceholderIndex + 1);
      const placeholderMatch = placeholder.match(
        /@prettier-placeholder-(.+)-id([\s\S]*)/
      );
      const placeholderID = placeholderMatch[1];
      // When the expression has a suffix appended, like:
      // animation: linear ${time}s ease-out;
      const suffix = placeholderMatch[2];
      const expression = expressions[placeholderID];

      replaceCounter++;
      parts = parts
        .slice(0, atPlaceholderIndex)
        .concat(["${", expression, "}" + suffix])
        .concat(rest);
    }
    return Object.assign({}, doc, {
      parts: parts
    });
  });

  return expressions.length === replaceCounter ? newDoc : null;
}
function replacePlaceholders(quasisDoc, expressionDocs) {
  if (!expressionDocs || !expressionDocs.length) {
    return quasisDoc;
  }

  const expressions = expressionDocs.slice();
  let replaceCounter = 0;
  const newDoc = mapDoc(quasisDoc, doc => {
    if (!doc || !doc.parts || !doc.parts.length) {
      return doc;
    }
    let parts = doc.parts;
    const atIndex = parts.indexOf("@");
    const placeholderIndex = atIndex + 1;
    if (
      atIndex > -1 &&
      typeof parts[placeholderIndex] === "string" &&
      parts[placeholderIndex].startsWith("prettier-placeholder")
    ) {
      // If placeholder is split, join it
      const at = parts[atIndex];
      const placeholder = parts[placeholderIndex];
      const rest = parts.slice(placeholderIndex + 1);
      parts = parts
        .slice(0, atIndex)
        .concat([at + placeholder])
        .concat(rest);
    }
    const atPlaceholderIndex = parts.findIndex(
      part =>
        typeof part === "string" && part.startsWith("@prettier-placeholder")
    );
    if (atPlaceholderIndex > -1) {
      const placeholder = parts[atPlaceholderIndex];
      const rest = parts.slice(atPlaceholderIndex + 1);
      const placeholderMatch = placeholder.match(
        /@prettier-placeholder-(.+)-id([\s\S]*)/
      );
      const placeholderID = placeholderMatch[1];
      // When the expression has a suffix appended, like:
      // animation: linear ${time}s ease-out;
      const suffix = placeholderMatch[2];
      const expression = expressions[placeholderID];

      replaceCounter++;
      parts = parts
        .slice(0, atPlaceholderIndex)
        .concat(["${", expression, "}" + suffix])
        .concat(rest);
    }
    return Object.assign({}, doc, {
      parts: parts
    });
  });

  return expressions.length === replaceCounter ? newDoc : null;
}
function replacePlaceholders ( quasisDoc , expressionDocs ) { if ( ! expressionDocs || ! expressionDocs . length ) { return quasisDoc ; } const expressions = expressionDocs . slice ( ) ; let replaceCounter = 0 ; const newDoc = mapDoc ( quasisDoc , doc => { if ( ! doc || ! doc . parts || ! doc . parts . length ) { return doc ; } let parts = doc . parts ; const atIndex = parts . indexOf ( "@" ) ; const placeholderIndex = atIndex + 1 ; if ( atIndex > - 1 && typeof parts [ placeholderIndex ] === "string" && parts [ placeholderIndex ] . startsWith ( "prettier-placeholder" ) ) { // If placeholder is split, join it const at = parts [ atIndex ] ; const placeholder = parts [ placeholderIndex ] ; const rest = parts . slice ( placeholderIndex + 1 ) ; parts = parts . slice ( 0 , atIndex ) . concat ( [ at + placeholder ] ) . concat ( rest ) ; } const atPlaceholderIndex = parts . findIndex ( part => typeof part === "string" && part . startsWith ( "@prettier-placeholder" ) ) ; if ( atPlaceholderIndex > - 1 ) { const placeholder = parts [ atPlaceholderIndex ] ; const rest = parts . slice ( atPlaceholderIndex + 1 ) ; const placeholderMatch = placeholder . match ( / @prettier-placeholder-(.+)-id([\s\S]*) / ) ; const placeholderID = placeholderMatch [ 1 ] ; // When the expression has a suffix appended, like: // animation: linear ${time}s ease-out; const suffix = placeholderMatch [ 2 ] ; const expression = expressions [ placeholderID ] ; replaceCounter ++ ; parts = parts . slice ( 0 , atPlaceholderIndex ) . concat ( [ "${" , expression , "}" + suffix ] ) . concat ( rest ) ; } return Object . assign ( { } , doc , { parts : parts } ) ; } ) ; return expressions . length === replaceCounter ? newDoc : null ; }
Search all the placeholders in the quasisDoc tree and replace them with the expression docs one by one returns a new doc with all the placeholders replaced, or null if it couldn't replace any expression
Search all the placeholders in the quasisDoc tree and replace them with the expression docs one by one returns a new doc with all the placeholders replaced or null if it couldn t replace any expression