Skip to content

Commit

Permalink
Restrict the kinds of expressions that force a .concat call split
Browse files Browse the repository at this point in the history
This avoids creating extra .concat calls unless the result could be
potentially observably different from real template evaluation.
  • Loading branch information
Diogo Franco (Kovensky) committed Aug 12, 2017
1 parent 9243c78 commit 86adc6f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ export default function({ types: t }) {
function buildConcatCallExressions(items) {
let avail = true;
return items.reduce(function(left, right) {
let canBeInserted = t.isLiteral(right);
// these can potentially observe whether the previous template expression
// has been evaluated by ToString or not
let canBeInserted = !(
t.isSequenceExpression(right) ||
t.isCallExpression(right) ||
t.isMemberExpression(right)
);

if (!canBeInserted && avail) {
canBeInserted = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var t = "'".concat(foo, "' \"").concat(bar, "\"");
var t = "'".concat(foo, "' \"", bar, "\"");
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var foo = "test ".concat(_.test(foo), " ").concat(bar);
var foo = "test ".concat(_.test(foo), " ", bar);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var foo = "".concat(1, f, "oo", true).concat(b, "ar", 0).concat(baz);
var foo = "".concat(1, f, "oo", true, b, "ar", 0, baz);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var foo = "test ".concat(foo, " ").concat(bar);
var foo = "test ".concat(foo, " ", bar);

0 comments on commit 86adc6f

Please sign in to comment.