From b59168832c9f11317bc57cabb5064c9ca97c4e98 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 9 Oct 2014 14:35:46 +1100 Subject: [PATCH] support tagged template literals - closes #16 --- lib/6to5/transformers/template-literals.js | 16 ++++++++++++++++ test/fixtures/template-literals/tag/actual.js | 1 + test/fixtures/template-literals/tag/expected.js | 1 + 3 files changed, 18 insertions(+) create mode 100644 test/fixtures/template-literals/tag/actual.js create mode 100644 test/fixtures/template-literals/tag/expected.js diff --git a/lib/6to5/transformers/template-literals.js b/lib/6to5/transformers/template-literals.js index bd42449c09..20f81f0b00 100644 --- a/lib/6to5/transformers/template-literals.js +++ b/lib/6to5/transformers/template-literals.js @@ -5,6 +5,22 @@ var buildBinaryExpression = function (left, right) { return b.binaryExpression("+", left, right); }; +exports.TaggedTemplateExpression = function (node) { + var args = []; + var quasi = node.quasi; + + var strings = quasi.quasis.map(function (elem) { + return b.literal(elem.value.raw); + }); + args.push(b.arrayExpression(strings)); + + _.each(quasi.expressions, function (expr) { + args.push(expr); + }); + + return b.callExpression(node.tag, args); +}; + exports.TemplateLiteral = function (node) { var nodes = []; diff --git a/test/fixtures/template-literals/tag/actual.js b/test/fixtures/template-literals/tag/actual.js new file mode 100644 index 0000000000..34a227f571 --- /dev/null +++ b/test/fixtures/template-literals/tag/actual.js @@ -0,0 +1 @@ +var foo = bar`a${ 42 }b ${_.foobar()}`; diff --git a/test/fixtures/template-literals/tag/expected.js b/test/fixtures/template-literals/tag/expected.js new file mode 100644 index 0000000000..bc8d9342bd --- /dev/null +++ b/test/fixtures/template-literals/tag/expected.js @@ -0,0 +1 @@ +var foo = bar(["a", "b ", ""], 42, _.foobar());