mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-19 00:42:28 -05:00
Emit tagged templates when targeting ES3 or 5
This commit is contained in:
@@ -2059,8 +2059,26 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression);
|
||||
|
||||
if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
// Emit should like:
|
||||
// foo(["a", "b", "c"], expressions0, expression1)
|
||||
// First we emit the string literal array
|
||||
write("[");
|
||||
emitLiteral(node.head);
|
||||
forEach(node.templateSpans, templateSpan => {
|
||||
write(", ");
|
||||
emitLiteral(templateSpan.literal);
|
||||
});
|
||||
write("]");
|
||||
|
||||
// Now we emit the expressions
|
||||
forEach(node.templateSpans, templateSpan => {
|
||||
write(", ");
|
||||
emit(templateSpan.expression);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var emitOuterParens = isExpression(node.parent)
|
||||
&& templateNeedsParens(node, <Expression>node.parent);
|
||||
|
||||
@@ -2487,10 +2505,15 @@ module ts {
|
||||
}
|
||||
|
||||
function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void {
|
||||
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode.");
|
||||
emit(node.tag);
|
||||
write(" ");
|
||||
emit(node.template);
|
||||
if (compilerOptions.target >= ScriptTarget.ES6) {
|
||||
write(" ");
|
||||
emit(node.template);
|
||||
} else {
|
||||
write("(");
|
||||
emit(node.template);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
|
||||
function emitParenExpression(node: ParenthesizedExpression) {
|
||||
|
||||
Reference in New Issue
Block a user