From cbec9a3a3a4646a660cd32b01f1a6959f9e03dce Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 23 Jan 2015 15:44:21 +0100 Subject: [PATCH] Respond to CR --- src/compiler/emitter.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3631d1f1d1c..a4374690fb0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2051,16 +2051,21 @@ module ts { return '"' + escapeString(node.text) + '"'; } - function emitDownlevelRawTemplateLiteral(node: LiteralExpression, isLast: boolean) { + function emitDownlevelRawTemplateLiteral(node: LiteralExpression) { var text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), // thus we need to remove those characters. // First template piece starts with "`", others with "}" // Last template piece ends with "`", others with "${" + var isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; text = text.substring(1, text.length - (isLast ? 1 : 2)); - write('"' + escapeString(text) + '"'); + // Newline normalization + text = text.replace(/\r\n?/g, "\n"); + text = escapeString(text); + + write('"' + text + '"'); } function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { @@ -2074,8 +2079,8 @@ module ts { emit(node.template); } else { - emit(( node.template).head); - forEach(( node.template).templateSpans, (child) => { + emit((node.template).head); + forEach((node.template).templateSpans, (child) => { write(", "); emit(child.literal); }); @@ -2085,13 +2090,13 @@ module ts { emit(tempVariable); write(".raw = ["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - emitDownlevelRawTemplateLiteral( node.template, true); + emitDownlevelRawTemplateLiteral(node.template); } else { - emitDownlevelRawTemplateLiteral(( node.template).head, false); - forEach(( node.template).templateSpans, (child, index) => { + emitDownlevelRawTemplateLiteral((node.template).head); + forEach((node.template).templateSpans, (child, index) => { write(", "); - emitDownlevelRawTemplateLiteral(child.literal, index === ( node.template).templateSpans.length - 1); + emitDownlevelRawTemplateLiteral(child.literal); }); } write("], "); @@ -2102,10 +2107,10 @@ module ts { // Now we emit the expressions if (node.template.kind === SyntaxKind.TemplateExpression) { - forEach(( node.template).templateSpans, templateSpan => { + forEach((node.template).templateSpans, templateSpan => { write(", "); var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression - && ( templateSpan.expression).operator === SyntaxKind.CommaToken; + && (templateSpan.expression).operator === SyntaxKind.CommaToken; emitParenthesized(templateSpan.expression, needsParens); }); }