From 4fdcf685d3d6d4164d5e8556beb7bda5ea468682 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Tue, 13 Jan 2015 14:48:31 -0500 Subject: [PATCH] add loose transform for tagged template literals --- lib/6to5/file.js | 1 + .../templates/tagged-template-literal-loose.js | 4 ++++ .../transformers/es6-template-literals.js | 11 +++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 lib/6to5/transformation/templates/tagged-template-literal-loose.js diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 2757dcb1e2..66c86d7fce 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -24,6 +24,7 @@ File.helpers = [ "prototype-properties", "apply-constructor", "tagged-template-literal", + "tagged-template-literal-loose", "interop-require", "to-array", "sliced-to-array", diff --git a/lib/6to5/transformation/templates/tagged-template-literal-loose.js b/lib/6to5/transformation/templates/tagged-template-literal-loose.js new file mode 100644 index 0000000000..d8dd44bb7a --- /dev/null +++ b/lib/6to5/transformation/templates/tagged-template-literal-loose.js @@ -0,0 +1,4 @@ +(function (strings, raw) { + strings.raw = raw; + return strings; +}); diff --git a/lib/6to5/transformation/transformers/es6-template-literals.js b/lib/6to5/transformation/transformers/es6-template-literals.js index 4be21d4269..81872a7766 100644 --- a/lib/6to5/transformation/transformers/es6-template-literals.js +++ b/lib/6to5/transformation/transformers/es6-template-literals.js @@ -17,11 +17,14 @@ exports.TaggedTemplateExpression = function (node, parent, file) { raw.push(t.literal(elem.value.raw)); } - args.push(t.callExpression(file.addHelper("tagged-template-literal"), [ - t.arrayExpression(strings), - t.arrayExpression(raw) - ])); + strings = t.arrayExpression(strings); + raw = t.arrayExpression(raw); + var template = file.isLoose("templateLiterals") ? + "tagged-template-literal-loose" : + "tagged-template-literal"; + + args.push(t.callExpression(file.addHelper(template), [strings, raw])); args = args.concat(quasi.expressions); return t.callExpression(node.tag, args);