Add some docs for why template literals use a chain of .concat() calls.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user