src/codegeneration/TemplateLiteralTransformer.js
function createGetTemplateObject(elements, getTemplateObject) {
  let cooked = [];
  let raw = [];
  let same = true;
  for (let i = 0; i < elements.length; i += 2) {
    let loc = elements[i].location;
    let str = elements[i].value.value;
    let cookedStr = toCookedString(str);
    let rawStr = toRawString(str);
    let cookedLiteral = createStringLiteralExpression(loc, cookedStr);
    cooked.push(cookedLiteral);
    if (cookedStr !== rawStr) {
      same = false;
      let rawLiteral = createStringLiteralExpression(loc, rawStr);
      raw.push(rawLiteral);
    } else {
      raw.push(cookedLiteral);
    }
  }

  maybeAddEmptyStringAtEnd(elements, cooked);
  let cookedLiteral = createArrayLiteral(cooked);
  let args = [cookedLiteral];
  if (!same) {
    maybeAddEmptyStringAtEnd(elements, raw);
    let rawLiteral = createArrayLiteral(raw);
    args.unshift(rawLiteral);
  }

  return createCallExpression(
      getTemplateObject,
      createArgumentList(args));
}
function createGetTemplateObject(elements, getTemplateObject) {
  let cooked = [];
  let raw = [];
  let same = true;
  for (let i = 0; i < elements.length; i += 2) {
    let loc = elements[i].location;
    let str = elements[i].value.value;
    let cookedStr = toCookedString(str);
    let rawStr = toRawString(str);
    let cookedLiteral = createStringLiteralExpression(loc, cookedStr);
    cooked.push(cookedLiteral);
    if (cookedStr !== rawStr) {
      same = false;
      let rawLiteral = createStringLiteralExpression(loc, rawStr);
      raw.push(rawLiteral);
    } else {
      raw.push(cookedLiteral);
    }
  }

  maybeAddEmptyStringAtEnd(elements, cooked);
  let cookedLiteral = createArrayLiteral(cooked);
  let args = [cookedLiteral];
  if (!same) {
    maybeAddEmptyStringAtEnd(elements, raw);
    let rawLiteral = createArrayLiteral(raw);
    args.unshift(rawLiteral);
  }

  return createCallExpression(
      getTemplateObject,
      createArgumentList(args));
}
function createGetTemplateObject ( elements , getTemplateObject ) { let cooked = [ ] ; let raw = [ ] ; let same = true ; for ( let i = 0 ; i < elements . length ; i += 2 ) { let loc = elements [ i ] . location ; let str = elements [ i ] . value . value ; let cookedStr = toCookedString ( str ) ; let rawStr = toRawString ( str ) ; let cookedLiteral = createStringLiteralExpression ( loc , cookedStr ) ; cooked . push ( cookedLiteral ) ; if ( cookedStr !== rawStr ) { same = false ; let rawLiteral = createStringLiteralExpression ( loc , rawStr ) ; raw . push ( rawLiteral ) ; } else { raw . push ( cookedLiteral ) ; } } maybeAddEmptyStringAtEnd ( elements , cooked ) ; let cookedLiteral = createArrayLiteral ( cooked ) ; let args = [ cookedLiteral ] ; if ( ! same ) { maybeAddEmptyStringAtEnd ( elements , raw ) ; let rawLiteral = createArrayLiteral ( raw ) ; args . unshift ( rawLiteral ) ; } return createCallExpression ( getTemplateObject , createArgumentList ( args ) ) ; }
Generetes the runtime call to create the template object.
The tagged template literal

f `a${42}\n`

gets compiled into:

f($traceurRuntime.getTemplateObject(['a', '\\n], ['a', '\n']), 42)

Note that if the cooked and the raw strings are identical the runtime call
only pass one array.

@param {Array<ParseTree>} elements
@return {ParseTree}
Generetes the runtime call to create the template object . The tagged template literal