diff --git a/src/babel/transformation/transformers/es6/template-literals.js b/src/babel/transformation/transformers/es6/template-literals.js index 9facba8537..73ae1e88e4 100644 --- a/src/babel/transformation/transformers/es6/template-literals.js +++ b/src/babel/transformation/transformers/es6/template-literals.js @@ -60,20 +60,16 @@ export var visitor = { if (expr) nodes.push(expr); } + // filter out empty string literals + nodes = nodes.filter(n => !t.isLiteral(n, { value: "" })); + + // since `+` is left-to-right associative + // ensure the first node is a string if first/second isn't + if (!isString(nodes[0]) && !isString(nodes[1])) { + nodes.unshift(t.literal("")); + } + if (nodes.length > 1) { - // filter out empty string literals - nodes = nodes.filter(n => !t.isLiteral(n, { value: "" })); - - if (nodes.length === 1 && isString(nodes[0])) { - return nodes[0]; - } - - // since `+` is left-to-right associative - // ensure the first node is a string if first/second isn't - if (!isString(nodes[0]) && !isString(nodes[1])) { - nodes.unshift(t.literal("")); - } - var root = buildBinaryExpression(nodes.shift(), nodes.shift()); for (let node of (nodes: Array)) { diff --git a/test/core/fixtures/transformation/es6.template-literals/expression-first/actual.js b/test/core/fixtures/transformation/es6.template-literals/expression-first/actual.js index ee6e49ef50..2ad884f81c 100644 --- a/test/core/fixtures/transformation/es6.template-literals/expression-first/actual.js +++ b/test/core/fixtures/transformation/es6.template-literals/expression-first/actual.js @@ -6,3 +6,4 @@ const example = `${"a"}`; const example2 = `${1}`; const example3 = 1 + `${foo}${bar}${baz}`; const example4 = 1 + `${foo}bar${baz}`; +const example5 = `${""}`; diff --git a/test/core/fixtures/transformation/es6.template-literals/expression-first/expected.js b/test/core/fixtures/transformation/es6.template-literals/expression-first/expected.js index 5185926b93..1fbcec8925 100644 --- a/test/core/fixtures/transformation/es6.template-literals/expression-first/expected.js +++ b/test/core/fixtures/transformation/es6.template-literals/expression-first/expected.js @@ -8,3 +8,4 @@ var example = "a"; var example2 = "" + 1; var example3 = 1 + ("" + foo + bar + baz); var example4 = 1 + (foo + "bar" + baz); +var example5 = "";