Merge pull request #480 from monsanto/loose-templates

Add loose transform for tagged template literals
This commit is contained in:
Sebastian McKenzie 2015-01-14 07:54:19 +11:00
commit fe6f53d471
3 changed files with 12 additions and 4 deletions

View File

@ -24,6 +24,7 @@ File.helpers = [
"prototype-properties",
"apply-constructor",
"tagged-template-literal",
"tagged-template-literal-loose",
"interop-require",
"to-array",
"sliced-to-array",

View File

@ -0,0 +1,4 @@
(function (strings, raw) {
strings.raw = raw;
return strings;
});

View File

@ -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);