src/codegeneration/TemplateLiteralTransformer.js
/**
 * Takes a raw string and returns a string that is suitable for the cooked
 * value. This involves removing line continuations, escaping double quotes
 * and escaping whitespace.
 */
Takes a raw string and returns a string that is suitable for the cooked
value. This involves removing line continuations, escaping double quotes
and escaping whitespace.
Takes a raw string and returns a string that is suitable for the cooked value . This involves removing line continuations escaping double quotes and escaping whitespace .
function cookString(s) {
  var sb = ['"'];
  var i = 0, k = 1, c, c2;
  while (i < s.length) {
    c = s[i++];
    switch (c) {
      case '\\':
        c2 = s[i++];
        switch (c2) {
          case '\n':
          case '\u2028':
          case '\u2029':
            break;
          case '\r':
            if (s[i + 1] === '\n') {
              i++;
            }
            break;
          default:
            sb[k++] = c;
            sb[k++] = c2;
        }
        break;
      case '"':
        sb[k++] = '\\"';
        break;
      case '\n':
        sb[k++] = '\\n';
        break;
      case '\r':
        if (s[i] === '\n')
          i++;
        sb[k++] = '\\n';
        break;
      case '\t':
        sb[k++] = '\\t';
        break;
      case '\f':
        sb[k++] = '\\f';
        break;
      case '\b':
        sb[k++] = '\\b';
        break;
      case '\u2028':
        sb[k++] = '\\u2028';
        break;
      case '\u2029':
        sb[k++] = '\\u2029';
        break;
      default:
        sb[k++] = c;
    }
  }
  sb[k++] = '"';
  return sb.join('');
}
function cookString ( s ) { var sb = [ '"' ] ; var i = 0 , k = 1 , c , c2 ; while ( i < s . length ) { c = s [ i ++ ] ; switch ( c ) { case '\\' : c2 = s [ i ++ ] ; switch ( c2 ) { case '\n' : case '\u2028' : case '\u2029' : break ; case '\r' : if ( s [ i + 1 ] === '\n' ) { i ++ ; } break ; default : sb [ k ++ ] = c ; sb [ k ++ ] = c2 ; } break ; case '"' : sb [ k ++ ] = '\\"' ; break ; case '\n' : sb [ k ++ ] = '\\n' ; break ; case '\r' : if ( s [ i ] === '\n' ) i ++ ; sb [ k ++ ] = '\\n' ; break ; case '\t' : sb [ k ++ ] = '\\t' ; break ; case '\f' : sb [ k ++ ] = '\\f' ; break ; case '\b' : sb [ k ++ ] = '\\b' ; break ; case '\u2028' : sb [ k ++ ] = '\\u2028' ; break ; case '\u2029' : sb [ k ++ ] = '\\u2029' ; break ; default : sb [ k ++ ] = c ; } } sb [ k ++ ] = '"' ; return sb . join ( '' ) ; }
Takes a raw string and returns a string that is suitable for the cooked
 value.
Takes a raw string and returns a string that is suitable for the cooked value .
// Strip line continuation. // \ \r \n should be stripped as one // Since we wrap the string in " we need to escape those. // Whitespace // <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> // for both TV and TRV.