Add some docs for why template literals use a chain of .concat() calls.

This commit is contained in:
Logan Smyth
2017-09-13 13:42:20 -07:00
parent 18f77b3aa9
commit c65742602b

View File

@@ -1,4 +1,19 @@
export default function({ types: t }) {
/**
* This function groups the objects into multiple calls to `.concat()` in
* order to preserve execution order of the primitive conversion, e.g.
*
* "".concat(obj.foo, "foo", obj2.foo, "foo2")
*
* would evaluate both member expressions _first_ then, `concat` will
* convert each one to a primitive, whereas
*
* "".concat(obj.foo, "foo").concat(obj2.foo, "foo2")
*
* would evaluate the member, then convert it to a primitive, then evaluate
* the second member and convert that one, which reflects the spec behavior
* of template literals.
*/
function buildConcatCallExressions(items) {
let avail = true;
return items.reduce(function(left, right) {