index.js
function trimCommonWhitespaceFromLines (
  templateStrings,
  {
    trimEolAtStart = false,
    trimEolAtEnd = false
  } = {}) {
  // Find a common prefix to remove
  const commonPrefix = commonPrefixOfTemplateStrings(templateStrings)

  let prefixPattern = null
  if (commonPrefix) {
    // commonPrefix contains no RegExp metacharacters since it only contains
    // whitespace.
    prefixPattern = new RegExp(
      `(${LINE_TERMINATORS.source})${commonPrefix}`, 'g')
  } else if (trimEolAtStart || trimEolAtEnd) {
    // We don't need to remove a prefix, but we might need to do some
    // post processing, so just use a prefix pattern that never matches.
    prefixPattern = /(?!)/
  } else {
    // Fast path.
    return templateStrings
  }

  const { raw, length } = templateStrings

  // Apply slice so that raw is in the same realm as the tag function.
  const trimmedRaw = Array.prototype.slice.apply(raw).map(
    (chunk) => chunk.replace(prefixPattern, '$1'))
  if (trimEolAtStart) {
    trimmedRaw[0] = trimmedRaw[0].replace(LINE_TERMINATOR_AT_START, '')
  }
  if (trimEolAtEnd) {
    trimmedRaw[length - 1] = trimmedRaw[length - 1]
      .replace(LINE_TERMINATOR_AT_END, '')
  }
  const trimmedCooked = trimmedRaw.map(cook)

  trimmedCooked.raw = trimmedRaw
  Object.freeze(trimmedRaw)
  Object.freeze(trimmedCooked)
  return trimmedCooked
}
function trimCommonWhitespaceFromLines (
  templateStrings,
  {
    trimEolAtStart = false,
    trimEolAtEnd = false
  } = {}) {
  // Find a common prefix to remove
  const commonPrefix = commonPrefixOfTemplateStrings(templateStrings)

  let prefixPattern = null
  if (commonPrefix) {
    // commonPrefix contains no RegExp metacharacters since it only contains
    // whitespace.
    prefixPattern = new RegExp(
      `(${LINE_TERMINATORS.source})${commonPrefix}`, 'g')
  } else if (trimEolAtStart || trimEolAtEnd) {
    // We don't need to remove a prefix, but we might need to do some
    // post processing, so just use a prefix pattern that never matches.
    prefixPattern = /(?!)/
  } else {
    // Fast path.
    return templateStrings
  }

  const { raw, length } = templateStrings

  // Apply slice so that raw is in the same realm as the tag function.
  const trimmedRaw = Array.prototype.slice.apply(raw).map(
    (chunk) => chunk.replace(prefixPattern, '$1'))
  if (trimEolAtStart) {
    trimmedRaw[0] = trimmedRaw[0].replace(LINE_TERMINATOR_AT_START, '')
  }
  if (trimEolAtEnd) {
    trimmedRaw[length - 1] = trimmedRaw[length - 1]
      .replace(LINE_TERMINATOR_AT_END, '')
  }
  const trimmedCooked = trimmedRaw.map(cook)

  trimmedCooked.raw = trimmedRaw
  Object.freeze(trimmedRaw)
  Object.freeze(trimmedCooked)
  return trimmedCooked
}
function trimCommonWhitespaceFromLines ( templateStrings , { trimEolAtStart = false , trimEolAtEnd = false } = { } ) { // Find a common prefix to remove const commonPrefix = commonPrefixOfTemplateStrings ( templateStrings ) let prefixPattern = null if ( commonPrefix ) { // commonPrefix contains no RegExp metacharacters since it only contains // whitespace. prefixPattern = new RegExp ( ` ${ LINE_TERMINATORS . source } ${ commonPrefix } ` , 'g' ) } else if ( trimEolAtStart || trimEolAtEnd ) { // We don't need to remove a prefix, but we might need to do some // post processing, so just use a prefix pattern that never matches. prefixPattern = / (?!) / } else { // Fast path. return templateStrings } const { raw , length } = templateStrings // Apply slice so that raw is in the same realm as the tag function. const trimmedRaw = Array . prototype . slice . apply ( raw ) . map ( ( chunk ) => chunk . replace ( prefixPattern , '$1' ) ) if ( trimEolAtStart ) { trimmedRaw [ 0 ] = trimmedRaw [ 0 ] . replace ( LINE_TERMINATOR_AT_START , '' ) } if ( trimEolAtEnd ) { trimmedRaw [ length - 1 ] = trimmedRaw [ length - 1 ] . replace ( LINE_TERMINATOR_AT_END , '' ) } const trimmedCooked = trimmedRaw . map ( cook ) trimmedCooked . raw = trimmedRaw Object . freeze ( trimmedRaw ) Object . freeze ( trimmedCooked ) return trimmedCooked }
Simplifies tripping common leading whitespace from a multiline
template tag so that a template tag can be re-indented as a block.

This may be called from a computeStaticHandler so that it need not
happen every time a particular template is reached.

"Whitespace" and "line terminators" mean the same as they do in ES6:
https://www.ecma-international.org/ecma-262/6.0/#sec-white-space
https://www.ecma-international.org/ecma-262/6.0/#sec-line-terminators
Simplifies tripping common leading whitespace from a multiline template tag so that a template tag can be re - indented as a block .