coerce template literal expressions to strings - fixes #1065

This commit is contained in:
Sebastian McKenzie 2015-03-23 22:04:40 +11:00
parent c12cfe3ed0
commit 0ee230d13c

View File

@ -1,9 +1,17 @@
import * as t from "../../../types";
var buildBinaryExpression = function (left, right) {
return t.binaryExpression("+", left, right);
return t.binaryExpression("+", coerce(left), coerce(right));
};
function coerce(node) {
if (t.isLiteral(node) && typeof node.value === "string") {
return node;
} else {
return t.callExpression(t.identifier("String"), [node]);
}
}
export function check(node) {
return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);
}