Skip to content

Commit

Permalink
constant-folding: Handle simple template strings in .join()s
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Aug 15, 2017
1 parent ff2d722 commit f45656b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("constant-folding-plugin", () => {
[null, 1].join("/");
[/xyz/im, true].join("abc");
[\`a\${xyz}\`].join("1");
[\`a\`, \`c\`].join('b');
[1, 2, 3].length;
[1, 2, 3][1];
Expand Down Expand Up @@ -140,6 +141,7 @@ describe("constant-folding-plugin", () => {
"/1";
"/xyz/imabctrue";
[\`a\${xyz}\`].join("1");
"abc";
3;
2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module.exports = ({ types: t }) => {
) {
return el.value;
}
if (t.isTemplateLiteral(el) && el.expressions.length === 0) {
return el.quasis[0].value.cooked;
}
bad = true;
return;
})
Expand Down

0 comments on commit f45656b

Please sign in to comment.